:root {
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --surface-alt: #EAEEF2;
  --border: #DDE3E9;
  --text: #17212B;
  --text-muted: #64707D;
  --primary: #204E6B;
  --primary-dark: #163C54;
  --accent: #0E7C86;
  --accent-soft: #E4F2F1;
  --success: #157F3C;
  --success-soft: #E5F5EA;
  --warning: #A15C07;
  --warning-soft: #FBF0DE;
  --danger: #B3261E;
  --danger-soft: #FBEAE9;
  --info: #2457A8;
  --info-soft: #E7EFFB;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --header-h: 56px;
  --nav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

#app-root {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------------- Header ---------------- */
.app-header {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.app-header .hdr-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.app-header .hdr-back {
  border: none; background: transparent; font-size: 20px; line-height: 1;
  padding: 6px 4px; cursor: pointer; color: var(--primary); flex: 0 0 auto;
}
.app-header .hdr-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .hdr-tenant {
  font-size: 11px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 8px; background: var(--surface-alt); cursor: pointer; flex: 0 0 auto; white-space: nowrap;
}
.app-header .hdr-status { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--warning-soft); color: var(--warning); flex: 0 0 auto; }

.app-header-sub {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 12px; font-size: 11px; color: var(--text-muted);
  background: var(--surface); border-bottom: 1px solid var(--border);
}

/* ---------------- Body / screens ---------------- */
.app-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: 12px;
  gap: 10px;
  overflow: hidden;
}
.screen.scroll-y { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen-scroll-region {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 10px;
}

.eyebrow-title { font-size: 13px; color: var(--text-muted); margin: 0 0 2px; }
.screen h2 { font-size: 17px; margin: 0; }
.screen h3 { font-size: 14px; margin: 0 0 6px; color: var(--text); }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
}
.card + .card { margin-top: 0; }
.card-tight { padding: 10px 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row + .row { margin-top: 6px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hstack { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.bold { font-weight: 600; }
.mono-num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.divider { height: 1px; background: var(--border); margin: 8px 0; border: none; }

/* ---------------- Badges / status chips ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.2px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-muted);
  white-space: nowrap;
}
.badge-DEMO { background: var(--warning-soft); color: var(--warning); }
.badge-LIVE { background: var(--success-soft); color: var(--success); }
.badge-CACHED { background: var(--info-soft); color: var(--info); }
.badge-STALE { background: var(--danger-soft); color: var(--danger); }
.badge-UNAVAILABLE { background: var(--danger-soft); color: var(--danger); }
.badge-INSUFFICIENT { background: var(--danger-soft); color: var(--danger); }
.badge-USERPROVIDED { background: var(--info-soft); color: var(--info); }
.badge-INTERNAL { background: var(--accent-soft); color: var(--accent); }
.badge-Fresh { background: var(--success-soft); color: var(--success); }
.badge-Aging { background: var(--warning-soft); color: var(--warning); }
.badge-Stale { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); }

.pill-status {
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
}
.pill-Draft { background: var(--surface-alt); color: var(--text-muted); }
.pill-ProcurementReview, .pill-Reviewer, .pill-Approver { background: var(--info-soft); color: var(--info); }
.pill-HPSLocked { background: var(--success-soft); color: var(--success); }
.pill-Rejected { background: var(--danger-soft); color: var(--danger); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px; font-weight: 600;
  padding: 11px 14px;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; min-height: 34px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }
.btn-group .btn { flex: 1; }

.fab-bar {
  flex: 0 0 auto;
  display: flex; gap: 8px;
  padding-top: 4px;
}

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 11px; background: var(--surface); color: var(--text);
  min-height: 44px;
}
.field textarea { min-height: 64px; resize: vertical; }
.field-hint { font-size: 11px; color: var(--text-muted); }
.chip-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-opt {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; color: var(--text);
}
.chip-opt.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.stepper-track { display: flex; gap: 4px; }
.stepper-dot { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.stepper-dot.active { background: var(--accent); }
.stepper-dot.done { background: var(--primary); }

/* ---------------- Bottom nav ---------------- */
.bottom-nav {
  flex: 0 0 var(--nav-h);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; background: transparent; cursor: pointer; color: var(--text-muted);
  font-size: 10.5px; font-weight: 600; padding: 4px 0;
}
.nav-item .nav-ic { font-size: 18px; line-height: 1; }
.nav-item.active { color: var(--primary); }

/* ---------------- HPS number hero ---------------- */
.hps-hero { text-align: center; padding: 10px 4px; }
.hps-hero .hps-amount { font-size: 30px; font-weight: 700; color: var(--primary); letter-spacing: -0.5px; }
.hps-hero .hps-range { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.range-bar { position: relative; height: 6px; background: var(--surface-alt); border-radius: 3px; margin: 10px 0 4px; }
.range-bar .marker { position: absolute; top: -5px; width: 2px; height: 16px; background: var(--primary); }
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }

/* ---------------- Sliders ---------------- */
.slider-row { display: flex; flex-direction: column; gap: 2px; }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent); }
.slider-row .slider-val { font-size: 12px; font-weight: 700; color: var(--accent); }

/* ---------------- Modal / bottom sheet ---------------- */
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(15, 23, 32, 0.45); z-index: 40;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--surface); width: 100%; max-height: 84%;
  border-radius: 18px 18px 0 0; padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 4px; }
.modal-full {
  position: absolute; inset: 0; background: var(--surface); z-index: 41;
  display: flex; flex-direction: column;
}
.modal-full .modal-body { flex: 1; overflow-y: auto; padding: 12px; }

/* ---------------- Banners / errors ---------------- */
.banner { border-radius: var(--radius-md); padding: 10px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; }
.banner-warning { background: var(--warning-soft); color: var(--warning); }
.banner-danger { background: var(--danger-soft); color: var(--danger); }
.banner-info { background: var(--info-soft); color: var(--info); }
.banner-success { background: var(--success-soft); color: var(--success); }
.banner .banner-action { align-self: flex-start; }

/* ---------------- Agent chips (research mission) ---------------- */
.agent-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 12.5px;
  background: var(--surface);
}
.agent-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex: 0 0 auto; }
.agent-chip.done .dot { background: var(--success); }
.agent-chip.active .dot { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.35;} }

/* ---------------- Misc ---------------- */
.empty-state { text-align: center; padding: 24px 12px; color: var(--text-muted); }
.list-scroll { overflow-y: auto; }
a.linklike { color: var(--accent); text-decoration: none; font-weight: 600; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (prefers-reduced-motion: reduce) {
  .agent-chip.active .dot { animation: none; }
}
