:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1c2230;
  --muted: #667085;
  --border: #d8dce4;
  --accent: #2f6fde;
  --apply: #1f9d55;
  --maybe: #c98a0b;
  --no: #8a94a6;
  --danger: #d1453b;
  --open: #2f6fde;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b2029;
    --surface-2: #242a35;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2f3644;
    --accent: #6c9cf0;
    --apply: #3cc47c;
    --maybe: #e8b03a;
    --no: #7d8799;
    --danger: #ef6b62;
    --open: #6c9cf0;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.muted { color: var(--muted); }
kbd {
  font: 11px ui-monospace, monospace;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  background: var(--surface-2);
}

/* header and filters */
.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { font-weight: 650; font-size: 16px; }
.brand .muted { font-weight: 400; font-size: 13px; margin-left: 6px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: none; background: none; padding: 6px 12px; border-radius: 6px; }
.tabs button.active { background: var(--accent); color: #fff; }
.geo-status { margin-left: auto; font-size: 12px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: end;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.filters input[type=search] { width: 260px; }
.filters input[type=number] { width: 80px; }
.chips { border: none; margin: 0; padding: 0; display: flex; gap: 10px; align-items: center; }
.chips legend { font-size: 12px; color: var(--muted); padding: 0; float: left; margin-right: 6px; }
.chips label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); font-size: 13px; }

main { padding: 16px; }
.view { display: none; }
.view.active { display: block; }

/* badges */
.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge.apply { background: var(--apply); color: #fff; border-color: transparent; }
.badge.maybe { background: var(--maybe); color: #fff; border-color: transparent; }
.badge.no { background: var(--no); color: #fff; border-color: transparent; }
.badge.urgent { border-color: var(--danger); color: var(--danger); }
.badge.passed { background: var(--danger); color: #fff; border-color: transparent; }
.badge.warn { border-color: var(--maybe); color: var(--maybe); }

/* card view */
.card-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-nav .hint { font-size: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 18px 20px; max-width: 1200px;
}
.card h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
.card .sub { color: var(--muted); margin-bottom: 10px; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.card-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; }
@media (max-width: 860px) { .card-grid { grid-template-columns: 1fr; } }
.ai { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.ai h3, .posting h3, .mine h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.score { font-size: 34px; font-weight: 700; line-height: 1; }
.score small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.ai ul { padding-left: 18px; margin: 6px 0 10px; }
.ai li { margin-bottom: 4px; }
.ai .plus li::marker { content: "+  "; color: var(--apply); }
.ai .minus li::marker { content: "–  "; color: var(--danger); }
.ai .notes { white-space: pre-wrap; font-size: 13px; }
.posting { min-width: 0; }
.posting .text {
  white-space: pre-wrap; font-size: 13px; max-height: 420px; overflow: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg);
}
.posting .actions { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.mine { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.decisions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.decisions button.sel-apply { background: var(--apply); color: #fff; border-color: transparent; }
.decisions button.sel-maybe { background: var(--maybe); color: #fff; border-color: transparent; }
.decisions button.sel-no { background: var(--no); color: #fff; border-color: transparent; }
.stars { display: inline-flex; gap: 2px; margin-left: 12px; }
.stars button { border: none; background: none; font-size: 20px; padding: 0 2px; color: var(--border); }
.stars button.on { color: var(--maybe); }
.mine-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.mine-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.mine-fields .wide { grid-column: 1 / -1; }
.mine-fields textarea { min-height: 70px; resize: vertical; }
@media (max-width: 700px) { .mine-fields { grid-template-columns: 1fr; } }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); cursor: pointer; white-space: nowrap; user-select: none; }
th.sorted::after { content: " ▾"; }
th.sorted.asc::after { content: " ▴"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* map */
#map { height: calc(100vh - 190px); min-height: 420px; border-radius: 10px; border: 1px solid var(--border); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content ul { padding-left: 16px; margin: 4px 0; }

/* pipeline */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; }
.column { background: var(--surface-2); border-radius: 10px; padding: 10px; min-height: 200px; }
.column h3 { margin: 0 0 10px; font-size: 13px; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.pcard .t { font-weight: 600; }
.pcard .c { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.pcard select, .pcard button { font-size: 12px; }
.pcard code { font-size: 11px; word-break: break-all; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 2000;
}
#toast.show { opacity: .95; }

.filter-toggle, .actionbar, .narrow { display: none; }
.logout[hidden] { display: none; }

/* login page */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login h2 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { font-size: 16px; padding: 10px 12px; }
.login button { background: var(--accent); color: #fff; border-color: transparent; padding: 10px; font-weight: 600; }
.login .error { margin: 0; min-height: 1.4em; color: var(--danger); }

/* phone: thumb-sized targets, filters behind a toggle, decisions in a bottom bar */
@media (max-width: 700px) {
  body { font-size: 15px; }
  /* 16px stops mobile browsers from zooming into a focused field */
  input, select, textarea { font-size: 16px; padding: 8px 10px; }
  button { padding: 8px 12px; }
  .top {
    gap: 8px 10px; padding: 8px 16px 0;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .brand { flex: 1; min-width: 0; font-size: 15px; }
  .brand .muted { display: block; margin-left: 0; font-size: 12px; }
  .filter-toggle { display: inline-block; }
  .filter-toggle[aria-expanded=true] { background: var(--accent); color: #fff; border-color: transparent; }
  .tabs { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
  .tabs button { padding: 10px 4px; border-radius: 0; border-bottom: 2px solid transparent; }
  .tabs button.active { background: none; color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  .geo-status { display: none; }

  .filters { display: none; padding: 12px 16px; gap: 12px; background: var(--surface); }
  .filters.open { display: grid; grid-template-columns: 1fr 1fr; }
  .filters label:first-child, .filters .chips, .filters label.check { grid-column: 1 / -1; }
  .filters input[type=search], .filters input[type=number] { width: 100%; }
  .chips { flex-wrap: wrap; gap: 6px; }
  .chips legend { float: none; width: 100%; margin-bottom: 4px; }
  .chips label { border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; }
  .filters input[type=checkbox] { width: 18px; height: 18px; }

  main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }

  .card-nav { display: none; }
  .card { padding: 14px; border-radius: 10px; }
  .card h2 { font-size: 18px; }
  .card-grid { gap: 14px; }
  .posting .text { max-height: none; font-size: 14px; }
  .decisions > button { display: none; }
  .stars { margin-left: 0; }
  .stars button { font-size: 30px; padding: 2px 6px; }

  .actionbar {
    display: grid; grid-template-columns: 48px 1fr 1fr 1fr 48px; gap: 6px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(16, 24, 40, .08);
  }
  .actionbar button { min-height: 48px; padding: 0 4px; font-weight: 600; }
  .actionbar button:disabled { opacity: .35; }
  .actionbar .sel-apply { background: var(--apply); color: #fff; border-color: transparent; }
  .actionbar .sel-maybe { background: var(--maybe); color: #fff; border-color: transparent; }
  .actionbar .sel-no { background: var(--no); color: #fff; border-color: transparent; }

  .opt { display: none; }
  .narrow { display: block; font-size: 12px; }
  th, td { padding: 10px 8px; }

  #map { height: calc(100dvh - 160px); min-height: 300px; }

  .board { grid-template-columns: repeat(5, 85vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .pcard select { width: 100%; margin: 4px 0; }

  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (hover: none) {
  button:hover { border-color: var(--border); }
  tbody tr:hover { background: none; }
}
