/* Kapato admin panel. Brand colours from vps/site/css/input.css; the design is admin-mockup/. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Montserrat:wght@700;800&display=swap');

:root {
  --brand: #FF5733;
  --brand-dark: #E04420;
  --brand-tint: #FFEDE8;
  --teal: #0E4D64;
  --teal-light: #1A6B8A;
  --teal-tint: #E3EFF3;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --ink: #0F172A;
  --text: #334155;
  --muted: #64748B;
  --faint: #94A3B8;
  --line: #E2E8F0;
  --line-soft: #F1F5F9;
  /* status — reserved for good / warning / critical, always with an icon + label */
  --good: #0ca30c;
  --good-tint: #E7F6E7;
  --warn: #fab219;
  --warn-tint: #FEF5E1;
  --crit: #d03b3b;
  --crit-tint: #FBEAEA;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05);
  /* what the dark theme swaps besides the above */
  --side-bg: #0E4D64;
  --th-bg: #FBFCFD;
  --row-hover: #FBFCFE;
  --input-bg: #FFFFFF;
  --input-border: #CBD5E1;
  --choice-on: #FFF8F6;
  --info-border: #C7DDE5;
  --ok-border: #C3E6C3;
  --warn-border: #F5DFA8;
  --crit-border: #EFC1C1;
  --test-ink: #E04420;
  --test-border: #F8C6B8;
  --chart-line: #0E4D64;
  --grid: #EEF2F6;
  --pop-bg: #0F172A; /* tooltips and toasts — dark in both themes */
}

