:root {
  --ink: #1C1B17;
  --graphite: #3B3933;
  --paper: #FBFAF6;
  --panel: #FFFFFF;
  --card-2: #F3F2EC;
  --jade: #5C7C63;
  --jade-bright: #6E9173;
  --jade-soft: #E6EBE2;
  --jade-line: #CFE3D9;
  --amber: #977A3C;
  --amber-soft: #EDE6D3;
  --amber-line: #DCD2B7;
  --red: #9C544A;
  --red-soft: #ECDED9;
  --red-line: #DCC8C1;
  --muted: #6F6D63;
  --muted-2: #9D9B90;
  --line: #E7E5DC;
  --primary: #5C7C63;
  --bg: #FBFAF6;
  --soft: #E6EBE2;
  --r: 10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(28, 27, 23, 0.05);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  font-family: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }

/* ============================ app shell ============================ */
.app { display: flex; min-height: 100vh; }
.device { width: 248px; flex: 0 0 248px; background: var(--panel); display: flex; flex-direction: column; padding: 24px 14px; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; color: var(--ink); }
.seal-logo { width: 34px; height: 34px; flex: 0 0 34px; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.12; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.2px; }
.brand-sub { font-size: 10px; color: var(--muted-2); font-family: var(--mono); letter-spacing: 1.5px; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 1px; margin-top: 2px; }
.nav-label { font-size: 10px; letter-spacing: 1.6px; color: var(--muted-2); font-family: var(--mono); padding: 14px 11px 6px; text-transform: uppercase; }
.nav-btn { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: var(--graphite); font-size: 14px; font-weight: 500; transition: background 0.16s, color 0.16s; }
.nav-btn svg { width: 18px; height: 18px; flex: 0 0 18px; stroke-width: 1.6; }
.nav-btn:hover { background: var(--card-2); }
.nav-btn.active { background: var(--ink); color: var(--paper); }
.nav-btn.active svg { stroke: var(--paper); }
.device-foot { margin-top: auto; padding-top: 16px; }
.status { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; font-size: 12px; color: var(--muted); }
.status-row { display: flex; align-items: center; gap: 8px; }
.status-row + .status-row { margin-top: 7px; }
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--jade); flex: 0 0 7px; }

.surface { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 15px 30px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; margin: 0; }
.pill--local { margin-left: auto; }
.pill--local svg { width: 14px; height: 14px; }
.scroll { flex: 1; overflow-y: auto; background-color: var(--paper); background-image: radial-gradient(circle, rgba(28, 27, 23, 0.045) 1px, transparent 1.4px); background-size: 23px 23px; }
.wrap, .container { max-width: 1040px; margin: 0 auto; padding: 28px 30px 110px; }

.tabbar { display: none; }

