/* energy_router_web -- application stylesheet.
   Neutral light theme built on the tokens below; every page fragment under /pages uses only the
   component classes defined here (page-header, toolbar, section, cards, kv, btn, form-grid,
   auth-card, datebar, ...). Tabulator is themed in tab_overrides.css with the same tokens. */

:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe4ea;
  --border-strong: #c7cfd8;
  --text: #1f2933;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --nav: #0f172a;
  --nav-text: rgba(255, 255, 255, .82);
  --nav-h: 56px;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --focus: 0 0 0 3px rgba(37, 99, 235, .25);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- base ---------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; color: var(--text); }
p { margin: 0 0 10px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.form-note { font-size: 13px; color: var(--muted); margin: 0 0 12px; max-width: 80ch; }
.mono { font-family: var(--mono); }

/* ---- top navigation ------------------------------------------------------------------------ */
.top-menu {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
  background: var(--nav);
  color: var(--nav-text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06), 0 2px 8px rgba(0, 0, 0, .25);
}
.top-menu .brand {
  color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px; margin-right: 18px; white-space: nowrap;
}
.top-menu .brand::before {
  content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .3);
}
.top-menu .menu-items { display: flex; align-items: center; gap: 2px; min-width: 0; }
.top-menu .menu-item { position: relative; }
.top-menu .menu-item > div:not(.submenu) {
  display: block; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--nav-text); font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.top-menu .menu-item > div:not(.submenu) > a.menu-link { color: inherit; text-decoration: none; }
