/* ==========================================================================
   TILBITĖ SCADA + VICTRON 3~ — DARK PRO INDUSTRIAL UI (tilbites.id.lv)
   Responsive Desktop / Tablet / Mobile • Zero External CDN Dependencies
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg-deep: #070c17;
  --bg-card: #0e1729;
  --bg-card-alt: #131f36;
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(56, 189, 248, 0.35);
  --txt-main: #f1f5f9;
  --txt-muted: #94a3b8;
  --txt-dim: #64748b;
  --accent-sky: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-indigo: #818cf8;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(ellipse 80% 45% at 20% -10%, rgba(14, 165, 233, 0.14), transparent 65%),
    radial-gradient(ellipse 60% 40% at 85% 0%, rgba(16, 185, 129, 0.08), transparent 60%);
  color: var(--txt-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
}

.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Shell & Header ---------- */
.shell {
  width: 100%;
  max-width: 1520px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: linear-gradient(180deg, #131f37 0%, #0d1628 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 11px 18px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(56,189,248,0.2), rgba(245,158,11,0.2));
  border: 1px solid rgba(56,189,248,0.4);
  display: grid; place-items: center;
}
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: 0.04em; color: #f8fafc; }
.brand-sub {
  font-size: 11px; font-weight: 600; color: var(--txt-muted);
  padding: 3px 10px; border-radius: 999px;
  background: rgba(7, 12, 23, 0.75); border: 1px solid var(--border-subtle);
}

.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ws-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em; background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35); color: #34d399;
}
.ws-pill.offline {
  background: rgba(244, 63, 94, 0.14); border-color: rgba(244, 63, 94, 0.4); color: #fda4af;
}
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%; background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.lang-switch {
  display: inline-flex; background: #080e1c; border: 1px solid var(--border-subtle);
  border-radius: 9px; padding: 2px;
}
.lang-btn {
  border: 0; background: transparent; color: var(--txt-muted);
  font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.lang-btn.active { background: #1e2f50; color: #f8fafc; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #172540; color: #e2e8f0; border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 9px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.15s ease;
}
.btn:hover { background: #1f3256; border-color: rgba(56, 189, 248, 0.45); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  border-color: #38bdf8; color: #fff; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-amber {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border-color: #fbbf24; color: #090e1a; font-weight: 800;
}

/* ---------- PLC Halted & Alarm Banner ---------- */
.halt-banner {
  display: none;
  background: linear-gradient(90deg, rgba(159, 18, 57, 0.92), rgba(127, 29, 29, 0.92));
  border: 1px solid #fb7185; border-radius: 12px;
  padding: 12px 16px; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(244, 63, 94, 0.25);
}
.halt-banner.visible { display: block; }
.halt-banner h3 { margin: 0 0 4px; font-size: 14px; color: #fff; }
.halt-banner p { margin: 0; font-size: 12px; color: #ffe4e6; }

/* ---------- KPI Strip ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi-card {
  background: linear-gradient(180deg, #111c33 0%, #0c1526 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 11px 14px;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 82px;
}
.kpi-lbl { font-size: 11px; font-weight: 600; color: var(--txt-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-val { font-size: 21px; font-weight: 800; color: #f8fafc; margin: 3px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11px; color: var(--txt-dim); font-variant-numeric: tabular-nums; }

/* ---------- Main 12-Column Grid ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.card {
  background: linear-gradient(180deg, var(--bg-card) 0%, #0a1222 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 15px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
  padding-bottom: 9px; border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}
.card-title { font-size: 14px; font-weight: 700; color: #f8fafc; margin: 0; }
.card-sub { font-size: 11px; color: var(--txt-dim); }

/* ---------- Custom 2-Dot Dual Range Sliders ---------- */
.dual-slider-card {
  background: rgba(15, 25, 45, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px;
  padding: 13px 14px;
  margin-bottom: 12px;
}
.dual-slider-card.hw { border-left: 3px solid var(--accent-amber); }
.dual-slider-card.ht { border-left: 3px solid var(--accent-sky); }

.ds-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.ds-name { font-size: 13.5px; font-weight: 700; color: #f8fafc; }
.ds-bounds { font-size: 11px; font-weight: 600; color: var(--txt-muted); background: #080f1e; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border-subtle); }

.ds-badges { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.ds-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 8px; font-size: 11.5px; background: #091122;
  border: 1px solid rgba(148, 163, 184, 0.18); font-variant-numeric: tabular-nums;
}
.dot-hollow { width: 10px; height: 10px; border-radius: 50%; border: 2.5px solid #94a3b8; background: #091122; display: inline-block; }
.dot-solid-hw { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-amber); box-shadow: 0 0 8px rgba(245,158,11,0.8); display: inline-block; }
.dot-solid-ht { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-sky); box-shadow: 0 0 8px rgba(56,189,248,0.8); display: inline-block; }
.ds-delta { font-size: 11px; font-weight: 700; color: var(--txt-muted); }

.ds-track-area { position: relative; height: 42px; user-select: none; touch-action: none; margin: 4px 6px 2px; }
.ds-rail {
  position: absolute; top: 14px; left: 0; right: 0; height: 8px;
  background: #070d19; border-radius: 999px; border: 1px solid rgba(148, 163, 184, 0.18);
}
.ds-fill {
  position: absolute; top: 14px; height: 8px; border-radius: 999px;
}
.hw .ds-fill { background: linear-gradient(90deg, rgba(245,158,11,0.35), #f59e0b); }
.ht .ds-fill { background: linear-gradient(90deg, rgba(56,189,248,0.35), #38bdf8); }

.ds-now-pin {
  position: absolute; top: 8px; width: 3px; height: 20px; border-radius: 2px;
  background: #10b981; box-shadow: 0 0 8px #10b981; transform: translateX(-50%);
  pointer-events: none; z-index: 2;
}
.ds-now-lbl {
  position: absolute; top: -12px; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; color: #34d399; white-space: nowrap; pointer-events: none;
}

.ds-handle {
  position: absolute; top: 7px; width: 22px; height: 22px; border-radius: 50%;
  transform: translateX(-50%); cursor: grab; z-index: 4;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}
.ds-handle:active { cursor: grabbing; transform: translateX(-50%) scale(1.14); }
.ds-handle.min-h {
  background: #0d172a; border: 3px solid #cbd5e1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.hw .ds-handle.set-h {
  background: #f59e0b; border: 3px solid #fef3c7;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.75);
}
.ht .ds-handle.set-h {
  background: #0ea5e9; border: 3px solid #e0f2fe;
  box-shadow: 0 0 12px rgba(14, 165, 233, 0.75);
}

.ds-ticks { position: absolute; top: 27px; left: 0; right: 0; font-size: 10px; color: var(--txt-dim); }
.ds-tick { position: absolute; transform: translateX(-50%); }
.ds-tick:first-child { transform: none; }
.ds-tick:last-child { transform: translateX(-100%); }

.ds-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(148,163,184,0.12);
}
.ds-hint { font-size: 11.5px; color: var(--txt-muted); }
.ds-warn { font-size: 11px; color: #fbbf24; margin-top: 5px; display: none; }
.ds-warn.show { display: block; }

/* ---------- SVG Hydraulic Schema ---------- */
.schema-wrap {
  width: 100%; background: #080f1e; border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 12px; padding: 8px; overflow: hidden;
}
#hp_svg_schema { width: 100%; height: auto; display: block; }
.svg-tag-txt { font-family: inherit; font-size: 10.5px; font-weight: 700; }
.svg-temp-txt { font-family: inherit; font-size: 13.5px; font-weight: 800; fill: #f8fafc; font-variant-numeric: tabular-nums; }
.svg-dt-txt { font-family: inherit; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.svg-badge-bg { fill: rgba(13, 22, 40, 0.92); stroke-width: 1.4; }
.svg-pipe-base { fill: none; stroke-width: 5.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.48; }
.svg-flow {
  fill: none; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 8 10; opacity: 0;
}
.svg-flow.active { opacity: 0.95; animation: pipeflow 0.85s linear infinite; }
@keyframes pipeflow { from { stroke-dashoffset: 18; } to { stroke-dashoffset: 0; } }
.svg-unit-off .pump-ring { fill: #111c33; stroke: #475569; stroke-width: 2; }
.svg-unit-off .pump-arrow { fill: #64748b; }
.svg-unit-on .pump-ring { fill: rgba(16, 185, 129, 0.22); stroke: #10b981; stroke-width: 2.4; }
.svg-unit-on .pump-arrow { fill: #34d399; }

.schema-legend { display: flex; gap: 12px; align-items: center; font-size: 11px; color: var(--txt-muted); }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }

/* ---------- Mid Grid: Optimizer + Victron 3-Phase ---------- */
.mid-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 14px;
  margin-bottom: 14px;
}

.tip-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.tip-item {
  padding: 8px 11px; border-radius: 9px; font-size: 12px;
  background: rgba(16, 185, 129, 0.09); border: 1px solid rgba(16, 185, 129, 0.28); color: #d1fae5;
}
.tip-item.tip { background: rgba(56, 189, 248, 0.1); border-color: rgba(56, 189, 248, 0.32); color: #e0f2fe; }
.tip-item.warn { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.38); color: #fef3c7; }

.opt-box {
  background: #091120; border: 1px solid var(--border-subtle);
  border-radius: 11px; padding: 12px;
}
.opt-toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.switch-chk {
  position: relative; width: 44px; height: 24px; appearance: none;
  background: #1e293b; border-radius: 99px; cursor: pointer; border: 1px solid #475569;
  transition: background 0.2s; flex-shrink: 0;
}
.switch-chk::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #cbd5e1; transition: transform 0.2s;
}
.switch-chk:checked { background: #059669; border-color: #34d399; }
.switch-chk:checked::after { transform: translateX(20px); background: #fff; }

.opt-inputs {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 10px 0;
}
.opt-field label { display: block; font-size: 10.5px; color: var(--txt-muted); margin-bottom: 3px; }
.opt-field input {
  width: 100%; background: #0e192d; border: 1px solid rgba(148,163,184,0.25);
  color: #f8fafc; border-radius: 7px; padding: 5px 7px; font-size: 12px; font-weight: 700;
}

/* ---------- Victron Energy Grid ---------- */
.vic-flow-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px;
}
.vic-node {
  background: #091120; border: 1px solid var(--border-subtle); border-radius: 10px; padding: 10px 11px;
}
.vic-node-lbl { font-size: 10.5px; font-weight: 700; color: var(--txt-muted); text-transform: uppercase; }
.vic-node-val { font-size: 18px; font-weight: 800; margin: 3px 0; font-variant-numeric: tabular-nums; }
.vic-node-sub { font-size: 11px; color: var(--txt-dim); font-variant-numeric: tabular-nums; }

.phase-bars, .mppt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.mppt-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 10px; }
.mini-tile {
  background: rgba(13, 22, 40, 0.78); border: 1px solid rgba(148,163,184,0.12);
  border-radius: 8px; padding: 7px 9px; font-variant-numeric: tabular-nums;
}
.mini-tile-k { font-size: 10.5px; color: var(--txt-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-tile-v { font-size: 13px; font-weight: 700; color: #f8fafc; margin-top: 2px; }

/* ---------- History Charts ---------- */
.chart-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.seg-group { display: inline-flex; background: #080f1d; border: 1px solid var(--border-subtle); border-radius: 9px; padding: 2px; flex-wrap: wrap; }
.seg-btn {
  border: 0; background: transparent; color: var(--txt-muted);
  font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 7px; cursor: pointer;
}
.seg-btn.active { background: #1c2d4d; color: #38bdf8; }

.hist-summary { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--txt-muted); margin-bottom: 8px; }
.hist-summary b { color: #f8fafc; }

.chart-stage {
  position: relative; width: 100%; height: 290px;
  background: #070d1a; border: 1px solid rgba(148, 163, 184, 0.12); border-radius: 11px; padding: 8px;
}
#hist_canvas { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 11.5px; color: var(--txt-muted); }
.cleg-item { display: inline-flex; align-items: center; gap: 5px; }
.cleg-swatch { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---------- Login Screen & Modal ---------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 410px;
  background: linear-gradient(180deg, #121f38 0%, #0b1324 100%);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 18px; padding: 28px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.field-input {
  width: 100%; background: #070d1a; border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 10px; padding: 11px 13px; color: #f8fafc; font-size: 14px; outline: none;
}
.field-input:focus { border-color: var(--accent-sky); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 7, 18, 0.78);
  backdrop-filter: blur(4px); display: none; place-items: center; z-index: 100; padding: 16px;
}
.modal-backdrop.open { display: grid; }
.modal-card {
  width: 100%; max-width: 420px; background: #0f1a2f;
  border: 1px solid rgba(148, 163, 184, 0.26); border-radius: 15px; padding: 20px;
}

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: #0f2922; border: 1px solid #10b981; color: #ecfdf5;
  padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: 12.5px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.45); opacity: 0; pointer-events: none;
  transform: translateY(10px); transition: all 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: #3b121d; border-color: #f43f5e; color: #ffe4e6; }

/* ---------- Responsive Breakpoints ---------- */
@media (max-width: 1220px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .main-grid { grid-template-columns: 1fr; }
  .mid-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { padding: 8px 10px 24px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vic-flow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mppt-grid { grid-template-columns: repeat(2, 1fr); }
  .opt-inputs { grid-template-columns: repeat(2, 1fr); }
  .kpi-val { font-size: 18px; }
}
