/* NextGen Forecast — design system, shared with battery-dispatch.
   Tokens, the app shell, and the sign-in, account, and admin pages. Light by default, dark follows the OS.
   Sizes are in px so the operator screens can keep their own denser root size. */

:root {
  /* Dark is the only theme: a near-black page, one slightly lighter surface, hairline dividers,
     off-white text and a single green accent. Body text meets WCAG AA on every surface. */
  color-scheme: dark;
  --bg: #0b0e12;
  --surface: #0f1318;
  --surface-2: #151a20;
  --surface-3: #1c222a;
  --border: #1f262e;
  --border-strong: #2e3742;
  --text: #e6eaef;
  --text-2: #a7b0bb;
  --text-3: #808a96;
  --accent: #34c79f;
  --accent-hover: #52d6b2;
  --accent-soft: #10261f;
  --accent-text: #04130f;
  --focus: #34c79f55;
  --danger: #f2716a;
  --danger-soft: #2a1413;
  --info: #6ea2f5;
  --info-soft: #13203a;
  --warn: #e6c36a;
  --warn-soft: #2a2310;
  --sidebar-bg: #090c0f;
  --sidebar-text: #c2cad3;
  --sidebar-muted: #7d8895;
  --sidebar-hover: #13181e;
  --sidebar-active: #161d22;
  --chart-text: #8d98a5;
  --chart-grid: #1b222a;
  --chart-actual: #6ea2f5;
  --chart-forecast: #f2716a;
  --chart-gap: #e6c36a;
  --chart-bft: #34c99f;
  --chart-before: #8a94a1;
  --seg-on: #262e38;
  --console-bg: #0b0f13;
  --shadow-sm: none;
  --shadow: none;
  --shadow-lg: 0 16px 40px -16px rgba(0, 0, 0, 0.75);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 10px;
  --sidebar-w: 236px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.hint, .lede { color: var(--text-3); font-size: 13px; line-height: 1.5; }
p.is-error, p.is-ok { padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin: 0 0 16px; }
p.is-error { color: var(--danger); background: var(--danger-soft); }
p.is-ok { color: var(--accent); background: var(--accent-soft); }

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

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 18px 12px 14px;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  font-size: 14px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px;
  color: #fff; text-decoration: none; font-weight: 650; font-size: 15px; letter-spacing: -0.01em;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand img { border-radius: 8px; flex: none; }
.sidebar-brand span { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand small { color: var(--sidebar-muted); font-weight: 500; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  margin: 10px 10px 6px; padding: 0; color: var(--sidebar-muted);
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--sidebar-text);
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.5; text-align: left; text-decoration: none;
  cursor: pointer; transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.is-active {
  background: var(--sidebar-active); color: #fff;
  box-shadow: inset 2px 0 0 #2fc49c;
}
.nav-item.is-active svg { opacity: 1; color: #2fc49c; }

.sidebar-footer {
  margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex; flex-direction: column; gap: 10px;
}
.account { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 4px 6px; margin: -4px -6px; border-radius: 8px; text-decoration: none; }
a.account:hover, a.account.is-active { background: var(--sidebar-hover); text-decoration: none; }
a.account:hover .account-email { color: #fff; }
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #1b3a36; color: #7ee0c3; font-weight: 650; font-size: 13px; text-transform: uppercase;
}
.account-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--sidebar-text); }
.sidebar-footer form { margin: 0; }
.sidebar-footer button {
  width: 100%; min-height: 30px; padding: 5px 12px; border-radius: 8px;
  background: transparent; color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.sidebar-footer button:hover { background: var(--sidebar-hover); color: #fff; border-color: rgba(255, 255, 255, 0.2); }
.nav-toggle {
  display: none; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; color: var(--sidebar-text); cursor: pointer;
}
.nav-toggle:hover, .nav-open:checked ~ .nav-toggle { background: var(--sidebar-hover); color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.page-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.page-header .lede { margin-top: 2px; max-width: 72ch; }
.content { padding: 24px 28px 40px; }

/* ---------- Cards, forms, buttons, tables (sign-in, account, admin) ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel > h2 + .hint, .panel > h2 + p { margin-top: 4px; }

:is(.auth, .admin-content) label {
  display: flex; flex-direction: column; gap: 6px;
  color: var(--text-2); font-size: 13px; font-weight: 550;
}
:is(.auth, .admin-content) :is(input, select) {
  width: 100%;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 36px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
:is(.auth, .admin-content) :is(input, select):hover { border-color: var(--text-3); }
:is(.auth, .admin-content) :is(input, select):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
:is(.auth, .admin-content) select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
:is(.auth, .admin-content) button, a.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 5px 12px; min-height: 30px;
  border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text);
  cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
:is(.auth, .admin-content) button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
:is(.auth, .admin-content) :is(button.ghost, a.ghost) {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm);
}
:is(.auth, .admin-content) :is(button.ghost, a.ghost):hover { background: var(--surface-2); border-color: var(--text-3); text-decoration: none; }
a.ghost.link { display: inline-flex; align-items: center; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; }

.table-wrap {
  max-height: 360px; overflow: auto; margin-top: 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.users { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.users th, .users td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.users th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-3);
  font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase;
}
.users td { color: var(--text); }
.users tbody tr:last-child td { border-bottom: 0; }
.users tbody tr:hover td { background: var(--surface-2); }
.users td form { display: inline-flex; margin: 0; }
.users td button { min-height: 26px; padding: 3px 9px; font-size: 12px; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Show / Hide inside a password box */
.password-field { position: relative; display: block; }
.password-field input { padding-right: 64px; }
:is(.auth, .admin-content) .password-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  min-height: 0; height: 28px; width: auto; margin: 0; padding: 0 10px; border-radius: 6px;
  background: transparent; border: 0; box-shadow: none;
  color: var(--text-3); font-size: 12px; font-weight: 600;
}
:is(.auth, .admin-content) .password-toggle:hover { background: var(--surface-3); color: var(--text); border: 0; }

/* ---------- Sign-in ---------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-aside {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: 32px;
  padding: 40px 48px;
  background: radial-gradient(120% 80% at 10% 0%, #134e43 0%, #0b1d1f 55%, #070d10 100%);
  color: #d6e4e1;
}
.auth-aside::after {
  content: ""; position: absolute; inset: auto -10% -30% -10%; height: 60%;
  background: repeating-linear-gradient(90deg, rgba(47, 196, 156, 0.08) 0 1px, transparent 1px 48px),
              repeating-linear-gradient(0deg, rgba(47, 196, 156, 0.08) 0 1px, transparent 1px 48px);
  mask-image: linear-gradient(to top, #000, transparent);
}
.auth-aside .sidebar-brand { padding: 0; }
.auth-pitch { position: relative; z-index: 1; max-width: 30rem; }
.auth-pitch h2 { color: #fff; font-size: 28px; line-height: 1.2; font-weight: 650; }
.auth-pitch p { margin-top: 12px; color: #9fb7b2; font-size: 15px; }
.auth-points { position: relative; z-index: 1; display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; color: #c6d8d4; font-size: 14px; }
.auth-points li { display: flex; gap: 10px; align-items: center; }
.auth-points li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #2fc49c; flex: none; }
.auth-main { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.auth-card {
  width: min(420px, 100%); padding: 32px 32px 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--shadow-lg);
}
.auth-card :is(input, select) { min-height: 40px; }
.auth-card h1 { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; }
.auth-mobile-brand { display: none; align-items: center; gap: 10px; margin-bottom: 28px; font-weight: 650; }
.auth-mobile-brand img { border-radius: 8px; }
.auth-card > .hint { margin: 6px 0 24px; font-size: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card form button[type="submit"] { width: 100%; padding: 8px 14px; margin-top: 4px; }

/* ---------- Account and admin ---------- */

.admin-content { display: flex; flex-direction: column; gap: 20px; max-width: 960px; }
.account-panel { max-width: 520px; }
.password-form { display: flex; flex-direction: column; gap: 14px; margin: 16px 0 12px; }
.password-form button[type="submit"] { align-self: flex-start; }
.add-user { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; margin-top: 16px; }
.invite-link { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.invite-link input { font-family: var(--mono); font-size: 13px; background: var(--surface-2); }

/* ---------- Small screens ---------- */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  /* The sidebar becomes a top bar; ☰ opens the full menu (workspaces included) as a drawer under it. */
  .sidebar {
    position: sticky; top: 0; z-index: 40; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0;
    padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    overflow: visible;
  }
  .sidebar-brand { flex: 1 1 auto; padding: 0; font-size: 14px; }
  .sidebar-brand img { width: 28px; height: 28px; }
  .nav-toggle { display: inline-flex; }
  .sidebar .nav, .sidebar .sidebar-footer { display: none; }
  .nav-open:checked ~ .nav {
    display: flex; flex-basis: 100%; margin-top: 8px; padding-top: 4px; border-top: 1px solid rgba(255, 255, 255, 0.07);
    max-height: calc(100dvh - 130px); overflow-y: auto; overscroll-behavior: contain;
  }
  .nav-open:checked ~ .sidebar-footer {
    display: flex; flex-basis: 100%; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px;
    margin: 8px 0 0; padding: 10px 2px 2px;
  }
  .nav-open:checked ~ .sidebar-footer .account { margin: 0; }
  .sidebar-footer button { width: auto; }
  .nav-item { padding: 9px 10px; }
  .page-header { position: static; padding: 16px 16px 12px; flex-direction: column; align-items: stretch; border-bottom: 0; background: transparent; backdrop-filter: none; }
  .content { padding: 0 12px 24px; }
  .panel { padding: 16px; }
  .add-user { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-main { place-items: start center; padding-top: 72px; }
  .auth-card { padding: 24px 20px; box-shadow: var(--shadow); }
  .auth-mobile-brand { display: flex; }
  :is(.auth, .admin-content) :is(input, select) { min-height: 42px; font-size: 16px; } /* 16px stops iOS zooming on focus */
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
