/* ============================================================
   SLS Energy — Design System · platform entry point
   Ported from: B:\SLS\SLS-Digital-Twin\SLS Energy Design System
   Brand: primary teal #007377, secondary gray #9EA2A2, Neutral Black #252525.
   Link this file on any page; it carries tokens, fonts, and the plain-CSS
   component classes (.btn, .badge, .ds-input, .stat-card, .ds-card) that
   stand in for the design system's React primitives on this PHP stack.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700;800&family=Hanken+Grotesk:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* ---------- Brand anchors (SLS Brand Guidelines 2022) ---------- */
  --brand-teal:  #007377;
  --brand-gray:  #9EA2A2;
  --brand-black: #252525;

  /* ---------- Primary scale (teal) ---------- */
  --teal-50:  #EBF4F4;
  --teal-100: #D9EAEB;
  --teal-200: #B3D5D6;
  --teal-300: #80B9BB;
  --teal-400: #409699;
  --teal-500: #007377;
  --teal-600: #005F62;
  --teal-700: #004B4E;
  --teal-800: #00393B;
  --teal-900: #002A2B;

  /* ---------- Neutral scale (cool gray) ---------- */
  --gray-50:  #F0F1F1;
  --gray-100: #E2E3E3;
  --gray-200: #CFD1D1;
  --gray-300: #B6B9B9;
  --gray-400: #9EA2A2;
  --gray-500: #7E8282;
  --gray-600: #626666;
  --gray-700: #4A4D4D;
  --gray-800: #2E3131;
  --gray-900: #252525;

  /* ---------- Semantic / functional ---------- */
  --charge-50:  #E8F6EE;
  --charge-500: #1F9D5E;
  --charge-600: #178049;
  --warn-50:  #FBF1E0;
  --warn-500: #C9871C;
  --warn-600: #A66E10;
  --crit-50:  #FBEDEC;
  --crit-500: #C9453F;
  --crit-600: #A8332E;
  --info-50:  var(--teal-50);
  --info-500: #007377;

  /* ---------- Semantic surface + text roles ---------- */
  --bg:        #FFFFFF;
  --bg-subtle: var(--gray-50);
  --surface:   #FFFFFF;
  --surface-2: var(--gray-50);
  --ink:       var(--brand-black);
  --ink-2:     var(--gray-600);
  --ink-3:     var(--gray-500);
  --ink-onbrand: #FFFFFF;
  --line:      var(--gray-200);
  --line-2:    var(--gray-300);

  --accent:        var(--teal-500);
  --accent-hover:  var(--teal-600);
  --accent-press:  var(--teal-700);
  --accent-weak:   var(--teal-50);
  --focus-ring:    rgba(0, 115, 119, .45);

  /* ---------- Dark shell (sidebars, footers, hero) ---------- */
  --d-bg:      var(--brand-black);
  --d-surface: var(--gray-800);
  --d-ink:     var(--gray-50);
  --d-ink-2:   var(--gray-400);
  --d-line:    rgba(255, 255, 255, .12);

  /* ---------- Type families ---------- */
  --font-display: 'Montserrat', 'Segoe UI', system-ui, sans-serif;
  --font-body:    'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  /* ---------- Type scale (1.20 minor third) ---------- */
  --fs-display: 60px;
  --fs-h1: 44px;
  --fs-h2: 34px;
  --fs-h3: 26px;
  --fs-h4: 21px;
  --fs-lg: 18px;
  --fs-base: 16px;
  --fs-sm: 14px;
  --fs-xs: 12.5px;

  /* ---------- Radius ---------- */
  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* ---------- Spacing (4px base) ---------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px; --sp-20: 80px; --sp-24: 96px;

  /* ---------- Elevation ---------- */
  --shadow-xs: 0 1px 2px rgba(16, 36, 37, .06);
  --shadow-sm: 0 1px 3px rgba(16, 36, 37, .08), 0 1px 2px rgba(16, 36, 37, .05);
  --shadow-md: 0 4px 12px rgba(16, 36, 37, .08), 0 2px 4px rgba(16, 36, 37, .05);
  --shadow-lg: 0 12px 28px rgba(16, 36, 37, .12), 0 4px 10px rgba(16, 36, 37, .06);
  --shadow-brand: 0 8px 24px rgba(0, 115, 119, .22);

  /* ---------- Motion ---------- */
  --ease: cubic-bezier(.2, .7, .3, 1);
  --dur: 180ms;

  /* ---------- Plus-grid motif ---------- */
  --plus-color: rgba(0, 115, 119, .15);
  --plus-gap: 28px;
}