/* Dark theme: theme.js sets data-theme="dark" (Auto follows the system). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-tint: rgba(255, 87, 51, .16);
  --teal: #13698A;
  --teal-light: #6CC3E0;
  --teal-tint: rgba(108, 195, 224, .13);
  --bg: #0B1220;
  --surface: #131C2E;
  --ink: #F1F5F9;
  --text: #CBD5E1;
  --muted: #94A3B8;
  --faint: #64748B;
  --line: #27344D;
  --line-soft: #1A2438;
  --good-tint: rgba(12, 163, 12, .18);
  --warn-tint: rgba(250, 178, 25, .15);
  --crit-tint: rgba(208, 59, 59, .22);
  --shadow: none;
  --side-bg: #0A1626;
  --th-bg: #172136;
  --row-hover: #18233A;
  --input-bg: #0F1828;
  --input-border: #34425E;
  --choice-on: rgba(255, 87, 51, .10);
  --info-border: rgba(108, 195, 224, .35);
  --ok-border: rgba(12, 163, 12, .4);
  --warn-border: rgba(250, 178, 25, .4);
  --crit-border: rgba(208, 59, 59, .45);
  --test-ink: #FF8A70;
  --test-border: rgba(255, 87, 51, .4);
  --chart-line: #6CC3E0;
  --grid: #1F2A40;
}
/* OpenStreetMap has no dark tiles — dim and invert them */
:root[data-theme="dark"] .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88); }
:root[data-theme="dark"] .leaflet-container { background: #1B2333; }
:root[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-attribution { background: rgba(19, 28, 46, .8); color: var(--muted); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--teal-light); }
:root[data-theme="dark"] .leaflet-tooltip { background: var(--surface); color: var(--ink); border-color: var(--line); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--teal-light); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); margin: 0; }
h1 { font: 700 22px/1.25 'Inter', sans-serif; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---- shell: sidebar + main ---------------------------------- */

.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.side {
  background: var(--side-bg);
  color: #CFE3EA;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font: 800 19px/1 'Montserrat', sans-serif;
  letter-spacing: .06em;
  color: #fff;
  padding: 4px 10px 22px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand:hover { text-decoration: none; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }
.brand small { font: 500 11px 'Inter', sans-serif; color: #9CC3D1; letter-spacing: .08em; text-transform: uppercase; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  color: #CFE3EA;
  padding: 8px 10px;
  border-radius: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
}
.side nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.side nav a.on { background: rgba(255, 255, 255, .13); color: #fff; }
.side nav .count {
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
}
.side nav .count.hot { background: var(--brand); }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 12px; color: #9CC3D1; }
.side-foot b { color: #fff; font-weight: 600; }
.side-foot a { display: block; color: #CFE3EA; margin-top: 4px; }

main { padding: 24px 32px 48px; max-width: 1320px; width: 100%; }
.topline { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topline .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ---- building blocks ----------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card > .hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.card > .hd .muted { font-size: 12.5px; }
.card > .bd { padding: 16px 18px; }
.card > .bd.flush { padding: 0; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: 600 13px/1 'Inter', sans-serif;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--line-soft); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.teal:hover { background: var(--teal-light); }
.btn.danger { color: var(--crit); border-color: var(--crit-border); }
.btn.danger:hover { background: var(--crit-tint); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn .sub { font-weight: 500; opacity: .8; }

/* status pills: dot = identity of the mode, never colour alone — the label says it */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: var(--line-soft);
  white-space: nowrap;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.pill.far { background: var(--teal-tint); }
.pill.far i { background: var(--teal); }
.pill.near { background: var(--brand-tint); }
.pill.near i { background: var(--brand); box-shadow: 0 0 0 3px rgba(255, 87, 51, .25); }
.pill.planned i { background: transparent; border: 2px solid var(--teal); width: 9px; height: 9px; }
.pill.new i { background: transparent; border: 2px dashed var(--faint); width: 9px; height: 9px; }
.pill.v1 { background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.pill.ok { background: var(--good-tint); }
.pill.ok i { background: var(--good); }
/* the two alarm pills carry a glyph, so a colour-blind reader still gets it */
.pill.late, .pill.low, .pill.pending { padding-left: 4px; }
.pill.late { background: var(--crit-tint); }
.pill.low { background: var(--warn-tint); }
.pill.pending { background: var(--warn-tint); }
.pill.late i, .pill.low i, .pill.pending i {
  width: 15px; height: 15px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font: 800 10px/1 'Inter', sans-serif; font-style: normal; color: #fff;
}
.pill.late i { background: var(--crit); }
.pill.low i { background: var(--warn); color: #0F172A; }
.pill.pending i { background: var(--warn); color: #0F172A; }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--line-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}
.tag.retained { background: var(--surface); border-style: dashed; }
.tag.test { background: var(--brand-tint); color: var(--test-ink); border-color: var(--test-border); letter-spacing: .04em; }

/* battery meter: fill in ink tones; low = warning fill + the word "low" */
.bat { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; color: var(--ink); font-weight: 500; }
.bat .cell {
  position: relative;
  width: 24px; height: 11px;
  border: 1.5px solid var(--faint);
  border-radius: 3px;
  padding: 1px;
}
.bat .cell::after { content: ''; position: absolute; right: -4px; top: 2.5px; width: 2px; height: 4px; background: var(--faint); border-radius: 0 1px 1px 0; }
.bat .cell b { display: block; height: 100%; border-radius: 1px; background: var(--teal-light); }
.bat.low .cell { border-color: #D9A21A; }
.bat.low .cell b { background: var(--warn); }
.bat .mv { color: var(--muted); font-weight: 400; font-size: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--th-bg);
  white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--row-hover); }
td .main { color: var(--ink); font-weight: 600; }
td .sub { font-size: 12.5px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.id { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; color: var(--muted); }

/* key/value list */
.kv { display: grid; grid-template-columns: 120px 1fr; row-gap: 10px; column-gap: 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; color: var(--ink); }
.kv dd .sub { display: block; font-size: 12.5px; color: var(--muted); }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
.tile { padding: 14px 16px; }
.tile .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.tile .value { font: 700 28px/1.15 'Inter', sans-serif; color: var(--ink); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile .note .pill { font-size: 11px; }

/* attention list */
.alerts-list { list-style: none; margin: 0; padding: 0; }
.alerts-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); }
.alerts-list li:last-child { border-bottom: 0; }
.alerts-list .what { color: var(--ink); font-weight: 500; }
.alerts-list .why { font-size: 12.5px; color: var(--muted); }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl .day { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 18px 6px; }
.tl li.ev { display: grid; grid-template-columns: 52px 18px 1fr; gap: 8px; padding: 5px 18px; }
.tl .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; padding-top: 1px; }
.tl .mk { position: relative; }
.tl .mk::before { content: ''; position: absolute; left: 8px; top: -6px; bottom: -6px; width: 1.5px; background: var(--line); }
.tl .mk i { position: relative; display: block; width: 9px; height: 9px; margin: 5px 0 0 4px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 2px var(--surface); }
.tl .mk i.fix { background: var(--teal); }
.tl .mk i.near { background: var(--brand); }
.tl .mk i.cmd { background: var(--surface); border: 2px solid var(--teal); }
.tl .mk i.bad { background: var(--crit); }
.tl .mk i.warn { background: var(--warn); }
.tl .x { color: var(--ink); }
.tl .x .sub { display: block; font-size: 12.5px; color: var(--muted); }

/* forms */
label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=time], select, textarea {
  font: 14px 'Inter', sans-serif;
  color: var(--ink);
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(26, 107, 138, .35); outline-offset: 0; border-color: var(--teal-light); }
textarea { min-height: 78px; resize: vertical; }
.field { margin-bottom: 16px; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--surface); }
.choice + .choice { margin-top: 8px; }
.choice input { margin-top: 3px; accent-color: var(--brand); }
.choice.on { border-color: var(--brand); background: var(--choice-on); }
.choice .t { color: var(--ink); font-weight: 600; }
.choice .d { font-size: 12.5px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a, .seg span { padding: 7px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); background: var(--surface); }
.seg :last-child { border-right: 0; }
.seg .on { background: var(--teal); color: #fff; }

/* notices */
.note-box { border-radius: 8px; padding: 11px 14px; font-size: 13px; border: 1px solid var(--line); background: var(--line-soft); }
.note-box b { color: var(--ink); }
.note-box.info { background: var(--teal-tint); border-color: var(--info-border); }
.note-box.ok { background: var(--good-tint); border-color: var(--ok-border); }
.note-box.warn { background: var(--warn-tint); border-color: var(--warn-border); }
.note-box.crit { background: var(--crit-tint); border-color: var(--crit-border); }

/* payload preview */
.payload {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12.5px;
  background: #0F172A;
  color: #E2E8F0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre;
}
.payload .k { color: #7DD3FC; }
.payload .c { color: #64748B; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs a { padding: 9px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); }

/* filters row */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input { width: auto; padding: 7px 10px; font-size: 13px; }
.chip { font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.chip.on { background: var(--teal); border-color: var(--teal); color: #fff; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.photo { aspect-ratio: 4 / 3; border-radius: 8px; background: linear-gradient(135deg, #3B2A20, #6B4A33 55%, #A57B55); position: relative; overflow: hidden; }
.photo::after { content: attr(data-cap); position: absolute; left: 8px; bottom: 6px; font-size: 11px; color: #fff; opacity: .85; }
.photo.add { background: var(--surface); border: 1.5px dashed var(--input-border); display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 600; font-size: 13px; }
.photo.add::after { content: none; }

/* map placeholder */
.map { display: block; width: 100%; height: auto; border-radius: 0 0 var(--radius) var(--radius); background: #EEF2EA; }

/* chart */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--pop-bg);
  color: #fff;
  border: 1px solid #334155;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 7px;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  opacity: 0;
  transition: opacity .08s;
}
.tip b { font-weight: 600; }
.tip .sub { color: #CBD5E1; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--teal) 0%, #093A4C 60%, #062A37 100%); padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 32px 30px 26px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.login-card .brand { color: var(--ink); padding: 0 0 6px; justify-content: center; font-size: 24px; }
.login-card .brand small { color: var(--muted); }
.login-card .lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.login-foot { text-align: center; font-size: 12px; color: #9CC3D1; margin-top: 18px; }

/* mockup ribbon */
.mock {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 10;
  font-size: 11.5px;
  background: var(--ink);
  color: #E2E8F0;
  border-radius: 8px;
  padding: 7px 11px;
  opacity: .85;
}
.mock a { color: #7DD3FC; }

@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .brand { padding: 0 14px 0 0; }
  .side nav { flex-direction: row; }
  .side-foot { display: none; }
  main { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .inline-fields { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .photos { grid-template-columns: repeat(2, 1fr); }
}

/* long payloads wrap instead of pushing the table wider; wide tables scroll on phones */
td.mono:nth-child(4) { word-break: break-all; }
.card > .bd.flush { overflow-x: auto; }

/* ---- the live panel ---------------------------------------------- */

[hidden] { display: none !important; }
.map-box { height: 380px; border-radius: 0; z-index: 0; }
.empty { padding: 22px 18px; color: var(--muted); text-align: center; }
.page-error { max-width: 560px; }
button.btn { font-family: inherit; }
.link-btn { background: none; border: 0; padding: 0; color: var(--teal-light); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.secret { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 15px; letter-spacing: .03em; background: var(--warn-tint); border: 1px solid var(--warn-border); border-radius: 8px; padding: 8px 12px; display: inline-block; user-select: all; }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: var(--pop-bg); border: 1px solid #334155; color: #fff; border-radius: 9px; padding: 10px 14px; font-size: 13px; box-shadow: 0 8px 24px rgba(15, 23, 42, .25); border-left: 4px solid var(--good); }
.toast.crit { border-left-color: var(--crit); }
.toast.warn { border-left-color: var(--warn); }

/* the theme switch in the sidebar */
.side-foot .theme-btn { display: block; margin-top: 8px; color: #CFE3EA; font-size: 12px; }

/* the battery chart takes its colours from the theme */
.chart-wrap .ch-grid { stroke: var(--grid); }
.chart-wrap .ch-base { stroke: var(--line); }
.chart-wrap .ch-label { fill: var(--muted); }
.chart-wrap .ch-strong { fill: var(--ink); }
.chart-wrap .ch-line { stroke: var(--chart-line); }
.chart-wrap .ch-dot { fill: var(--chart-line); stroke: var(--surface); }
.chart-wrap .ch-shade { fill: var(--brand-tint); }
.chart-wrap .ch-cross { stroke: var(--faint); }
