/* Sarah (Brain Dashboard) - Muted Gray admin design system ([[UI Design System - Muted Gray]]) */
:root {
  --bg-page: #f4f5f7; --surface: #ffffff; --surface-2: #eceff1; --border: #d9dde2;
  --text: #3f4650; --text-muted: #6f7781;
  --primary: #7890a8; --primary-dk: #5d7690;
  --success: #829b89; --success-dk: #56705d; --success-bg: #eef3ef;
  --danger: #b98484;  --danger-dk: #8f5959;  --danger-bg: #f6eeee;
  --warning: #b69a73; --warning-dk: #86693f; --warning-bg: #f6f1ea;
  --info: #9589a6;    --info-dk: #6a5d80;    --info-bg: #f1eff5;
  --teal: #769b9a;    --teal-dk: #4d706f;    --teal-bg: #edf3f3;
  --primary-bg: #edf1f5;
  --radius: 10px; --shadow: 0 1px 2px rgba(63, 70, 80, .06), 0 1px 3px rgba(63, 70, 80, .05);
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg-page); color: var(--text); font: 14px/1.5 var(--font); overflow-x: hidden; }
a { color: var(--primary-dk); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; min-width: 0; }
.brand img { width: 26px; height: 26px; }
.topbar .spacer { flex: 1; }
.updated { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(63,70,80,.12); min-width: 200px; padding: 4px; }
.menu-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1480px; margin: 0 auto; }
.col { display: contents; }
#p-sarah { order: 0; grid-column: 1 / -1; } #p-needs { order: 1; } #p-questions { order: 2; } #p-capture { order: 3; } #p-tasks { order: 4; } #p-projects { order: 5; } #p-chat { order: 6; } #p-agents { order: 7; } #p-recent { order: 8; }
@media (min-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); padding: 20px; gap: 20px; align-items: start; }
  .col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
}

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.panel > header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel > header h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel > header .count { margin-left: auto; }
.panel .body { padding: 14px 16px; }
.empty { color: var(--text-muted); padding: 4px 0; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 7px; padding: 7px 12px; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e3e7ea; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dk); }
.btn-danger { background: var(--surface); color: var(--danger-dk); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 7px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input[type=text], input[type=search], input[type=password], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; outline: none;
}
input::placeholder, textarea::placeholder { color: #a0a7af; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(120, 144, 168, .18); }
textarea { resize: vertical; min-height: 42px; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 180px; min-width: 0; }

/* ---------- badges, lights ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .01em; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.b-decision { background: var(--info-bg); color: var(--info-dk); }
.b-blocked, .b-red { background: var(--danger-bg); color: var(--danger-dk); }
.b-handoff { background: var(--teal-bg); color: var(--teal-dk); }
.b-task, .b-amber { background: var(--warning-bg); color: var(--warning-dk); }
.b-green { background: var(--success-bg); color: var(--success-dk); }
.b-primary { background: var(--primary-bg); color: var(--primary-dk); }
.light { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--border); }
.light.green { background: var(--success); } .light.amber { background: var(--warning); } .light.red { background: var(--danger); } .light.gray { background: #b7bdc4; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--surface-2); min-width: 0; }
.list > li:first-child { padding-top: 2px; }
.list > li:last-child { border-bottom: 0; padding-bottom: 0; }
.item-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.item-title { font-weight: 500; overflow-wrap: anywhere; }
.item-detail { color: var(--text-muted); margin-top: 2px; overflow-wrap: anywhere; }
.item-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.linkish { background: none; border: 0; padding: 0; color: var(--primary-dk); cursor: pointer; text-align: left; overflow-wrap: anywhere; }
.linkish:hover { text-decoration: underline; }
.decide { margin-top: 8px; display: grid; gap: 8px; }
.decide .row .btn { flex: none; }
.more { margin-top: 8px; }
.b-question { background: var(--primary-bg); color: var(--primary-dk); }
.b-new { background: var(--success-bg); color: var(--success-dk); }

/* ---------- open tasks ---------- */
.filters { margin-bottom: 10px; }
.filters select { width: auto; flex: none; }
.group { border-bottom: 1px solid var(--surface-2); }
.group:last-child { border-bottom: 0; }
.group > summary { cursor: pointer; padding: 8px 0; font-weight: 600; display: flex; gap: 8px; align-items: center; list-style: none; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--text-muted); width: 10px; }
.group[open] > summary::before { content: "▾"; }
.group > summary .badge { margin-left: auto; }
.group .list { padding: 0 0 8px 18px; }
.subnotes { margin: 4px 0 0; padding-left: 18px; color: var(--text-muted); font-size: 12.5px; }
.acts { margin-top: 6px; }