/* ============================================================
   Signature texture + brand marks
   ============================================================ */
.ds-plusgrid {
  background-color: var(--plus-color);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M14 10v8M10 14h8' stroke='%23fff' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M14 10v8M10 14h8' stroke='%23fff' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  -webkit-mask-size: var(--plus-gap) var(--plus-gap);
          mask-size: var(--plus-gap) var(--plus-gap);
  -webkit-mask-repeat: repeat;
          mask-repeat: repeat;
}
.ds-plus {
  position: relative;
  display: inline-block;
  width: 1em;
  height: 1em;
  color: var(--accent);
}
.ds-plus::before,
.ds-plus::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 1px;
}
.ds-plus::before { left: 50%; top: 12%; width: 0.16em; height: 0.76em; transform: translateX(-50%); }
.ds-plus::after  { top: 50%; left: 12%; height: 0.16em; width: 0.76em; transform: translateY(-50%); }

@keyframes sls-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(31, 157, 94, .55); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) {
  @keyframes sls-pulse { 0%,100% { box-shadow: none; } }
}

/* Flat modular card — borders first, no resting shadow. */
.ds-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.ds-card--raised { box-shadow: var(--shadow-sm); }

/* ============================================================
   Base typography
   ============================================================ */
.ds-type, body.ds-type {
  font-family: var(--font-body);
  color: var(--ink);
  font-size: var(--fs-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.ds-type h1, .ds-display, .ds-type h2, .ds-type h3, .ds-type h4 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 600;
  margin: 0;
}
.ds-display { font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.03em; }
.ds-type h1 { font-size: var(--fs-h1); font-weight: 700; }
.ds-type h2 { font-size: var(--fs-h2); }
.ds-type h3 { font-size: var(--fs-h3); }
.ds-type h4 { font-size: var(--fs-h4); letter-spacing: -0.01em; }
.ds-type p  { margin: 0 0 1em; max-width: 68ch; }
.ds-lead    { font-size: var(--fs-lg); color: var(--ink-2); line-height: 1.55; }
.ds-small   { font-size: var(--fs-sm); color: var(--ink-2); }
.ds-caption { font-size: var(--fs-xs); color: var(--ink-3); }
.ds-eyebrow {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.ds-metric {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: -0.01em;
}
code, .ds-code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--gray-100);
  color: var(--teal-700);
  padding: 0.12em 0.4em;
  border-radius: var(--r-xs);
}

/* ============================================================
   Buttons — plain-CSS port of components/core/Button.jsx
   Teal is reserved for action; secondary/ghost are lower emphasis.
   ============================================================ */
