/* ============================================================================
   Transformer Fleet — control-room visual language.
   Palette: near-black navy panels, hairline dividers, oscillograph accents.
   Score colors run green (1, best) through red (5, worst) — the one place
   color carries real meaning; everything else stays quiet and monochrome.
   ============================================================================ */

:root {
  --bg:        #0A1120;
  --panel:     #111A2C;
  --panel-2:   #16223A;
  --border:    #223049;
  --border-soft: #1A2438;
  --text:      #E6EDF7;
  --text-dim:  #8A97AC;
  --text-faint:#5B6980;
  --accent:    #2DD4BF;
  --accent-dim:#1B8A7D;
  --amber:     #FBBF24;

  --s1: #4ADE80;  /* score 1 — best */
  --s2: #A3D93B;
  --s3: #FBBF24;
  --s4: #FB923C;
  --s5: #F87171;  /* score 5 — worst */

  --font-display: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; }

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

::selection { background: var(--accent-dim); color: #fff; }

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

/* --- App shell -------------------------------------------------------- */

#app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  padding: 20px 0;
  display: flex; flex-direction: column;
}

.brand {
  padding: 0 20px 20px 20px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 12px;
}
.brand-mark { font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: 0.02em; }
.brand-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; cursor: pointer;
  color: var(--text-dim); font-size: 13.5px; font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { color: var(--text); border-left-color: var(--accent); background: var(--panel-2); }

.sidebar-footer {
  margin-top: auto; padding: 16px 20px 4px 20px;
  border-top: 1px solid var(--border-soft);
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint);
}

.main { padding: 28px 36px 60px 36px; max-width: 1400px; }

.view { display: none; }
.view.active { display: block; }

h1 { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 0 0 4px 0; }
h2 { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin: 0 0 14px 0; color: var(--text); }
.page-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }

/* --- oscillograph divider (signature element) -------------------------- */
.trace-divider { width: 100%; height: 20px; margin: 20px 0; opacity: 0.5; }
.trace-divider path { fill: none; stroke: var(--accent-dim); stroke-width: 1; }

/* --- Panels / cards ------------------------------------------------------ */

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 18px 20px;
}

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.stat-value { font-family: var(--font-mono); font-size: 28px; font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--text-dim); }

/* --- Score badge -------------------------------------------------------- */

.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 13px;
  width: 30px; height: 22px; border-radius: 4px; color: #0A1120;
}
.score-1 { background: var(--s1); }
.score-2 { background: var(--s2); }
.score-3 { background: var(--s3); }
.score-4 { background: var(--s4); }
.score-5 { background: var(--s5); }
.score-na { background: var(--border); color: var(--text-faint); }

/* --- Table --------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 500; color: var(--text-faint);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 8px 12px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text-dim); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); color: var(--text); }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--panel-2); }
.mono { font-family: var(--font-mono); }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* --- Filters row ---------------------------------------------------------- */

.filter-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
select, input[type=text], input[type=number], input[type=date] {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 7px 10px; border-radius: 4px; font-size: 13px;
  font-family: var(--font-body);
}
select:focus, input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

button {
  background: var(--accent); color: #06231F; border: none;
  padding: 8px 16px; border-radius: 4px; font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: var(--font-body);
}
button:hover { background: #45E0CA; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--border-soft); }

/* --- Map ------------------------------------------------------------------ */

#map { height: 520px; border-radius: 6px; border: 1px solid var(--border-soft); }
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 6px; }
.leaflet-popup-tip { background: var(--panel); }

/* --- Detail page ----------------------------------------------------------- */

.subscore-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.subscore-label { flex: 1; font-size: 13px; }
.subscore-bar-track { flex: 2; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.subscore-bar-fill { height: 100%; border-radius: 3px; }
.placeholder-tag { font-size: 10px; color: var(--text-faint); font-family: var(--font-mono); border: 1px solid var(--border); padding: 1px 5px; border-radius: 3px; }

.life-range-track { position: relative; height: 8px; background: var(--panel-2); border-radius: 4px; margin: 20px 0 8px 0; }
.life-range-fill { position: absolute; height: 100%; background: var(--accent-dim); border-radius: 4px; }
.life-range-point { position: absolute; top: -4px; width: 3px; height: 16px; background: var(--accent); }

.chart-wrap { background: var(--panel-2); border-radius: 6px; padding: 12px; margin-bottom: 16px; }

/* --- Forms ------------------------------------------------------------------ */

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.form-field input, .form-field select { width: 100%; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--panel); border: 1px solid var(--accent); padding: 12px 18px; border-radius: 6px; font-size: 13px; display: none; }
.toast.error { border-color: var(--s5); }

/* --- Config / weights ---------------------------------------------------- */

.weight-row { display: grid; grid-template-columns: 200px 1fr 80px; align-items: center; gap: 14px; padding: 8px 0; }
input[type=range] { accent-color: var(--accent); }
.weight-sum { font-family: var(--font-mono); font-size: 13px; margin-top: 12px; }
.weight-sum.bad { color: var(--s5); }
.weight-sum.good { color: var(--s1); }

/* --- Typeahead (name search -> ID) ---------------------------------------- */
.typeahead-wrap { position: relative; }
.typeahead-list {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
  max-height: 220px; overflow-y: auto;
}
.typeahead-item { padding: 8px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border-soft); }
.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover, .typeahead-item.highlighted { background: var(--border-soft); }
.typeahead-item .th-sub { color: var(--text-faint); font-size: 11.5px; }
.typeahead-empty { padding: 8px 10px; font-size: 12.5px; color: var(--text-faint); }
.typeahead-selected-tag { font-size: 11px; color: var(--accent); margin-top: 4px; font-family: var(--font-mono); min-height: 14px; }

/* --- Tabs (entry forms) ---------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border-soft); }
.tab { padding: 8px 14px; font-size: 13px; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
}