:root {
  --bg: #121016;
  --panel: #1b1820;
  --panel-2: #241f2b;
  --text: #eee9f3;
  --muted: #a49cae;
  --accent: #e0789a;
  --accent-2: #f3a6bf;
  --border: #322b3a;
  --error: #ff8080;
  --radius: 14px;
  --on-accent: #1a0f14;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

button {
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--accent-2); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 0; }

/* Centered card screens */
.card-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: min(480px, 100%);
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; }
.card ul { padding-left: 18px; margin: 0; display: grid; gap: 8px; }

/* App layout */
#main { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head, .side-foot { display: flex; gap: 8px; padding: 14px; align-items: center; }
.side-head { justify-content: space-between; }
.side-foot { margin-top: auto; border-top: 1px solid var(--border); flex-wrap: wrap; gap: 6px; }
.side-foot button { padding: 6px 10px; font-size: 13px; }
.brand { font-size: 20px; font-weight: 700; color: var(--accent-2); }
#conversations { overflow-y: auto; padding: 0 8px; flex: 1; }
#conversations a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#conversations a:hover { background: var(--panel-2); color: var(--text); }
#conversations a.active { background: var(--panel-2); color: var(--text); }

#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
#chat-head h2 { margin: 0; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toggle-sidebar { display: none; }
.ai-badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(720px, 85%); padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.notice { align-self: center; max-width: 560px; font-size: 13px; color: var(--muted); background: transparent; border: 1px dashed var(--border); text-align: center; }
.msg.notice.crisis { color: var(--text); border: 1px solid var(--accent); }
.msg.error { align-self: center; color: var(--error); font-size: 13px; }
.msg.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.empty { margin: auto; text-align: center; color: var(--muted); }

#composer { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); align-items: flex-end; }
#input { resize: none; max-height: 200px; }

/* Settings dialog */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 94vw);
  max-height: 90vh;
  padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.settings-body { padding: 24px; display: grid; gap: 10px; }
.settings-body h2, .settings-body h3 { margin: 6px 0 0; }
.settings-body h3 { font-size: 14px; color: var(--accent-2); }
.settings-body label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.settings-body label.row { display: flex; align-items: center; gap: 8px; }
.settings-body label.row input { width: auto; }
.provider { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel-2); border-radius: 10px; }
.provider span { flex: 1; }
.provider small { color: var(--muted); }
details { display: grid; gap: 8px; }
details[open] > summary { margin-bottom: 8px; }
summary { cursor: pointer; color: var(--accent-2); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.small { font-size: 12px; }

/* Tool activity */
.tool { align-self: flex-start; max-width: min(720px, 85%); width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); font-size: 13px; }
.tool summary { display: flex; gap: 10px; padding: 6px 10px; cursor: pointer; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "›"; color: var(--muted); transition: transform .15s; }
.tool[open] summary::before { transform: rotate(90deg); }
.tool-summary { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-status { color: var(--muted); white-space: nowrap; }
.tool.running .tool-status { color: var(--accent-2); }
.tool.error .tool-status, .tool.denied .tool-status { color: var(--error); }
.tool pre, .approval pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); }
.approval { align-self: flex-start; max-width: min(720px, 85%); width: 100%; border: 1px solid var(--accent); border-radius: 10px; background: var(--panel-2); padding: 10px 12px; display: grid; gap: 8px; }
.approval p { margin: 0; }
.approval pre { border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.approval .row { display: flex; gap: 8px; }
.tool-perm { display: flex !important; align-items: center; justify-content: space-between; gap: 12px; }
.tool-perm span { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); }
.tool-perm select { width: auto; }

/* Sara status + page */
.title-wrap { display: flex; flex-direction: column; min-width: 0; }
.sara-status { background: none; border: none; padding: 0; color: var(--muted); font-size: 12px; text-align: left; cursor: pointer; }
.sara-status:hover { color: var(--accent-2); }
.day-note { white-space: pre-wrap; font-style: italic; }
.route-row { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 6px; align-items: center; }
.route-row span { font-size: 13px; color: var(--muted); }
.msg.proactive { border-left: 3px solid var(--accent-2); }

