:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1d2230;
  --fg: #e6e8ee;
  --muted: #8b91a3;
  --accent: #7aa2ff;
  --warn: #d99a3a;
  --danger: #d96b6b;
  --border: #2a2f3e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.error { color: var(--danger); }

/* layout */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 600; color: var(--fg); }
.topbar nav { display: flex; gap: 12px; flex: 1; flex-wrap: wrap; }
.topbar .hamburger { background: transparent; border: 1px solid var(--border);
  color: var(--fg); cursor: pointer; padding: 2px 9px; border-radius: 4px;
  font-size: 16px; line-height: 1.0; }
.topbar .hamburger:hover { background: var(--panel-2); }
.nav-tab { color: var(--accent); padding: 2px 0; }
.nav-tab.is-active { color: var(--fg); border-bottom: 2px solid var(--accent);
  padding-bottom: 0; }
.nav-tab.nav-tab-promoted { opacity: 0.85; font-style: italic; }
.nav-tab.nav-tab-promoted::before { content: "↳ "; opacity: 0.6; }
main { max-width: 1200px; margin: 16px auto; padding: 0 16px; }

/* sidebar (hamburger menu) */
.nav-sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 50; }
.nav-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 280px;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 60;
  box-shadow: 0 0 24px rgba(0,0,0,0.5); }
/* The class rules above are more specific than the user-agent's
   [hidden] { display: none } rule, which would otherwise hide them.
   These re-apply display:none when the attribute is present. */
.nav-sidebar[hidden], .nav-sidebar-backdrop[hidden] { display: none; }
.nav-sidebar-header { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); }
.nav-sidebar-header .brand { font-weight: 600; color: var(--fg); }
.nav-sidebar-close { background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; }
.nav-sidebar-close:hover { color: var(--fg); }
.nav-sidebar-list { flex: 1; overflow-y: auto; padding: 8px 0;
  display: flex; flex-direction: column; }
.nav-sidebar .nav-sidebar-list a.nav-tab { display: block; width: 100%;
  padding: 10px 16px; border-bottom: 1px solid transparent;
  text-align: left; }
.nav-sidebar .nav-sidebar-list a.nav-tab:hover { background: var(--panel-2);
  text-decoration: none; }
.nav-sidebar .nav-sidebar-list a.nav-tab.is-active { background: var(--panel-2);
  color: var(--fg); border-left: 3px solid var(--accent); padding-left: 13px; }
.nav-sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px; background: var(--panel-2); }
.nav-account-label { letter-spacing: 0.04em; text-transform: uppercase; }
.nav-account-email { font-size: 12px; word-break: break-all; color: var(--fg); }
.nav-sidebar-foot .logout button { background: transparent; color: var(--muted);
  border: 1px solid var(--border); padding: 6px 12px; border-radius: 4px;
  cursor: pointer; width: 100%; }
.nav-sidebar-foot .logout button:hover { color: var(--danger); border-color: var(--danger); }
body.nav-sidebar-open { overflow: hidden; }

