/* ═══════════════════════════════════════════════════════════════
   WaterStation Configurator — Shared Design System
   Matches the WaterStation HMI dark theme
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --bg:      #0d1117;
  --surf:    #161b22;
  --surf2:   #21262d;
  --surf3:   #2d333b;
  --border:  #30363d;
  --text:    #e6edf3;
  --text2:   #c9d1d9;
  --muted:   #8b949e;
  --green:   #3fb950;
  --red:     #f85149;
  --yellow:  #d29922;
  --blue:    #58a6ff;
  --brand:   #1f6feb;
  --teal:    #2dd4bf;
  --orange:  #fb923c;
  --purple:  #bc8cff;
  --cyan:    #39d3f4;

  --radius:  8px;
  --radius-sm: 5px;
  --shadow:  0 4px 24px rgba(0,0,0,0.5);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── SCROLLBAR ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surf); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── TOPBAR ────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  background: var(--surf);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.topbar-logo svg { flex-shrink: 0; }
.topbar-logo .brand {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
}
.topbar-logo .sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.topbar-spacer { flex: 1; }
/* ── responsive topbar: icons scale down for tablet, icon-only on phones —
      44px touch targets for field crews (WCAG) ─────────────────────────── */
@media (max-width: 1100px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-logo .sub { display: none; }
  .topbar-user > span { display: none; }        /* hide company text */
}
@media (max-width: 820px) {
  .nav-lnk .nav-txt { display: none; }          /* icon-only nav */
  .nav-lnk { font-size: 19px; padding: 9px 10px; min-width: 44px;
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .topbar { height: 52px; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar-logo .brand { display: none; }        /* logo mark only */
  .topbar-avatar { width: 28px; height: 28px; font-size: 11px; }
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text2);
}
.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

/* ── BUTTONS ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary  { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover:not(:disabled)  { background: #2879f5; }
.btn-ghost    { background: transparent; color: var(--text2); border-color: var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--surf2); color: var(--text); }
.btn-danger   { background: transparent; color: var(--red); border-color: rgba(248,81,73,0.4); }
.btn-danger:hover:not(:disabled)   { background: rgba(248,81,73,0.1); }
.btn-success  { background: transparent; color: var(--green); border-color: rgba(63,185,80,0.4); }
.btn-success:hover:not(:disabled)  { background: rgba(63,185,80,0.1); }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-lg { padding: 11px 24px; font-size: 15px; }
.btn-icon { padding: 6px; }

/* ── FORM ELEMENTS ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text2); }
.input, .select, .textarea {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.12s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); }
.input::placeholder { color: var(--muted); }
.textarea { resize: vertical; min-height: 80px; }
.select { cursor: pointer; appearance: none; }
.field-error { font-size: 11px; color: var(--red); margin-top: 2px; }

/* ── CARDS ─────────────────────────────────────────────────────── */
.card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-sm { padding: 14px; }
.card-hover { transition: border-color 0.12s, box-shadow 0.12s; cursor: pointer; }
.card-hover:hover { border-color: var(--blue); box-shadow: 0 0 0 1px var(--brand); }

/* ── STATUS BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-draft    { color: var(--muted);   background: var(--surf3);               border: 1px solid var(--border); }
.badge-submitted{ color: var(--blue);    background: rgba(88,166,255,0.12);      border: 1px solid rgba(88,166,255,0.3); }
.badge-quoted   { color: var(--yellow);  background: rgba(210,153,34,0.12);      border: 1px solid rgba(210,153,34,0.3); }
.badge-approved { color: var(--green);   background: rgba(63,185,80,0.12);       border: 1px solid rgba(63,185,80,0.3); }
.badge-deployed { color: var(--teal);    background: rgba(45,212,191,0.12);      border: 1px solid rgba(45,212,191,0.3); }

/* ── DIVIDER ───────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ── TOAST NOTIFICATIONS ───────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  min-width: 240px;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
  pointer-events: auto;
}
.toast.ok   { border-left: 3px solid var(--green); }
.toast.err  { border-left: 3px solid var(--red); }
.toast.warn { border-left: 3px solid var(--yellow); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ── MODAL ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── LOADING SPINNER ───────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ───────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  color: var(--muted);
  text-align: center;
}
.empty-icon { font-size: 40px; opacity: 0.4; }
.empty-title { font-size: 16px; font-weight: 700; color: var(--text2); }
.empty-sub   { font-size: 13px; max-width: 280px; }

/* ── UTILITY ───────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.flex    { display: flex; }
.gap-8   { gap: 8px; }
.gap-12  { gap: 12px; }
.gap-16  { gap: 16px; }
.mt-8    { margin-top: 8px; }
.mt-16   { margin-top: 16px; }
.text-muted   { color: var(--muted); }
.text-sm      { font-size: 12px; }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }

/* ── REV BAR ───────────────────────────────────────────────────── */
#rev-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 999;
  background: rgba(13,17,23,0.92);
  border-top: 1px solid var(--border);
  padding: 4px 16px;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  font-size: 10px; font-weight: 700; color: var(--muted);
  letter-spacing: .06em; pointer-events: none;
  backdrop-filter: blur(6px);
}

