:root {
  --ink: #0a2219; --ink-soft: #2f4a3e; --paper: #f6faf7; --paper2: #eaf3ee; --card: #ffffff; --line: #cbddd2;
  --green: #14e08f; --green-d: #087a4b; --mint-soft: #dbf8ea; --focus: #0b6bcb; --danger: #b42318; --danger-soft: #fde8e6;
  --warn: #8a5a00; --warn-soft: #fff3d6; --muted: #5b6a68; --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
a { color: var(--green-d); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
main { padding: 12px 16px 24px; max-width: 1200px; margin: 0 auto; outline: none; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--ink); color: #fff; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand span { color: var(--green); }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a { color: #d3f2e3; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.topnav a.on { background: rgba(255,255,255,.12); color: #fff; }
.top .linkish { margin-left: auto; color: #d3f2e3; }
@media (min-width: 900px) { .topnav { display: flex; } body { padding-bottom: 0; } .tabbar { display: none !important; } }

/* bottom tab bar (phones) */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; font-size: .75rem; color: var(--ink-soft); text-decoration: none; }
.tabbar a .ico { font-size: 1.25rem; line-height: 1; }
.tabbar a.on { color: var(--green-d); font-weight: 700; }
.tabbar a.add .ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--green); color: var(--ink); font-size: 1.6rem; font-weight: 700; }

/* controls */
button, .btn { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 14px; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-primary, button.primary { background: var(--green); border-color: var(--green); color: var(--ink); font-weight: 700; }
.btn-danger, button.danger { background: var(--danger-soft); border-color: #f3b8b2; color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
.linkish { background: none; border: 0; padding: 4px 6px; min-height: 0; color: var(--green-d); text-decoration: underline; }
.wide { width: 100%; }
input, select, textarea { font: inherit; width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
textarea { min-height: 88px; resize: vertical; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--green-d); }
label { display: block; font-size: .875rem; font-weight: 600; color: var(--ink-soft); margin: 10px 0 4px; }
label.inline { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 140px; }
.row > .auto { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.err { color: var(--danger); font-size: .9rem; margin: 6px 0; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--mint-soft); color: var(--green-d); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 8px 14px; min-height: 40px; border: 1px solid var(--line); background: #fff; }
.chip[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em; padding: 2px 7px; border-radius: 6px; background: var(--paper2); color: var(--ink-soft); vertical-align: middle; white-space: nowrap; }
.badge.dnc { background: var(--danger); color: #fff; }
.badge.tps-reg { background: var(--danger-soft); color: var(--danger); }
.badge.tps-unc { background: var(--warn-soft); color: var(--warn); }
.badge.tps-clear { background: var(--mint-soft); color: var(--green-d); }
.badge.over { background: var(--danger-soft); color: var(--danger); }
tr.is-dnc td:first-child, .item.is-dnc { box-shadow: inset 4px 0 0 var(--danger); }

/* stage tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 10px; padding: 2px 16px; scroll-snap-type: x proximity; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: 0 0 auto; scroll-snap-align: start; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.tabs a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs .n { display: inline-block; min-width: 1.6em; text-align: center; margin-left: 4px; padding: 0 5px; border-radius: 999px; background: var(--paper2); color: var(--ink); font-size: .8rem; font-weight: 700; }
.tabs a.on .n { background: var(--green); }

/* tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--paper2); white-space: nowrap; vertical-align: middle; }
th { background: var(--paper2); font-size: .8rem; color: var(--ink-soft); position: sticky; top: 0; }
th button { all: unset; cursor: pointer; font-weight: 700; }
th button:focus-visible { outline: 3px solid var(--focus); }
td.name { position: sticky; left: 0; background: #fff; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
td.name a { font-weight: 600; }
td select { min-height: 36px; padding: 4px 8px; width: auto; font-size: .85rem; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); }

/* lists */
.item { display: flex; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 8px 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .acts { display: flex; gap: 6px; flex: 0 0 auto; }
.item .acts .btn, .item .acts button { padding: 8px 10px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 4px 0 10px 12px; margin-left: 6px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--green-d); }
.timeline .when { font-size: .78rem; color: var(--muted); }
.timeline .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* deal board */
.board { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 8px; }
.col { flex: 0 0 min(82vw, 290px); scroll-snap-align: start; background: var(--paper2); border-radius: var(--radius); padding: 10px; }
.col h3 { margin: 0 0 4px; font-size: .95rem; }
.col .tot { font-size: .8rem; color: var(--ink-soft); margin-bottom: 8px; }
.dcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.dcard .t { font-weight: 650; }
.dcard select { margin-top: 6px; min-height: 38px; padding: 4px 8px; }
.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 8px 0 12px; }
.totals .card { margin: 0; padding: 10px; }
.totals .k { font-size: .78rem; color: var(--muted); }
.totals .v { font-weight: 700; }

/* stage stepper on record */
.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 8px 0; }
.stepper button { min-height: 52px; padding: 4px; font-size: .74rem; line-height: 1.15; border-radius: 8px; }
.stepper button[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }
.stepper.deal { grid-template-columns: repeat(3, 1fr); }

.sticky-actions { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 30%); padding-top: 12px; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100vw - 32px); }
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth h1 { font-size: 1.6rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.copybox { display: flex; gap: 6px; }
.copybox input { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; }
