/* VectorD Maps — operator UI, dark theme.
   Ported from the vectord-billing design system: same semantic class names,
   same shell/nav structure, same radii and spacing. Surfaces are inverted to a
   warm dark (their light theme is warm paper, so the dark is warm too, not a
   neutral grey), and the brand red is lifted slightly for contrast on dark. */
:root {
  --red:        #d92435;
  --red-deep:   #a3141f;
  --red-hover:  #e8394a;
  --red-grad:   linear-gradient(135deg, #d92435 0%, #a3141f 100%);
  --red-text:   #f0808a;   /* red as text on dark — the solid red fails contrast */
  --red-soft:   rgba(217,36,53,.14);

  --ink:        #f2ede7;
  --muted:      #a8a099;
  --faint:      #6f675f;
  --line:       #2c2621;
  --line-strong:#3d352d;
  --card-border:rgba(255,240,225,.08);
  --canvas:     #13100d;
  --surface:    #1b1714;
  --surface-2:  #241f1a;

  --ok:         #4ade80;
  --ok-soft:    rgba(74,222,128,.14);
  --warn:       #fbbf24;
  --warn-soft:  rgba(251,191,36,.14);
  --danger:     #f87171;
  --danger-soft:rgba(248,113,113,.14);

  --radius:     16px;
  --radius-sm:  10px;
  --shadow:     0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100vw; }
body {
  background: var(--canvas);
  color: var(--ink);
  font-family: "Ubuntu Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
code, .mono { font-family: "Ubuntu Sans Mono", ui-monospace, "SF Mono", Menlo, monospace; }

/* ── App shell ── */
.shell { display: flex; flex-direction: column; min-height: 100dvh; }
@media (min-width: 860px) { .shell { flex-direction: row; } }

.side {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; flex-direction: row; gap: 2px;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@media (min-width: 860px) {
  .side {
    inset: 0 auto 0 0; flex-direction: column; gap: 4px;
    width: 210px; height: 100dvh; border-top: none; border-right: 1px solid var(--line);
    padding: 18px 12px;
  }
}
.brand { display: none; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand img { width: 20px; height: 20px; }
@media (min-width: 860px) { .brand { display: flex; } }

.navlink {
  flex: 1; min-width: 0; min-height: 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: var(--radius-sm); color: var(--muted); font-size: 10px; font-weight: 600;
}
.navlink svg { width: 20px; height: 20px; }
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink--active { background: var(--red-soft); color: var(--red-text); }
@media (min-width: 860px) {
  .navlink { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 44px; padding: 0 12px; font-size: 14px; font-weight: 500; }
  .navlink svg { width: 17px; height: 17px; }
  .nav-spacer { margin-top: auto; }
}

.main { flex: 1; min-width: 0; padding: 20px 16px calc(76px + env(safe-area-inset-bottom)); }
@media (min-width: 860px) { .main { padding: 26px 30px 40px; margin-left: 210px; } }

/* ── Headers ── */
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pagetitle { font-size: 21px; font-weight: 700; }
.subtle { color: var(--muted); font-size: 13px; }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 26px 0 10px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card--flat { box-shadow: none; }

/* ── Buttons ── */
.btn {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; font-family: inherit;
  transition: background-color .12s, border-color .12s, color .12s, filter .12s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--red-grad); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn--secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--line); }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(248,113,113,.3); }
.btn--danger:hover:not(:disabled) { background: rgba(248,113,113,.22); }
.btn--sm { min-height: 44px; padding: 0 12px; font-size: 13px; }
@media (min-width: 860px) { .btn--sm { min-height: 36px; } }
.btn--full { width: 100%; }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; color: var(--faint); }
.input, .select, .textarea {
  min-height: 44px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0 13px; font-size: 16px; color: var(--ink); background: var(--surface-2);
  font-family: inherit; width: 100%;
}
@media (min-width: 860px) { .input, .select, .textarea { font-size: 15px; } }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(217,36,53,.2);
}
.input::placeholder { color: var(--faint); }

