/* Modus dashboard: shared layout and parts (see SPEC.md). Same brand as the homepage:
   Cream background, Charcoal text, Oxblood brand; Sage = Allow / running, Ochre = Ask first / waiting,
   Plum = Never / blocked / paused. Color is never used alone: every status also has its word. */

:root {
  --font-heading: "Fraunces", Georgia, serif;
  --font-body: "Instrument Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --cream: #FBF7F0;
  --cream-tint: #F6F0E6;
  --cream-chip: #F3ECE2;
  --line: #E8DFD3;
  --line-soft: #F1E9DD;
  --line-strong: #CFC3B4;
  --white: #FFFFFF;

  --charcoal: #1C1A19;
  --text-2: #4F4C49;
  --text-3: #63605C;

  --oxblood: #8C1C24;
  --oxblood-hover: #731720;
  --oxblood-soft: #F3E3E3;

  --ok: #3D6340;    --ok-bg: #E3EDE2;   --sage: #4F7A52;
  --ask: #7A5913;   --ask-bg: #F6EBD2;  --ochre: #B7861F;
  --never: #5B3E73; --never-bg: #EDE6F2;

  /* Roles that differ between the light and dark themes */
  --field: #FFFFFF;                 /* inputs and the message bar */
  --primary-bg: #8C1C24;            /* main buttons */
  --primary-bg-hover: #731720;
  --on-primary: #FBF7F0;
  --ok-fill: #3D6340;               /* solid green buttons (Resume) */
  --me-bubble: #1C1A19;             /* your own chat messages */
  --me-bubble-text: #FBF7F0;
  --ask-card-bg: #FBF4E4;           /* Ask first requests */
  --ask-card-line: #E9D9B4;
  --done-bg: #FAFDF9;               /* success panels */
  --done-line: #CFE0CD;
  --picked-bg: #FFFCFA;             /* a picked choice card */
  --danger-line: #CDB8DA;           /* Delete, Disconnect, Clear */
  --pause-bg: #1C1A19;              /* the big Pause button */
  --pause-text: #FBF7F0;
  --pause-line: #1C1A19;
  --topbar-bg: rgba(251, 247, 240, 0.94);
  --shadow: rgba(28, 26, 25, 0.12);
  --backdrop: rgba(28, 26, 25, 0.35);
  --code-bg: #121110;
  --code-text: #E8E4DF;
  color-scheme: light;

  --sidebar: 252px;
  --topbar: 64px;
}

/* Dark theme (the default; theme.js sets data-theme before the page paints).
   Every text color here passes 4.5 to 1 on the backgrounds it is used on. */
