.character-dialog { width: min(560px, calc(100vw - 32px)); max-height: 90vh; overflow: auto; border: 1px solid #dedbd3; border-radius: 16px; background: #f7f6f2; color: #292721; padding: 24px; }
.character-dialog::backdrop { background: rgb(30 26 20 / 30%); }
.character-dialog textarea { min-height: 240px; resize: vertical; }
#characterSelect { width: 100%; margin-bottom: 8px; }
#editCharacter, #addCharacter { display: block; flex-shrink: 0; white-space: nowrap; }
#editCharacter[hidden] { display: none; }
:root {
  color-scheme: light;
  --paper: #f7f6f2;
  --panel: #efede7;
  --surface: #fff;
  --ink: #252421;
  --muted: #77736b;
  --line: #ddd9d0;
  --accent: #c65f38;
  --accent-dark: #9f4528;
  --sage: #5e7568;
  --shadow: 0 18px 50px rgba(37, 36, 33, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }

.login-screen { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: var(--paper); }
.login-screen[hidden] { display: none; }
.login-form { width: min(360px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #faf9f6; box-shadow: var(--shadow); }
.login-mark { display: grid; width: 42px; height: 42px; margin-bottom: 18px; place-items: center; border-radius: 8px; background: var(--accent); color: #fff; font-family: Georgia, serif; font-size: 19px; }
.login-form h1 { margin: 0 0 20px; font-family: Georgia, "Songti SC", serif; font-size: 25px; font-weight: 500; }
.login-remember { margin-top: 14px; }
.login-button { width: 100%; margin-top: 2px; }

button, textarea { font: inherit; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  display: flex;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  flex-direction: column;
  padding: 18px 14px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand-row { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 8px; font-weight: 650; }
.brand-mark, .welcome-mark { display: grid; place-items: center; color: #fff; background: var(--accent); font-family: Georgia, serif; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; }
.brand-row .icon-button { margin-left: auto; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 42px;
  margin: 18px 0 22px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.55);
  cursor: pointer;
}
.new-chat:hover { background: #fff; }
.plus { color: var(--accent); font-size: 20px; line-height: 1; }

.sidebar-label { padding: 0 10px 8px; color: var(--muted); font-size: 12px; }
.session-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 3px; overflow-y: auto; }
.session-item {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  color: #4c4943;
}
.session-item:hover, .session-item.active { background: rgba(255,255,255,.72); color: var(--ink); }

.sidebar-footer { flex-shrink: 0; padding-top: 12px; border-top: 1px solid var(--line); }
.sidebar-action { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; width: 100%; height: 42px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.sidebar-action:hover { background: rgba(255,255,255,.65); }
.memory-total, .provider-ready { color: var(--muted); font-size: 12px; }
.mode-row { display: flex; align-items: center; gap: 8px; padding: 9px 10px 0; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #aaa; }
.status-dot.live { background: #4f8a62; }
.status-dot.demo { background: #c58a3f; }

.chat-main { display: grid; min-width: 0; min-height: 0; grid-template-rows: 58px minmax(0, 1fr) auto; background: var(--paper); }
.topbar { display: grid; grid-template-columns: 72px 1fr 72px; align-items: center; padding: calc(8px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 8px calc(18px + env(safe-area-inset-left)); border-bottom: 1px solid rgba(221,217,208,.7); }
.conversation-title-wrap { display: grid; min-width: 0; justify-items: center; }
.conversation-title { max-width: 100%; overflow: hidden; border: 0; background: transparent; font-weight: 600; text-align: center; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.conversation-title::after { margin-left: 6px; color: var(--muted); content: "✎"; font-size: 11px; opacity: .45; }
.conversation-title:hover::after { color: var(--accent); opacity: 1; }
.conversation-title-input { width: min(360px, 100%); height: 34px; padding: 0 10px; border: 1px solid #c8c2b8; border-radius: 6px; outline: none; background: rgba(255,255,255,.82); color: var(--ink); font: inherit; font-weight: 600; text-align: center; }
.conversation-title-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(204, 96, 52, .1); }
.topbar-actions { display: flex; justify-self: end; }
.icon-button { display: grid; width: 36px; height: 36px; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 19px; }
.icon-button:hover { background: rgba(0,0,0,.055); }
.icon-button.syncing span { animation: spin .7s linear infinite; }

.messages { min-height: 0; overflow-y: auto; padding: 34px max(24px, calc((100% - 760px) / 2)) 22px; overscroll-behavior-y: contain; scrollbar-gutter: stable; scroll-behavior: smooth; }
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 8px; background: #c8c4bc; background-clip: padding-box; }
.messages::-webkit-scrollbar-thumb:hover { background-color: #aaa59b; }
.load-older { display: block; min-height: 34px; margin: 0 auto 26px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.load-older:hover { border-color: #c3beb4; background: var(--panel); color: var(--ink); }
.load-older:disabled { cursor: wait; opacity: .65; }
.welcome { display: flex; min-height: 100%; flex-direction: column; align-items: center; justify-content: center; padding-bottom: 10vh; text-align: center; }
.welcome-mark { width: 48px; height: 48px; margin-bottom: 20px; border-radius: 10px; font-size: 22px; box-shadow: 0 8px 22px rgba(198,95,56,.2); }
.welcome h1 { margin: 0 0 10px; font-family: Georgia, "Songti SC", serif; font-size: 30px; font-weight: 500; letter-spacing: 0; }
.welcome p { margin: 0; color: var(--muted); line-height: 1.7; }

.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 13px; margin-bottom: 30px; animation: appear .22s ease-out; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-selector { display: none; position: absolute; z-index: 2; top: 2px; left: 0; width: 25px; height: 25px; place-items: center; padding: 0; border: 1px solid #bbb5aa; border-radius: 50%; background: #fff; color: #fff; cursor: pointer; font-size: 14px; font-weight: 700; }
.messages.selection-mode .message { position: relative; padding-left: 38px; cursor: pointer; }
.messages.selection-mode .message.user { padding-right: 38px; padding-left: 0; }
.messages.selection-mode .message.user .message-selector { right: 0; left: auto; }
.messages.selection-mode .message-selector { display: grid; }
.messages.selection-mode .message-selected .message-selector { border-color: var(--accent); background: var(--accent); }
.messages.selection-mode .message-selected .message-content { border-radius: 7px; outline: 2px solid rgba(204, 126, 71, .28); outline-offset: 6px; }
.messages.selection-mode .message-actions { display: none !important; }
.avatar { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 7px; background: var(--accent); color: #fff; font-family: Georgia, serif; font-size: 14px; }
.message-content { min-width: 0; max-width: 100%; cursor: pointer; }
.message.user .message-content { display: flex; width: 100%; flex-direction: column; align-items: flex-end; }
.message-timestamp { display: none; margin: 0 0 7px; color: var(--muted); font-size: 11px; line-height: 1.3; }
.message.actions-open .message-timestamp { display: block; }
.message-body { max-width: 100%; font-size: 16px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.message.user .message-body { max-width: min(620px, 88%); padding: 11px 15px; border: 1px solid var(--line); border-radius: 8px; background: #eeece6; line-height: 1.6; }
.message-attachments { display: grid; width: min(620px, 88%); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.message-attachment-image { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: #e9e6df; }
.message-attachment-image img { display: block; width: 100%; max-height: 360px; object-fit: cover; }
.message-attachment-file { display: flex; min-width: 0; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #eeece6; color: var(--ink); text-decoration: none; }
.message-file-icon { display: grid; width: 34px; height: 38px; flex: 0 0 auto; place-items: center; border-radius: 5px; background: #fff; color: var(--accent-dark); font-size: 11px; font-weight: 700; }
.message-file-meta { min-width: 0; }
.message-file-name { display: block; overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.message-file-size { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.message-quote { display: grid; width: min(560px, 88%); margin: 0 0 7px; padding: 7px 10px; overflow: hidden; border: 0; border-left: 2px solid var(--accent); border-radius: 0 5px 5px 0; background: rgba(203, 198, 188, .2); color: var(--muted); cursor: pointer; text-align: left; }
.message-quote strong { color: var(--accent-dark); font-size: 11px; font-weight: 650; }
.message-quote span { overflow: hidden; font-size: 12px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.message.user .message-quote { margin-left: auto; }
.message-context-references { width: min(560px, 88%); margin: 0 0 8px; overflow: hidden; border-left: 2px solid #8b9b83; background: rgba(139, 155, 131, .09); color: var(--muted); font-size: 12px; }
.message.user .message-context-references { margin-left: auto; }
.message-context-references summary { padding: 7px 10px; cursor: pointer; color: #60705a; font-weight: 650; list-style-position: inside; }
.message-context-list { display: grid; max-height: 180px; gap: 4px; padding: 0 8px 8px; overflow-y: auto; }
.message-context-list button { display: grid; min-width: 0; gap: 1px; padding: 6px 8px; border: 0; border-radius: 5px; background: rgba(255,255,255,.7); cursor: pointer; text-align: left; }
.message-context-list button:hover { background: #fff; }
.message-context-list strong { color: #60705a; font-size: 10px; }
.message-context-list span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.message-actions { display: none; align-items: center; gap: 3px; height: 34px; padding-top: 5px; }
.message.actions-open .message-actions { display: flex; }
.message-action-icon { display: grid; width: 29px; height: 29px; place-items: center; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; }
.message-action-icon:hover { background: var(--panel); color: var(--ink); }
.message-action-icon.favorite-active { color: #d18a28; }
.message-action-icon.danger:hover { color: #a5372d; }
.message-highlight .message-content { animation: message-highlight 1.8s ease; }
.message.assistant.thinking .message-body { color: var(--muted); }
.thinking-dots span { display: inline-block; animation: pulse 1.2s infinite; }
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }

.composer-wrap { padding: 8px max(20px, calc((100% - 800px) / 2)) 12px; background: linear-gradient(to bottom, rgba(247,246,242,0), var(--paper) 16px); }
.composer { display: grid; position: relative; grid-template-columns: 38px minmax(0,1fr) 40px; align-items: end; gap: 6px; min-height: 58px; padding: 10px; border: 1px solid #d4d0c7; border-radius: 8px; background: #fff; box-shadow: 0 4px 18px rgba(37,36,33,.07); }
.composer:focus-within { border-color: #b9b3a8; box-shadow: 0 5px 22px rgba(37,36,33,.1); }
.composer textarea { width: 100%; max-height: 180px; resize: none; padding: 7px 0; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.5; }
.composer textarea::placeholder { color: #9a968e; }
.attachment-preview { display: flex; grid-column: 1 / -1; gap: 8px; padding: 0 2px 5px; overflow-x: auto; }
.attachment-preview[hidden] { display: none; }
.attachment-chip { position: relative; display: flex; width: 142px; min-width: 142px; height: 56px; align-items: center; gap: 8px; padding: 6px 28px 6px 7px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #f7f6f2; }
.attachment-chip-thumb { width: 42px; height: 42px; flex: 0 0 auto; overflow: hidden; border-radius: 5px; background: #e5e2db; }
.attachment-chip-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-chip-icon { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 5px; background: #ebe8e1; color: var(--accent-dark); font-size: 10px; font-weight: 700; }
.attachment-chip-name { overflow: hidden; font-size: 11px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip-detail { margin-top: 3px; color: var(--muted); font-size: 10px; }
.attachment-chip-remove { position: absolute; top: 3px; right: 3px; display: grid; width: 22px; height: 22px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.attachment-chip-remove:hover { background: #dedad2; color: var(--ink); }
.attachment-control { position: relative; }
.attachment-button { display: grid; width: 36px; height: 36px; place-items: center; padding: 0 0 2px; border: 0; border-radius: 7px; background: transparent; color: #57534d; cursor: pointer; font-size: 27px; font-weight: 300; }
.attachment-button:hover, .attachment-button.active { background: var(--panel); }
.attachment-button:disabled { cursor: wait; opacity: .4; }
.attachment-menu { position: absolute; z-index: 8; bottom: 46px; left: 0; width: 154px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: 0 12px 34px rgba(37,36,33,.16); }
.attachment-menu[hidden] { display: none; }
.attachment-menu button { display: flex; width: 100%; height: 38px; align-items: center; gap: 9px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; font-size: 13px; text-align: left; }
.attachment-menu button:hover { background: var(--panel); }
.attachment-menu span { width: 18px; color: var(--accent-dark); text-align: center; }
.reply-preview { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 8px 8px 10px; border-left: 2px solid var(--accent); background: #f7f5f0; color: var(--muted); }
.reply-preview[hidden] { display: none; }
.reply-preview div { display: grid; min-width: 0; gap: 2px; }
.reply-preview strong { color: var(--accent-dark); font-size: 11px; }
.reply-preview span { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview button { width: 26px; height: 26px; flex: 0 0 auto; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; }
.reply-preview button:hover { background: #e8e4dc; color: var(--ink); }
.selection-preview { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 9px 9px 10px; border-left: 2px solid #8b9b83; background: #f2f5f0; color: var(--muted); }
.selection-preview[hidden] { display: none; }
.selection-preview div { display: grid; min-width: 0; gap: 2px; }
.selection-preview strong { color: #60705a; font-size: 12px; }
.selection-preview div > span { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.selection-preview button { flex: 0 0 auto; height: 28px; padding: 0 9px; border: 1px solid #c9d0c5; border-radius: 5px; background: transparent; color: #60705a; cursor: pointer; font-size: 11px; }
.selection-preview button:hover { background: #fff; }
.send-button { display: grid; width: 38px; height: 38px; place-items: center; border: 0; border-radius: 7px; background: var(--ink); color: #fff; cursor: pointer; font-size: 21px; }
.send-button:hover { background: #000; }
.send-button:disabled { cursor: default; opacity: .35; }
.composer-note { margin: 7px 0 0; color: #99958d; font-size: 11px; text-align: center; }

.mind-drawer { position: fixed; z-index: 20; top: 0; right: 0; display: grid; width: min(440px, 100%); height: 100dvh; grid-template-rows: auto auto minmax(0,1fr); padding: 24px; background: #faf9f6; box-shadow: var(--shadow); transform: translateX(105%); transition: transform .25s ease; }
.mind-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 18px; }
.drawer-header h2 { margin: 3px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 25px; font-weight: 500; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; letter-spacing: 0; text-transform: uppercase; }
.mind-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.mind-tab { height: 34px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.mind-tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(37,36,33,.08); }
.mind-tab span { margin-left: 2px; font-size: 10px; }
.mind-list { min-height: 0; padding-top: 16px; overflow-y: auto; }
.mind-card { padding: 15px 2px; border-bottom: 1px solid var(--line); }
.mind-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.mind-kind { color: var(--accent-dark); font-weight: 650; }
.mind-weight { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.weight-track { width: 46px; height: 3px; overflow: hidden; border-radius: 2px; background: #ddd9d0; }
.weight-fill { height: 100%; background: var(--sage); }
.mind-body { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 15px; line-height: 1.7; }
.mind-context { margin: -2px 0 8px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.saved-message-body { max-height: 170px; padding-right: 7px; overflow-y: auto; white-space: pre-wrap; }
.document-title { margin: 0 0 9px; font-family: Georgia, "Songti SC", serif; font-size: 17px; font-weight: 600; }
.document-body { max-height: 300px; margin: 0; padding: 11px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: #f3f1eb; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.mind-actions { display: flex; gap: 4px; margin-top: 10px; opacity: 0; transition: opacity .15s; }
.mind-card:hover .mind-actions, .mind-actions:focus-within { opacity: 1; }
.mind-action { height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.mind-action:hover { background: var(--panel); color: var(--ink); }
.mind-action.danger:hover { color: #a5372d; }
.mind-empty { padding: 80px 24px; color: var(--muted); text-align: center; line-height: 1.8; }

.drawer-scrim, .sidebar-scrim { position: fixed; z-index: 15; inset: 0; display: none; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(37,36,33,.18); backdrop-filter: blur(2px); }
.drawer-scrim.open { display: block; }
.sidebar-scrim { z-index: 24; }
.provider-scrim { position: fixed; z-index: 30; inset: 0; display: none; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(37,36,33,.28); backdrop-filter: blur(3px); }
.provider-scrim.open { display: block; }
.provider-dialog { position: fixed; z-index: 35; top: 50%; left: 50%; display: none; width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: 24px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #faf9f6; box-shadow: var(--shadow); transform: translate(-50%, -50%); }
.provider-dialog.open { display: block; }
.provider-dialog .drawer-header { padding-bottom: 20px; }
.dialog-header-actions { display: flex; gap: 2px; }
.field-label { display: block; margin: 15px 0 7px; color: #555149; font-size: 13px; font-weight: 600; }
.field-control { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: #fff; color: var(--ink); }
.field-control:focus { border-color: #aaa49a; box-shadow: 0 0 0 3px rgba(198,95,56,.08); }
.field-help { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.mcp-safety-note { margin-top: 18px; padding: 11px 12px; border-left: 3px solid var(--accent); background: rgba(198,95,56,.06); }
.secret-field { display: grid; grid-template-columns: minmax(0,1fr) 42px; gap: 6px; }
.secret-toggle { border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: 12px; }
.remember-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.remember-row input { accent-color: var(--accent); }
.advanced-settings { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.advanced-settings summary { cursor: pointer; color: #555149; font-size: 13px; font-weight: 600; }
.provider-cache-row { margin-top: 9px; }
.headers-input { min-height: 92px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.provider-status { min-height: 20px; margin-top: 14px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.provider-status.success { color: var(--sage); }
.provider-status.error { color: #a5372d; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.clear-provider { margin-right: auto; }
.primary-button, .secondary-button { height: 40px; padding: 0 16px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.primary-button { border: 1px solid var(--ink); background: var(--ink); color: #fff; }
.secondary-button { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.primary-button:disabled, .secondary-button:disabled { cursor: default; opacity: .45; }
.switch-row { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 13px 0 17px; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 14px; }
.switch-row small { margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
.switch-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-ui { position: relative; width: 42px; height: 24px; border-radius: 12px; background: #c8c4bc; transition: background .16s; }
.switch-ui::after { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); content: ""; transition: transform .16s; }
.switch-row input:checked + .switch-ui { background: var(--sage); }
.switch-row input:checked + .switch-ui::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch-ui { outline: 3px solid rgba(198,95,56,.18); }
.settings-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
.number-field { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.notification-row { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.usage-dialog { width: min(560px, calc(100% - 32px)); }
.usage-summary { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.usage-period { min-width: 0; padding: 17px 16px 18px 0; }
.usage-period + .usage-period { padding-left: 18px; border-left: 1px solid var(--line); }
.usage-period span, .usage-period strong, .usage-period small { display: block; }
.usage-period span { color: var(--muted); font-size: 11px; }
.usage-period strong { margin-top: 5px; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 500; }
.usage-period small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.usage-totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.usage-totals span, .usage-totals strong { display: block; }
.usage-totals span { color: var(--muted); font-size: 10px; }
.usage-totals strong { margin-top: 4px; font-size: 13px; }
.latency-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 10px; padding: 13px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.latency-summary span, .latency-summary strong { display: block; }
.latency-summary span { color: var(--muted); font-size: 10px; }
.latency-summary strong { margin-top: 4px; font-size: 13px; }
.usage-heading { margin: 20px 0 7px; color: #555149; font-size: 12px; font-weight: 650; }
.usage-list { border-top: 1px solid var(--line); }
.usage-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px; min-height: 54px; border-bottom: 1px solid var(--line); }
.usage-row strong, .usage-row small { display: block; }
.usage-row strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.usage-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.usage-row-amount { text-align: right; }
.usage-empty { margin: 0; padding: 18px 0; color: var(--muted); font-size: 12px; }
.usage-note { margin: 17px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.mobile-only { display: none; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); max-width: min(420px, calc(100% - 32px)); padding: 10px 14px; border-radius: 7px; background: #2c2a27; color: #fff; box-shadow: var(--shadow); transform: translateX(-50%); font-size: 13px; }

@keyframes appear { from { opacity: 0; transform: translateY(4px); } }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes message-highlight { 0%, 100% { background: transparent; } 20%, 70% { background: rgba(204, 126, 71, .16); box-shadow: 0 0 0 8px rgba(204, 126, 71, .08); } }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 25; top: 0; left: 0; width: min(300px, 86vw); height: 100dvh; padding: calc(18px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left)); transform: translateX(-105%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim.open { display: block; }
  .mobile-only { display: grid; }
  .chat-main { height: 100vh; height: 100dvh; }
  .messages { padding: 24px 16px 14px; }
  .topbar { grid-template-columns: 72px minmax(0, 1fr) 72px; padding-right: max(8px, env(safe-area-inset-right)); padding-left: max(8px, env(safe-area-inset-left)); }
  .composer-wrap { padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .message-attachments { grid-template-columns: 1fr; }
  .message-attachment-image img { max-height: 300px; }
  .welcome h1 { font-size: 25px; }
  .message { gap: 10px; }
  .message.user .message-body { max-width: 92%; }
  .mind-drawer { padding: calc(20px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .mind-actions { opacity: 1; }
  .provider-dialog { width: calc(100% - 20px); max-height: calc(100dvh - 20px); padding: 20px 16px; }
  .dialog-actions { flex-wrap: wrap; }
  .settings-grid { grid-template-columns: 1fr; gap: 0; }
  .usage-summary { grid-template-columns: 1fr; }
  .usage-period { padding: 14px 0; }
  .usage-period + .usage-period { padding-left: 0; border-top: 1px solid var(--line); border-left: 0; }
  .usage-totals { grid-template-columns: repeat(2, 1fr); }
  .latency-summary { grid-template-columns: repeat(2, 1fr); }
  .login-form { padding: 24px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
