:root {
  --bg: #0f1419;
  --panel: #1a2028;
  --border: #2a3340;
  --text: #e4e8ee;
  --muted: #8a93a3;
  --accent: #4a9eff;
  --accent-h: #6fb3ff;
  --ok: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }
nav.top { display: flex; align-items: center; gap: 1.5em; padding: 12px 20px; background: var(--panel);
          border-bottom: 1px solid var(--border); }
nav.top .brand { font-weight: 700; color: var(--text); }
nav.top .spacer { flex: 1; }
nav.top .user { color: var(--muted); }
.bu-pill { background: var(--accent); color: white; padding: 4px 10px; border-radius: 4px; font-size: 12px; }
main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin: 16px 0; }
.card.narrow { max-width: 480px; margin: 60px auto; }
h1 { margin-top: 0; }
h2 { margin-top: 0; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
input, textarea, select, button {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 4px; font-size: 14px; font-family: inherit;
}
textarea { width: 100%; min-height: 60px; font-family: ui-monospace, monospace; }
input[type=text], input[type=email] { width: 100%; max-width: 400px; }
button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: white; font-weight: 500; }
button:hover { background: var(--accent-h); }
button.link { background: transparent; border: none; color: var(--accent); padding: 4px 8px; }
button.link:hover { background: rgba(74,158,255,0.1); }
button.link.danger { color: var(--bad); }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin-right: 8px; }
form label { display: block; color: var(--muted); font-size: 12px; margin-top: 8px; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
tr.past td { color: var(--bad); }
tr.soon td { color: var(--warn); }

.pill { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; background: var(--border); color: var(--text); margin-right: 4px; }
.pill.active { background: var(--accent); color: white; }
.pill .count { opacity: 0.7; margin-left: 4px; }
.status-strip { margin: 16px 0; display: flex; flex-wrap: wrap; gap: 4px; }

.status-new { background: #475569; color: white; }
.status-triaged { background: #0ea5e9; color: white; }
.status-qualified { background: #10b981; color: white; }
.status-drafting { background: #f59e0b; color: white; }
.status-review { background: #8b5cf6; color: white; }
.status-submitted { background: #06b6d4; color: white; }
.status-won { background: #22c55e; color: white; }
.status-lost { background: #ef4444; color: white; }
.status-no_bid { background: #6b7280; color: white; }

.filter-bar { display: flex; gap: 8px; margin: 12px 0; align-items: center; flex-wrap: wrap; }
.filter-bar-wide .q-input { flex: 1; min-width: 260px; }
.inline-lbl { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.link-btn { padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); }
.link-btn:hover { color: var(--text); border-color: var(--accent); }

/* Sortable table headers */
th.sortable a { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
th.sortable a:hover { color: var(--text); }
th.sortable.active a { color: var(--accent); }
th.sortable .sort-arrow { font-size: 10px; opacity: 0.9; }
th.sortable .sort-arrow.dim { opacity: 0.35; }

/* Fit badges */
.fit-cell { text-align: center; padding: 4px !important; }
.fit-badge { display: inline-block; font-size: 15px; line-height: 1; }
.fit-badge.hi { filter: drop-shadow(0 0 3px rgba(16,185,129,0.6)); }
.fit-badge.mid { color: var(--warn); }
.fit-badge.lo { color: var(--muted); opacity: 0.5; }
tr.fit-hi { background: rgba(16,185,129,0.06); }
tr.fit-hi:hover { background: rgba(16,185,129,0.12); }
tr.fit-mid { background: rgba(251,191,36,0.04); }

/* Win % coloring */
.win-num { font-variant-numeric: tabular-nums; font-weight: 500; }
.win-num.hi { color: var(--ok); }
.win-num.mid { color: var(--warn); }
.win-num.lo { color: var(--muted); }

.ok { color: var(--ok); }
.bad { color: var(--bad); }
.src { font-size: 11px; background: var(--border); padding: 2px 6px; border-radius: 3px; }

.bu-list { list-style: none; padding: 0; }
.bu-card { display: block; padding: 20px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; color: var(--text); }
.bu-card:hover { border-color: var(--accent); }
.bu-name { font-size: 18px; font-weight: 600; }

.raw { white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); max-height: 300px; overflow: auto; }
.draft-body { max-width: 900px; line-height: 1.6; }
.draft-body h2 { margin-top: 28px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.draft-body code { background: var(--bg); padding: 2px 6px; border-radius: 3px; font-size: 12px; }
.draft-body table th, .draft-body table td { border: 1px solid var(--border); padding: 6px 10px; }

.approvals { list-style: none; padding: 0; }
.approvals li { padding: 12px; border-bottom: 1px solid var(--border); }

.scanner-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-top: 12px; }
.scanner-grid form { margin: 0; }
.scanner-grid button { width: 100%; }
.dev-block { background: #2a2410; border: 1px solid #5c4f1a; padding: 12px; border-radius: 4px; margin: 12px 0; word-break: break-all; }
.dev-block a { color: var(--warn); }

/* ---- Responsive: phones (iPhone SE 375px → iPhone Pro Max 430px) ---- */
@media (max-width: 768px) {
  body { font-size: 15px; }  /* slightly larger for touch readability */

  /* Nav: wrap, tighter, full-width sign-out row */
  nav.top {
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 10px 14px;
  }
  nav.top .brand { flex-basis: 100%; font-size: 16px; }
  nav.top .spacer { display: none; }
  nav.top .user { font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bu-pill { font-size: 11px; }

  /* Main: cut chrome padding so cards aren't squeezed */
  main { padding: 14px 12px; }
  .card { padding: 14px; margin: 12px 0; border-radius: 6px; }
  .card.narrow { margin: 24px auto; max-width: 100%; }

  h1 { font-size: 22px; }
  h2 { font-size: 17px; }

  /* Inputs: bigger touch targets, full width */
  input, textarea, select, button {
    font-size: 16px;  /* prevents iOS zoom-on-focus */
    padding: 10px 12px;
  }
  input[type=text], input[type=email] { max-width: 100%; }

  /* Filter bar: stack */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select, .filter-bar button { width: 100%; }

  /* Status pills: scrollable horizontal strip on phones */
  .status-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .status-strip .pill { flex: 0 0 auto; white-space: nowrap; }

  /* Opportunities table → card-style rows on phones.
     Hides table headers and stacks each row's cells with inline labels. */
  table.opps thead { display: none; }
  table.opps, table.opps tbody, table.opps tr, table.opps td { display: block; width: 100%; }
  table.opps tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  table.opps td {
    border: none;
    padding: 4px 0;
  }
  table.opps td:first-child {
    font-size: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
  }
  /* Inline labels for non-title cells (9-col layout: Fit,Title,Source,Country,Detected,Deadline,Score,Win,Status) */
  table.opps td:nth-child(1) { display: none; }  /* fit badge hidden on mobile (in title area is enough) */
  table.opps td:nth-child(3)::before { content: "Source: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(4)::before { content: "Country: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(5)::before { content: "Detected: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(6)::before { content: "Deadline: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(7)::before { content: "Score: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(8)::before { content: "Win: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(9)::before { content: "Status: "; color: var(--muted); font-size: 12px; }
  table.opps td:nth-child(4):empty { display: none; }

  /* Generic non-opps tables: allow horizontal scroll instead of breaking layout */
  main > table:not(.opps),
  .card > table:not(.opps) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Draft body tables (inside markdown): also scroll */
  .draft-body { max-width: 100%; }
  .draft-body table { display: block; overflow-x: auto; }

  /* Scanner grid: 2-column on phones */
  .scanner-grid { grid-template-columns: repeat(2, 1fr); }

  /* Raw JSON pre: don't blow out width */
  .raw { font-size: 11px; max-height: 220px; }

  /* Inline forms wrap */
  form.inline { flex-wrap: wrap; }
}

/* Very narrow phones (≤380px): drop scanner grid to 1 column */
@media (max-width: 380px) {
  .scanner-grid { grid-template-columns: 1fr; }
  nav.top { gap: 8px 10px; }
}
