/* EG228 Portal - the agent's light theme (eg228-pv-agent public/app.css) plus portal additions at the end.
   Keep the shared part in sync with the agent so both UIs look like one product. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-dot: #10b981;
  --success-soft: #ecfdf5;
  --warning: #b45309;
  --warning-dot: #f59e0b;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-dot: #ef4444;
  --danger-soft: #fef2f2;
  --violet: #7c3aed;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 4px 12px rgba(15, 23, 42, 0.08);
  --sidebar-w: 220px;
  --mono: 'Consolas', 'SFMono-Regular', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- app shell ---- */

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

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-name { font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-muted); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; }

.main { padding: 24px 28px 40px; min-width: 0; }

.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 24px; font-weight: 600; color: var(--text); }
.page-header p { color: var(--text-muted); margin-top: 2px; }
.page-header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 12px; }
  .brand { padding-bottom: 10px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .main { padding: 16px; }
}

/* ---- cards & sections ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-narrow { max-width: 820px; }
.section-title {
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 14px;
}
.section-title + .section-title, .card .section-title:not(:first-child) { margin-top: 26px; }

/* stat tiles */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; border-left: 4px solid var(--border-strong);
  transition: box-shadow 0.2s;
}
.stat:hover { box-shadow: var(--shadow-hover); }
.stat.ok { border-left-color: var(--success-dot); }
.stat.warn { border-left-color: var(--warning-dot); }
.stat.bad { border-left-color: var(--danger-dot); }
.stat.info { border-left-color: var(--primary); }
.stat-title { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; font-weight: 600; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-value .unit { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 3px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.progress { margin-top: 10px; background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width 0.3s; }

/* key/value grid */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kv { background: var(--surface-muted); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.kv-label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: 0.4px; margin-bottom: 3px; }
.kv-value { font-size: 14px; color: var(--text); font-family: var(--mono); word-break: break-all; }

/* status dots */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.dot-ok { background: var(--success-dot); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
.dot-bad { background: var(--danger-dot); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }
.dot-warn { background: var(--warning-dot); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.dot-off { background: var(--text-faint); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.3px; }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-bad { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--surface-muted); color: var(--text-muted); border: 1px solid var(--border); }

/* ---- forms ---- */

.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 12px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
input[type="checkbox"] { width: auto; }
.hint { margin-top: 5px; color: var(--text-muted); font-size: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .row2, .row3 { grid-template-columns: 1fr; } }

/* ---- buttons ---- */

button, .btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: #fff; border: 1px solid var(--primary);
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover, .btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover { background: var(--surface-muted); }
button.warning { background: var(--warning-dot); border-color: var(--warning-dot); color: #fff; }
button.warning:hover { background: #d97706; border-color: #d97706; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: #b91c1c; border-color: #b91c1c; }
button.ghost { background: transparent; border-color: transparent; color: var(--primary); padding-left: 8px; padding-right: 8px; }
button.ghost:hover { background: var(--primary-soft); }
button.sm { padding: 5px 11px; font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }

/* ---- tables ---- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px;
  background: var(--surface-muted); position: sticky; top: 0;
}
td { color: var(--text); }
tbody tr:hover { background: var(--surface-muted); }
tr.active-row, tr.active-row:hover { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- messages & code ---- */

.msg { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid transparent; overflow-wrap: anywhere; }
.msg.success { background: var(--success-soft); color: var(--success); border-color: #a7f3d0; }
.msg.error { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.msg.warn { background: var(--warning-soft); color: var(--warning); border-color: #fde68a; }
.msg.info { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }
.text-ok { color: var(--success); }
.text-bad { color: var(--danger); }
.text-muted { color: var(--text-muted); }

pre {
  background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-top: 12px; overflow: auto; max-height: 280px;
  font-family: var(--mono); font-size: 12px; color: var(--text);
}

.confirm-box { margin-top: 12px; padding: 14px; background: var(--danger-soft); border: 1px solid #fecaca; border-radius: 8px; }
.confirm-box p { color: var(--danger); font-weight: 600; margin-bottom: 10px; }

/* ---- segmented choice (e.g. device type) ---- */

.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  display: flex; gap: 12px; align-items: flex-start; margin: 0; cursor: pointer;
  padding: 14px 16px; border: 1.5px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.segmented label:hover { border-color: var(--primary); }
.segmented input:checked + label { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.segmented input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 2px; }
.seg-icon { font-size: 22px; line-height: 1; }
.seg-title { font-weight: 600; }
.seg-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; color: var(--text); font-weight: 500; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--primary); }

/* compact inputs inside tables */
td input, td select { padding: 6px 8px; font-size: 13px; }

/* ---- language switch ---- */

.lang-switch { display: flex; align-items: center; gap: 4px; margin: 22px 10px 0; padding-top: 14px; border-top: 1px solid var(--border); }
.lang-label { font-size: 12px; color: var(--text-muted); margin-right: auto; }
.lang-btn {
  background: var(--surface); color: var(--text-muted); border: 1px solid var(--border-strong);
  padding: 3px 9px; font-size: 12px; font-weight: 600; border-radius: var(--radius-sm);
}
.lang-btn:hover { background: var(--surface-muted); color: var(--text); border-color: var(--border-strong); }
.lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (max-width: 900px) {
  .lang-switch { margin: 10px 0 0; padding-top: 10px; }
}

/* =====================================================================
   Portal additions
   ===================================================================== */

:root {
  --pv: #2a78d6;
  --grid: #eb6834;
  --limit: #94a3b8;
}

.sidebar { display: flex; flex-direction: column; }
.sidebar .nav { flex: 0 0 auto; }
.nav-group { font-size: 11px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-faint); padding: 16px 12px 6px; }
.user-box { margin: auto 10px 0; padding-top: 14px; border-top: 1px solid var(--border); }
.user-name { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.user-email { font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.user-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.sidebar .lang-switch { margin-top: 14px; }
@media (max-width: 900px) {
  .nav-group { display: none; }
  .user-box { margin: 10px 0 0; padding-top: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .user-actions { margin-top: 0; }
}

.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }

/* ---- login ---- */

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-hover); padding: 28px; }
.auth-card .brand { padding: 0 0 20px; }
.auth-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.auth-card .lead { color: var(--text-muted); margin-bottom: 20px; }
.auth-card button[type="submit"] { width: 100%; justify-content: center; padding: 11px 18px; }
.auth-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 12px; color: var(--text-muted); }
.auth-foot .lang-switch { margin: 0; padding: 0; border: 0; }

/* ---- site list ---- */

.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.site-card {
  display: block; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; transition: box-shadow 0.2s, border-color 0.2s;
}
.site-card:hover { text-decoration: none; box-shadow: var(--shadow-hover); border-color: var(--border-strong); }
.site-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.site-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.site-card-name { font-weight: 600; font-size: 15px; color: var(--text); }
.site-card-org { font-size: 12px; color: var(--text-muted); }
.site-card-figures { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.figure-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.figure-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.figure-value .unit { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.site-card-foot { margin-top: 12px; font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"] { width: 240px; max-width: 100%; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }

/* ---- site dashboard ---- */

.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.chart-head .section-title { margin-bottom: 0; }
.date-nav { display: flex; gap: 6px; align-items: center; }
.date-nav input { width: auto; padding: 6px 10px; }
.chart-box { position: relative; height: 320px; }
@media (max-width: 640px) { .chart-box { height: 260px; } }
.day-totals { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.day-totals b { color: var(--text); font-variant-numeric: tabular-nums; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }

.meter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.meter-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface-muted); }
.meter-card-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.meter-values { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; }
.meter-values dd { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.meter-values dt { color: var(--text-muted); }

/* ---- admin ---- */

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.secret-box { margin-top: 14px; padding: 14px; border: 1px solid #fde68a; background: var(--warning-soft); border-radius: 8px; }
.secret-box p { color: var(--warning); font-weight: 600; margin-bottom: 8px; }
.secret-value { display: flex; gap: 8px; align-items: stretch; }
.secret-value code { flex: 1; min-width: 0; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.secret-box pre { max-height: 220px; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 200px; overflow-y: auto; }
.check-list .toggle { font-weight: 400; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25); padding: 0; width: min(560px, calc(100vw - 32px)); color: var(--text); }
dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
.dialog-body { padding: 22px; }
.dialog-body h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
td .actions { margin-top: 0; gap: 6px; flex-wrap: nowrap; }
.muted-row td { color: var(--text-faint); }
/* ---- dashboard state strip ---- */
.state-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.state-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 8px; background: var(--surface-muted); border-left: 4px solid var(--border-strong); }
.state-item.ok { border-left-color: var(--success-dot); }
.state-item.warn { border-left-color: var(--warning-dot); }
.state-item.bad { border-left-color: var(--danger-dot); }
.state-item.muted { color: var(--text-muted); }
.state-icon { font-size: 22px; line-height: 1; }
.state-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.state-value { font-weight: 600; font-size: 14px; }
#stateCard { padding: 14px 16px; }

/* ---- polish ---- */
@media (max-width: 900px) { .app { grid-template-rows: auto 1fr; } .user-box { justify-content: space-between; } }
.figure-value .text-muted { font-size: 12px; font-weight: 500; margin-left: 4px; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-muted); }
.btn.sm { padding: 5px 11px; font-size: 12px; }
.toolbar select { width: auto; max-width: 100%; }
/* ---- help page ---- */
.help { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.help-toc { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; padding: 16px; }
.help-toc a { color: var(--text-muted); text-decoration: none; font-size: 13px; padding: 5px 8px; border-radius: 6px; }
.help-toc a:hover { background: var(--surface-muted); color: var(--text); }
.help-body { min-width: 0; max-width: 860px; }
.help-body h2 { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.help-body h3 { font-size: 14px; font-weight: 600; margin: 18px 0 6px; }
.help-body p, .help-body li, .help-body dd { color: var(--text); font-size: 14px; line-height: 1.55; }
.help-body p + p { margin-top: 8px; }
.help-body ul { margin: 6px 0 0 18px; }
.help-body li + li { margin-top: 4px; }
.help-body dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin-top: 8px; }
.help-body dt { font-weight: 600; font-size: 14px; }
.help-body code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }
.help-body section { scroll-margin-top: 16px; }
@media (max-width: 900px) {
  .help { grid-template-columns: 1fr; }
  .help-toc { position: static; }
  .help-body dl { grid-template-columns: 1fr; gap: 2px; }
  .help-body dd { margin-bottom: 8px; }
}
