/* Gorilla CRM — charcoal command bar, off-white working area, Gorilla orange accent.
   One control height (32px), one radius family, everything centred on its row. */
:root {
  --bar: #16130F; --bar-fg: #ECE7DD; --bar-muted: #A89F91; --bar-line: #2E2923; --bar-field: #211D18;
  --bg: #F7F5F1; --surface: #FFFFFF; --surface-2: #F2EFE9; --fg: #1A1714; --muted: #6E675D;
  --line: #E4DED3; --line-strong: #CFC7B9;
  --accent: #F08A24; --accent-ink: #1A1206; --accent-soft: #FDF0E1; --accent-line: #F6C18A;
  --red: #B42318; --red-soft: #FDECEA; --red-line: #F3B8B2;
  --green: #2D6A35; --green-soft: #E8F3E8; --green-line: #B7D8BA;
  --shadow: 0 1px 2px rgba(22, 19, 15, .06), 0 4px 14px rgba(22, 19, 15, .06);
  --overlay: rgba(22, 19, 15, .4);
  --r: 8px; --r-sm: 6px; --h: 32px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512; --surface: #1F1C18; --surface-2: #27231E; --fg: #EDE8DF; --muted: #A69D8F;
    --line: #34302A; --line-strong: #4A443B; --accent: #F59A3C; --accent-soft: #3A2A1A; --accent-line: #7A4E22;
    --red: #F28B80; --red-soft: #3B1F1C; --red-line: #6E322C; --green: #8FCB95; --green-soft: #1E3122; --green-line: #355E3B;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25); --overlay: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bar); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bar); color: var(--bar-fg);
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.topbar-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; white-space: nowrap; height: var(--h); }
.hex { width: 15px; height: 17px; background: var(--accent); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); flex: none; }
.nav { display: flex; gap: 2px; }
.nav button { display: inline-flex; align-items: center; height: var(--h); padding: 0 11px; border: 0; border-radius: var(--r-sm); background: none; color: var(--bar-muted); cursor: pointer; font-weight: 500; }
.nav button:hover { color: var(--bar-fg); background: var(--bar-line); }
.nav button[aria-current="page"] { color: var(--bar-fg); background: var(--bar-line); box-shadow: inset 0 -2px 0 var(--accent); }
.search { position: relative; flex: 1 1 260px; min-width: 0; max-width: 460px; }
.search input { width: 100%; height: var(--h); padding: 0 12px; border: 1px solid var(--bar-line); border-radius: var(--r-sm); background: var(--bar-field); color: var(--bar-fg); }
.search input::placeholder { color: #7F7669; }
.results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); max-height: 380px; overflow: auto; z-index: 40; padding: 4px; }
.results button { display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; }
.results button:hover, .results button:focus { background: var(--surface-2); }
.usermenu { position: relative; margin-left: auto; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 4px; min-width: 180px; z-index: 40; }
.menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

main { max-width: 1400px; margin: 0 auto; padding-block: 20px 56px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* ---------------------------------------------------------------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h); padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 500; line-height: 1; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.04); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12.5px; }
.btn.ghost-dark { background: transparent; border-color: var(--bar-line); color: var(--bar-fg); }
.btn.ghost-dark:hover { background: var(--bar-line); }
.btn.link { height: auto; border: 0; background: none; padding: 0; text-decoration: underline; text-underline-offset: 2px; color: var(--muted); font-weight: 400; }
.btn.danger { border-color: var(--red-line); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
select, input[type=text], input[type=email], input[type=url], input[type=date], input[type=number], input[type=password], input[type=search], textarea {
  height: var(--h); padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); max-width: 100%; }
