:root { --sidebar-width: 260px; }
.history-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); z-index: 45; display: flex; flex-direction: column; padding: 18px 12px 14px; background: #e7dfdf; border-right: 1px solid #bcb0b7; color: var(--text); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 4px 16px 8px; font-size: 14px; }
.history-icon { display: inline-flex; justify-content: center; align-items: center; width: 36px; height: 36px; flex-shrink: 0; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; font-size: 24px; }
.history-icon:hover { background: #d6c9ce; }
.sidebar-new { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 12px; border: 1px solid #c1aab5; border-radius: 10px; background: #f2e5e0; cursor: pointer; text-align: left; font-size: 13px; font-weight: 600; }
.history-search { display: flex; gap: 8px; align-items: center; margin: 14px 0 8px; padding: 8px 10px; border: 1px solid #c9bdc3; border-radius: 9px; background: #f1eaea; }
.history-search input { min-width: 0; width: 100%; height: 26px; font: inherit; font-size: 12px; background: none; border: none; color: var(--text); outline: none; }
.history-search:focus-within { outline: 2px solid #89516d; outline-offset: 2px; }
.history-list-wrap { min-height: 0; flex: 1; overflow: auto; padding-bottom: 20px; scrollbar-width: thin; }
.history-empty { padding: 16px 10px; font-size: 12px; line-height: 1.8; color: #63535e; }
.history-group { margin: 20px 10px 8px; font-size: 11px; color: #6a5964; font-weight: 600; }
.history-row { display: flex; align-items: center; border-radius: 8px; margin: 3px 0; min-height: 44px; border: 1px solid transparent; }
.history-row:hover { background: #ddd1d6; }
.history-row.active { background: #d5c3cd; border-color: #baa3b0; }
.history-open { flex: 1; min-width: 0; padding: 11px 9px; background: none; border: none; font: inherit; font-size: 12px; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-row-actions { display: flex; flex-shrink: 0; padding-right: 3px; }
.history-row-actions .history-icon { width: 28px; height: 32px; }
.history-row-actions svg { width: 13px; height: 13px; }
.sidebar-footer { display: grid; gap: 10px; border-top: 1px solid #cbbbc4; padding: 14px 6px 0; }
.sidebar-footer .account-entry { max-width: 100%; display: block; }
.sidebar-footer small { font-size: 10px; line-height: 1.6; color: #665360; }
.history-more { width: 100%; padding: 10px; border: 1px solid #c1aab5; background: transparent; border-radius: 8px; font-size: 12px; cursor: pointer; }
.history-sidebar button:disabled { opacity: .5; cursor: wait; }
.history-sidebar button:focus-visible, .history-icon:focus-visible, #historyDialog button:focus-visible, #historyTitleInput:focus-visible { outline: 2px solid #89516d; outline-offset: 2px; }
.chat-app { margin-left: var(--sidebar-width); }
.app-header, .composer-dock { left: var(--sidebar-width); }
.app-header { gap: 12px; }
.app-header .brand { margin-right: auto; min-width: 0; }
.sidebar-collapsed .chat-app { margin-left: 0; }
.sidebar-collapsed .app-header, .sidebar-collapsed .composer-dock { left: 0; }
.sidebar-collapsed .history-sidebar { display: none; }
.sidebar-backdrop { display: none; }
.history-context { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; padding-top: 12px; font-size: 12px; color: #64555f; }
#conversationTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#historySaveState { flex-shrink: 0; font-size: 11px; }
#historyNotice { padding: 10px 14px; background: #f5e6d7; border: 1px solid #c8ada4; border-radius: 9px; color: #683b34; font-size: 12px; line-height: 1.6; }
#historyDialog { width: min(440px, calc(100vw - 32px)); padding: 26px; border: 1px solid #c1aab5; border-radius: 16px; background: var(--surface); color: var(--text); }
#historyDialog::backdrop { background: #22283866; }
#historyDialog h2 { margin: 0 0 12px; font-size: 20px; }
#historyDialog p { font-size: 13px; line-height: 1.6; }
#historyTitleLabel { display: block; margin: 16px 0 8px; font-size: 13px; }
#historyTitleInput { width: 100%; padding: 12px; font: inherit; border: 1px solid #c1aab5; border-radius: 8px; background: white; }
.history-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.history-dialog-actions button { min-height: 40px; padding: 8px 16px; border: 1px solid #c1aab5; border-radius: 8px; background: transparent; cursor: pointer; }
#historyDialogSubmit { background: #754258; color: white; }
#historyDialogError { color: #902b42; }
@media (max-width: 1100px) { .app-header .brand small { display: none; } }
@media (max-width: 760px) {
  .chat-app { margin-left: 0; }
  .app-header, .composer-dock { left: 0; }
  .history-sidebar { width: min(290px, calc(100vw - 48px)); box-shadow: 12px 0 40px #22283822; z-index: 60; }
  .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; border: none; background: #22283866; z-index: 55; }
  body:not(.sidebar-collapsed) { overflow: hidden; }
  .app-header { gap: 6px; padding-left: 10px; padding-right: 12px; }
  .history-context { font-size: 11px; }
  .sidebar-toggle { width: 32px; }
}

.app-header .sidebar-toggle { color: #f2e5e0; border-color: #647089; }
.app-header .sidebar-toggle:hover { background: #465267; }