/* ---------- projects ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card:hover { border-color: #c3c9d0; box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.card-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.card .sub { color: var(--text-muted); font-size: 12px; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.kv { font-size: 12.5px; overflow-wrap: anywhere; }
.kv b { font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-right: 4px; }
.kv.block { color: var(--danger-dk); }
.card-foot { display: flex; justify-content: space-between; gap: 8px; color: var(--text-muted); font-size: 12px; margin-top: auto; }

/* ---------- agents table ---------- */
.agent { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.agent .light { align-self: start; margin-top: 6px; }
.agent .when { font-size: 12px; color: var(--text-muted); text-align: right; white-space: nowrap; }
.agent .item-detail { grid-column: 2 / 4; }

/* ---------- chat ---------- */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; margin-bottom: 10px; }
.msg { padding: 9px 12px; border-radius: 9px; max-width: 100%; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.q { align-self: flex-end; background: var(--primary-bg); max-width: 88%; }
.msg.a { background: var(--surface-2); }
.msg.err { background: var(--danger-bg); color: var(--danger-dk); }
.msg.wait { color: var(--text-muted); font-style: italic; }
.chat-form { display: grid; gap: 8px; }
.chat-form .row { justify-content: space-between; }

/* ---------- note viewer ---------- */
dialog.viewer { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 40px); color: var(--text); background: var(--surface); box-shadow: 0 12px 40px rgba(63,70,80,.2); }
dialog.viewer::backdrop { background: rgba(63, 70, 80, .35); }
.viewer header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.viewer header h3 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.viewer .md { padding: 12px 20px 20px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 6px; line-height: 1.3; }
.md h1 { font-size: 20px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14.5px; } .md h4 { font-size: 13.5px; }
.md p { margin: 6px 0; }
.md ul { margin: 4px 0; padding-left: 22px; }
.md li.task { list-style: none; margin-left: -20px; }
.md li.task.done > span { color: var(--text-muted); text-decoration: line-through; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 7px; overflow-x: auto; font-size: 12.5px; white-space: pre; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--primary); background: var(--primary-bg); border-radius: 0 6px 6px 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md .fm { font-size: 12px; color: var(--text-muted); background: var(--surface-2); border-radius: 7px; padding: 6px 10px; margin-bottom: 8px; }
.md .fm summary { cursor: pointer; font-weight: 600; }
.md .fm > div { white-space: pre-wrap; margin-top: 6px; }
.md hr { border: 0; border-top: 1px solid var(--border); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 20; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger-dk); }
.alert { background: var(--warning-bg); color: var(--warning-dk); border: 1px solid #e6dccd; border-radius: 8px; padding: 8px 12px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .body { display: grid; gap: 12px; padding: 20px; }
.login h1 { font-size: 17px; margin: 0; }
.login label.f { display: grid; gap: 4px; font-size: 13px; font-weight: 500; }
.login .error { background: var(--danger-bg); color: var(--danger-dk); border-radius: 7px; padding: 8px 10px; font-size: 13px; }

@media (max-width: 520px) {
  .topbar { padding: 10px 12px; }
  .updated { display: none; }
  .panel .body { padding: 12px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
#banner { grid-column: 1 / -1; order: 0; }

/* ---------- Sarah ---------- */
.brand .tagline { font-weight: 400; }
.sarah { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; background: linear-gradient(180deg, #fbf7f4 0%, var(--surface) 70%); }
@media (min-width: 760px) { .sarah { grid-template-columns: 170px minmax(0, 1fr); gap: 20px; padding: 20px; } }
.sarah-face { display: flex; flex-direction: column; align-items: center; gap: 8px; }
@media (max-width: 759px) { .sarah-face { flex-direction: row; align-items: center; } .sarah-face .avatar { width: 84px; } .sarah-status { flex: 1; } }
.avatar { width: 150px; aspect-ratio: 1; border-radius: 50%; position: relative; cursor: pointer; flex: none; }
.avatar svg { width: 100%; height: 100%; display: block; border-radius: 50%; box-shadow: 0 2px 10px rgba(63, 70, 80, .12); }
.avatar::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid transparent; pointer-events: none; }
.avatar.listening::after { border-color: var(--success); animation: pulse 1.2s ease-in-out infinite; }
.avatar.thinking::after { border-color: var(--primary); border-top-color: transparent; animation: spin 1.2s linear infinite; }
.avatar .eyes { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.avatar .talk { opacity: 0; transform-box: fill-box; transform-origin: center; }
.avatar.talking .smile { opacity: 0; }
.avatar.talking .talk { opacity: 1; animation: talk .22s ease-in-out infinite alternate; }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes talk { from { transform: scaleY(.3); } to { transform: scaleY(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .avatar .eyes, .avatar.talking .talk, .avatar.listening::after, .avatar.thinking::after { animation: none; } }
.sarah-status { min-height: 18px; text-align: center; }
.sarah-tools { justify-content: center; }
#voice-toggle .mute { display: none; }
#voice-toggle.off .mute { display: inline; }
#voice-toggle.off .wave { display: none; }
.sarah-talk { display: grid; gap: 10px; min-width: 0; }
.sarah .chat-log { max-height: 380px; min-height: 90px; margin: 0; padding: 2px; }
.sarah .msg.a { background: var(--surface); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; box-shadow: var(--shadow); white-space: normal; font-size: 15px; }
.sarah .msg.a .md p:first-child { margin-top: 0; } .sarah .msg.a .md p:last-child { margin-bottom: 0; }
.sarah .msg.q { border-radius: 14px 14px 4px 14px; }
.topic { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: var(--warning-bg); border-radius: 8px; padding: 6px 10px; }
.topic .linkish { font-weight: 600; }
.icon-btn.tiny { width: 24px; height: 24px; font-size: 16px; line-height: 1; margin-left: auto; }
.topic-actions:empty { display: none; }
.quick .btn { border-radius: 999px; }
.say { position: relative; }
.say textarea { padding-right: 56px; font-size: 15px; }
.mic { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.mic svg { width: 20px; height: 20px; }
.mic:hover { background: var(--primary-dk); }
.mic.on { background: var(--success-dk); animation: pulse 1.2s ease-in-out infinite; }
.btn-talk { background: var(--warning-bg); color: var(--warning-dk); border-color: #e6dccd; }
.btn-talk:hover:not(:disabled) { background: #efe5d6; }
.acts .row { margin-top: 2px; }

/* ---------- collapsible panels ---------- */
.col .panel > header { cursor: pointer; user-select: none; }
.fold { background: none; border: 0; padding: 0; width: 16px; color: var(--text-muted); cursor: pointer; }
.fold::before { content: "▾"; }
.panel.collapsed .fold::before { content: "▸"; }
.panel.collapsed > .body { display: none; }
.panel.collapsed > header { border-bottom: 0; }
.sarah .msg.changed { background: var(--success-bg); color: var(--success-dk); padding: 6px 12px; white-space: normal; }
