:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #18212b; --muted: #687587; --line: #e3e7ec;
  --brand: #0f766e; --brand-ink: #fff; --brand-soft: #e6f4f2;
  --danger: #c2410c; --danger-soft: #fdece4; --good: #15803d; --warn: #b45309;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .1rem 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .nowrap { white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: .82rem; margin-top: 2px; }
.empty { color: var(--muted); padding: .75rem 0; margin: 0; }
.hint { color: var(--muted); font-size: .85rem; margin: -.25rem 0 1rem; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #0d1b26; color: #c9d3dd; display: flex; flex-direction: column; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-size: 1.05rem; padding: .25rem .5rem 1.25rem; }
.brand:hover { text-decoration: none; }
.brand.big { color: var(--ink); font-size: 1.3rem; justify-content: center; padding-bottom: 1rem; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a, .sidebar .who { color: #c9d3dd; padding: .55rem .7rem; border-radius: 8px; display: flex; align-items: center; gap: .5rem; }
.sidebar nav a:hover, .sidebar .who:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.sidebar nav a.active, .sidebar .who.active { background: rgba(20,184,166,.18); color: #fff; }
.me { border-top: 1px solid rgba(255,255,255,.1); padding-top: .75rem; }
.me form { padding: 0 .7rem; }
.me .link { color: #8c9aa8; }
main { padding: 1.5rem 2rem 3rem; max-width: 1400px; width: 100%; min-width: 0; }

/* bits */
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-grid; place-items: center; font-size: .72rem; font-weight: 700; flex: none; vertical-align: middle; }
.avatar.sm { width: 22px; height: 22px; font-size: .62rem; }
.sidebar .avatar { background: var(--brand); color: #fff; }
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: .5rem .9rem; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f3f5; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #0b5f58; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; justify-content: center; padding: .7rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
button.link.danger { color: var(--danger); font-size: .8rem; margin-left: .4rem; }
.flash { background: var(--brand-soft); color: #134e4a; border: 1px solid #b7e1db; padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; }
.flash.error { background: var(--danger-soft); color: #9a3412; border-color: #f7c8b2; }
.nudge { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.nudge-actions { display: flex; gap: .75rem; align-items: center; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.crumb { font-size: .82rem; color: var(--muted); }
.amount { font-size: 1.15rem; font-weight: 600; color: var(--good); margin-top: .2rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg a { padding: .45rem .8rem; color: var(--muted); }
.seg a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.seg a:hover { text-decoration: none; }

.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef1f4; color: #475467; white-space: nowrap; }
.sg-lead { background: #eef2ff; color: #4338ca; } .sg-qualified { background: #e0f2fe; color: #0369a1; }
.sg-proposal { background: #fef3c7; color: #92400e; } .sg-negotiation { background: #fae8ff; color: #86198f; }
.sg-won { background: #dcfce7; color: #166534; } .sg-lost { background: #f1f5f9; color: #64748b; }
.st-todo { background: #eef1f4; color: #475467; } .st-in_progress { background: #e0f2fe; color: #0369a1; } .st-done { background: #dcfce7; color: #166534; }
.prio { font-size: .78rem; font-weight: 600; }
.prio::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; background: currentColor; }
.p-high { color: #dc2626; } .p-medium { color: var(--warn); } .p-low { color: #64748b; }
.overdue { color: #dc2626; font-weight: 600; } .today { color: var(--warn); font-weight: 600; }

/* tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.panel .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.check { width: 34px; }
td.check input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; }
tr.is-done .task-title, tr.is-done td:first-child a { color: var(--muted); text-decoration: line-through; }
.task-title { color: var(--ink); font-weight: 500; }

/* forms */
.search, .filters input[type=search] { width: 100%; max-width: 420px; }
input, select, textarea { font: inherit; padding: .5rem .65rem; border: 1px solid #cfd6de; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,118,110,.25); border-color: var(--brand); }
.search { margin-bottom: 1rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters select { width: auto; }
.filters input[type=search] { flex: 1; min-width: 180px; }
.form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.25rem; max-width: 820px; box-shadow: var(--shadow); }
.form.narrow { max-width: 460px; grid-template-columns: 1fr; }
.form label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 600; color: #344054; }
.form .full { grid-column: 1 / -1; }
.form fieldset { border: 1px dashed var(--line); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0; }
.form legend { font-size: .8rem; color: var(--muted); padding: 0 .3rem; }
.with-btn { display: flex; gap: .5rem; }
.with-btn input { flex: 1; min-width: 0; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.check-label { flex-direction: row !important; align-items: center; font-weight: 500 !important; }
.check-label input { width: auto; }
.form-actions { display: flex; gap: .5rem; }

/* company lookup + website scan */
.scan-area:empty { display: none; }
.scan-area.htmx-request { position: relative; min-height: 3rem; }
.scan-area.htmx-request::after { content: "Searching…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.8); color: var(--muted); font-weight: 600; border-radius: 8px; }
.lookup-results { display: flex; flex-direction: column; gap: .5rem; font-weight: 400; }
.cand { display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between; border: 1px solid var(--line); border-radius: 8px; padding: .65rem .8rem; background: #fbfcfd; }
.cand-main { min-width: 0; }
.cand-facts { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .82rem; margin-top: .35rem; overflow-wrap: anywhere; }
.site-results { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; background: #fbfcfd; }
.site-desc { margin: 0 0 .75rem; color: #344054; }
.site-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.found { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .25rem 0; font-size: .88rem; overflow-wrap: anywhere; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .2rem; }
.stat:hover { text-decoration: none; border-color: #c6d0da; }
.stat .k { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v.bad { color: #dc2626; } .stat .v.good { color: var(--good); }
.stat .sub { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.25rem; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; min-width: 0; }
.narrow-panel { max-width: 640px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; gap: .5rem; }
.panel-head a { font-size: .85rem; }
.panel .panel-head:not(:first-child) { margin-top: 1.25rem; }
.push-status { font-weight: 600; }
.help { margin-top: .75rem; font-size: .88rem; color: #344054; }
.help summary { cursor: pointer; color: var(--brand); }
.pipeline { list-style: none; margin: 0; padding: 0; }
.pipeline li { display: grid; grid-template-columns: 1fr auto auto; gap: .9rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.pipeline li:last-child { border-bottom: 0; }

/* detail */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: 1.25rem; align-items: start; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem 1.25rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1.25rem; box-shadow: var(--shadow); }
.facts dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.facts dd { margin: .2rem 0 0; overflow-wrap: anywhere; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; gap: .65rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.stage-bar { display: flex; margin: 0 0 1.25rem; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.stage-bar button { flex: 1; border: 0; border-right: 1px solid var(--line); background: transparent; padding: .55rem .25rem; font: inherit; font-size: .82rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.stage-bar button:last-child { border-right: 0; }
.stage-bar button:hover { background: #f4f6f8; }
.stage-bar button.current.sg-lead { background: #eef2ff; color: #4338ca; }
.stage-bar button.current.sg-qualified { background: #e0f2fe; color: #0369a1; }
.stage-bar button.current.sg-proposal { background: #fef3c7; color: #92400e; }
.stage-bar button.current.sg-negotiation { background: #fae8ff; color: #86198f; }
.stage-bar button.current.sg-won { background: #dcfce7; color: #166534; }
.stage-bar button.current.sg-lost { background: #e2e8f0; color: #334155; }

.notes textarea { resize: vertical; }
.note-form { display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; margin-bottom: .75rem; }
.note { border-top: 1px solid var(--line); padding: .7rem 0; }
.note-meta { font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.note-body { overflow-wrap: anywhere; line-height: 1.5; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.timeline li { display: flex; gap: .6rem; padding: .45rem 0; }
.timeline .dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; margin-top: .4rem; flex: none; }

/* kanban */
.board { display: grid; grid-template-columns: repeat(6, minmax(210px, 1fr)); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.board.three { grid-template-columns: repeat(3, minmax(240px, 1fr)); }
.col { background: #eef1f4; border-radius: var(--radius); padding: .6rem; min-height: 300px; display: flex; flex-direction: column; transition: background .12s; }
.col.drop-over { background: var(--brand-soft); outline: 2px dashed var(--brand); }
.col header { display: flex; align-items: center; gap: .4rem; padding: .2rem .2rem .6rem; font-size: .8rem; }
.col .count { color: var(--muted); font-weight: 600; }
.col .total { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.cards { display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .65rem .7rem; color: var(--ink); box-shadow: var(--shadow); cursor: grab; display: block; }
.card:hover { text-decoration: none; border-color: #b9c4cf; }
.card.dragging { opacity: .45; }
.card-title { font-weight: 600; font-size: .9rem; line-height: 1.3; }
.card-amt { color: var(--good); font-weight: 600; font-size: .85rem; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.card-meta { display: flex; align-items: center; gap: .5rem; font-size: .78rem; color: var(--muted); margin-top: .4rem; }
.card-meta .avatar { margin-left: auto; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 10px 30px rgba(16,24,40,.08); }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 600; }

/* installed app (home screen): respect the notch / home indicator */
@media (display-mode: standalone) {
  .sidebar { padding-top: max(1rem, env(safe-area-inset-top)); }
  main { padding-bottom: max(3rem, env(safe-area-inset-bottom)); }
}

/* responsive */
@media (max-width: 1100px) {
  .detail, .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .5rem 16px; gap: .25rem; }
  .brand { padding: .25rem 0; margin-right: auto; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; flex: none; }
  .sidebar nav a { padding: .4rem .6rem; font-size: .9rem; }
  .me { border: 0; padding: 0; display: flex; align-items: center; gap: .5rem; }
  .me .who span:last-child { display: none; }
  main { padding: 1rem 16px 2rem; }
  .form { grid-template-columns: 1fr; padding: 1rem; }
  .row3, .site-grid { grid-template-columns: 1fr; }
  .cand { flex-direction: column; }
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stage-bar { flex-wrap: wrap; }
  .stage-bar button { flex: 1 0 33%; border-bottom: 1px solid var(--line); }
  h1 { font-size: 1.3rem; }
}
@media (max-width: 760px) and (display-mode: standalone) {
  .sidebar { padding-top: max(.5rem, env(safe-area-inset-top)); }
}

/* ---------- AI ---------- */
.ai-card { border: 1px solid #c9e7e2; background: #f3fbf9; border-radius: 10px; padding: .8rem 1rem; margin: 0 0 1rem; }
.ai-card-head { font-weight: 700; font-size: .85rem; color: var(--brand); margin-bottom: .35rem; }
.ai-error { color: #9a3412; }
.md p { margin: .35rem 0; } .md ul, .md ol { margin: .35rem 0; padding-left: 1.3rem; } .md li { margin: .15rem 0; }
.md code { background: #eef1f4; padding: 0 .3rem; border-radius: 4px; font-size: .88em; }
.md pre { background: #0d1b26; color: #e6edf3; padding: .7rem; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; color: inherit; padding: 0; }
.narrow-text { max-width: 760px; }
.section-gap { margin-top: 2rem; margin-bottom: .75rem; }
.section-gap-b { margin-bottom: 1rem; }
.inline, .inline-form { display: inline; margin: 0; }
.inline-form { display: block; margin-top: 1rem; }

.assistant { display: grid; grid-template-columns: 240px 1fr; gap: 1.25rem; height: calc(100vh - 3rem); min-height: 520px; }
.chat-list { display: flex; flex-direction: column; gap: .3rem; overflow-y: auto; }
.chat-link { display: flex; flex-direction: column; padding: .5rem .65rem; border-radius: 8px; color: var(--ink); font-size: .88rem; }
.chat-link:hover { background: #eef1f4; text-decoration: none; }
.chat-link.on { background: var(--brand-soft); color: #134e4a; font-weight: 600; }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.chat-log { flex: 1; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.chat-empty { margin: auto; max-width: 560px; text-align: center; color: #344054; }
.suggestions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1rem; }
.chip { border: 1px solid var(--line); background: #fafbfc; border-radius: 999px; padding: .4rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; color: var(--ink); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(760px, 88%); padding: .6rem .85rem; border-radius: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: #f1f4f7; border-bottom-left-radius: 4px; }
.tool-chip { align-self: flex-start; font-size: .78rem; color: var(--muted); background: #f6f7f9; border: 1px dashed var(--line); border-radius: 999px; padding: .15rem .6rem; }
.action-card { align-self: flex-start; max-width: min(760px, 92%); border: 1px solid #f2d39b; background: #fffaf0; border-radius: 10px; padding: .7rem .85rem; display: flex; flex-direction: column; gap: .45rem; }
.action-card.st-done { border-color: #b7e1c5; background: #f3fbf5; }
.action-card.st-rejected { opacity: .7; background: #f6f7f9; border-color: var(--line); }
.action-card.st-failed { border-color: #f7c8b2; background: var(--danger-soft); }
.action-head { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--warn); }
.st-done .action-head { color: var(--good); }
.action-summary { font-weight: 600; }
.action-body { white-space: pre-wrap; font: inherit; font-size: .88rem; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .6rem; margin: 0; max-height: 260px; overflow-y: auto; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; margin-top: .6rem; }
.chat-form textarea { flex: 1; resize: none; }
.chat-form .thinking { display: none; color: var(--muted); font-size: .85rem; align-self: center; }
.chat-form.htmx-request .thinking { display: inline; }
.chat-form.htmx-request .thinking::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1.2em } }

/* ---------- inbox ---------- */
table.inbox td { vertical-align: top; }
table.inbox td.from { width: 26%; }
table.inbox tr.unread .subj, table.inbox tr.unread td.from > a { font-weight: 700; }
.subj { color: var(--ink); }
.email-head { display: grid; gap: .25rem; margin: 0 0 1rem; font-size: .9rem; }
.email-head div { display: flex; gap: .6rem; }
.email-head dt { width: 3.5rem; color: var(--muted); flex: none; }
.email-head dd { margin: 0; overflow-wrap: anywhere; }
.email-body { white-space: pre-wrap; font: inherit; line-height: 1.55; margin: 0; overflow-wrap: anywhere; max-height: 70vh; overflow-y: auto; }
.draft-form { display: flex; flex-direction: column; gap: .5rem; margin-top: .75rem; }

@media (max-width: 760px) {
  .assistant { grid-template-columns: 1fr; height: auto; }
  .chat-list { flex-direction: row; overflow-x: auto; }
  .chat-list .chat-link { min-width: 150px; }
  .chat-log { min-height: 55vh; }
  table.inbox td.from { width: auto; }
}

.link-code code { font-size: 1.5rem; letter-spacing: .08em; padding: .3rem .6rem; user-select: all; }

.map-embed { display: block; width: 100%; height: 280px; border: 0; border-radius: 10px; margin: 0 0 1rem; }
@media (max-width: 600px) { .map-embed { height: 220px; } }