/* Avatar */
.brand { display: inline-flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.login-portrait { display: block; width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 8px; object-fit: cover; }
#sara-dialog .portrait { float: right; width: 140px; height: 140px; border-radius: 14px; margin: 0 0 10px 14px; object-fit: cover; }

/* Avatar upload */
.file-btn { cursor: pointer; text-decoration: underline; }

/* Conversation list: projects */
.side-tools { display: flex; gap: 6px; padding: 0 16px 6px; }
.conv-group { margin-bottom: 6px; }
.group-head { display: flex; align-items: center; gap: 2px; border-radius: 6px; padding-right: 4px; }
.group-head.drop { outline: 2px dashed var(--accent); }
.group-toggle { flex: 1; text-align: left; background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 6px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-btn { padding: 0 6px; font-size: 13px; color: var(--muted); opacity: .7; }
.group-btn:hover { opacity: 1; }
.group-empty { padding: 2px 10px; margin: 0; }
#conversations a.conv { display: flex; align-items: center; gap: 6px; }
#conversations a.conv .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conv-more { visibility: hidden; padding: 0 6px; line-height: 1.4; color: var(--muted); }
#conversations a.conv:hover .conv-more, #conversations a.conv.active .conv-more { visibility: visible; }
@media (hover: none) { .conv-more { visibility: visible; } }
.pop-menu { position: fixed; z-index: 50; min-width: 190px; max-height: 70vh; overflow-y: auto; background: var(--panel-2); border: 1px solid var(--border, #2f2a36); border-radius: 10px; padding: 4px; box-shadow: 0 8px 28px rgba(0,0,0,.45); }
.pop-menu hr { border: 0; border-top: 1px solid var(--border, #2f2a36); margin: 4px 0; }
.pop-label { font-size: 11px; color: var(--muted); padding: 4px 10px; text-transform: uppercase; }
.pop-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 10px; border-radius: 6px; font-size: 14px; }
.pop-item:hover { background: var(--panel); }
.danger-text { color: #ff8a8a !important; }
button.danger { background: #b3383d; color: #fff; }

/* Settings tabs */
section.settings-tab { display: grid; gap: 10px; }
section.settings-tab[hidden] { display: none; }
.route-row { display: grid; grid-template-columns: 7.5em minmax(0, 1fr) minmax(0, 1.4fr); gap: 6px; align-items: center; }
.model-chooser { display: flex; gap: 6px; align-items: center; min-width: 0; }
.model-chooser select, .model-chooser input { min-width: 0; flex: 1; }
.route-help { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
@media (max-width: 560px) { .route-row { grid-template-columns: 1fr; } }

/* Subscriptions */
.sub-card { border: 1px solid var(--border, #2a2730); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.sub-card p { margin: 6px 0; }
.chatgpt-btn { background: #000; color: #fff; border: 1px solid #444; border-radius: 999px; padding: 6px 14px; font-weight: 600; }
#sub-chatgpt-url, #sub-claude-token { width: min(420px, 100%); }

/* Health + backups */
ul.health, ul.backups { list-style: none; padding: 0; margin: 4px 0 8px; font-size: 13px; }
ul.health li, ul.backups li { padding: 3px 0; }
ul.health .mark { display: inline-block; width: 18px; font-weight: 700; }
ul.health li.ok .mark { color: #5fbf7f; }
ul.health li.bad .mark { color: #e0a040; }
ul.health strong { margin-right: 4px; }
input.tiny { width: 4.5em; display: inline-block; }

/* Channels */
.channel-tag { display: block; font-size: 11px; color: var(--muted); text-transform: lowercase; }

/* Voice */
button.icon { padding: 6px 10px; font-size: 16px; line-height: 1; }
#mic.recording, #call.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#speak-toggle[aria-pressed="true"] { color: var(--accent-2); border-color: var(--accent); }
#activity[data-status="listening"] .spinner, #activity[data-status="hearing"] .spinner { border-top-color: var(--accent-2); }

/* Export / import */
a.button, label.button { display: inline-block; padding: 6px 14px; border-radius: 10px; border: 1px solid var(--border); color: var(--text); text-decoration: none; cursor: pointer; font-size: 14px; }
.file-button input { display: none; }

/* Planner */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 6px 12px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; }
.add-row input:first-child { flex: 2 1 200px; }
.add-row input, .add-row select { flex: 1 1 120px; width: auto; }
/* A button next to labelled fields lines up with the field, not the label above it. */
.add-row:has(> label) { align-items: flex-end; }
.add-row:has(> label) > button { margin-bottom: 1px; }
#task-list, #rem-list, #rem-recent, #note-list { display: grid; gap: 6px; max-height: 45vh; overflow-y: auto; }
.proj-name { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-2); margin-top: 6px; }
.item { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 6px 10px; }
.item .grow { flex: 1; min-width: 0; }
.item .sub { font-size: 12px; color: var(--muted); }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item .overdue { color: var(--error); }
.item .high { color: var(--accent); font-weight: 600; }
.item input[type=checkbox] { width: auto; }
.item button { font-size: 12px; padding: 3px 10px; }
.note-body { white-space: pre-wrap; font-size: 13px; color: var(--muted); max-height: 4.5em; overflow: hidden; }
#note-edit { display: grid; gap: 6px; }
.msg.reminder { border-left: 3px solid var(--accent); }
.msg.reminder::before { content: "⏰ "; }

/* Memory */
.mem-tools { display: flex; gap: 8px; }
.mem-tools select { width: auto; }
#mem-list { display: grid; gap: 8px; max-height: 50vh; overflow-y: auto; }
.mem { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; display: grid; gap: 6px; }
.mem-head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.mem-head .kind { text-transform: uppercase; letter-spacing: .04em; color: var(--accent-2); }
.mem-head a { color: var(--muted); }
.mem-text { white-space: pre-wrap; }
.mem-evidence { font-size: 12px; color: var(--muted); font-style: italic; }
.mem .row { display: flex; gap: 6px; justify-content: flex-end; }
.mem .row button { font-size: 12px; padding: 3px 10px; }
.msg.forgotten { opacity: .45; }
.msg.forgotten::after { content: " (forgotten: hidden from Sara)"; font-size: 11px; font-style: italic; }
.msg.highlight { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Receipts + undo */
.msg.unverified { border: 1px solid var(--error); }
.claim-flag { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--error); font-size: 12px; color: var(--error); white-space: normal; }
.tool .undo { margin: 6px 10px 8px; font-size: 12px; padding: 4px 10px; }
.msg.notice.restore { border-style: solid; }

/* Activity indicator */
#activity { display: flex; align-items: center; gap: 10px; padding: 8px 18px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); background: var(--panel); }
#activity-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
#activity[data-status="running"] #activity-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#activity[data-status="waiting"] { background: var(--panel-2); }
#activity[data-status="waiting"] #activity-text { color: var(--accent-2); font-weight: 600; }
#activity-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
#activity[data-status="waiting"] .spinner { animation: pulse 1.2s ease-in-out infinite; border-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .3; } }
.working-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: middle; animation: pulse 1.2s ease-in-out infinite; }
#models-status { margin-right: 6px; }

.small { font-size: 12px; }
#conv-settings-btn { padding: 3px 10px; font-size: 12px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcp { display: grid; gap: 4px; padding: 8px 10px; background: var(--panel-2); border-radius: 10px; }
.mcp .row { display: flex; gap: 8px; align-items: center; }
.mcp .row span { flex: 1; }
.mcp .st-ready { color: #7fd99a; }
.mcp .st-error { color: var(--error); }
.mcp small { color: var(--muted); word-break: break-word; }
.tool-perm small { color: var(--muted); font-family: inherit; margin-left: 6px; }
.tool-perm.unavailable span { opacity: .5; }
textarea { resize: vertical; }

@media (max-width: 760px) {
  #main { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 30% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  #main.show-sidebar #sidebar { transform: none; }
  #toggle-sidebar { display: inline-block; }
  .msg { max-width: 92%; }
}

/* Replies: Markdown */
#messages .msg { font-size: var(--chat-size, 15px); }
#input { font-size: var(--chat-size, 15px); }
.msg.assistant { white-space: normal; }
.msg .md > :first-child { margin-top: 0; }
.msg .md > :last-child { margin-bottom: 0; }
.msg .md p { margin: 0 0 .6em; white-space: pre-wrap; }
.msg .md h3, .msg .md h4, .msg .md h5, .msg .md h6, .msg .md h7, .msg .md h8 { margin: .8em 0 .3em; font-size: 1.05em; }
.msg .md h3 { font-size: 1.15em; }
.msg .md ul, .msg .md ol { margin: 0 0 .6em; padding-left: 1.4em; }
.msg .md li { margin: .15em 0; }
.msg .md blockquote { margin: 0 0 .6em; padding: 2px 0 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.msg .md hr { border: 0; border-top: 1px solid var(--border); margin: .8em 0; }
.msg .md a { color: var(--accent-2); }
.msg .md code { font: .9em ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--panel); padding: 1px 5px; border-radius: 5px; }
.msg .md .code-block { margin: 0 0 .6em; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.msg .md .code-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 2px 10px; font-size: 12px; color: var(--muted); background: var(--panel); }
.msg .md .code-head button { padding: 2px 8px; font-size: 12px; }
.msg .md pre { margin: 0; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.msg .md pre code { background: none; padding: 0; font-size: .88em; }
.msg-actions { align-self: flex-start; display: flex; gap: 4px; align-items: center; margin: -6px 0 2px 4px; opacity: .55; transition: opacity .15s; }
.msg.user + .msg-actions { align-self: flex-end; margin: -6px 4px 2px 0; }
.msg-actions:hover, .msg-actions:focus-within { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: .8; } }
.msg-actions button { padding: 1px 8px; font-size: 12px; }
.msg-model { font-size: 11px; color: var(--muted); padding: 0 6px; }
.continue-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.editing-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 16px; padding: 4px 10px; font-size: 13px; color: var(--muted); border: 1px dashed var(--accent); border-radius: 10px; }

/* Search */
.side-search { padding: 0 12px 6px; }
.side-search input { width: 100%; padding: 6px 10px; border-radius: 8px; font-size: 13px; }
#conversations a.search-hit { display: block; white-space: normal; }
.hit-title { display: block; color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-snippet { display: block; font-size: 12px; color: var(--muted); }

/* Light theme */
:root[data-theme="light"] {
  --bg: #faf7fb;
  --panel: #f1ecf4;
  --panel-2: #e8e1ed;
  --text: #241c2b;
  --muted: #6b6274;
  --accent: #c94f78;
  --accent-2: #a83d61;
  --border: #d9d0e0;
  --error: #c0303a;
  --on-accent: #fff;
  color-scheme: light;
}
:root[data-theme="light"] .pop-menu { box-shadow: 0 8px 28px rgba(60,30,70,.18); }
:root[data-theme="light"] .danger-text { color: #c0303a !important; }

/* Buttons that aren't filled must not take the accent's text colour. */
.group-toggle, .group-btn, .conv-more, .pop-item, .sara-status { color: var(--muted); }
.pop-item { color: var(--text); }

/* Photos */
.msg-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg-photos img { max-width: 220px; max-height: 220px; border-radius: 10px; cursor: zoom-in; object-fit: cover; }
.msg.user:empty, .msg.user .msg-photos:only-child { margin-bottom: 0; }
.attachments { display: flex; gap: 8px; padding: 6px 16px 0; flex-wrap: wrap; }
.attachment { position: relative; }
.attachment img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.attachment button { position: absolute; top: -8px; right: -8px; padding: 0 6px; border-radius: 999px; background: var(--panel-2); line-height: 1.4; }

/* Project page */
#project-page { width: min(980px, 96vw); }
.pp-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pp-head h2 { margin: 0; }
.pp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; }
@media (max-width: 720px) { .pp-grid { grid-template-columns: 1fr; } }
.pp-grid h3 { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.pp-list { display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
.pp-item { display: block; padding: 5px 8px; border-radius: 6px; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-item:hover { background: var(--panel-2); }
.pp-file { font: 13px ui-monospace, Consolas, monospace; }
.pp-task { display: flex; gap: 8px; align-items: center; padding: 3px 4px; }
.pp-note summary { cursor: pointer; padding: 4px 6px; }
.pp-note-body { white-space: pre-wrap; padding: 4px 10px 8px; color: var(--muted); font-size: 14px; }
.pp-file-view { max-height: 300px; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px; white-space: pre; }

ul.health li.ok strong { color: #4fae70; }
ul.health li.warn strong { color: #d29a2e; }
ul.health li.bad strong { color: var(--error); }

/* Animated portrait (presence) */
.presence { position: relative; overflow: visible; }
.presence img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.presence .presence-blink { opacity: 0; transition: opacity 70ms linear; }
.presence .presence-talk { opacity: 0; transition: opacity 90ms ease-out; }
.presence .presence-oo, .presence .presence-ee { opacity: 0; }
.presence .presence-head { position: absolute; inset: 0; border-radius: inherit; transform-origin: 50% 85%; will-change: transform; }
.presence .presence-ring { position: absolute; inset: -6px; border-radius: inherit; box-shadow: 0 0 0 3px var(--accent), 0 0 28px 6px color-mix(in srgb, var(--accent) 55%, transparent); opacity: 0; transition: opacity .2s; pointer-events: none; }
.presence.alive { animation: breathe 5.5s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.012) translateY(-1px); } }
@media (prefers-reduced-motion: reduce) { .presence.alive { animation: none; } }
#sara-dialog .portrait.presence { overflow: visible; }
.call-panel { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); background: linear-gradient(var(--panel), transparent); }
#call-presence { width: min(34vh, 260px); aspect-ratio: 1; border-radius: 50%; }
.call-status { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
@media (max-width: 560px) { #call-presence { width: min(26vh, 180px); } }

.ph-taken { display: flex; gap: 6px; flex-wrap: wrap; }
.ph-taken img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.msg.assistant.photo { padding: 6px; }
.msg.assistant.photo .md:empty { display: none; }
.msg.assistant .msg-photos:last-child { margin-bottom: 0; }

/* Scrapbook */
#scrapbook { width: min(860px, 96vw); }
.sb-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; max-height: 60vh; overflow-y: auto; }
.sb-card { position: relative; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.sb-card.joke { border-left: 3px solid var(--accent-2); }
.sb-head { font-size: 12px; color: var(--muted); padding-right: 18px; }
.sb-text { white-space: pre-wrap; font-size: 14px; }
.sb-del { position: absolute; top: 4px; right: 4px; padding: 0 6px; }
.sb-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; max-height: 60vh; overflow-y: auto; }
.sb-photo { margin: 0; }
.sb-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; display: block; }
.sb-photo figcaption { margin-top: 2px; }

/* Make it yours */
.yours-head { display: flex; gap: 16px; align-items: flex-start; }
.my-face { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; flex: none; }
.yours-who { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { border: 1px solid var(--border); background: transparent; color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.my-preview { background: var(--panel-2); border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.my-preview ul { margin: 6px 0; padding-left: 18px; }
.actions-left { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.look-draft { display: grid; gap: 8px; justify-items: start; margin: 8px 0; }
.look-draft img { width: 220px; height: 220px; object-fit: cover; border-radius: 14px; }
@media (max-width: 560px) { .yours-head { flex-direction: column; align-items: center; } }

/* First-run setup guide */
#setup { width: min(620px, 96vw); }
.setup-step { margin: 0 0 4px; }
.su-choice { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.su-choice summary { cursor: pointer; font-weight: 600; }
.su-found { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.setup-actions { justify-content: flex-end; }
.setup-actions #su-skip { margin-right: auto; }
.setup-tips li { margin: 6px 0; }

.dev-list { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 6px; }
.dev-list li { padding: 6px 10px; border-radius: 10px; background: var(--panel-2); }
.dev-list li.current { outline: 1px solid var(--accent); }
.tok-new code { font-size: 14px; word-break: break-all; }

.mem-upcoming { padding: 8px 12px; border-radius: 10px; background: var(--panel-2); margin: 8px 0; font-size: 14px; }
.mem-add { align-items: end; flex-wrap: wrap; }
.mem-add label:first-child { flex: 1 1 260px; }
.mem.replaced { opacity: .6; }
ul.threads { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 6px; }
ul.threads li { padding: 6px 10px; border-radius: 10px; background: var(--panel-2); }
ul.threads li.done { opacity: .65; }
ul.threads li button { margin-left: 6px; }

.jobs-strip { display: grid; gap: 4px; margin: 0 0 6px; }
.job-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--panel-2); font-size: 14px; min-width: 0; }
.job-row .job-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.job-row .job-last { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, monospace; }
.pp-file-view.diff div.add { color: #3fb950; }
.pp-file-view.diff div.del { color: #f85149; }
.pp-file-view.diff div.hunk { color: var(--muted); }

.offrecord-bar { padding: 8px 12px; border-radius: 10px; margin: 0 0 6px; font-size: 14px; background: var(--panel-2); border: 1px dashed var(--muted); }
#main.offrecord #attach, #main.offrecord #camera-btn { display: none; }
a.conv.offrecord .conv-title { font-style: italic; }

ol.setup-steps { padding-left: 20px; display: grid; gap: 6px; }
ol.setup-steps code { word-break: break-all; }

/* ---------- Windows (Phase 15): ✕, Saved ✓, unsaved changes ---------- */
dialog { position: relative; }
dialog > .dialog-top { position: sticky; top: 0; height: 0; z-index: 5; }
.dialog-top > .dialog-x { position: absolute; top: 10px; right: 10px; z-index: 5; width: 32px; height: 32px; padding: 0; border-radius: 999px; background: var(--panel); font-size: 15px; line-height: 1; color: var(--muted); }
dialog .dialog-x:hover { color: var(--text); background: var(--panel-2); }
dialog .saved-tag { position: absolute; top: 14px; right: 52px; z-index: 5; font-size: 13px; color: var(--accent-2, var(--accent)); opacity: 0; pointer-events: none; }
dialog .saved-tag.show { animation: saved-fade 2.6s ease forwards; }
dialog .saved-tag.error { color: var(--error); animation: none; opacity: 1; pointer-events: auto; max-width: 60%; }
@keyframes saved-fade { 0% { opacity: 0; transform: translateY(-3px); } 10%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.unsaved-bar { position: sticky; bottom: 0; z-index: 6; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; background: var(--panel-2); border-top: 1px solid var(--border); box-shadow: 0 -6px 18px rgba(0,0,0,.25); }
.unsaved-bar span { flex: 1 1 200px; font-size: 14px; }
dialog .settings-body > h2:first-child, dialog .settings-body > h2:first-of-type { padding-right: 40px; }

/* ---------- Settings: list of pages + one page ---------- */
dialog.settings-dialog { width: min(1040px, 96vw); height: min(820px, 90vh); max-height: 90vh; overflow: hidden; }
.settings-layout { display: grid; grid-template-columns: 240px 1fr; height: 100%; min-height: 0; }
.settings-nav { border-right: 1px solid var(--border); padding: 18px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.settings-nav h2 { margin: 0 6px; font-size: 18px; }
.settings-nav input[type=search] { margin: 0; }
.settings-nav-group { display: grid; gap: 1px; margin-top: 4px; }
.settings-nav-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 8px 2px; }
.settings-nav-item { text-align: left; background: transparent; border: 0; color: var(--text); padding: 7px 10px; border-radius: 8px; font-size: 14px; font-weight: 400; }
.settings-nav-item:hover { background: var(--panel-2); }
.settings-nav-item[aria-current="true"] { background: var(--accent); color: var(--on-accent); }
.settings-nav-item.dim { opacity: .35; }
.settings-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.settings-page-head { display: flex; align-items: center; gap: 8px; padding: 18px 56px 4px 24px; }
.settings-page-head h2 { margin: 0; font-size: 18px; }
#settings-back { display: none; }
.settings-pages { flex: 1; overflow-y: auto; padding-top: 8px; outline: none; }
.settings-page { display: grid; gap: 10px; }
.settings-page[hidden] { display: none; }
.settings-pages.searching .settings-page:not([hidden]) ~ .settings-page:not([hidden]) { border-top: 1px solid var(--border); padding-top: 14px; }
.settings-pages.searching .settings-page::before { content: attr(data-group) ' › ' attr(data-title); font-size: 12px; color: var(--muted); }
.settings-actions { margin: 0; padding: 12px 24px; border-top: 1px solid var(--border); align-items: center; }
.settings-actions .muted { margin-right: auto; }
#settings-error:empty { display: none; }
#settings-error { margin: 0; padding: 0 24px; }

@media (max-width: 720px) {
  dialog.settings-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; max-width: 100vw; border-radius: 0; margin: 0; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { border-right: 0; }
  .settings-nav-item { padding: 12px 10px; font-size: 15px; }
  .settings-dialog .settings-main { display: none; }
  .settings-dialog.page-open .settings-nav { display: none; }
  .settings-dialog.page-open .settings-main { display: flex; }
  #settings-back { display: inline-block; }
  .settings-page-head { padding: 14px 52px 4px 12px; }
  .settings-hint, #settings-hint { display: none; }
  dialog:not(.settings-dialog) { width: 100vw; max-width: 100vw; max-height: 100dvh; height: auto; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}

/* ---------- Sidebar icon bar (Phase 15) ---------- */
.side-bar { margin-top: auto; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px 4px; padding: 6px 8px 8px; }
.side-bar button { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: transparent; border: 0; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 500; min-width: 0; text-align: left; }
.side-bar button:hover, .side-bar button:focus-visible { background: var(--panel-2); color: var(--text); }
.side-bar svg { width: 18px; height: 18px; flex: none; }
.side-bar .side-face { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex: none; }
.side-bar span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Today ---------- */
dialog.today-dialog { width: min(860px, 96vw); }
.today-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.today-her .muted { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.today-her .muted.open { -webkit-line-clamp: unset; }
.today-card { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; align-content: start; }
.today-card h3 { margin: 0 0 2px; }
.today-list { display: grid; gap: 4px; }
.today-row { display: flex; gap: 8px; align-items: baseline; font-size: 14px; min-width: 0; }
.today-row .today-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.today-row .today-side { white-space: nowrap; }
.today-row.overdue .today-side { color: var(--accent); }
.today-row.past { opacity: .55; }
.today-her { display: flex; gap: 12px; align-items: flex-start; }
.today-her p { margin: 0 0 4px; }
.today-face { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; flex: none; }

/* ---------- Pairing (Phase 16) ---------- */
#pair-show { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; background: var(--panel-2); border-radius: 12px; padding: 12px; }
#pair-show[hidden] { display: none; }
.pair-qr { width: 200px; height: 200px; border-radius: 10px; background: #fff; image-rendering: pixelated; }
.pair-how { flex: 1 1 220px; display: grid; gap: 6px; }
.pair-how p { margin: 0; }
.pair-code-big { font: 600 24px/1.2 ui-monospace, monospace; letter-spacing: .08em; }
.pair-code input { font: 600 20px ui-monospace, monospace; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- Demo server (Phase 16): only what a visitor can use ---------- */
body.demo #open-planner, body.demo #open-memory, body.demo #open-scrapbook, body.demo #open-settings,
body.demo #new-project, body.demo #new-offrecord, body.demo #conv-settings-btn, body.demo #attach,
body.demo #sd-save, body.demo #sd-reroll, body.demo #pe-reset, body.demo .conv-more,
body.demo #mic, body.demo #call, body.demo #speak-toggle { display: none !important; }
body.demo .side-bar { grid-template-columns: repeat(2, 1fr); }

/* ---------- iPhone app notifications (Phase 17) ---------- */
.apns-box { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.apns-box summary { cursor: pointer; }
.apns-box textarea { width: 100%; font: 12px ui-monospace, monospace; }
.apns-box .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Store rules and reports (Phase 19) ---------- */
.app-only { display: none; }
body.in-app .app-only { display: list-item; }
body.in-app .web-only { display: none; }
#report-quote { margin: 0 0 10px; padding: 8px 10px; border-left: 3px solid var(--border); background: var(--panel-2); border-radius: 6px; white-space: pre-wrap; }
.report-reasons { border: 0; padding: 0; margin: 0 0 8px; display: grid; gap: 4px; }

/* Phones: the conversation-settings button shrinks to an icon so the title has room
   (the "AI companion" badge always stays: it's part of the AI disclosure). */
@media (max-width: 520px) {
  #conv-summary { display: none; }
  #conv-settings-btn::before { content: '⚙'; font-size: 16px; }
  #chat-head .ai-badge { font-size: 11px; padding: 2px 7px; }
}

/* ---------- Phase 21: colours, chat backgrounds, layout (per device) ---------- */
:root[data-accent="lavender"] { --accent: #a78bfa; --accent-2: #c4b5fd; --on-accent: #160f26; }
:root[data-accent="ocean"] { --accent: #4fb3d9; --accent-2: #8fd3ec; --on-accent: #06171e; }
:root[data-accent="forest"] { --accent: #5fbf8a; --accent-2: #93dbb2; --on-accent: #07190f; }
:root[data-accent="amber"] { --accent: #e8a948; --accent-2: #f3c886; --on-accent: #1e1405; }
:root[data-accent="mono"] { --accent: #c9c4d0; --accent-2: #e6e2ea; --on-accent: #141217; }
:root[data-theme="light"][data-accent="lavender"] { --accent: #7c5cd6; --accent-2: #6643c4; --on-accent: #fff; }
:root[data-theme="light"][data-accent="ocean"] { --accent: #1f7fa8; --accent-2: #17698c; --on-accent: #fff; }
:root[data-theme="light"][data-accent="forest"] { --accent: #2f8a57; --accent-2: #246f45; --on-accent: #fff; }
:root[data-theme="light"][data-accent="amber"] { --accent: #b9761a; --accent-2: #9a6213; --on-accent: #fff; }
:root[data-theme="light"][data-accent="mono"] { --accent: #4a4452; --accent-2: #2f2a35; --on-accent: #fff; }

.ap-swatches { display: flex; gap: 8px; margin: 4px 0 8px; }
.ap-swatch { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--border); }
.ap-swatch[data-accent="rose"] { background: #e0789a; }
.ap-swatch[data-accent="lavender"] { background: #a78bfa; }
.ap-swatch[data-accent="ocean"] { background: #4fb3d9; }
.ap-swatch[data-accent="forest"] { background: #5fbf8a; }
.ap-swatch[data-accent="amber"] { background: #e8a948; }
.ap-swatch[data-accent="mono"] { background: #c9c4d0; }
:root[data-accent="rose"] .ap-swatch[data-accent="rose"], :root[data-accent="lavender"] .ap-swatch[data-accent="lavender"],
:root[data-accent="ocean"] .ap-swatch[data-accent="ocean"], :root[data-accent="forest"] .ap-swatch[data-accent="forest"],
:root[data-accent="amber"] .ap-swatch[data-accent="amber"], :root[data-accent="mono"] .ap-swatch[data-accent="mono"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }

:root[data-chatbg="glow"] #messages { background: radial-gradient(ellipse at 85% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%), radial-gradient(ellipse at 0% 100%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 55%); }
:root[data-chatbg="dusk"] #messages { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 12%, var(--bg)) 0%, var(--bg) 70%); }
:root[data-chatbg="dots"] #messages { background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1.2px); background-size: 18px 18px; }
:root[data-chatbg="stars"] #messages {
  background:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,.55), transparent 60%), radial-gradient(1px 1px at 72% 12%, rgba(255,255,255,.45), transparent 60%),
    radial-gradient(1.5px 1.5px at 42% 62%, rgba(255,255,255,.4), transparent 60%), radial-gradient(1px 1px at 88% 48%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1px 1px at 22% 82%, rgba(255,255,255,.35), transparent 60%), radial-gradient(1.5px 1.5px at 60% 30%, rgba(255,255,255,.3), transparent 60%),
    linear-gradient(180deg, #0d1022 0%, #15122a 60%, var(--bg) 100%);
  background-attachment: local;
}
:root[data-theme="light"][data-chatbg="stars"] #messages { background: linear-gradient(180deg, #e8e6f6 0%, var(--bg) 80%); }

:root[data-density="compact"] #messages { padding: 12px 14px; gap: 6px; }
:root[data-density="compact"] .msg { padding: 6px 11px; line-height: 1.4; }
:root[data-density="compact"] #conversations a { padding-top: 4px; padding-bottom: 4px; }
:root[data-density="compact"] #composer { padding: 8px 12px; }
:root[data-density="compact"] #input { padding-top: 6px; padding-bottom: 6px; }

/* Saved looks */
.look-saved { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 10px; margin: 6px 0 10px; }
.look-card { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); font-size: 13px; }
.look-card.current { border-color: var(--accent); }
.look-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.look-card span:not(.muted) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.look-card div { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
