/* Gerson Sales Control — mobile-first, no framework. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #16202a;
  --muted: #5b6875;
  --line: #dde3e8;
  --brand: #0f3d5e;
  --brand-2: #1b6aa1;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dd;
  --bad: #b3261e;
  --bad-bg: #fde8e7;
  --info-bg: #e8f1f9;
  --purple: #5b3fa0;
  --purple-bg: #efeafa;
  --radius: 12px;
  --tap: 44px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand-2); }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
.card h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.container { max-width: 1100px; margin: 0 auto; padding: 12px 14px 24px; }

/* Header / navigation */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 800; text-decoration: none; font-size: 1.15rem; letter-spacing: -.01em; }
.brand span { font-weight: 400; opacity: .8; margin-left: 2px; }
.brand-lg { color: var(--brand); font-size: 2rem; }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a { color: #d8e6f1; text-decoration: none; padding: 8px 10px; border-radius: 8px; }
.topnav a.active, .topnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.usermenu { margin-left: auto; position: relative; }
.usermenu summary {
  list-style: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 700;
}
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu-panel {
  position: absolute; right: 0; top: 44px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.usermenu-panel p { margin: 0 0 8px; }
.usermenu-panel a { display: block; padding: 8px 0; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; font-size: .72rem; color: var(--muted); text-decoration: none;
}
.bottomnav a .ico { font-size: 1.15rem; line-height: 1.2; }
.bottomnav a.active { color: var(--brand); font-weight: 700; }

.demo-banner {
  background: var(--bad); color: #fff; text-align: center; font-weight: 800;
  padding: 6px 10px; font-size: .85rem; letter-spacing: .02em;
}

/* Layout pieces */
.page-head { margin: 6px 0 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.back { display: inline-block; margin: 4px 0 8px; text-decoration: none; min-height: var(--tap); line-height: var(--tap); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card.empty { text-align: center; color: var(--muted); }
details.card > summary { cursor: pointer; min-height: 32px; display: flex; gap: 8px; align-items: center; }
.footnote { color: var(--muted); font-size: .8rem; margin-top: 18px; }

/* Buttons */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.actions form { margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--brand-2); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--brand); border-color: var(--line); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.htmx-request { opacity: .55; cursor: default; }

/* KPI cards */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; color: inherit; text-decoration: none;
}
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 1.35rem; font-weight: 800; overflow-wrap: anywhere; }
.kpi-value small { font-size: .8rem; font-weight: 600; color: var(--muted); }
.kpi-sub { font-size: .8rem; color: var(--muted); }
.kpi-link:active { background: #eef3f7; }
.kpi-bad { border-left: 4px solid var(--bad); }
.kpi-warn { border-left: 4px solid var(--warn); }

/* Lists / opportunity cards */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: 0; }
.opp-card {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: inherit; text-decoration: none;
}
.opp-card.is-stale { border-left: 4px solid var(--bad); }
.opp-card.needs-attention { border-left: 4px solid var(--warn); box-shadow: inset 0 0 0 1px var(--warn-bg); }
.opp-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.opp-customer { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.opp-value { font-weight: 800; white-space: nowrap; }
.opp-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .85rem; color: var(--muted); margin: 2px 0 6px; }
.opp-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.opp-next { font-size: .88rem; }
.overdue { color: var(--bad); font-weight: 700; }

.tag, .badge {
  display: inline-block; font-size: .74rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: #eef1f4; color: var(--muted);
}
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.tag-status-unreviewed { background: #eef1f4; color: #3c4854; }
.tag-status-active { background: var(--info-bg); color: var(--brand-2); }
.tag-status-won { background: var(--ok-bg); color: var(--ok); }
.tag-status-lost { background: #ececec; color: #555; }
.tag-status-invalid { background: #ececec; color: #777; }
.tag-priority-high { background: var(--purple-bg); color: var(--purple); }
.tag-priority-elevated { background: var(--warn-bg); color: var(--warn); }
.tag-stale { background: var(--bad-bg); color: var(--bad); }
.tag-attention { background: var(--warn-bg); color: var(--warn); }
.tag-help { background: var(--purple-bg); color: var(--purple); }
.tag-demo { background: var(--bad); color: #fff; }
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-run-success { background: var(--ok-bg); color: var(--ok); }
.tag-run-partial { background: var(--warn-bg); color: var(--warn); }
.tag-run-failed { background: var(--bad-bg); color: var(--bad); }
.tag-run-running { background: var(--info-bg); color: var(--brand-2); }

/* Chips & filters */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.filters { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 12px; }

/* Forms */
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
input, select, textarea {
  font: inherit; font-size: 16px; /* prevents iOS zoom */
  min-height: var(--tap); padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; margin-bottom: 14px; }
.seg { position: relative; }
.seg input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 8px;
  border: 1px solid var(--line); border-radius: 10px; font-weight: 600; font-size: .9rem; text-align: center; cursor: pointer;
}
.seg input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg-won input:checked + span { background: var(--ok); border-color: var(--ok); }
.seg-lost input:checked + span { background: #555; border-color: #555; }
.seg input:focus-visible + span { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.toggle { flex-direction: row !important; align-items: center; gap: 10px !important; min-height: var(--tap); }
.toggle input { width: 24px; height: 24px; min-height: 0; }
.sticky-save { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form label { flex: 1 1 180px; margin-bottom: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.row-actions form { margin: 0; }

/* Alerts & warnings */
.alert { border-radius: var(--radius); padding: 10px 12px; margin: 8px 0 12px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-info { background: var(--info-bg); color: #15466b; }
.alert-critical { background: var(--bad-bg); color: var(--bad); }
.warning-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.warning { border-left: 4px solid var(--line); padding: 6px 10px; background: #fafbfc; border-radius: 6px; }
.warning-critical { border-color: var(--bad); background: var(--bad-bg); }
.warning-warning { border-color: var(--warn); background: var(--warn-bg); }
.warning-info { border-color: var(--brand-2); background: var(--info-bg); }
.warning-title { font-weight: 700; }
.warning-detail { font-size: .88rem; }
.warning-link { font-size: .85rem; }

/* Detail pages */
.summary-value { font-size: 1.8rem; font-weight: 800; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.match { border-left: 4px solid var(--line); padding-left: 10px !important; }
.match-probable { border-color: var(--warn); }
.match-confirmed { border-color: var(--ok); }
.match-rejected { opacity: .6; }

/* Sellers */
.seller-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; align-items: center; }
.seller-head h2 { margin: 0; }
.seller-head a { text-decoration: none; color: inherit; }
.seller-incomplete { border-left: 4px solid var(--warn); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0 0; }
.metrics dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; }
.metrics dd { margin: 0; font-weight: 700; }
.metrics dd.bad { color: var(--bad); }
.incomplete { color: var(--warn); font-size: .85rem; margin: 8px 0 0; }

/* Sync & reports */
.run { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.run-head { display: flex; justify-content: space-between; gap: 8px; }
.run-failed { border-left: 4px solid var(--bad); }
.run-partial { border-left: 4px solid var(--warn); }
.run-error { color: var(--bad); overflow-wrap: anywhere; }
.report-row { display: flex; flex-direction: column; gap: 6px; }
.identity.unmapped { border-left: 4px solid var(--warn); }
.identity-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin-bottom: 8px; }

.login { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.login .card { text-align: left; margin-top: 16px; }

code { font-size: .85em; background: #eef1f4; padding: 1px 4px; border-radius: 4px; }

@media (min-width: 720px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .usermenu { margin-left: 0; }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters { grid-template-columns: 2fr 1fr auto; }
  .list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .runs { grid-template-columns: 1fr; }
  .sticky-save { position: static; }
  .metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .report-row { flex-direction: row; justify-content: space-between; align-items: center; }
  h1 { font-size: 1.7rem; }
}