/* filters */
.filters form { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end;
  background: var(--panel); padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.filters label.grow { flex: 1; min-width: 200px; }
.filters input, .filters select { background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 6px 8px; border-radius: 4px; font-size: 13px; }

/* tables */
table.events { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
table.events th, table.events td { padding: 6px 10px; border-bottom: 1px solid var(--border);
  text-align: left; vertical-align: top; }
table.events th { background: var(--panel-2); font-weight: 600; font-size: 12px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
table.events tr:hover td { background: var(--panel-2); }

/* per-account color swatch (on /accounts identity headers) */
.account-swatch { display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; vertical-align: middle; margin-right: 8px;
  border: 1px solid rgba(255,255,255,0.15); }

/* pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  border: 1px solid var(--border); margin-right: 4px; white-space: nowrap; }
.pill.kind { color: var(--accent); }
.pill.person { background: var(--panel-2); color: var(--fg); }
.pill.person.is-user { color: var(--warn); border-color: var(--warn); }
.pill.person.unknown { color: var(--muted); }
.pill.status { font-weight: 600; }
.pill.status.status-proposed { color: var(--warn); border-color: var(--warn); }
.pill.status.status-approved  { color: var(--accent); border-color: var(--accent); }
.pill.status.status-executed  { color: var(--muted); }
.pill.status.status-failed    { color: var(--danger); border-color: var(--danger); }
.pill.status.status-cancelled { color: var(--muted); text-decoration: line-through; }
.pill.status.status-reversed  { color: var(--muted); }
.pill.status.status-superseded { color: var(--muted); text-decoration: line-through; }

/* Approve / Deny forms */
.approve-form { display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); padding: 14px; border: 1px solid var(--border);
  border-radius: 6px; margin: 12px 0; }
.approve-form label { display: flex; flex-direction: column; gap: 4px; }
.approve-form input, .approve-form textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 4px; font-family: inherit; font-size: 13px; }
.approve-form textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.approve-form input:disabled { color: var(--muted); }
.approve-form .approve-actions { display: flex; gap: 10px; }
.approve-form button.primary, .deny-form button.danger {
  padding: 8px 16px; border: 0; border-radius: 4px; cursor: pointer; font-weight: 600; }
.approve-form button.primary { background: var(--accent); color: #0f1115; }
.deny-form { margin: 8px 0 16px; }
.deny-form button.danger { background: transparent; color: var(--danger);
  border: 1px solid var(--danger); }

/* AI revise sub-form */
.ai-revise { border: 1px dashed var(--border); padding: 10px 12px;
  border-radius: 4px; display: flex; gap: 8px; align-items: stretch;
  margin-top: 4px; }
.ai-revise legend { padding: 0 6px; }
.ai-revise input { flex: 1; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 8px 10px; border-radius: 4px;
  font-size: 13px; }
.ai-revise button { background: transparent; color: var(--accent);
  border: 1px solid var(--accent); padding: 6px 14px; border-radius: 4px;
  cursor: pointer; font-size: 13px; white-space: nowrap; }
.ai-revise button:hover { background: var(--panel-2); }
.ai-revise button[disabled] { opacity: 0.5; cursor: progress; }

/* Bulk-approve bar */
.bulk-bar { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; background: var(--panel-2); padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 4px; margin-bottom: 8px; }
.bulk-bar label { display: flex; align-items: center; gap: 6px; }
.bulk-bar button.small { padding: 4px 12px; font-size: 12px; }
button.primary.small { background: var(--accent); color: #0f1115; border: 0;
  border-radius: 4px; cursor: pointer; font-weight: 600; }
input.bulk-check, #bulk-select-all { accent-color: var(--accent); }

/* Explain-this block */
section.explain { background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 16px; margin: 14px 0; }
section.explain h2 { margin-top: 0; }
section.explain h3 { font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin: 14px 0 4px; }
.explain-text { white-space: pre-wrap; font-family: var(--mono); font-size: 12px;
  background: var(--bg); padding: 10px; border-radius: 4px; border: 1px solid var(--border);
  max-height: 50vh; overflow: auto; margin: 4px 0 0; }
.explain-fields { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px;
  margin: 8px 0; }
.explain-fields dt { color: var(--muted); font-size: 12px; }
.explain-fields dd { margin: 0; }
.explain-meta { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--border); }

/* Flags */
.pill.flag { background: var(--panel-2); color: var(--danger);
  border-color: var(--danger); }
.flag-form { margin: 14px 0; }
.flag-list { list-style: none; padding-left: 0; margin: 8px 0; }
.flag-list li { padding: 6px 10px; border-left: 3px solid var(--danger);
  background: var(--panel); margin-bottom: 6px; border-radius: 0 4px 4px 0; }
.flag-note { margin-top: 4px; font-style: italic; color: var(--muted); }

/* Tasks */
form.inline { display: inline; }
form.inline select { background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); padding: 2px 6px; border-radius: 3px;
  font-size: 12px; }
