/* ═══════════════════════════════════════════════════════════
   FLOTIX DATALOG — Design System v2
   Wzorowany na Flotix FMS. Wordmark: Alexandria 600.
═══════════════════════════════════════════════════════════ */

@font-face {
  font-family: Alexandria;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/vendor/alexandria-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: Alexandria;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/vendor/alexandria-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB,
    U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── TOKENY ─────────────────────────────────────────────── */
:root {
  --bg:        #f0f1f3;
  --surface:   #ffffff;
  --surface-2: #f8f9fb;
  --sidebar-bg: #0b0b0d;
  --sidebar-w: 240px;
  --text:   #111317;
  --text-2: #42464f;
  --text-3: #6f7480;
  --text-4: #a4a9b3;
  --line:   #e2e5ea;
  --line-2: #eceef2;
  --good:    #16a34a;
  --good-bg: #dcfce7;
  --good-fg: #15803d;
  --mid:     #d97706;
  --mid-bg:  #fef3c7;
  --mid-fg:  #92400e;
  --bad:     #dc2626;
  --bad-bg:  #fee2e2;
  --bad-fg:  #991b1b;
  --blue:    #2563eb;
  --blue-bg: #dbeafe;
  --blue-fg: #1d4ed8;
  --teal:    #0d9488;
  --teal-bg: #ccfbf1;
  --teal-fg: #0f766e;
  --sh-xs: 0 1px 2px rgba(0,0,0,.05);
  --sh-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --sh-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}

/* ── RESET ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100dvh; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { cursor: pointer; border: none; background: none; padding: 0; font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ── WORDMARK ────────────────────────────────────────────── */
.wordmark {
  font-family: Alexandria, system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.03em;
}

/* ════════════════════════════════════════════════════════════
   LOGIN
═════════════════════════════════════════════════════════════*/
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 900px 500px at 60% -10%, rgba(13,148,136,.15) 0%, transparent 60%),
    radial-gradient(ellipse 600px 400px at 10% 110%, rgba(37,99,235,.10) 0%, transparent 60%),
    #0d0f11;
}
.gate-card {
  width: min(400px, 100%);
  background: #161a1e;
  border: 1px solid #2a3038;
  border-radius: var(--r-xl);
  padding: 32px 28px 28px;
  box-shadow: 0 24px 64px rgba(0,0,0,.45);
}
.gate-card .sub   { color: #7a8895; font-size: 13px; margin: 4px 0 24px; }
.gate-card label  { display: block; font-size: 12px; color: #7a8895; margin: 12px 0 5px; }
.gate-card input  {
  width: 100%; background: #0d0f11; border: 1px solid #2a3038;
  border-radius: var(--r-sm); padding: 11px 12px; outline: none;
  color: #e8ecf1;
}
.gate-card input:focus { border-color: var(--teal); }

/* ════════════════════════════════════════════════════════════
   ADMIN SHELL — identyczny układ jak Flotix
═════════════════════════════════════════════════════════════*/
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background: var(--bg);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.nav {
  background: var(--sidebar-bg);
  border-right: 1px solid #1e1e23;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}
.nav .brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 10px 16px;
  border-bottom: 1px solid #1e1e23;
  margin-bottom: 8px;
}
.nav .brand-name  { font-size: 20px; color: #ffffff; }
.nav .brand-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .18em;
  color: var(--teal);
  text-transform: uppercase;
}
.nav .section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  color: #3a3d46;
  text-transform: uppercase;
  padding: 12px 10px 4px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  font-size: 14px;
  color: #6b7280;
  transition: background .15s, color .15s;
}
.nav-btn .ico { width: 18px; height: 18px; opacity: .7; flex-shrink: 0; }
.nav-btn:hover   { background: #16181d; color: #c4c9d4; }
.nav-btn.active  { background: #1a1d24; color: #ffffff; }
.nav-btn.active .ico { opacity: 1; }
.nav .spacer { flex: 1; }
.nav .user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: #6b7280;
  border-top: 1px solid #1e1e23;
  margin-top: 8px;
  padding-top: 12px;
  cursor: pointer;
}
.nav .user-btn:hover { color: #c4c9d4; }

/* ── Main content ────────────────────────────────────────── */
.main { padding: 24px 28px 48px; overflow: auto; min-width: 0; }
.page-head { margin: 0 0 20px; }
.page-head h2 { font-size: 26px; color: var(--text); }
.page-head p  { color: var(--text-3); font-size: 13px; margin-top: 4px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  box-shadow: var(--sh-xs);
}
.card-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; color: var(--text-3); text-transform: uppercase; }
.card-value { font-size: 28px; font-weight: 650; letter-spacing: -0.03em; color: var(--text); margin-top: 6px; }
.grid-stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--sh-xs);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface-2); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600;
  background: var(--blue); color: #ffffff;
  border: 0; cursor: pointer; transition: opacity .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover   { opacity: .88; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-ghost   { background: transparent; color: var(--text-2); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-teal    { background: var(--teal); }
.btn-danger  { background: var(--bad); }
.btn-sm      { padding: 5px 10px; font-size: 12px; }
.btn-row     { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Inputs ──────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-3); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface);
  outline: none; font-size: 13px; color: var(--text);
}
.field input:focus, .field select:focus { border-color: var(--blue); }

/* ── Tags / badges ───────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background: var(--blue-bg); color: var(--blue-fg);
}
.tag.admin  { background: #ede9fe; color: #6d28d9; }
.tag.sensor { background: var(--mid-bg); color: var(--mid-fg); }
.tag.live   { background: var(--good-bg); color: var(--good-fg); }
.tag.closed { background: var(--line); color: var(--text-3); }
.tag.off    { background: var(--bad-bg); color: var(--bad-fg); }
.tag.teal   { background: var(--teal-bg); color: var(--teal-fg); }

/* ── Live dot ───────────────────────────────────────────────*/
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.on   { background: var(--good); box-shadow: 0 0 0 2px var(--good-bg); }
.dot.warn { background: var(--mid); box-shadow: 0 0 0 2px var(--mid-bg); }
.dot.off  { background: var(--text-4); }