.top-menu .menu-item > div:not(.submenu):hover, .top-menu .menu-item > div:not(.submenu):focus-visible,
.top-menu .menu-item:focus-within > div:not(.submenu) { background: rgba(255, 255, 255, .1); color: #fff; }
.top-menu .menu-item.active > div:not(.submenu) { background: rgba(255, 255, 255, .14); color: #fff; }
/* dropdown heads get a small caret */
.top-menu .menu-item:has(> .submenu) > div:not(.submenu)::after {
  content: ''; display: inline-block; margin-left: 7px; width: 6px; height: 6px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg); opacity: .8;
}
.top-menu .submenu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 1001;
  min-width: 220px; padding: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.top-menu .submenu::before { /* invisible bridge so the pointer can travel from head to menu */
  content: ''; position: absolute; left: 0; right: 0; top: -6px; height: 6px;
}
.top-menu .menu-item:hover > .submenu, .top-menu .menu-item:focus-within > .submenu { display: block; }
.top-menu .submenu a {
  display: block; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 14px; white-space: nowrap;
}
.top-menu .submenu a:hover, .top-menu .submenu a:focus-visible { background: var(--surface-2); color: var(--accent-hover); }
.top-menu .submenu a.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.top-menu .nav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-menu .user-email { color: var(--nav-text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.top-menu .badge-warn { background: var(--warn); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.top-menu .mac-select {
  /* sizes to its widest option; capped only by the viewport so options are never trimmed */
  height: 32px; padding: 0 4px 0 10px; width: auto; max-width: calc(100vw - 24px);
  background: rgba(255, 255, 255, .08); color: #fff;
  border: 1px solid rgba(255, 255, 255, .22); border-radius: var(--radius-sm); font-size: 13px;
}
.top-menu .mac-select option { color: var(--text); background: var(--surface); }
.top-menu .nav-right button[data-lang] {
  background: transparent; border: 2px solid transparent; border-radius: 4px; padding: 1px; line-height: 0;
  opacity: .55; transition: opacity .15s ease, border-color .15s ease;
}
.top-menu .nav-right button[data-lang]:hover { opacity: .9; }
.top-menu .nav-right button[data-lang].active { opacity: 1; border-color: rgba(255, 255, 255, .85); }
.top-menu .nav-right img { width: 28px; height: 20px; display: block; border-radius: 2px; }
.top-menu .nav-right .menu-items:empty { display: none; }
.top-menu .nav-right .menu-items { margin-left: 6px; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .18); }

/* ---- feedback toast ------------------------------------------------------------------------ */
#feedback {
  position: fixed; top: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%);
  z-index: 1100; max-width: min(720px, calc(100vw - 32px));
  padding: 10px 16px; border-radius: var(--radius); font-size: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
#feedback:empty { display: none; }
#feedback.info { border-color: var(--accent-soft); background: #eff6ff; color: #1e3a8a; }
#feedback.ok { border-color: #bbf7d0; background: var(--ok-soft); color: #14532d; }
#feedback.error { border-color: #fecaca; background: var(--danger-soft); color: #7f1d1d; }
#feedback a { color: inherit; text-decoration: underline; }
#feedback .btn { margin-left: 8px; padding: 3px 10px; font-size: 13px; }

/* ---- content shell ------------------------------------------------------------------------- */
.content { padding: calc(var(--nav-h) + 24px) 32px 48px; }
.page { width: 100%; max-width: 1800px; margin: 0 auto; }
.page > * + * { margin-top: 18px; }
.page-header { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 600; }
.page-header .muted { margin-left: auto; text-align: right; }
.page-header .page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-header .page-actions .muted { margin-left: 0; }

/* Cards / sections */
.card, .section, .toolbar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card { padding: 18px 20px; }
.card h2, .section-title {
  font-size: 15px; font-weight: 600; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.section { padding: 18px 20px; }
.section > .section-title + .check-group { margin-top: -2px; }
.section-note { margin-top: 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 18px; align-items: start; }
.cards .card.wide { grid-column: 1 / -1; }
.cards.side { grid-template-columns: minmax(320px, 460px) minmax(0, 1fr); }
.cards.side .card.wide { grid-column: auto; }
.cards.side.tight { grid-template-columns: minmax(340px, 24%) minmax(0, 1fr); }
@media (max-width: 1539px) { .cards.side.tight { grid-template-columns: 1fr; } }
.cards.centered { display: flex; justify-content: center; flex-wrap: wrap; align-items: stretch; }
.cards.centered > .card { width: 100%; max-width: 460px; margin-left: 0; margin-right: 0; }
/* Card whose main content centers vertically between the h2 rule and the card bottom. */
.card.v-center { display: flex; flex-direction: column; }
.card.v-center > .btn-group { margin-top: auto; margin-bottom: auto; }
.page.narrow { max-width: 720px; }
.about-box { line-height: 1.55; }
.about-box p { font-size: 15px; }

/* Toolbar */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; padding: 10px 14px; }
.toolbar label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.toolbar label > span:first-child { font-weight: 500; }
.toolbar .toolbar-end { margin-left: auto; display: inline-flex; align-items: center; gap: 12px; }
.toolbar .toolbar-sep { width: 1px; height: 26px; background: var(--border); }
.toolbar .datebar { margin: 0; }

/* Inputs */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  height: 34px; padding: 0 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input:disabled, input[readonly], select:disabled { background: var(--surface-2); color: var(--muted); }
input::placeholder { color: #9aa5b1; }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.w-xs { width: 64px; } .w-sm { width: 90px; } .w-md { width: 130px; } .w-lg { width: 180px; }

/* Checkbox groups */
.check-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; margin: 0 0 12px; }
.check-group.centered { justify-content: center; }
label.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; white-space: nowrap; }
label.check span { color: var(--text); }

/* Buttons */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); border-color: #9aa5b1; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.inline-form label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.form-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.card.centered .btn-group, .card.centered .inline-form { justify-content: center; }
.card.centered .status-line, .card.centered .muted { text-align: center; }
.card.centered, .section.centered { width: fit-content; max-width: 100%; margin-left: auto; margin-right: auto; }
.card.centered h2, .card.title-centered h2, .section.centered .section-title, .section.title-centered .section-title { text-align: center; }