/* ============================ typography ============================ */
h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); margin: 0 0 8px; letter-spacing: -0.03em; font-weight: 700; }
h2 { margin-top: 0; letter-spacing: -0.02em; font-weight: 600; font-size: 1.35rem; }
h3, h4, h5 { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
code { font-family: var(--mono); background: var(--card-2); padding: 2px 6px; border-radius: 6px; font-size: 0.85em; color: var(--graphite); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.72rem; color: var(--muted); font-weight: 600; font-family: var(--mono); margin-bottom: 8px; }
.page-heading { max-width: 820px; margin-bottom: 20px; }

/* ============================ cards / panels ============================ */
.card, .panel, .empty-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow); }
.panel-header { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 4px; }
.card-header { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.company-card { transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s; }
.company-card:hover { transform: translateY(-3px); box-shadow: 0 6px 22px rgba(28, 27, 23, 0.07); border-color: #D2CEC0; }

/* ============================ pills / tags ============================ */
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--jade-soft); color: #4A6651; border: 1px solid var(--jade-line); border-radius: 6px; padding: 4px 10px; font-size: 0.78rem; font-weight: 600; }
.pill--active { background: var(--jade-soft); color: #4A6651; border-color: var(--jade-line); }
.pill--forming { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }

/* ============================ buttons ============================ */
.button, button { border: 1px solid var(--line); border-radius: 10px; padding: 10px 15px; background: var(--panel); color: var(--ink); cursor: pointer; font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; transition: background 0.14s, border-color 0.14s, filter 0.14s; }
.button:hover, button:hover { background: var(--card-2); }
button.primary, .button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary:hover, .button.primary:hover { background: var(--graphite); }
button.secondary, .button.secondary { background: var(--graphite); color: var(--paper); border-color: var(--graphite); }
button.secondary:hover, .button.secondary:hover { background: var(--ink); }
.button.danger, button.danger { background: #fff; color: var(--red); border-color: var(--red-line); }
.button.danger:hover, button.danger:hover { background: var(--red-soft); }
button.big { min-height: 46px; font-weight: 700; }
.button.small, a.button.small { padding: 5px 11px; font-size: 0.82rem; border-radius: 8px; }

/* Modal (e.g. "add your signature to sign" upload prompt) */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(28, 27, 23, 0.45); }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; max-width: 440px; width: 100%; box-shadow: 0 24px 70px rgba(28, 27, 23, 0.25); }
.modal h3 { margin: 0 0 8px; }
.modal p { color: var(--muted); margin: 0 0 18px; font-size: 0.95rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ============================ forms ============================ */
label { display: grid; gap: 6px; color: var(--graphite); font-weight: 600; font-size: 0.9rem; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--jade); box-shadow: 0 0 0 3px var(--jade-soft); }
textarea { resize: vertical; }
.checkbox { display: flex; gap: 8px; align-items: center; color: var(--ink); font-weight: 500; }
.checkbox input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.executed { align-self: center; margin-bottom: 11px; }
.file-drop input { padding: 9px; }

/* ============================ tables ============================ */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 11px 8px; vertical-align: top; }
th { color: var(--muted); font-size: 0.74rem; font-family: var(--mono); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 500; }
dl { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; }
dt { color: var(--muted); }
dd { margin: 0; }

/* ============================ stats / hero ============================ */
.hero, .company-hero { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.company-hero.compact h2 { margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 15px 16px; }
.stats span { color: var(--muted); display: block; font-size: 0.78rem; font-family: var(--mono); letter-spacing: 0.04em; }
.stats strong { display: block; margin-top: 5px; font-weight: 600; }
.two-col { display: grid; grid-template-columns: minmax(300px, 0.9fr) minmax(300px, 1.1fr); gap: 16px; align-items: start; margin-bottom: 16px; }

/* ============================ company page tabs ============================ */
.page-tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 4px 0 22px; }
.page-tab { background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px 16px; font-weight: 600; font-size: 0.95rem; color: var(--muted); cursor: pointer; }
.page-tab:hover { color: var(--ink); }
.page-tab.active { color: var(--ink); border-bottom-color: var(--jade); }
.page-tab .pill { margin-left: 6px; }
.tab-panel[hidden] { display: none; }

/* ============================ documents sub-tabs ============================ */
.doc-tabbar { display: flex; gap: 6px; flex-wrap: wrap; }
.doc-tab { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-weight: 600; font-size: 0.85rem; }
.doc-tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.doc-tab .pill { background: rgba(251, 250, 246, 0.2); color: inherit; margin-left: 4px; border: none; }
.doc-tab:not(.active) .pill { background: var(--panel); color: var(--muted); }

/* ============================ "I need" bar ============================ */
.need-bar { margin-bottom: 24px; }
.need-bar-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 14px; box-shadow: var(--shadow); }
.need-bar-label { font-weight: 600; color: var(--jade); white-space: nowrap; padding-left: 4px; font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0.06em; text-transform: uppercase; }
.need-bar-row textarea { min-height: 42px; }
.need-result { margin: 10px 0 0; padding: 12px 14px; background: var(--jade-soft); border: 1px solid var(--jade-line); border-radius: 12px; }
.need-result .button.big { margin-top: 4px; }
.need-links { margin: 10px 2px 0; }
.need-links a { color: var(--jade); font-weight: 600; }
.need-links a:hover { text-decoration: underline; }

