:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #16181d;
  --muted: #5d6573;
  --border: #dde1e7;
  --accent: #2458d6;
  --accent-text: #ffffff;
  --good: #137a3f;
  --good-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --info: #3f4aa8;
  --info-bg: #e7e9fb;
  --neutral-bg: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --border: #2b303b;
    --accent: #6d95ff;
    --accent-text: #0b1020;
    --good: #5fd08f;
    --good-bg: #16301f;
    --warn: #f0c060;
    --warn-bg: #33290f;
    --bad: #ff8a80;
    --bad-bg: #3a1a18;
    --info: #a9b1ff;
    --info-bg: #1f2240;
    --neutral-bg: #252a34;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
h2 { margin: 0 0 4px; font-size: 20px; }
h3 { margin: 0 0 10px; font-size: 15px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
#tabs { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
#tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
#tabs button:hover { background: var(--panel-2); color: var(--text); }
#tabs button.active { background: var(--panel-2); color: var(--text); }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--panel-2); font-size: 12px; white-space: nowrap; }
button.link { background: none; border: 0; color: var(--muted); padding: 4px; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 80px; }
.tab { display: none; }
.tab.active { display: block; }
.section-head { margin-bottom: 14px; }
.section-head p { margin: 0; }

/* controls */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
}
button:hover { background: var(--panel-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel);
}
textarea { resize: vertical; font-size: 13px; }
input[type=checkbox] { width: auto; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.searchbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.searchbar .grow { flex: 1 1 260px; }
.searchbar label:not(.grow):not(.inline) { width: 130px; }
.types { display: flex; flex-wrap: wrap; gap: 4px 12px; flex: 1 1 100%; }
.types legend { width: 100%; }
.types label { flex-direction: row; align-items: center; gap: 5px; color: var(--text); font-weight: 400; font-size: 13px; }

.status { margin: 6px 0 12px; color: var(--muted); min-height: 20px; }
.status.error { color: var(--bad); }

.buckets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.buckets button { padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.buckets button.on { outline: 2px solid var(--accent); outline-offset: -1px; }

/* verdict pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.v-Pursue { background: var(--good-bg); color: var(--good); }
.v-Stretch { background: var(--info-bg); color: var(--info); }
.v-Maybe { background: var(--warn-bg); color: var(--warn); }
.v-Later { background: var(--neutral-bg); color: var(--muted); }
.v-Pass { background: var(--bad-bg); color: var(--bad); }
.v-Unscored { background: var(--neutral-bg); color: var(--muted); border: 1px dashed var(--border); }
.criteria { margin-top: 8px; }
.tag.ok { background: var(--good-bg); color: var(--good); }
.tag.miss { background: var(--bad-bg); color: var(--bad); }
.strat-bar { align-items: flex-end; }
.strat-bar .grow { flex: 1 1 200px; }
.strat-bar select, .strat-bar input { min-width: 180px; }
.filebtn { flex-direction: row; cursor: pointer; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 14px; font-weight: 400; }
.tier-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: var(--panel-2); }
.tier-card .tier-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.tier-card .tier-head input { font-weight: 600; flex: 1; }
.tier-card .tier-head button { padding: 5px 9px; }
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.tier-sub { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.chips label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); font-weight: 400; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.r-Low { color: var(--good); } .r-Medium { color: var(--warn); } .r-High { color: var(--bad); } .r-Unknown { color: var(--muted); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); font-size: 11px; color: var(--muted); margin: 1px 2px 1px 0; }
.tag.hot { background: var(--warn-bg); color: var(--warn); }

/* results table */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
td .addr { font-weight: 600; }
td .sub { font-size: 12px; color: var(--muted); }
.thumb { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; background: var(--panel-2); display: block; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.fields.cols4 { grid-template-columns: repeat(4, 1fr); align-items: end; }
.fields .span2 { grid-column: span 2; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(980px, 100%); overflow-y: auto;
  background: var(--bg); padding: 20px 22px 60px; border-left: 1px solid var(--border);
}
.drawer-close { position: sticky; top: 0; float: right; font-size: 22px; line-height: 1; padding: 4px 10px; z-index: 2; }
.detail-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.detail-head img { width: 220px; height: 150px; object-fit: cover; border-radius: 8px; background: var(--panel-2); }
.detail-head h2 { font-size: 19px; }
.reasons { margin: 8px 0 0; padding-left: 18px; }
.reasons li { margin: 2px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.kv div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.kv .sep { grid-column: 1 / -1; border-top: 1px solid var(--border); margin: 3px 0; }
.assump { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }
.desc { white-space: pre-wrap; font-size: 13px; color: var(--muted); max-height: 160px; overflow: auto; }

/* strategy editor */
.strat-section { margin-bottom: 16px; }
.strat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.strat-grid .changed input { border-color: var(--accent); }
.tier-table input { min-width: 90px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(340px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 800px) {
  .grid2, .cols { grid-template-columns: 1fr; }
  .fields.cols4, .assump { grid-template-columns: 1fr 1fr; }
  .detail-head { flex-direction: column; }
  .detail-head img { width: 100%; height: 190px; }
  .searchbar label:not(.grow):not(.inline) { width: calc(50% - 6px); }
  .hide-sm { display: none; }
}