/* ── MOBILE BOTTOM TAB BAR (shared.js renderTabbar) ─────────────── */
:root { --tabh: 0px; }                          /* 0 on desktop — pages can subtract it safely */
@media (max-width: 819px) { :root { --tabh: 58px; } }
#tabbar { display: none; }
@media (max-width: 819px) {
  body { padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom)); }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    height: calc(var(--tabh) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #11151c; border-top: 1px solid #30363d; }
  #tabbar a.tb { flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; text-decoration: none; color: #8b949e;
    min-height: 44px; -webkit-tap-highlight-color: transparent; }
  #tabbar a.tb.on { color: #58a6ff; }
  #tabbar a.tb.on .ti { transform: scale(1.12); }
  #tabbar .ti { font-size: 21px; line-height: 1; position: relative; transition: transform .12s; }
  #tabbar .tl { font-size: 9.5px; font-weight: 700; letter-spacing: .02em; }
  #tabbar .ti b { position: absolute; top: -6px; right: -12px; background: #f85149; color: #fff;
    font-size: 9px; font-weight: 800; border-radius: 8px; padding: 1px 5px; font-style: normal; }
  #tb-more { display: none; position: fixed; right: 8px; bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 8px);
    background: #161b22; border: 1px solid #30363d; border-radius: 12px; padding: 6px;
    box-shadow: 0 8px 28px rgba(0,0,0,.6); min-width: 190px; }
  #tb-more.open { display: block; }
  #tb-more a { display: block; padding: 12px 14px; color: #e6edf3; text-decoration: none;
    font-size: 14px; font-weight: 600; border-radius: 8px; min-height: 44px; }
  #tb-more a:active, #tb-more a.on { background: #1f6feb22; color: #58a6ff; }
  #rev-bar { display: none; }                 /* tabbar replaces it on phones */
}

/* ── ⓘ TRAIN-AS-YOU-GO INFO SYSTEM (ported from the HMI) ────────── */
.info-btn { display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%; background: #1f6feb; color: #fff;
  font-size: 11px; font-weight: 800; font-style: italic; font-family: Georgia, serif;
  cursor: pointer; vertical-align: middle; margin-left: 6px; flex: none;
  -webkit-tap-highlight-color: transparent; }
.info-btn:hover { background: #2b7bff; box-shadow: 0 0 0 3px rgba(31,111,235,.25); }
body.noinfo .info-btn { display: none !important; }
.info-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 500;
  display: none; align-items: center; justify-content: center; padding: 18px; }
.info-overlay.open { display: flex; }
.info-popup { background: var(--surf, #161b22); border: 1px solid #1f6feb; border-radius: 14px;
  max-width: 520px; width: 100%; max-height: 80vh; overflow-y: auto; padding: 18px 20px;
  position: relative; box-shadow: 0 18px 60px rgba(0,0,0,.7); }
.info-popup-close { position: absolute; top: 10px; right: 10px; background: #21262d;
  border: 1px solid var(--border, #30363d); color: var(--text, #e6edf3); border-radius: 8px;
  width: 34px; height: 34px; font-size: 14px; cursor: pointer; }
.info-popup-title { font-size: 15px; font-weight: 800; margin-bottom: 10px; padding-right: 40px; }
.info-row { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed #2a333f;
  font-size: 12.5px; line-height: 1.55; }
.info-row-label { flex: none; width: 118px; font-size: 10px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .05em; color: #58a6ff; padding-top: 2px; }
.info-row-body { color: var(--text2, #c9d1d9); }
.info-note { margin-top: 10px; font-size: 12px; color: #d29922; background: rgba(210,153,34,.08);
  border: 1px solid rgba(210,153,34,.4); border-radius: 8px; padding: 8px 11px; line-height: 1.5; }
.info-formula { margin-top: 10px; font-family: ui-monospace, monospace; font-size: 11.5px;
  color: #7ee787; background: #0d1117; border-radius: 8px; padding: 8px 11px; }

/* ── SCROLLBARS EVERYWHERE (rule 2026-09-30): anything that can overflow
      scrolls inside itself with a consistent slim dark bar — content must
      never silently run off the page ─────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: #2e3946 transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #2e3946; border-radius: 5px; }
*::-webkit-scrollbar-thumb:hover { background: #3d4a5c; }
*::-webkit-scrollbar-track { background: transparent; }