:root[data-theme="dark"] {
  --cream: #141312;
  --cream-tint: #1A1817;
  --cream-chip: #2A2725;
  --line: #2E2B29;
  --line-soft: #262321;
  --line-strong: #45403C;
  --white: #1E1C1A;

  --charcoal: #ECE6DC;
  --text-2: #BFB8AE;
  --text-3: #9F988F;

  --oxblood: #E8737A;
  --oxblood-hover: #F0888E;
  --oxblood-soft: #3A1F21;

  --ok: #93C496;    --ok-bg: #1D2B1E;   --sage: #6FA273;
  --ask: #E2B65C;   --ask-bg: #33290F;  --ochre: #D19E35;
  --never: #C9AEE3; --never-bg: #2A2135;

  --field: #171514;
  --primary-bg: #A1252F;
  --primary-bg-hover: #B52D38;
  --on-primary: #FBF7F0;
  --ok-fill: #4A7A4E;
  --me-bubble: #43252A;
  --me-bubble-text: #F4ECE2;
  --ask-card-bg: #2A2312;
  --ask-card-line: #4A3B1C;
  --done-bg: #18201A;
  --done-line: #2C3D2D;
  --picked-bg: #2A1D1E;
  --danger-line: #4A3A5A;
  --pause-bg: #3B3633;
  --pause-text: #F4ECE2;
  --pause-line: #6A625B;
  --topbar-bg: rgba(20, 19, 18, 0.92);
  --shadow: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(0, 0, 0, 0.6);
  --code-bg: #0D0C0B;
  --code-text: #E8E4DF;
  color-scheme: dark;
}
/* Logos drawn in black or very dark colors are lightened on the dark theme */
:root[data-theme="dark"] img[src$="03-openai.svg"],
:root[data-theme="dark"] img[src$="14-langgraph.svg"] { filter: invert(1) hue-rotate(180deg) brightness(1.05); }

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--cream); color: var(--charcoal);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--oxblood); }
a:hover { color: var(--oxblood-hover); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 2px; }
::placeholder { color: var(--text-3); opacity: 1; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell: sidebar + (top bar and page) ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; flex: 0 0 var(--sidebar); min-width: 0; /* a long email can't widen it */
  background: var(--cream-tint); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px; padding: 16px 12px;
}
.workspace {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 8px 10px;
  background: transparent; border: 1px solid transparent; border-radius: 12px; cursor: pointer; text-align: left;
}
.workspace:hover { background: var(--white); border-color: var(--line); }
.workspace-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.workspace-text strong { font-family: var(--font-heading); font-weight: 600; font-size: 17px; }
.workspace-text span { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caret { margin-left: auto; color: var(--text-3); font-size: 12px; }

.nav { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; margin: 0 -4px; padding: 0 4px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px;
  padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--text-2); font-size: 15px; font-weight: 500;
}
.nav a:hover { background: var(--white); color: var(--charcoal); }
.nav a[aria-current="page"] { background: var(--white); color: var(--charcoal); font-weight: 600; box-shadow: inset 3px 0 0 var(--oxblood); }
.nav-group { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); padding: 16px 12px 6px; letter-spacing: 0.04em; }
.nav-bottom { flex: none; overflow: visible; padding-top: 8px; border-top: 1px solid var(--line); }
.nav .count { font-family: var(--font-mono); font-size: 12px; font-weight: 600; background: var(--ask-bg); color: var(--ask); padding: 1px 8px; border-radius: 999px; }
.nav .later { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); border: 1px solid var(--line-strong); padding: 0 6px; border-radius: 999px; }

.user {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 10px;
  background: var(--white); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; text-align: left;
}
.user:hover { border-color: var(--line-strong); }
.user-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-text span { font-size: 12px; color: var(--text-3); }
.user-wrap { position: relative; }
.popover.account-menu { bottom: calc(100% + 8px); top: auto; left: 0; right: auto; width: 100%; min-width: 230px; }
.account-menu .menu-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); padding: 8px 10px 4px; }
.account-menu .signed-in { margin: 0; padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); }
.account-menu .signed-in .menu-label { display: block; }
.account-menu .signed-in-email { display: block; padding: 0 10px; font-size: 14px; overflow-wrap: anywhere; }
.theme-options { display: flex; flex-direction: column; gap: 2px; padding: 0 2px 6px; margin: 0; border: 0; min-width: 0; }
.theme-options legend { padding: 8px 10px 4px; }
.theme-options label { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.theme-options label:hover { background: var(--cream-tint); }
.theme-options input { accent-color: var(--oxblood); width: 16px; height: 16px; }
.account-menu .menu-item { display: flex; align-items: center; width: 100%; min-height: 44px; padding: 6px 10px; border: 0; border-top: 1px solid var(--line-soft); background: transparent; text-align: left; font-size: 14px; cursor: pointer; border-radius: 0 0 10px 10px; color: var(--charcoal); }
.account-menu .menu-item:hover { background: var(--cream-tint); }
a.menu-item { text-decoration: none; } /* Sign out is a link when there is a sign-in to end */
.avatar-sm {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--charcoal); color: var(--cream); font-family: var(--font-mono); font-size: 12px; font-weight: 600;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* Top bar: menu (phone), search, command bar, alerts, approvals */
.topbar {
  position: sticky; top: 0; z-index: 15; height: var(--topbar);
  display: flex; align-items: center; gap: 10px; padding: 0 24px;
  background: var(--topbar-bg); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.menu-btn { display: none !important; }
.search { position: relative; flex: 1 1 auto; max-width: 420px; }
.search input {
  width: 100%; min-height: 40px; padding: 8px 12px 8px 36px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--field); font-size: 15px;
}
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 10px;
  background: transparent; border: 1px solid transparent; cursor: pointer; color: var(--charcoal); text-decoration: none;
}
.icon-btn:hover { background: var(--white); border-color: var(--line); color: var(--charcoal); }
.cmd-icon { display: none; }
.kbd { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); border: 1px solid var(--line-strong); border-radius: 6px; padding: 1px 6px; background: var(--white); }
.bell-dot { position: absolute; top: 9px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--oxblood); border: 2px solid var(--cream); }
.approvals-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 12px; border-radius: 999px;
  font-size: 14px; font-weight: 600; text-decoration: none; background: var(--white); color: var(--text-2); border: 1px solid var(--line-strong);
}
.approvals-chip.waiting { background: var(--ask-bg); color: var(--ask); border-color: var(--ask-card-line); }
.approvals-chip:hover { color: var(--charcoal); }

