:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e3e6ec;
  --line-strong: #cfd4dd;
  --text: #17202e;
  --muted: #5d6779;
  --faint: #8b93a3;
  --accent: #2a5bd7;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --ok: #157f3b;  --ok-soft: #e4f5ea;
  --warn: #a35a00; --warn-soft: #fdf1df;
  --bad: #b42318;  --bad-soft: #fde8e6;
  --idle: #5d6779; --idle-soft: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b23; --panel-2: #1c212b; --line: #262c38; --line-strong: #333b4a;
    --text: #e6e9ef; --muted: #a2aaba; --faint: #7a8396;
    --accent: #6c93ff; --accent-ink: #0b1020; --accent-soft: #1d2740;
    --ok: #4ccf7e; --ok-soft: #12291c; --warn: #f0a640; --warn-soft: #2d220f;
    --bad: #ff7b6e; --bad-soft: #321613; --idle: #a2aaba; --idle-soft: #222834;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ------------------------------------------------------------ chrome */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 54px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand svg { color: var(--accent); }
.nav { display: flex; gap: 2px; height: 100%; }
.nav a {
  display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; text-decoration: none;
}
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.topbar .spacer { flex: 1; }
.runner-pill { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

/* ------------------------------------------------------------ controls */
button, .btn {
  font: inherit; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--idle-soft); }
button.small, .btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 64px; }
.field { margin-bottom: 18px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; height: 34px; min-width: 46px; padding: 0 10px; border-left: 1px solid var(--line-strong); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.linkish { background: none; border: 0; height: auto; padding: 0; color: var(--accent); font-weight: 500; font-size: 12px; }
.linkish:hover { background: none; text-decoration: underline; }

.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 0 0 10px; cursor: pointer; }
.check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--accent); }
.check small { display: block; color: var(--muted); font-size: 12px; }

.switch { position: relative; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 999px; transition: .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(14px); }

/* ------------------------------------------------------------ panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.panel-head .spacer { flex: 1; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.sent { color: var(--ok); background: var(--ok-soft); }
.chip.generated { color: var(--accent); background: var(--accent-soft); }
.chip.partial { color: var(--warn); background: var(--warn-soft); }
.chip.failed, .chip.missed { color: var(--bad); background: var(--bad-soft); }
.chip.running, .chip.queued { color: var(--accent); background: var(--accent-soft); }
.chip.running::before { animation: pulse 1s infinite; }
.chip.off { color: var(--idle); background: var(--idle-soft); }

/* ------------------------------------------------------------ schedules */
.sched-list { display: grid; gap: 12px; }
.sched-list .panel + .panel { margin-top: 0; }
.sched {
  display: grid; grid-template-columns: auto 1.5fr 1.2fr 1.2fr auto; gap: 20px; align-items: center;
  padding: 16px 20px;
}
.sched.disabled .sched-main, .sched.disabled .sched-when { opacity: .55; }
.sched-main h2 { margin-bottom: 3px; }
.sched-main h2 a { color: var(--text); }
.sched-meta { font-size: 12.5px; color: var(--muted); }
.kv { font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; margin-bottom: 3px; }
.sched-when .big { font-weight: 600; }
.sched-actions { display: flex; gap: 6px; }
.empty { text-align: center; padding: 56px 20px; }
.empty p { color: var(--muted); max-width: 440px; margin: 8px auto 18px; }