textarea { height: auto; min-height: 84px; padding: 8px 10px; width: 100%; resize: vertical; line-height: 1.45; }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); vertical-align: middle; }
label.f { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 12px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; align-content: start; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { margin-top: 4px; }

/* ---------------------------------------------------------------- surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; min-height: 26px; }
.card-h h2 { display: inline-flex; align-items: center; gap: 8px; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; }
.count.hot { background: var(--red); color: #fff; }
.count.warm { background: var(--accent); color: var(--accent-ink); }
.empty { color: var(--muted); padding: 6px 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; align-items: start; }
.org-layout { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 920px) { .org-layout { grid-template-columns: minmax(0, 1fr); } }

.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; margin: 2px 4px 2px 0; border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 12px; line-height: 1; white-space: nowrap; background: var(--surface); vertical-align: middle; }
.chip.warm { border-color: var(--accent-line); background: var(--accent-soft); }
.chip.hot { border-color: var(--red-line); background: var(--red-soft); color: var(--red); font-weight: 600; }
.chip.good, .chip.won { border-color: var(--green-line); background: var(--green-soft); color: var(--green); }
.chip.quiet, .chip.lost, .chip.archived { border-color: var(--line); color: var(--muted); }
.chip.stage { background: var(--surface-2); border-color: var(--line); }
.chip.ext { font-family: var(--mono); font-size: 11.5px; border-radius: var(--r-sm); }
.chip.pri-high { border-color: var(--red-line); color: var(--red); }
.chip.pri-low { border-color: var(--line); color: var(--muted); }

.list { display: grid; }
.item { display: grid; grid-template-columns: 132px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .lead { display: flex; align-items: center; }
.item .actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 600px) { .item { grid-template-columns: minmax(0, 1fr); gap: 6px; } .item .actions { justify-content: flex-start; } }
.link { background: none; border: 0; padding: 0; font-weight: 600; cursor: pointer; text-align: left; color: inherit; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.link:hover { text-decoration-color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table.wide { min-width: 820px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line-strong); padding: 8px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: 10px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td .sub-line { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 14px; }

.next { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 12px 16px; margin-top: 14px; }
.next.none { border-color: var(--accent-line); background: var(--accent-soft); }
.dnc { background: var(--red-soft); border: 1px solid var(--red-line); color: var(--red); padding: 8px 12px; border-radius: var(--r); font-weight: 600; margin-bottom: 12px; }
.sub { border-bottom: 1px solid var(--line); padding: 10px 0; }
.sub:last-child { border-bottom: 0; padding-bottom: 0; }
.sub:first-of-type { padding-top: 0; }
.blocked { display: inline-block; border: 1px dashed var(--red-line); background: var(--red-soft); color: var(--red); padding: 3px 8px; border-radius: var(--r-sm); font-size: 12px; margin-top: 6px; }
.rel-grid { display: grid; gap: 10px; }
.rel-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 8px; background: var(--bg); }
.opp-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.opp-row:last-child { border-bottom: 0; }
.opp-row select { width: 100%; }
@media (max-width: 600px) { .opp-row { grid-template-columns: minmax(0, 1fr); } }
.pipe-group { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 14px 0 0; }
.meta-line { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.timeline li::after { content: ""; position: absolute; left: 6px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.system::before { background: var(--accent); }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- pipeline */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs .btn[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.board-wrap { overflow-x: auto; padding-bottom: 8px; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; min-width: min-content; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); min-height: 300px; padding: 0 0 8px; }
.col-h { padding: 10px 12px; display: flex; justify-content: space-between; gap: 6px; align-items: flex-start; }
.col-h b { font-size: 13px; }
.col-h .def { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.col.closed .col-h b { color: var(--muted); }
.col.drop { outline: 2px dashed var(--accent); outline-offset: -3px; }
.opp { margin: 0 8px 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); cursor: grab; box-shadow: 0 1px 1px rgba(0, 0, 0, .03); }
.opp:hover { border-color: var(--line-strong); }
.opp.flag { border-left: 3px solid var(--accent); }
.opp .o-title { font-weight: 600; line-height: 1.35; }
.opp .o-org { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.opp .o-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.opp .o-next { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.opp select { width: 100%; margin-top: 8px; height: 28px; font-size: 12.5px; }

/* ---------------------------------------------------------------- settings */
.settings { display: grid; grid-template-columns: minmax(0, 270px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .settings { grid-template-columns: minmax(0, 1fr); } }
.pipe-list { display: grid; gap: 6px; }
.pipe-list .btn { justify-content: space-between; height: auto; min-height: var(--h); padding: 7px 10px; white-space: normal; text-align: left; width: 100%; }
.pipe-list .btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
table.stages { min-width: 680px; }
table.stages td { padding: 6px 8px; }
table.stages input[type=text] { width: 100%; }
.warn { border: 1px solid var(--accent-line); background: var(--accent-soft); border-radius: var(--r-sm); padding: 7px 10px; font-size: 12.5px; margin-top: 10px; }
.order { display: inline-flex; gap: 4px; }

/* ---------------------------------------------------------------- tasks */
table.tasks { min-width: 900px; }
tr.done td { color: var(--muted); }
tr.done .t-title { text-decoration: line-through; }

/* ---------------------------------------------------------------- dialogs, login, toast */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--fg); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); padding: 20px 22px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; }
dialog::backdrop { background: var(--overlay); }
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog h1 { font-size: 18px; }
dialog .actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
dialog .actions .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { color: var(--red); font-size: 12.5px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 13px; margin: 14px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 6px 14px; margin-top: 4px; }
.checks label { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.section-h { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; margin-bottom: 6px; }
.danger-zone { border: 1px solid var(--red-line); background: var(--red-soft); border-radius: var(--r); padding: 10px 12px; margin-top: 8px; }
.danger-zone h2 { color: var(--red); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.login { width: min(400px, 100%); }
.login .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 16px; height: 38px; }
.toast { position: fixed; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); background: var(--bar); color: var(--bar-fg);
  border-radius: var(--r); padding: 10px 14px; box-shadow: var(--shadow); z-index: 60; max-width: min(460px, calc(100vw - 32px)); border-left: 3px solid var(--accent); }
.toast.bad { border-left-color: var(--red); }
details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 8px; }
@media (prefers-reduced-motion: no-preference) { .btn, .opp, .nav button { transition: background-color .12s ease, border-color .12s ease; } }
