* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The shell owns the viewport and only .content scrolls. Without this the page
   itself scrolls and the bottom tab bar — the only navigation on a phone —
   slides out of reach (Fitts). */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: var(--fs-body)/var(--lh) var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--fs-title); }
h2 { font-size: var(--fs-h); }
.micro { font-size: var(--fs-micro); text-transform: uppercase; letter-spacing: .06em; color: var(--dim); font-weight: 600; }
.small { font-size: var(--fs-small); color: var(--dim); }
.dim { color: var(--dim); }
.mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---- shell ------------------------------------------------------------- */
#app { height: 100%; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100dvh; max-height: 100dvh; overflow: hidden; }
.sidebar {
  background: var(--chrome); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--hair); padding: 12px 10px; overflow-y: auto;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 14px; }
.brand .mark { width: 28px; height: 28px; display: block; flex: none; }
.brand h1 { font-size: 17px; }
.nav-group { margin-top: 16px; }
.nav-group .micro { padding: 0 10px 6px; }
.nav-row {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px;
  border-radius: var(--r-btn); color: var(--ink); width: 100%; border: 0; background: transparent; text-align: left;
  transition: background var(--ease);
}
.nav-row:hover { background: var(--surface2); }
.nav-row.on { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.nav-row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--surface3); color: var(--dim); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.badge.accent { background: var(--accent); color: var(--accent-ink); }
.badge.bad { background: var(--bad); color: #fff; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; overflow: hidden; }
.banner { background: var(--bad); color: #fff; padding: 8px 16px; font-weight: 600; display: flex; gap: 12px; align-items: center; }
.banner button { border: 0; border-radius: var(--r-btn); padding: 6px 12px; background: rgba(255,255,255,.2); color: #fff; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px 10px; border-bottom: 1px solid var(--hair);
  padding-top: calc(14px + env(safe-area-inset-top)); background: var(--bg); position: sticky; top: 0; z-index: 2;
}
.topbar .back { border: 0; background: transparent; color: var(--accent); font-size: 17px; padding: 4px 8px 4px 0; display: none; }
.topbar h1 { flex: 1; }
.content { flex: 1; overflow-y: auto; padding: 16px 20px 40px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.content.chat { padding: 0; display: flex; flex-direction: column; }

/* ---- status + pills ---------------------------------------------------- */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.idle { background: var(--idle); }
.dot.thinking { background: var(--accent); animation: pulse 1.1s infinite; }
.dot.needs_you { background: var(--warn); }
.dot.down { background: var(--bad); }
.dot.good { background: var(--ok); }
.dot.watch { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.unknown { background: var(--idle); }
.dot.info { background: var(--idle); }
.dot.warn { background: var(--warn); }
.dot.critical { background: var(--bad); }
.dot.notice { background: var(--accent); }
.dot.error { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3 } }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600; background: var(--surface3); color: var(--dim); }
.pill.good { background: var(--ok-tint); color: var(--ok); }
.pill.watch, .pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.bad, .pill.critical { background: var(--bad-tint); color: var(--bad); }
.pill.accent { background: var(--accent-tint); color: var(--accent); }
.pill.kind { background: var(--surface2); color: var(--dim); font-weight: 500; }

/* ---- segmented control ------------------------------------------------- */
.seg { display: inline-flex; background: var(--surface2); border-radius: var(--r-btn); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--dim); transition: background var(--ease), color var(--ease); min-height: 38px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.scroll { display: flex; overflow-x: auto; scrollbar-width: none; max-width: 100%;
              -webkit-overflow-scrolling: touch;
              mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
              -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%); }
.seg.scroll button { flex: 0 0 auto; }
.seg.scroll::-webkit-scrollbar { display: none; }

/* ---- cards, rows, lists ------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-card); padding: 16px; margin-bottom: 12px; }
.card.tight { padding: 12px 14px; }
.row { display: flex; align-items: center; gap: 12px; min-height: var(--row-h); padding: 8px 0; border-bottom: 1px solid var(--hair); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-card); padding: 0 16px; margin-bottom: 16px; }
.list .row { cursor: pointer; }
.list .row:hover { background: transparent; }
.section { margin: 20px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.section h2 { flex: 1; }
.empty { text-align: center; color: var(--dim); padding: 40px 16px; }
.empty .big { font-size: 28px; margin-bottom: 6px; }
.empty button { margin-top: 12px; }

/* ---- buttons ------------------------------------------------------------ */
.btn { border: 1px solid var(--hair2); background: var(--surface); border-radius: var(--r-btn); padding: 8px 14px; font-weight: 600; font-size: 14px; color: var(--ink); transition: background var(--ease); min-height: 36px; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-quiet { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 5px 10px; font-size: 13px; min-height: 30px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.option { border: 1px solid var(--hair2); background: var(--surface); border-radius: var(--r-btn); padding: 9px 14px; font-size: 14px; text-align: left; min-height: 40px; }
.option:hover { background: var(--surface2); }
.option.on { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); font-weight: 600; }

/* ---- forms --------------------------------------------------------------- */
input[type=text], input[type=password], input[type=number], input[type=url], textarea, select {
  width: 100%; border: 1px solid var(--hair2); border-radius: var(--r-btn); padding: 9px 11px; background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; min-height: 88px; line-height: 1.45; }
textarea.directive { min-height: 360px; font-size: 14px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }

/* ---- inbox ---------------------------------------------------------------- */
.inbox-row { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--hair); cursor: pointer; align-items: flex-start; }
.inbox-row:last-child { border-bottom: 0; }
.inbox-row .dot { margin-top: 7px; }
.inbox-row .title { font-weight: 600; }
.inbox-row .meta { font-size: 13px; color: var(--dim); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.inbox-row.open-detail { cursor: default; }
.detail { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--hair); }
.detail .body { white-space: pre-wrap; word-break: break-word; }
pre.literal { margin: 8px 0; padding: 10px 12px; background: var(--surface2); border-radius: 8px; font: 12.5px/1.45 var(--mono); overflow-x: auto; white-space: pre-wrap; word-break: break-all; max-height: 280px; }
.answer-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.answer-form .btns { justify-content: flex-end; }
.snooze { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px;
          padding-top: 12px; border-top: 1px solid var(--hair); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--hair2); background: var(--surface); border-radius: var(--r-pill); padding: 4px 12px; font-size: 13px; color: var(--dim); min-height: 34px; display: inline-flex; align-items: center; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* ---- activity timeline ---------------------------------------------------- */
.day { position: sticky; top: 0; background: var(--bg); padding: 12px 0 6px; z-index: 1; }
.log { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--hair); }
.log .dot { margin-top: 8px; }
.log .when { width: 46px; flex: none; color: var(--dim); font-size: 13px; padding-top: 1px; font-variant-numeric: tabular-nums; }
.log .who { font-size: 12px; color: var(--faint); }
.log .text { }
.log .row.top { align-items: flex-start; }
.row.top .dot { margin-top: 6px; }
.row .chev { color: var(--faint); margin-left: 8px; }
.refs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.row.top { align-items: flex-start; }
.row.top .dot { margin-top: 6px; }
.row .chev { color: var(--faint); margin-left: 8px; }
.refs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.refs span { font-size: 11px; color: var(--dim); background: var(--surface2); border-radius: 6px; padding: 2px 7px; }
.log.system .text { color: var(--dim); }