/* ── Toolbar / filters ───────────────────────────────────── */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-xs);
}
.toolbar .field { min-width: 160px; flex: 1; }

/* ── Charts ─────────────────────────────────────────────── */
.chart-wrap {
  background: #111317;
  border-radius: var(--r-md);
  padding: 12px;
  margin-bottom: 12px;
}
.chart-title { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--text-4); margin-bottom: 8px; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; }
.chart-legend span { font-size: 11px; color: var(--text-3); }
.chart-legend b { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
canvas.chart, canvas.track { width: 100%; display: block; }
.chart-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }

/* ── Map container ───────────────────────────────────────── */
#gps-map {
  width: 100%;
  height: 340px;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

/* ── Modal ─────────────────────────────────────────────────*/
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: grid; place-items: center;
  padding: 16px; z-index: 50;
}
.modal {
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--sh-md);
  display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { font-size: 18px; margin: 0 0 4px; }

/* ── Token display ───────────────────────────────────────── */
.token-box {
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
}
.code-block {
  background: #111317;
  border-radius: var(--r-sm);
  padding: 14px 16px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px;
  color: #a8d8b2;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.6;
}

/* ── Section divider ─────────────────────────────────────── */
.section { margin-top: 28px; }
.section-title { font-size: 14px; font-weight: 650; color: var(--text-2); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* ════════════════════════════════════════════════════════════
   SENSOR VIEW — dark field UI
═════════════════════════════════════════════════════════════*/
.sensor-shell {
  min-height: 100dvh;
  background: #0d0f11;
  color: #e8ecf1;
  display: flex;
  flex-direction: column;
}
.sensor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #1e2228;
  background: #0b0c0e;
}
.sensor-topbar .brand-name { font-size: 18px; color: #fff; }
.sensor-topbar .brand-label { font-size: 9px; color: var(--teal); letter-spacing: .15em; }

.sensor-body {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

/* State bar */
.state-bar {
  background: #161a1e;
  border: 1px solid #2a3038;
  border-radius: var(--r-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.state-bar .state-text { font-size: 13px; color: #7a8895; }
.state-bar .state-text b { color: #e8ecf1; }

/* GPS phase */
.gps-wait {
  background: #0d1a18;
  border: 1px solid #0f3a30;
  border-radius: var(--r-md);
  padding: 20px 16px;
  text-align: center;
}
.gps-wait .acc-value { font-size: 40px; font-weight: 700; color: var(--teal); letter-spacing: -0.04em; }
.gps-wait .acc-label { font-size: 12px; color: #7a8895; margin-top: 4px; }
.gps-bar-wrap { background: #1a2624; border-radius: 99px; height: 6px; margin: 12px 0 8px; overflow: hidden; }
.gps-bar { height: 6px; background: var(--teal); border-radius: 99px; transition: width .3s; }

/* Sensor card */
.sensor-card {
  background: #161a1e;
  border: 1px solid #2a3038;
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.sensor-card-title { font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #4a5568; margin-bottom: 10px; }

/* Label input */
.sensor-label-wrap input {
  width: 100%;
  background: #0d0f11;
  border: 1px solid #2a3038;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: #e8ecf1;
  font-size: 14px;
  outline: none;
}
.sensor-label-wrap input:focus { border-color: var(--teal); }
.sensor-label-wrap input:disabled { opacity: .5; }

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.metric {
  background: #0d0f11;
  border: 1px solid #1e2228;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  text-align: center;
}
.metric-label { font-size: 10px; color: #4a5568; }
.metric-value { font-size: 20px; font-weight: 700; color: #e8ecf1; letter-spacing: -0.03em; margin-top: 2px; }
.metric-value.teal { color: var(--teal); }
.metric-value.warn { color: #f0b429; }
.metric-value.bad  { color: #f87171; }

/* Auto-pause indicators */
.pause-indicator {
  background: #1a130a;
  border: 1px solid #3d2a10;
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: #f0b429;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Start / stop button */
.start-btn {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  border-radius: var(--r-md);
  background: var(--teal);
  color: #fff;
  border: 0;
  cursor: pointer;
  transition: opacity .15s;
}
.start-btn:hover { opacity: .9; }
.start-btn.running {
  background: #7f1d1d;
  color: #fca5a5;
}
.start-btn:disabled { opacity: .5; cursor: default; }

/* Options */
.sensor-options { display: flex; flex-direction: column; gap: 8px; }
.sensor-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
}
.sensor-option input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--teal); cursor: pointer; }

/* Session info */
.session-info { font-size: 11px; color: #374151; word-break: break-all; padding: 6px 0; }

/* ── Error ───────────────────────────────────────────────── */
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ── Alert banner ────────────────────────────────────────── */
.alert {
  background: var(--bad-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--bad-fg);
  margin-bottom: 8px;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE
═════════════════════════════════════════════════════════════*/
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    height: auto;
    position: static;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid #1e1e23;
    gap: 4px;
  }
  .nav .brand { flex-direction: row; align-items: center; gap: 8px; padding: 2px 8px 2px; border: 0; margin: 0; }
  .nav .brand-label { margin: 0; }
  .nav .section-label { display: none; }
  .nav .spacer { flex: none; }
  .nav .user-btn { border: 0; padding: 9px 10px; margin: 0; }
  .main { padding: 16px; }
  .chart-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}