.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  padding: 11px 20px;
  border-radius: var(--r-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
  text-decoration: none;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.btn-primary {
  background: var(--teal-500);
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { background: var(--teal-600); }
.btn-primary:active { background: var(--teal-700); transform: translateY(1px); box-shadow: none; }
.btn-secondary {
  background: #fff;
  color: var(--teal-700);
  border-color: var(--teal-300);
}
.btn-secondary:hover { background: var(--teal-50); }
.btn-ghost {
  background: transparent;
  color: var(--teal-700);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--teal-50); }
.btn:disabled, .btn.is-disabled {
  background: var(--gray-200);
  color: var(--gray-400);
  box-shadow: none;
  border-color: transparent;
  cursor: not-allowed;
}

/* ============================================================
   Badges — plain-CSS port of components/core/Badge.jsx
   tone: charge / warn / crit / info / neutral. Add .badge-solid to fill.
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  background: var(--gray-100);
  color: var(--gray-700);
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray-500);
}
.badge-pulse::before { animation: sls-pulse 1.8s var(--ease) infinite; }
.badge-charge  { background: var(--charge-50); color: var(--charge-600); }
.badge-charge::before  { background: var(--charge-500); }
.badge-warn    { background: var(--warn-50); color: var(--warn-600); }
.badge-warn::before    { background: var(--warn-500); }
.badge-crit    { background: var(--crit-50); color: var(--crit-600); }
.badge-crit::before    { background: var(--crit-500); }
.badge-info    { background: var(--teal-50); color: var(--teal-700); }
.badge-info::before    { background: var(--teal-500); }
.badge-solid { color: #fff; }
.badge-solid::before { background: #fff; }
.badge-solid.badge-charge { background: var(--charge-500); }
.badge-solid.badge-warn   { background: var(--warn-500); }
.badge-solid.badge-crit   { background: var(--crit-500); }
.badge-solid.badge-info   { background: var(--teal-500); }
.badge-solid.badge-neutral{ background: var(--gray-500); }

/* ============================================================
   Inputs — plain-CSS port of components/core/Input.jsx
   1.5px hairline, teal on focus with a 3px teal focus ring.
   ============================================================ */
.form-row { display: flex; flex-direction: column; gap: 6px; font-family: var(--font-body); margin-bottom: var(--sp-4); }
.form-row label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form-row .hint { font-size: 12.5px; color: var(--ink-3); }
.form-row .hint.invalid { color: var(--crit-600); }
.ds-input,
.form-row input,
.form-row select,
.form-row textarea {
  font-family: var(--font-body);
  font-size: var(--fs-base);
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 10px 13px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ds-input:focus,
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.ds-input.invalid,
.form-row input.invalid {
  border-color: var(--crit-500);
}

/* ============================================================
   KPI / stat tiles — plain-CSS port of components/core/KPICard.jsx
   ============================================================ */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}
.stat-card .stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.stat-card .stat-value {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  color: var(--ink);
  margin-top: 8px;
  letter-spacing: -.02em;
}
.stat-card .stat-value .stat-unit {
  font-size: 15px;
  color: var(--ink-3);
  font-weight: 400;
}
.stat-card .stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 8px;
  color: var(--charge-600);
}
.stat-card .stat-delta.down { color: var(--crit-600); }

/* ============================================================
   App shell — shared sidebar + topbar (includes/app_nav.php)
   Dark fixed left rail per the design system's dashboard shell,
   paired with a light topbar. Replaces the .menu/.app-shell/
   .user-nav patterns previously duplicated per page.
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg-subtle);
}
.sidebar {
  width: 232px;
  flex: none;
  background: var(--d-bg);
  color: var(--d-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 4px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  color: #fff;
  text-decoration: none;
}
.sidebar-brand img { width: 30px; height: 30px; }
.sidebar-brand span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-section {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--d-ink-2);
  padding: 16px 12px 6px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--d-ink-2);
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-link.active { background: var(--teal-600); color: #fff; font-weight: 600; }
.sidebar-link svg, .sidebar-link i { width: 18px; height: 18px; flex: none; }
.sidebar-logout { margin-top: auto; border-top: 1px solid var(--d-line); padding-top: 14px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -.02em;
  color: var(--ink);
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal-100);
  color: var(--teal-700);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
}
.topbar-username { font-size: 14px; font-weight: 600; color: var(--ink); }
.app-main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-main { flex: 1; padding: 28px; overflow: auto; }

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  padding: 6px;
  border-radius: var(--r-sm);
  margin-right: 4px;
}
.sidebar-toggle svg, .sidebar-toggle i { width: 22px; height: 22px; }
.sidebar-toggle:hover { background: var(--gray-100); }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(37, 37, 37, .45);
  z-index: 210;
}
.sidebar-overlay.open { display: block; }

/* ============================================================
   Responsive — tablet/phone
   Sidebar becomes an off-canvas drawer under 900px; topbar, stat
   grids, tables, and forms collapse to single-column/stacked layouts.
   ============================================================ */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; min-height: 100vh; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 220;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 14px 16px; }
  .topbar-title { font-size: 18px; }
  .topbar-username { display: none; }
  .app-main { padding: 16px; }

  .dashboard-stats, .stats-grid, [class*="stats-grid"] { grid-template-columns: 1fr 1fr !important; }
  .stat-card { min-width: 0; }

  table:not(.no-responsive-scroll) { display: block; }
  .table-wrapper, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .form-row { width: 100%; }
  .btn { width: auto; }
  .modal-content { width: 92%; margin: 8% auto; padding: 20px; }
}

@media (max-width: 520px) {
  .dashboard-stats, .stats-grid, [class*="stats-grid"] { grid-template-columns: 1fr !important; }
  .topbar-title { font-size: 16px; }
  .app-main { padding: 12px; }
}

/* Comfortable tap targets on touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn, .sidebar-link, .ds-input, .form-row input, .form-row select, .form-row textarea {
    min-height: 44px;
  }
}