/* ---- chat ------------------------------------------------------------------ */
.chatlog { flex: 1; overflow-y: auto; padding: 16px 20px 8px; }
.msg { max-width: min(760px, 100%); margin: 0 auto 14px; }
.msg .who { font-size: 12px; color: var(--dim); margin-bottom: 3px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.you .body { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-card); padding: 9px 12px; }
.msg .tool { font: 12px/1.5 var(--mono); color: var(--dim); border-left: 2px solid var(--hair2); padding: 2px 0 2px 10px; margin: 4px 0; white-space: pre-wrap; word-break: break-all; }
.msg .tool.deny { border-left-color: var(--bad); }
.msg .tool.ask, .msg .tool.defer { border-left-color: var(--warn); }
.msg .sys { color: var(--dim); font-size: 13px; font-style: italic; }
.msg .err { color: var(--bad); font-size: 14px; }
.msg .cost { color: var(--faint); font-size: 11px; margin-top: 4px; }
.composer { border-top: 1px solid var(--hair); background: var(--chrome); backdrop-filter: blur(20px); padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 140px; }
.approval { border: 1px solid var(--warn); background: var(--warn-tint); border-radius: var(--r-card); padding: 12px; margin: 10px auto; max-width: min(760px, 100%); }
.approval h4 { margin: 0 0 6px; font-size: 13px; color: var(--warn); }
.approval.done { opacity: .5; border-color: var(--hair); background: transparent; }

/* ---- board --------------------------------------------------------------- */
.board-row { display: grid; grid-template-columns: minmax(0, 1fr) 104px 116px 16px; gap: 12px;
             align-items: center; padding: 12px 0; border-bottom: 1px solid var(--hair); cursor: pointer; }
.board-row .main { min-width: 0; }
.board-row .status { justify-self: start; }
.board-row .verdict { display: flex; gap: 8px; align-items: center; justify-self: start; min-width: 0; }
.board-row .waiting { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.board-row .chev { color: var(--faint); justify-self: end; }
.board-row:hover { background: var(--surface2); }
.board-row:last-child { border-bottom: 0; }
.board-row .name { font-weight: 600; }
.board-row .line { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 767px) {
  .board-row .line { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2;
                     -webkit-box-orient: vertical; text-overflow: clip; }
}

/* ---- gate ----------------------------------------------------------------- */
.gate { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 9; }
.gate .card { width: min(340px, 88vw); }

/* ---- sheet (mobile) ------------------------------------------------------- */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 8; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: var(--r-sheet) var(--r-sheet) 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 9; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); animation: up var(--ease-sheet); }
@keyframes up { from { transform: translateY(24px); opacity: 0 } }
@media (min-width: 768px) { .sheet { left: 50%; right: auto; bottom: auto; top: 12vh; transform: translateX(-50%); width: min(640px, 92vw); border-radius: var(--r-sheet); } }