/* ============================ to-do ============================ */
.todo-panel { border-left: 3px solid var(--amber); }
.todo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.todo-item { display: flex; justify-content: space-between; gap: 14px; align-items: start; padding: 13px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card-2); }
.todo-main { min-width: 0; }
.todo-how { margin-top: 6px; }
.todo-how summary { cursor: pointer; color: var(--jade); font-size: 0.85rem; font-weight: 600; }
.todo-how > div { margin-top: 6px; font-size: 0.9rem; color: var(--graphite); }
.todo-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.todo-actions form { margin: 0; }
/* Difficulty cue: green = do it yourself, amber = some work, red = may need a pro. */
.todo-item.diff-easy { border-left: 3px solid var(--jade); }
.todo-item.diff-moderate { border-left: 3px solid var(--amber); }
.todo-item.diff-hard { border-left: 3px solid var(--red); }
.diff-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; margin-left: 4px; white-space: nowrap; }
.diff-tag .d { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.diff-tag.easy { background: var(--jade-soft); color: var(--jade); }
.diff-tag.easy .d { background: var(--jade); }
.diff-tag.moderate { background: var(--amber-soft); color: var(--amber); }
.diff-tag.moderate .d { background: var(--amber); }
.diff-tag.hard { background: var(--red-soft); color: var(--red); }
.diff-tag.hard .d { background: var(--red); }

/* ============================ documents tables ============================ */
[data-doc-tabs] table { table-layout: auto; }
[data-doc-tabs] th:first-child, [data-doc-tabs] td:first-child { white-space: nowrap; width: 1%; }
[data-doc-tabs] td:nth-child(2) { max-width: 200px; }
[data-doc-tabs] td:nth-child(2) code { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
[data-doc-tabs] td:nth-child(3) { max-width: 190px; overflow-wrap: anywhere; }
[data-doc-tabs] th:last-child, [data-doc-tabs] td:last-child { white-space: nowrap; text-align: right; }
.doc-actions { white-space: nowrap; text-align: right; }
.doc-actions > a, .doc-actions > form, .doc-actions > span { display: inline-block; vertical-align: middle; }
.doc-actions > * + * { margin-left: 6px; }
.doc-actions form { margin: 0; }
.doc-locked { color: var(--muted); font-size: 0.82rem; }
.doc-await { color: var(--amber); font-size: 0.82rem; font-weight: 600; }

/* ============================ signature box ============================ */
.sig-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card-2); }
.sig-box.missing { background: var(--amber-soft); border-color: var(--amber-line); }
.sig-box form { margin: 0; display: flex; align-items: center; gap: 8px; }
.sig-thumb { height: 40px; max-width: 200px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; object-fit: contain; }

/* ============================ agent status bar ============================ */
.agent-status-panel { border-left: 3px solid var(--jade); }
.agent-status-panel.settled { border-left-color: var(--jade); }
.agent-status-head { display: flex; align-items: center; gap: 10px; }
.agent-status-line { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--jade); border-radius: 50%; display: inline-block; animation: cs-spin 0.8s linear infinite; flex: none; }
.agent-status-panel.settled .agent-spinner { display: none; }
@keyframes cs-spin { to { transform: rotate(360deg); } }
.agent-steps { margin-top: 10px; }
.agent-steps summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.agent-steps ol { margin: 8px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.85rem; display: grid; gap: 4px; }
.agent-final { margin-top: 12px; padding: 14px; background: var(--jade-soft); border: 1px solid var(--jade-line); border-radius: 12px; white-space: pre-wrap; line-height: 1.5; }