/* Key/value lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0 18px; margin: 0; font-size: 14px; }
.kv dt, .kv dd { padding: 5px 0; border-bottom: 1px dashed var(--border); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: none; }

/* Status text / badges */
.status-line { font-size: 14px; min-height: 1.4em; margin-top: 10px; }
.status-line:empty { min-height: 0; margin-top: 0; }
.status-line.pending { color: var(--warn); }
.status-line.ok { color: var(--ok); }
.status-line.bad { color: var(--danger); }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; line-height: 1.3; background: #e2e8f0; color: #334155; }
.badge.ok { background: var(--ok-soft); color: #166534; }
.badge.warn { background: var(--warn-soft); color: #92400e; }
.badge.bad { background: var(--danger-soft); color: #991b1b; }

/* Live readings (sensor table cells) */
.reading { white-space: nowrap; line-height: 1.5; text-align: left; }
.reading.stale { color: var(--warn); }
.reading-name { color: var(--muted); }

/* Battery configuration form (settings) */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 18px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.form-grid label input[type=number], .form-grid label input[type=text] { width: 100%; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; height: 34px; font-size: 14px; }
.form-grid label.readonly input { background: var(--surface-2); color: var(--muted); }
.form-grid .form-divider { grid-column: 1 / -1; height: 1px; background: var(--border); margin: 4px 0; }

/* Charts */
.chart-box { position: relative; width: 100%; }
.chart-box.h-sm { height: 260px; }
.chart-box.h-md { height: 380px; }
.chart-box.h-lg { height: 420px; }
.chart-box.h-xl { height: 480px; }
.chart-box canvas { display: block; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; background: repeating-linear-gradient(-45deg, transparent 0 12px, rgba(148, 163, 184, .08) 12px 24px); border-radius: var(--radius-sm); }
.table-wrapper { width: 100%; }
.table-center { text-align: center; }   /* .tabulator is inline-block, so this centers it */
.table-center .tabulator { text-align: left; }

/* Forecast table row states (dark text on tinted rows) */
.tabulator .tabulator-row.row-green-on { background: #dcfce7 !important; }
.tabulator .tabulator-row.row-green-on-forced { background: #ecfdf5 !important; }
.tabulator .tabulator-row.row-grey-off-forced { background: #e5e7eb !important; }
.tabulator .tabulator-row.row-green-on .tabulator-cell,
.tabulator .tabulator-row.row-green-on-forced .tabulator-cell { color: #14532d; }
.tabulator .tabulator-row.row-grey-off-forced .tabulator-cell { color: #374151; }

/* Datebar  ◀ [date] weekday ▶ */
.datebar { display: inline-flex; align-items: center; gap: 8px; }
.datebar .datebar-btn {
  width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); font-size: 12px;
}
.datebar .datebar-btn:hover { background: var(--surface-2); border-color: #9aa5b1; }
.datebar .datebar-center { display: inline-flex; align-items: center; gap: 10px; }
.datebar .datebar-date { width: 160px; }
.datebar .datebar-dow { color: var(--muted); font-size: 13px; white-space: nowrap; min-width: 8ch; text-transform: capitalize; }

/* ---- auth pages (login, register, reset, password change, verify) -------------------------- */
.auth-card {
  width: 100%; max-width: 420px; margin: 6vh auto 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 30px 32px 26px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 18px; text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; color: var(--muted); font-weight: 500; }
.form-group input { width: 100%; height: 38px; }
.auth-card .btn.block, .auth-card .login-button { margin-top: 6px; height: 40px; font-size: 15px; }
.login-button { /* legacy name kept for the auth forms */
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  border: none; border-radius: var(--radius-sm); background: var(--accent); color: #fff; font-weight: 500;
}
.login-button:hover { background: var(--accent-hover); }
.login-button:disabled { opacity: .55; cursor: default; }
.auth-links { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 18px; font-size: 14px; }
.auth-links a { text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.forgot-password, .create-account { text-align: center; margin-top: 8px; font-size: 14px; }
.error-message, .success-message {
  padding: 9px 12px; margin: 0 0 14px; border-radius: var(--radius-sm); font-size: 13.5px; line-height: 1.4; border: 1px solid;
}
.error-message { color: #7f1d1d; background: var(--danger-soft); border-color: #fecaca; }
.success-message { color: #14532d; background: var(--ok-soft); border-color: #bbf7d0; }
.error-message:empty, .success-message:empty { display: none; }
.home-loading { padding: 40px 0; text-align: center; }

/* ---- responsive ---------------------------------------------------------------------------- */
@media (max-width: 1000px) {
  .cards.side, .cards.side.tight { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .content { padding-left: 16px; padding-right: 16px; }
  .top-menu .user-email { display: none; }
}
@media (max-width: 760px) {
  /* the bar wraps and scrolls with the page (sticky) instead of a fixed-height overlay */
  .top-menu { position: sticky; flex-wrap: wrap; height: auto; padding: 6px 12px; row-gap: 2px; }
  .top-menu .brand { margin-right: 8px; }
  .top-menu .menu-items { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .top-menu .menu-item > div:not(.submenu) { padding: 6px 10px; font-size: 13px; }
  #feedback { top: 12px; }
  .content { padding: 16px 12px 32px; }
  .cards { grid-template-columns: 1fr; }
  .card, .section { padding: 14px; }
  .toolbar { padding: 10px; gap: 8px 14px; }
  .toolbar .toolbar-end { margin-left: 0; }
  .page-header .muted { margin-left: 0; text-align: left; }
  .auth-card { margin: 8px auto 0; padding: 22px 18px; }
  .chart-box.h-xl, .chart-box.h-lg { height: 340px; }
}