/* ---- toast ------------------------------------------------------------------ */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r-pill); font-size: 14px; z-index: 10; box-shadow: var(--shadow); }

/* ---- skeleton ------------------------------------------------------------- */
.skel { height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--surface2), var(--surface3), var(--surface2)); background-size: 200% 100%; animation: sk 1.2s infinite; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0 } }

/* ---- mobile ---------------------------------------------------------------- */
.tabbar { display: none; }
@media (max-width: 767px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { display: none; }
  .tabbar { display: flex; border-top: 1px solid var(--hair); background: var(--chrome); backdrop-filter: saturate(180%) blur(20px); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
  .tabbar button { flex: 1; border: 0; background: transparent; color: var(--dim); font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; min-height: 44px; }
  .tabbar button.on { color: var(--accent); }
  .tabbar .glyph { font-size: 20px; line-height: 1; }
  .topbar .back { display: inline-block; }
  .content { padding: 12px 14px 32px; }
  .board-row { grid-template-columns: minmax(0, 1fr) auto 12px; row-gap: 4px;
               grid-template-areas: "main status chev" "main verdict chev"; }
  .board-row .main { grid-area: main; }
  .board-row .status { grid-area: status; justify-self: end; }
  .board-row .verdict { grid-area: verdict; justify-self: end; }
  .board-row .chev { grid-area: chev; }
  .board-row .line { white-space: normal; }
  .seg button { min-height: 44px; padding: 6px 16px; }
  .chip { min-height: 44px; }
  .option, .btn { min-height: 44px; }
  /* the action you take most often is the one under your thumb */
  .answer-form .btns .btn { flex: 1; }
  .answer-form .snooze .btn { flex: 1; }
}

/* ---- board review ---------------------------------------------------------- */
.review-block { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--hair); }
.review-block .micro { margin-bottom: 8px; }
.review-line { display: grid; grid-template-columns: 92px 1fr; gap: 12px; align-items: start; padding: 5px 0; }
.review-line .pill { justify-self: start; }
.review-verdict { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--hair);
                  display: flex; gap: 10px; align-items: center; font-weight: 600; }
@media (max-width: 767px) {
  .review-line { grid-template-columns: 1fr; gap: 2px; }
}

/* Links page */
.links-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.links-bar .links-search { flex: 1 1 180px; min-width: 0; }
.links-title { margin: 14px 0 6px; }
a.link-row { color: inherit; text-decoration: none; }
a.link-row:hover .title { color: var(--accent); }
.dot-gap { width: 8px; flex: 0 0 8px; }
.kind-tag { font-size: 11px; font-weight: 600; color: var(--dim); background: var(--surface2); border-radius: 6px; padding: 2px 6px; flex: 0 0 auto; }

.google-btn { display: flex; justify-content: center; text-decoration: none; width: 100%; }

/* --- stocks --------------------------------------------------------------- */
.stk .up, .stk .sub.up { color: var(--ok); }
.stk .down, .stk .sub.down { color: var(--bad); }
.stk .pill { flex: none; white-space: nowrap; }
.stk-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stk-kpis .card { margin-bottom: 0; min-width: 0; }
.stk-big { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stk-row { border-bottom: 1px solid var(--hair); padding: 10px 0; cursor: pointer; }
.stk-row:last-child { border-bottom: 0; }
.stk-line { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stk-name { flex: 1; min-width: 0; }
.stk-name .title { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stk-name .title .pill { font-size: 11px; padding: 1px 8px; }
.stk-name .sub, .stk-num .sub { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stk-num { text-align: right; font-variant-numeric: tabular-nums; flex: none; min-width: 64px; }
.stk-num.wide { min-width: 96px; }
.spark { flex: none; }
.stk-detail { margin-top: 10px; cursor: default; }
.stk-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
.stk-facts .micro { display: block; }
.stk-signal { display: flex; gap: 8px; align-items: baseline; margin: 6px 0; overflow-wrap: anywhere; }
.stk-rules { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.stk-rules label { min-width: 0; }
.stk-rules input { width: 100%; box-sizing: border-box; }
.stk-cmd { display: flex; gap: 8px; }
.stk-cmd input { flex: 1; min-width: 0; }
.stk-wrap { overflow-wrap: anywhere; white-space: normal; }
@media (max-width: 767px) {
  .stk-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spark { display: none; }
  .stk-rules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stk-num.wide { min-width: 84px; }
}