/* ============================ Q&A chat ============================ */
.qa-panel { display: grid; gap: 12px; }
.chat-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 460px; overflow: auto; }
.chat-msg { padding: 10px 13px; border-radius: 12px; max-width: 85%; white-space: pre-wrap; line-height: 1.5; }
.chat-msg.chat-user { background: var(--ink); color: var(--paper); justify-self: end; }
.chat-msg.chat-assistant { background: var(--card-2); justify-self: start; }
.chat-msg.chat-thinking { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.chat-msg.chat-final { background: var(--jade-soft); border: 1px solid var(--jade-line); }
.chat-status { color: var(--muted); }
.chat-input { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.chat-input textarea { resize: vertical; }

/* rendered markdown (Q&A bubble + review box) */
.chat-rich { white-space: normal; }
.chat-rich > :first-child { margin-top: 0; }
.chat-rich > :last-child { margin-bottom: 0; }
.chat-rich p { margin: 0 0 8px; }
.chat-rich h3, .chat-rich h4, .chat-rich h5, .chat-rich h6 { margin: 10px 0 4px; font-size: 1rem; letter-spacing: -0.01em; }
.chat-rich ul, .chat-rich ol { margin: 4px 0 8px; padding-left: 20px; }
.chat-rich li { margin: 2px 0; }
.chat-rich a { color: var(--jade); text-decoration: underline; word-break: break-word; }
.chat-rich code { background: var(--card-2); }

/* ============================ intake hero ============================ */
.intake-agent-hero { display: grid; grid-template-columns: minmax(360px, 1.2fr) minmax(260px, 0.8fr); gap: 22px; align-items: stretch; margin-bottom: 24px; padding: 22px; border-radius: var(--r-lg); background: var(--card-2); border: 1px solid var(--line); color: var(--ink); }
.intake-agent-hero .eyebrow { color: var(--jade); }
.intake-copy { display: flex; flex-direction: column; justify-content: center; }
.intake-copy h1, .intake-copy h2 { max-width: 22ch; }
.intake-copy p { color: var(--graphite); font-size: 0.98rem; }
.intake-form { display: grid; gap: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.intake-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.intake-row.bottom { grid-template-columns: minmax(0, 1fr) auto; }
.intake-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }

/* ============================ templates picker ============================ */
.template-search { display: grid; gap: 6px; margin-bottom: 16px; }
.template-search input[type="search"] { max-width: 560px; }
.template-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.template-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; padding: 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); box-shadow: var(--shadow); transition: border-color 0.16s, box-shadow 0.16s, transform 0.16s; }
.template-card:hover { border-color: var(--jade); box-shadow: 0 6px 22px rgba(28, 27, 23, 0.07); transform: translateY(-2px); }
.template-card[hidden] { display: none; }
.template-card h4 { margin: 4px 0; }
.template-card .template-meta p { margin: 2px 0; }

/* ============================ fill / profile tables ============================ */
.fill-table, .profile-table { width: 100%; }
.fill-table input, .fill-table textarea, .profile-table input, .profile-table textarea { font-family: inherit; }
.profile-form .profile-table input[readonly] { background: var(--card-2); }
.fill-table td:first-child, .profile-table td:first-child { width: 30%; min-width: 200px; }
.fill-table td:last-child { width: 140px; }

/* ============================ misc panels ============================ */
.recent-wiki-panel { margin: 0 0 24px; }
.recent-wiki { max-height: 460px; }
.intake-transcript-panel { margin: 0 0 24px; }
.intake-transcript { display: grid; gap: 10px; margin: 0; padding-left: 22px; }
.intake-transcript li { padding: 10px 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; }
.intake-transcript li.final { background: var(--jade-soft); border-color: var(--jade-line); font-weight: 700; }
.telegram-panel { margin-bottom: 24px; }
.telegram-config-grid { margin-top: 14px; }
.wiki { white-space: pre-wrap; background: var(--card-2); border: 1px solid var(--line); color: var(--graphite); padding: 14px; border-radius: 12px; max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 0.84rem; }

/* ============================ responsive ============================ */
@media (max-width: 900px) {
  .device { display: none; }
  .wrap, .container { padding: 24px 16px 96px; }
  .topbar { padding: 13px 18px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); overflow-x: auto; }
  .tab { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 12px; color: var(--muted); font-size: 10.5px; font-weight: 600; border-radius: 10px; white-space: nowrap; }
  .tab svg { width: 20px; height: 20px; stroke-width: 1.7; }
  .tab.active { background: var(--ink); color: var(--paper); }
  .tab.active svg { stroke: var(--paper); }
  .form-grid, .two-col, .intake-agent-hero, .intake-row, .intake-row.bottom, .template-card, .chat-input, .cards { grid-template-columns: 1fr; }
  .hero, .company-hero { flex-direction: column; align-items: flex-start; }
  .intake-agent-hero .intake-copy { order: -1; }
}
@media (max-width: 680px) {
  .todo-item { flex-direction: column; align-items: stretch; gap: 10px; }
  .todo-actions { flex-wrap: wrap; justify-content: flex-start; }
}
@media (max-width: 560px) {
  .need-bar-row { grid-template-columns: auto 1fr; }
  .need-bar-row button { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { *, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; } }