.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px; margin-bottom: 14px; }
.form-ok { background: var(--ok-soft); color: var(--ok); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px; margin-bottom: 14px; }

/* ── Stats ──
   Two-up on phones rather than stacked: four full-width tiles pushed the map
   (the point of the page) entirely below the fold. */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 1000px) { .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; } }
.stat-tile { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 13px 14px; }
@media (min-width: 860px) { .stat-tile { padding: 16px 18px; } }
.stat-tile__label { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
@media (min-width: 860px) { .stat-tile__label { font-size: 12px; margin-bottom: 8px; } }
.stat-tile__value { font-size: 22px; font-weight: 700; line-height: 1.15; }
@media (min-width: 860px) { .stat-tile__value { font-size: 24px; } }
.stat-tile__sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge--active { background: var(--ok-soft); color: var(--ok); }
.badge--revoked { background: var(--danger-soft); color: var(--danger); }
.badge--idle { background: var(--surface-2); color: var(--muted); }
.badge--live { background: var(--ok-soft); color: var(--ok); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }

/* ── Copy-able code line (API URL, secrets) ── */
.codeline {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-family: "Ubuntu Sans Mono", ui-monospace, monospace; font-size: 13px;
  overflow-x: auto;
}
.codeline span { flex: 1; min-width: 0; white-space: nowrap; }

/* ── Login ── */
.login-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--card-border); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 32px 28px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-brand img { width: 26px; height: 26px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.empty { text-align: center; color: var(--faint); font-size: 14px; padding: 40px 8px; }

/* ── Usage bars ── */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.spark-bar { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; border-radius: 3px; }
.spark-bar:hover { background: rgba(255,255,255,.04); }
.spark-fill { width: 100%; background: var(--red-grad); border-radius: 3px; min-height: 2px; }

/* ── Docs ── */
.endpoint { border: 1px solid var(--card-border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; background: var(--surface); }
.endpoint__method { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 3px 8px; border-radius: 6px; background: var(--red-soft); color: var(--red-text); margin-right: 8px; }
.endpoint__path { font-family: "Ubuntu Sans Mono", ui-monospace, monospace; font-size: 13.5px; }
.endpoint__desc { color: var(--muted); font-size: 13px; margin: 10px 0 12px; line-height: 1.5; }
pre.code {
  background: var(--canvas); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; font-family: "Ubuntu Sans Mono", ui-monospace, monospace;
  font-size: 12.5px; line-height: 1.55; margin: 0; color: var(--ink);
}

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,.6); padding: 20px; width: 100%; max-width: 440px; max-height: 90dvh; overflow-y: auto; }
.modal-title { font-size: 17px; font-weight: 700; margin: 0 0 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ── Map ── */
#map { width: 100%; height: 100%; }
.map-card { padding: 0; overflow: hidden; height: clamp(340px, 58dvh, 640px); position: relative; }

/* On phones the map leads: it is the reason the page exists, so it goes above
   the stat tiles rather than after them. */
@media (max-width: 859px) {
  .main { display: flex; flex-direction: column; }
  .main .pagehead { order: 0; }
  .main .map-card { order: 1; height: clamp(320px, 48dvh, 460px); margin-bottom: 16px; }
  .main .stat-grid { order: 2; margin-bottom: 0; }
}
.map-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  background: rgba(19,16,13,.86); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 8px 11px; font-size: 12px; color: var(--muted);
  backdrop-filter: blur(6px);
}
.map-legend b { color: var(--ink); }

/* MapLibre control restyle for dark */
.maplibregl-ctrl-group { background: var(--surface) !important; border: 1px solid var(--line-strong) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button span { filter: invert(1) brightness(1.6); }
.maplibregl-ctrl-attrib { background: rgba(19,16,13,.8) !important; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-ctrl-scale { background: rgba(19,16,13,.7) !important; border-color: var(--line-strong) !important; color: var(--muted) !important; }