/* ------------------------------------------------------------ editor */
.editor { display: grid; grid-template-columns: minmax(360px, 440px) 1fr; gap: 20px; align-items: start; }
.editor-form { padding: 22px; }
.editor-form section { padding-bottom: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.editor-form section:last-of-type { border-bottom: 0; }
.editor-form section > h3 { margin-bottom: 14px; }
.map-col { position: sticky; top: 74px; }
.map-wrap { position: relative; height: calc(100vh - 110px); min-height: 460px; overflow: hidden; }
#map { position: absolute; inset: 0; border-radius: var(--radius); }
.map-search { position: absolute; z-index: 600; top: 12px; left: 56px; right: 12px; max-width: 420px; }
.map-search input { box-shadow: var(--shadow); height: 40px; padding-left: 12px; }
.results { margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.results button { display: block; width: 100%; height: auto; text-align: left; border: 0; border-radius: 0; padding: 8px 12px; font-weight: 400; border-top: 1px solid var(--line); }
.results button:first-child { border-top: 0; }
.results button b { font-weight: 600; }
.results button span { display: block; color: var(--muted); font-size: 12px; }
.results .none { padding: 10px 12px; color: var(--muted); }
.loc-card { position: absolute; z-index: 600; left: 12px; right: 12px; bottom: 12px; max-width: 520px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; }
.loc-card .lc-main { flex: 1; min-width: 0; }
.loc-card .lc-name { font-weight: 650; }
.loc-card .lc-sub { font-size: 12.5px; color: var(--muted); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.presets button { height: 26px; font-size: 12px; padding: 0 9px; font-weight: 500; border-radius: 999px; }
.models { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.upcoming { margin: 8px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.upcoming li { padding: 2px 0; }
.upcoming li b { color: var(--text); font-weight: 600; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }
.form-actions { display: flex; gap: 8px; align-items: center; padding-top: 4px; }
.form-actions .spacer { flex: 1; }
.leaflet-container { font: inherit; background: var(--panel-2); }

/* ------------------------------------------------------------ runs */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters select { width: auto; min-width: 180px; }
table.runs { width: 100%; border-collapse: collapse; }
table.runs th { text-align: left; font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.runs td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.runs tr:last-child td { border-bottom: 0; }
table.runs tbody tr { cursor: pointer; }
table.runs tbody tr:hover td { background: var(--panel-2); }
table.runs td.err { color: var(--bad); font-size: 12.5px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.runs td.warn { color: var(--warn); font-size: 12.5px; }
.more { display: flex; justify-content: center; padding: 14px; }

.run-detail { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.callout { border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 14px; }
.callout.bad { background: var(--bad-soft); color: var(--bad); }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
pre.log {
  margin: 0; padding: 14px 16px; max-height: 520px; overflow: auto;
  font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
  background: var(--panel-2); border-radius: 0 0 var(--radius) var(--radius);
}
pre.log .w { color: var(--warn); }
pre.log .e { color: var(--bad); font-weight: 600; }
pre.log .ok { color: var(--ok); }
.pdf-frame { width: 100%; height: 560px; border: 0; border-radius: 0 0 var(--radius) var(--radius); background: #525659; display: block; }

/* ------------------------------------------------------------ settings */
.settings { display: grid; gap: 16px; max-width: 980px; }
.status-line { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }

/* ------------------------------------------------------------ users */
.who { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 550; font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who:hover { text-decoration: none; color: var(--accent); }
.role { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; }
.role.admin { background: var(--accent-soft); color: var(--accent); }
.role.viewer { background: var(--idle-soft); color: var(--idle); }
table.users th, table.users td.num { white-space: nowrap; }
table.users tbody tr { cursor: default; }
table.users tbody tr:hover td { background: transparent; }
table.users tr.inactive td > div { opacity: .55; }
table.users select { width: auto; height: 30px; }
table.users td > button + button { margin-left: 4px; }
.add-user { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.add-user input[type=email] { flex: 2 1 220px; }
.add-user input[type=text] { flex: 1 1 160px; }
.add-user select { flex: 0 0 110px; }
.callout.ok { background: var(--ok-soft); color: var(--ok); }

/* ------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .panel { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .login-foot { margin: 16px 0 0; text-align: center; font-size: 13px; }
.login .callout { margin: 0 0 14px; }

#toast {
  position: fixed; z-index: 2000; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw;
}
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 960px) {
  .editor, .run-detail { grid-template-columns: 1fr; }
  .map-col { position: static; order: -1; }
  .map-wrap { height: 380px; min-height: 0; }
  .sched { grid-template-columns: auto 1fr; }
  .sched-when, .sched-last { grid-column: 2; }
  .sched-actions { grid-column: 1 / -1; }
  .topbar { gap: 12px; padding: 0 12px; }
  .brand span, .runner-pill { display: none; }
  .who { max-width: 120px; }
  .who .role { display: none; }
  .nav a { padding: 0 8px; white-space: nowrap; }
  main { padding: 16px; }
  table.runs .hide-sm { display: none; }
}
