/* Carfix Security Monitor — dark theme
   Design tokens first, then components. NOC-style: calm dark surface,
   high-contrast severity accents, generous spacing for at-a-glance reading. */
:root {
  --bg: #0b0f17;
  --bg-elev: #121826;
  --bg-elev-2: #1a2233;
  --border: #232c40;
  --border-strong: #324061;
  --text: #e6ebf4;
  --text-dim: #9aa7bd;
  --text-faint: #6b7790;

  --accent: #4f8cff;
  --accent-dim: #2a4a8a;

  --ok: #2fbf71;
  --info: #4f8cff;
  --low: #5bc0de;
  --medium: #e0a800;
  --high: #ff7a45;
  --critical: #ff4d4f;

  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: linear-gradient(180deg, #121826, #0d121d);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .shield {
  width: 22px; height: 22px;
  display: inline-block;
  background: url("/static/favicon.svg") center / contain no-repeat;
}
.topbar .spacer { flex: 1; }
.topbar nav a { color: var(--text-dim); margin-left: 18px; font-weight: 500; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); text-decoration: none; }

.conn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-faint);
}
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.conn.live .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

/* ---- KPI strip ---- */
.kpis { display: flex; gap: 16px; padding: 20px 24px 4px; flex-wrap: wrap; }
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 170px;
  flex: 1;
}
.kpi .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 4px; }
.kpi.good .value { color: var(--ok); }
.kpi.warn .value { color: var(--high); }
.kpi.bad .value { color: var(--critical); }

/* ---- Layout ---- */
.container { padding: 20px 24px 48px; }
h1, h2, h3 { font-weight: 650; }
.section-title { margin: 24px 0 12px; color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; }

/* ---- Store grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: var(--border-strong); }
.card.alarm { border-color: var(--critical); box-shadow: 0 0 0 1px var(--critical), 0 0 20px rgba(255,77,79,0.25); }
.card.warn { border-color: var(--high); }

.card .head { display: flex; justify-content: space-between; align-items: flex-start; }
.card .store-name { font-weight: 650; font-size: 16px; }
.card .store-code { color: var(--text-faint); font-size: 12px; font-family: var(--mono); }
.card .meta { color: var(--text-dim); font-size: 13px; margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; }

/* ---- Badges / pills ---- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--text-dim);
  border: 1px solid var(--border);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.online { color: var(--ok); }
.pill.offline { color: var(--text-faint); }
.pill.fault { color: var(--high); }

.sev { font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.sev.info { color: var(--info); }
.sev.low { color: var(--low); }
.sev.medium { color: var(--medium); }
.sev.high { color: var(--high); }
.sev.critical { color: var(--critical); }

.state-tag {
  font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 6px;
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text-dim);
}
.state-tag.active { color: var(--high); border-color: var(--high); }
.state-tag.resolved_false { color: var(--ok); border-color: var(--ok); }
.state-tag.dispatched, .state-tag.expired { color: var(--critical); border-color: var(--critical); }

/* ---- Countdown ring ---- */
.ring { --pct: 1; position: relative; width: 56px; height: 56px; }
.ring svg { transform: rotate(-90deg); }
.ring .bg { stroke: var(--border); }
.ring .fg { stroke: var(--high); transition: stroke-dashoffset 0.5s linear, stroke 0.3s; }
.ring .label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 13px; font-weight: 700;
}

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: var(--bg-elev); }

/* ---- Buttons ---- */
.btn {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--bg-elev-2); color: var(--text);
  transition: filter 0.12s, transform 0.05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #03240f; }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #2a0708; }
.btn.warn { background: var(--medium); border-color: var(--medium); color: #2a2100; }
.btn.ghost { background: transparent; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }

/* Native <select> ignores background unless appearance is reset — without this
   it renders as an OS-default white box on the dark theme. Force dark styling
   and a custom dropdown arrow, and style the option list too. */
select.btn, select.btn.ghost {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: var(--bg-elev-2) !important;
  color: var(--text);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%239aa7bd' d='M2 4l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
select.btn option {
  background-color: var(--bg-elev-2);
  color: var(--text);
}
/* Text inputs styled as .btn ghost should also read as dark fields. */
input.btn, input.btn.ghost {
  background-color: var(--bg-elev-2) !important;
  color: var(--text);
}
input.btn::placeholder { color: var(--text-faint); }

/* ---- Timeline ---- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 10px 0 10px 24px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 14px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
}
.timeline li.notify::before { background: var(--accent); }
.timeline li.ack::before { background: var(--ok); }
.timeline li.escalate::before { background: var(--high); }
.timeline li.dispatch::before { background: var(--critical); }
.timeline .when { color: var(--text-faint); font-size: 12px; font-family: var(--mono); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); }
.empty { color: var(--text-faint); padding: 40px; text-align: center; }
.flash { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { background: rgba(79,140,255,0.25); } 100% { background: transparent; } }