/* Popover under the bell */
.bell-wrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 25; width: 320px; max-width: calc(100vw - 32px);
  background: var(--white); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 40px var(--shadow); padding: 8px;
}
.popover h2 { font-family: var(--font-mono); font-size: 11px; font-weight: 500; color: var(--text-3); padding: 8px 10px 4px; }
.popover ul { margin: 0; padding: 0; }
.popover li { list-style: none; display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 10px; font-size: 14px; }
.popover .dot { margin-top: 7px; }

.page { padding: 32px 24px 72px; }
.page-inner { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* Page header */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.page-head-copy { display: flex; flex-direction: column; gap: 8px; }
.sample { font-family: var(--font-mono); font-size: 12px; color: var(--oxblood); }
.page-head h1 { font-family: var(--font-heading); font-weight: 600; font-size: 38px; line-height: 1.1; letter-spacing: -0.6px; }
.page-head p { color: var(--text-2); max-width: 600px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  font-size: 15px; font-weight: 600; text-decoration: none;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--primary-bg); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-bg-hover); color: var(--on-primary); }
.btn-primary:disabled, .btn-primary[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-outline { background: var(--white); color: var(--charcoal); border-color: var(--line-strong); }
.btn-outline:hover { background: var(--cream-tint); color: var(--charcoal); }
.btn.danger { color: var(--never); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--never-bg); color: var(--never); }

/* Status pills: always a word, never color alone */
.pill { display: inline-block; font-family: var(--font-mono); font-size: 11px; font-weight: 600; line-height: 1.5; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-ask { background: var(--ask-bg); color: var(--ask); }
.pill-never { background: var(--never-bg); color: var(--never); }
.pill-idle { background: var(--cream-chip); color: var(--text-3); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line-strong); }
.dot-ok { background: var(--sage); }
.dot-ask { background: var(--ochre); }
.dot-never { background: var(--never); }

/* Segmented filter (All / On a team / Solo) and selects */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--white); border: 1px solid var(--line); border-radius: 999px; }
.segmented button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 14px; border-radius: 999px;
  border: 0; background: transparent; font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.segmented button .mono { font-size: 12px; color: var(--text-3); }
.segmented button[aria-pressed="true"] { background: var(--charcoal); color: var(--cream); }
.segmented button[aria-pressed="true"] .mono { color: var(--line-strong); }
.select {
  min-height: 44px; padding: 8px 34px 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23928B83' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none; font-size: 14px; cursor: pointer;
}

/* "What's this?" tips: a real term with a plain explanation next to it */
.tip { position: relative; display: inline-flex; vertical-align: middle; margin-left: 4px; }
.tip-btn {
  position: relative; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--white);
  font-family: var(--font-mono); font-size: 11px; line-height: 1; color: var(--text-3); cursor: pointer; padding: 0;
}
.tip-btn::after { content: ""; position: absolute; inset: -13px; } /* 44px touch target */
.tip-text {
  position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 30; width: 240px;
  background: var(--charcoal); color: var(--cream); font-family: var(--font-body); font-size: 13px; font-weight: 400;
  text-transform: none; letter-spacing: 0; line-height: 1.45; padding: 10px 12px; border-radius: 10px; white-space: normal;
}

/* Cards and tables */
.card { background: var(--white); border: 1px solid var(--line); border-radius: 18px; }
.table-box { background: var(--white); border: 1px solid var(--line); border-radius: 18px; overflow-x: auto; }
.meter { display: block; height: 6px; border-radius: 4px; background: var(--line-soft); margin-top: 5px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 4px; background: var(--sage); }
.meter.warn span { background: var(--ochre); }
.meter.stop span { background: var(--never); }
.help { font-size: 13px; color: var(--text-3); }

/* Real or sample (boot.js sets html[data-mode]). Sample labels and notes show only with sample data,
   and nothing that says "sample" shows before the page knows which it is. */
