/* WDEM — shared stylesheet */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #16222e;
  --ink-soft: #51606e;
  --line: #dde3ea;
  --brand: #0b2a4a;
  --brand-2: #11406e;
  --accent: #0e7adb;
  --accent-soft: #e8f2fc;
  --good: #0a7d4f;
  --warn: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.06), 0 4px 14px rgba(16, 32, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

/* ---------------------------------------------------------------- header */

.topbar {
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  height: 58px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand svg { flex: none; }
.brand .title { font-size: 17px; font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; }
.brand .subtitle { font-size: 12px; opacity: 0.75; white-space: nowrap; }

.topbar .actions { display: flex; align-items: center; gap: 10px; }
.topbar .who { font-size: 13px; opacity: 0.85; margin-right: 4px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #f4f8fc; border-color: #c8d4e0; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #0c6bc2; }

.btn.ghost {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.2); }

.btn.danger { color: var(--warn); border-color: #e6c9c7; }
.btn.danger:hover { background: #fdf2f1; }

.btn.small { padding: 4px 10px; font-size: 12.5px; }

/* ---------------------------------------------------------------- layout */

.wrap {
  max-width: 1280px;
  margin: 22px auto 60px;
  padding: 0 22px;
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1020px) {
  .wrap { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card .card-head {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card .card-head h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.25px;
  text-transform: uppercase;
  color: var(--brand);
}

.card .card-body { padding: 16px 18px 18px; }

.muted { color: var(--ink-soft); font-size: 13px; }
.tiny { font-size: 12px; }

/* --------------------------------------------------------- appliance table */

table.appliances { width: 100%; border-collapse: collapse; }
table.appliances th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
  padding: 2px 4px 6px;
  border-bottom: 1px solid var(--line);
}
table.appliances td { padding: 2px 3px; border-bottom: 1px solid #f0f3f7; }
table.appliances td.row-del { width: 28px; text-align: center; }

/* compact variant: dense rows so 15+ appliance groups stay tidy */
table.appliances.compact input[type="text"],
table.appliances.compact input[type="number"] {
  padding: 4px 7px;
  font-size: 13px;
  border-radius: 6px;
}
table.appliances.compact .del-row { font-size: 14px; padding: 2px 5px; }

.del-row {
  appearance: none;
  border: none;
  background: none;
  color: #9aa7b4;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.del-row:hover { color: var(--warn); background: #fdf2f1; }

/* ------------------------------------------------------ unit switch (seg) */

.seg {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  appearance: none;
  background: transparent;
  border: none;
  color: #fff;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg button:hover { background: rgba(255, 255, 255, 0.18); }
.seg button.active { background: #fff; color: var(--brand); }

/* ------------------------------------------------------------ project bar */

.project-bar { grid-column: 1 / -1; }
.project-grid { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.project-grid .grow { flex: 1 1 320px; }
.project-grid .bt-field { flex: 0 0 200px; }

input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}
input.invalid { border-color: var(--warn); background: #fff7f7; }

td.col-k input, td.col-q input, td.col-p input { text-align: right; }
th.col-k, th.col-q, th.col-p { width: 86px; }

.table-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ------------------------------------------------------------- settings */

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-top: 4px;
}
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field .hint { font-size: 11.5px; color: #8694a3; margin-top: 3px; }

.radio-row { display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }
.radio-row label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}
.radio-row input { width: auto; margin-top: 3px; }

.run-bar { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.run-bar .btn.primary { padding: 11px 26px; font-size: 15px; }

.spinner {
  width: 18px; height: 18px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  margin-top: 12px;
  background: #fdf2f1;
  border: 1px solid #ecc8c5;
  color: var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
}

/* -------------------------------------------------------------- results */

.results-stack { display: flex; flex-direction: column; gap: 20px; }

.headline {
  background: linear-gradient(135deg, var(--brand) 0%, #123e69 70%, #155087 100%);
  color: #fff;
  border: none;
}
.headline .card-body { padding: 22px 24px; }
.headline .headline-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.headline .label { font-size: 18px; font-weight: 650; opacity: 0.95; letter-spacing: 0.3px; }
.headline .stamp { font-size: 12.5px; opacity: 0.75; }
.headline .value { font-size: 46px; font-weight: 700; line-height: 1.15; margin: 2px 0 2px; }
.headline .value .unit { font-size: 20px; font-weight: 500; opacity: 0.8; margin-left: 6px; }
.headline .sub { font-size: 13px; opacity: 0.85; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 2px; color: var(--brand); }
.stat .value .unit { font-size: 13px; color: var(--ink-soft); font-weight: 500; margin-left: 4px; }
.stat .note { font-size: 11.5px; color: #8694a3; margin-top: 2px; }
.stat.flag { border-left: 3px solid var(--accent); }

.meta-line { font-size: 12.5px; color: var(--ink-soft); }
.meta-line code {
  background: #eef2f7;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
}

.chart-box { position: relative; height: 260px; }
.chart-box.clickable { cursor: zoom-in; }
.chart-box.clickable:hover { opacity: 0.92; }

/* collapsible chart cards — fully minimised until expanded */
button.head-toggle {
  appearance: none;
  width: 100%;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
button.head-toggle:hover { background: #f7fafd; }
.collapsible .card-head { border-bottom: none; border-radius: var(--radius); }
.collapsible.open .card-head { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.collapsible .chev {
  margin-left: auto;
  color: var(--ink-soft);
  font-size: 13px;
  transition: transform 0.15s;
}
.collapsible.open .chev { transform: rotate(90deg); }

/* off-viewport holder used to render charts at print resolution for the PDF report */
.offscreen-chart {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1400px;
  height: 520px;
}

/* enlarged chart dialog */
dialog.chart-modal {
  width: min(1150px, 94vw);
  max-width: 94vw;
  padding: 18px 20px 20px;
}
.chart-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.chart-modal-head h3 { margin: 0; }
.chart-modal-body { position: relative; height: min(66vh, 640px); }

/* ---------------------------------------------------------- settings page */

.settings-shell { max-width: 780px; margin: 22px auto 60px; padding: 0 22px; }
h3.set-group {
  margin: 22px 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
h3.set-group:first-of-type { margin-top: 2px; }
.settings-grid .span2 { grid-column: 1 / -1; }
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.check-row input { width: auto; }

.placeholder {
  border: 1.5px dashed #ccd6e0;
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: #8694a3;
  background: #fafbfd;
}
.placeholder h3 { margin: 0 0 6px; color: var(--ink-soft); font-size: 16px; }

[hidden] { display: none !important; }

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

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(14, 122, 219, 0.18), transparent 60%),
    linear-gradient(160deg, #0b2a4a 0%, #0e3358 55%, #11406e 100%);
  padding: 24px;
}
.login-card {
  width: 380px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(4, 16, 28, 0.45);
  padding: 30px 30px 26px;
}
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-card h1 { font-size: 20px; margin: 0; color: var(--brand); }
.login-card .tagline { color: var(--ink-soft); font-size: 13px; margin: 2px 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn.primary { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }
.login-foot { margin-top: 16px; text-align: center; color: #8694a3; font-size: 12px; }

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

.admin-wrap { max-width: 1140px; margin: 24px auto 60px; padding: 0 22px; display: flex; flex-direction: column; gap: 20px; }

table.appliances.defaults th.col-p { width: 92px; }
table.appliances.defaults th.col-k { width: 60px; }
table.appliances.defaults th.col-q { width: 90px; }

table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--line);
}
table.users td { padding: 9px 8px; border-bottom: 1px solid #eef2f6; }
table.users td.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.pill.on { background: #e3f4ec; color: var(--good); }
.pill.off { background: #f4e6e5; color: var(--warn); }
.pill.role { background: var(--accent-soft); color: var(--accent); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr 140px auto; gap: 10px; align-items: end; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- modal */

dialog {
  border: none;
  border-radius: 12px;
  box-shadow: 0 20px 70px rgba(4, 16, 28, 0.4);
  padding: 24px;
  width: 360px;
  max-width: 92vw;
}
dialog::backdrop { background: rgba(10, 22, 34, 0.5); }
dialog h3 { margin: 0 0 14px; font-size: 16px; color: var(--brand); }
dialog .field { margin-bottom: 12px; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 50;
}
.toast.show { opacity: 1; }