details.new-task { background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px; margin: 14px 0; }
details.new-task summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.pill.status.status-todo { color: var(--accent); border-color: var(--accent); }
.pill.status.status-doing { color: var(--warn); border-color: var(--warn); }
.pill.status.status-snoozed { color: var(--muted); }
.pill.status.status-dropped { color: var(--muted); text-decoration: line-through; }
.danger.small { padding: 2px 8px; font-size: 12px; background: transparent;
  color: var(--danger); border: 1px solid var(--danger); border-radius: 3px;
  cursor: pointer; }
.recovery { margin-top: 4px; }
.recovery strong { color: var(--accent); font-weight: 600; }
.recovery.recovery-none strong { color: var(--muted); }

/* Memory snapshot */
section.memory-snapshot { background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 16px; margin: 14px 0; }
section.memory-snapshot h2 { margin-top: 0; }
.snapshot + .snapshot { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
table.snapshot-components { width: 100%; border-collapse: collapse; margin: 8px 0; }
table.snapshot-components th, table.snapshot-components td { padding: 4px 8px;
  border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.snapshot-components th { font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); }
table.snapshot-components .mono.small { margin-right: 6px; }

/* HTMX indicator pattern: htmx adds .htmx-request to the indicated element while the request runs */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }

.revise-spinner { color: var(--muted); font-size: 12px; align-items: center;
  gap: 6px; padding: 0 8px; }
.revise-spinner .spinner { display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dim the textarea while a revision is in flight so the user knows it'll swap */
.htmx-request #send-form-wrap, #send-form-wrap.htmx-request { opacity: 0.5; transition: opacity 150ms ease; }

/* detail */
.crumbs { margin-bottom: 8px; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px;
  margin: 14px 0; }
dl.meta dt { color: var(--muted); }
details { background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; margin-bottom: 10px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em; }
pre { background: var(--bg); border: 1px solid var(--border); padding: 10px;
  border-radius: 4px; overflow: auto; max-height: 60vh; font-family: var(--mono);
  font-size: 12px; }

/* pager */
nav.pager { display: flex; gap: 14px; justify-content: center; margin: 14px 0; }

/* login */
body.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; }
.login-card { background: var(--panel); padding: 28px 32px; border: 1px solid var(--border);
  border-radius: 8px; min-width: 320px; }
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-card input { background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 4px; font-size: 14px; }
.login-card button { background: var(--accent); color: #0f1115; border: 0;
  padding: 8px 10px; border-radius: 4px; cursor: pointer; font-weight: 600; }