html:not([data-mode="sample"]) .sample,
html:not([data-mode="sample"]) .sample-only { display: none !important; }
html:not([data-mode="real"]) .real-only { display: none !important; }

/* A feature the server doesn't have yet */
.soon-card { padding: 24px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; border-style: dashed; background: var(--cream-tint); }
.soon-card h3 { font-size: 16px; display: flex; align-items: center; gap: 10px; }
.soon-card p { color: var(--text-2); font-size: 14px; max-width: 620px; }
.soon { font-family: var(--font-mono); font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--cream-chip); color: var(--text-3); white-space: nowrap; }
.muted { color: var(--text-3); }
.field-error { font-size: 13px; font-weight: 600; color: var(--never); }
.field-error:empty { display: none; }
.popover-note { padding: 6px 10px 10px; font-size: 14px; color: var(--text-2); }

/* Login (real mode) */
.login-screen { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: var(--cream); }
.login-card { width: min(400px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 10px; }
.login-logo { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-heading); font-size: 20px; }
.login-card h1 { font-family: var(--font-heading); font-weight: 600; font-size: 30px; margin-top: 6px; }
.login-card label { font-size: 14px; font-weight: 600; margin-top: 6px; }
.login-card input { min-height: 48px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field); font-size: 16px; }
.login-card input[aria-invalid="true"] { border-color: var(--never); }
.login-card .btn { margin-top: 6px; }

.logged-out-bar {
  position: fixed; left: 16px; right: 16px; top: 12px; margin: 0 auto; width: fit-content; z-index: 55; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 12px; border: 1px solid var(--ask-card-line);
  background: var(--ask-card-bg); color: var(--charcoal); box-shadow: 0 12px 32px var(--shadow); font-size: 14px;
}
.logged-out-bar .btn { min-height: 36px; padding: 6px 14px; font-size: 14px; flex: none; }
.logged-out-bar .bar-close { flex: none; min-width: 36px; min-height: 36px; font-size: 20px; color: var(--text-2); }
@media (max-width: 600px) { .logged-out-bar { top: 8px; font-size: 13px; } .logged-out-bar .btn, .logged-out-bar .bar-close { min-height: 44px; } }
.signin-bar { z-index: 65; } /* above the login screen, which can't work until this is fixed */
.boot-error { grid-column: 1 / -1; padding: 32px 24px; }
.dup-id { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 6px; }

/* A failed load: logged out, or the server had a problem */
.error-card { padding: 28px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.error-card h2 { font-family: var(--font-heading); font-weight: 600; font-size: 26px; }
.error-card p { color: var(--text-2); max-width: 560px; }
.loading { color: var(--text-3); font-size: 14px; padding: 8px 0; }

/* Command bar (Cmd+K / Ctrl+K) */
.cmd-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--backdrop); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.cmd {
  width: 100%; max-width: 560px; background: var(--white); border-radius: 16px; overflow: hidden;
  box-shadow: 0 24px 60px var(--shadow); border: 1px solid var(--line);
}
.cmd input { width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 16px 18px; font-size: 17px; outline: none; }
.cmd ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.cmd li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.cmd li[aria-selected="true"] { background: var(--cream-tint); }
.cmd li .kind { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.cmd .cmd-empty { padding: 16px 18px; color: var(--text-3); font-size: 14px; }
.cmd-foot { padding: 8px 14px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--text-3); display: flex; gap: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--charcoal); color: var(--cream); padding: 12px 18px; border-radius: 12px;
  font-size: 14px; box-shadow: 0 12px 32px var(--shadow); max-width: calc(100vw - 32px);
}

/* Phone and small tablet: the sidebar becomes a slide-in menu */
.scrim { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 35; left: 0; top: 0; width: min(300px, 85vw); height: 100%;
    transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility .2s;
    box-shadow: 0 0 40px var(--shadow);
  }
  body.menu-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease, visibility 0s; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 34; background: var(--backdrop); }
  .menu-btn { display: inline-flex !important; }
  .topbar { padding: 0 12px; gap: 4px; }
  .search { max-width: none; }
  .kbd, .approvals-chip .label { display: none; }
  .cmd-icon { display: inline-flex; }
  .page { padding: 24px 16px 64px; }
  .page-head h1 { font-size: 32px; }
}
@media (max-width: 520px) {
  .search { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, body.menu-open .sidebar { transition: none; }
}