/* M5.5-mvp memory viewer */
.memory-header { margin-bottom: 18px; }
.memory-header h1 { margin: 0 0 4px; font-size: 18px; }
.mem-section { background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 14px 16px; margin-bottom: 14px; }
.mem-section h2 { margin: 0 0 4px; font-size: 14px; }
.mem-section > p { margin: 0 0 10px; }
.mem-list { margin: 0; padding-left: 18px; }
.mem-list li { margin: 4px 0; line-height: 1.5; }
.pinned-add { display: flex; gap: 6px; margin: 8px 0 12px; align-items: center; }
.pinned-add select, .pinned-add input[type=text] {
  padding: 4px 8px; font-size: 13px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--bg); color: var(--fg);
}
.pinned-add button { padding: 4px 12px; }
.inline-retire { display: inline; margin-left: 8px; }
.inline-retire button.link { background: none; border: 0; color: var(--muted, #888);
  cursor: pointer; padding: 0; font-size: 11px; text-decoration: underline; }
.inline-retire button.link:hover { color: var(--fg); }
.bootstrap-form textarea {
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px; font-size: 13px; line-height: 1.5; resize: vertical;
}
.thread { background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 8px 12px; margin-bottom: 6px; }
.thread summary { font-size: 13px; }
.thread-summary { margin-top: 8px; white-space: pre-wrap; line-height: 1.5;
  font-size: 13px; color: var(--fg); }

/* M12e chat */
.chat-shell { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column;
  gap: 12px; height: calc(100vh - 110px); }
.chat-header h1 { margin: 0; font-size: 18px; }
.chat-header p { margin: 4px 0 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 85%; }
.chat-msg.role-user { align-self: flex-end; }
.chat-msg.role-assistant { align-self: flex-start; }
.chat-msg.role-system { align-self: center; opacity: 0.6; font-style: italic; }
.chat-msg .bubble { background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; white-space: pre-wrap; word-wrap: break-word;
  line-height: 1.4; }
.chat-msg.role-user .bubble { background: rgba(80, 140, 220, 0.18); border-color: rgba(80, 140, 220, 0.35); }
.chat-msg.role-assistant .bubble { background: var(--bg); }
.chat-msg.streaming .bubble { border-color: var(--accent); }
.chat-msg .proposed-actions { margin: 4px 0 0 4px; font-size: 11px; }
.chat-msg .proposed-actions.hidden { display: none; }
.chat-msg .tool-indicator { font-size: 11px; opacity: 0.75; margin: 2px 0 2px 4px; font-family: var(--mono); }
.stream-cursor { display: inline-block; animation: chat-blink 1s infinite; opacity: 0.7; }
@keyframes chat-blink { 50% { opacity: 0; } }
#chat-form { display: flex; gap: 10px; align-items: flex-end; }
#chat-form textarea { flex: 1; background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px; font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 56px; }
#chat-form button { background: var(--accent); color: #0f1115; border: 0;
  padding: 9px 18px; border-radius: 6px; cursor: pointer; font-weight: 600; }

/* M12c keyboard hotkey UI — focused row + help overlay */
tr.hotkey-focused td { background: rgba(120, 170, 240, 0.12); }
tr.hotkey-focused td:first-child { border-left: 2px solid var(--accent); padding-left: 6px; }

.hotkey-help { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; }
.hotkey-help.hidden { display: none; }
.hotkey-help-inner { background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 22px 28px; min-width: 360px; max-width: 90vw;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); }
.hotkey-help-inner h2 { margin: 0 0 14px; font-size: 16px; }
.hotkey-help-inner table { border-spacing: 0 4px; width: 100%; }
.hotkey-help-inner th { text-align: left; font-weight: normal; padding-right: 16px;
  vertical-align: top; }
.hotkey-help-inner td { color: var(--muted); }
.hotkey-help-inner kbd { background: var(--bg); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 6px; font-family: var(--mono); font-size: 12px;
  color: var(--fg); }
.hotkey-help-inner p { margin: 14px 0 0; }

/* M14a calendar conflict warning — surfaced on create_calendar_event details */
.conflict-warning { background: rgba(220, 150, 60, 0.08);
  border-left: 3px solid #d2935a; padding: 10px 12px; border-radius: 4px;
  margin: 14px 0; }
.conflict-warning strong { color: #d2935a; display: block; margin-bottom: 6px; }
.conflict-warning ul { margin: 0; padding-left: 18px; }
.conflict-warning li { margin: 3px 0; }
.conflict-summary { font-weight: 600; }

/* M12d ask-box — "tell the assistant" textarea on the actions page */
.ask-box { background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 14px; margin-bottom: 14px; }
.ask-box form { display: flex; flex-direction: column; gap: 8px; }
.ask-label { font-weight: 600; }
.ask-box textarea { background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 4px; font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 56px; }
.ask-row { display: flex; gap: 14px; align-items: center; justify-content: flex-end; }
.ask-priority { display: flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ask-priority select { background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 4px; }
.ask-box button { background: var(--accent); color: #0f1115; border: 0;
  padding: 6px 14px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.ask-status.ok { background: rgba(120, 200, 130, 0.08); border-left: 3px solid #78c882;
  padding: 8px 10px; border-radius: 4px; margin-top: 4px;
  display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.ask-status.ok strong { color: #78c882; }
.htmx-request .ask-box, .ask-box.htmx-request { opacity: 0.7; transition: opacity 150ms ease; }
