:root {
  --brand-teal: #0a5a64;
  --brand-yellow: #ffcd1c;
  --ink: #17383d;
  --muted: #61777a;
  --surface: #ffffff;
  --canvas: #f1f5f4;
  --line: #d9e4e4;
  --green: #239a69;
  --red: #d84a3a;
  --blue: #2767c7;
  --purple: #7661a8;
  --shadow: 0 14px 38px rgba(10, 90, 100, .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 205, 28, .12), transparent 25rem),
    radial-gradient(circle at 92% 6%, rgba(10, 90, 100, .11), transparent 31rem),
    var(--canvas);
  font: 15px/1.45 "Gotham Pro", "Avenir Next", "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; color: var(--brand-teal); font-size: clamp(32px, 4vw, 46px); line-height: 1.02; letter-spacing: -.035em; }
h2 { margin-bottom: 4px; font-size: clamp(21px, 3vw, 27px); letter-spacing: -.025em; }
code { padding: 2px 5px; border-radius: 5px; color: var(--brand-teal); background: #edf5f5; }

.hero {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 152px;
  padding: 22px max(24px, calc((100vw - 1380px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 34px;
  background: rgba(255, 255, 255, .98);
  border-bottom: 5px solid var(--brand-yellow);
  box-shadow: 0 10px 30px rgba(10, 90, 100, .08);
}
.hero-brand { display: flex; align-items: center; gap: 32px; min-width: 0; }
.brand-logo { display: block; width: clamp(210px, 21vw, 282px); height: auto; flex: 0 0 auto; }
.hero-title { min-width: 0; padding-left: 32px; border-left: 1px solid #d8e4e4; }
.subtitle { margin: 0; color: var(--muted); }
.hero-actions { display: grid; justify-items: end; gap: 9px; }
.access-badge { padding: 6px 10px; border-radius: 999px; color: #385b60; background: #edf5f5; font-size: 10px; font-weight: 900; letter-spacing: .045em; }
.eyebrow { display: block; margin: 0 0 7px; color: var(--brand-teal); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hero-state { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid rgba(10,90,100,.16); border-radius: 999px; color: var(--brand-teal); background: #f1f7f7; white-space: nowrap; }
.state-dot { width: 9px; height: 9px; border-radius: 50%; }
.state-dot.ok { background: var(--green); box-shadow: 0 0 0 5px rgba(35,154,105,.14); }
.state-dot.error { background: var(--red); box-shadow: 0 0 0 5px rgba(216,74,58,.14); }
.state-dot.pending { background: var(--brand-yellow); box-shadow: 0 0 0 5px rgba(255,205,28,.18); }

main { width: min(1380px, calc(100% - 32px)); margin: 24px auto 44px; display: grid; gap: 18px; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.status-card { min-width: 0; min-height: 90px; padding: 15px; display: flex; align-items: center; gap: 13px; border: 1px solid rgba(10,90,100,.11); border-radius: 15px; background: rgba(255,255,255,.97); box-shadow: var(--shadow); }
.status-icon { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--brand-yellow); background: var(--brand-teal); font-size: 15px; }
.status-icon.ok { color: white; background: var(--green); }
.status-icon.error { color: white; background: var(--red); }
.status-icon.warning { color: #6c5710; background: var(--brand-yellow); }
.status-icon.neutral { color: var(--brand-teal); background: #e3eeee; font-weight: 900; }
.status-card div { min-width: 0; display: grid; gap: 2px; }
.status-card strong, .status-card small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-card strong { font-size: 16px; }
.status-card small { color: var(--muted); font-size: 11px; }
.status-label { color: #506b70; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }

.panel { padding: 22px 24px 24px; border: 1px solid rgba(10,90,100,.11); border-top: 3px solid var(--brand-yellow); border-radius: 17px; background: rgba(255,255,255,.98); box-shadow: var(--shadow); overflow: hidden; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.mode-badge, .info-badge, .freshness-badge { display: inline-flex; align-items: center; padding: 7px 11px; border-radius: 999px; color: var(--brand-teal); background: #edf5f5; font-size: 11px; font-weight: 800; white-space: nowrap; }
.mode-badge { color: #6c5710; background: rgba(255,205,28,.2); }
.permission-badge { display: inline-flex; align-items: center; padding: 7px 11px; border-radius: 999px; font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.permission-badge.owner { color: var(--brand-teal); background: #e2f1ed; }
.permission-badge.guest { color: #755e10; background: rgba(255,205,28,.2); }
.freshness-badge.stale { color: #9b3329; background: #fae8e5; }
.select-label { display: block; margin-bottom: 7px; color: #3c5b60; font-size: 13px; font-weight: 700; }
select, input { min-width: 0; height: 45px; padding: 9px 12px; border: 1px solid #c8d9da; border-radius: 10px; color: var(--ink); background: #fbfdfd; outline: none; }
select { width: min(100%, 620px); cursor: pointer; }
select:focus, input:focus { border-color: var(--brand-teal); box-shadow: 0 0 0 3px rgba(255,205,28,.28); }
.device-meta { margin-top: 10px; color: var(--muted); font-size: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi-card { --accent: var(--brand-teal); position: relative; min-width: 0; min-height: 105px; padding: 17px 15px 13px; display: flex; flex-direction: column; justify-content: center; gap: 5px; border: 1px solid #dce7e7; border-radius: 13px; background: linear-gradient(145deg, #fff, #f5f9f9); overflow: hidden; }
.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.kpi-card span { color: #506b70; font-size: 11px; font-weight: 800; letter-spacing: .035em; text-transform: uppercase; }
.kpi-card strong { overflow: hidden; color: var(--ink); font-size: clamp(18px, 2vw, 25px); line-height: 1.08; text-overflow: ellipsis; white-space: nowrap; }
.kpi-card small { color: var(--muted); font-size: 10px; }
.accent-teal { --accent: var(--brand-teal); } .accent-yellow { --accent: var(--brand-yellow); }
.accent-purple { --accent: var(--purple); } .accent-red { --accent: var(--red); }
.accent-green { --accent: var(--green); } .accent-blue { --accent: var(--blue); }
.secondary-kpis { margin-top: 13px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 8px 22px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: #f8fbfb; font-size: 12px; }
.secondary-kpis strong { margin-left: 5px; color: var(--ink); }

.sensor-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.sensor-card { min-width: 0; padding: 15px 13px; display: grid; gap: 3px; border: 1px solid var(--line); border-radius: 13px; background: #f8fbfb; }
.sensor-card.measured { border-top: 4px solid var(--green); }
.sensor-card.estimated { border-top: 4px solid var(--brand-yellow); background: #fffcf0; }
.sensor-card span { color: var(--brand-teal); font-size: 12px; font-weight: 900; }
.sensor-card strong { font-size: 21px; }
.sensor-card small { color: var(--muted); font-weight: 800; }
.sensor-card em { color: var(--muted); font-size: 10px; font-style: normal; }

.insulation-panel { display: flex; align-items: center; justify-content: space-between; gap: 25px; background: linear-gradient(120deg, #fff, #f4f9f9); }
.insulation-content { display: flex; align-items: center; gap: 18px; }
.insulation-symbol { width: 66px; height: 66px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 16px; color: white; background: var(--brand-teal); font-size: 18px; font-weight: 900; }
.insulation-content p:last-child { margin: 7px 0 0; color: var(--muted); }
.insulation-value { color: var(--brand-teal); font-size: clamp(24px, 4vw, 36px); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e3ebeb; text-align: right; white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 2; color: #456267; background: #f2f7f7; font-size: 11px; letter-spacing: .025em; text-transform: uppercase; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover { background: #f8fbfb; }
tbody tr:last-child td { border-bottom: 0; }
td { font-variant-numeric: tabular-nums; }
.empty { padding: 28px; color: var(--muted); text-align: center !important; }
.strings-wrap { max-height: 620px; }
.strings-table { min-width: 1430px; }
.strings-table td:nth-child(4) { text-align: left; }
.strings-table .model-label { display: block; color: var(--ink); font-weight: 700; }
.strings-table td small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.strings-table .reason-cell { max-width: 330px; text-align: left; white-space: normal; font-size: 11px; }
.strings-table tr.row-absent td { color: #87989b; background: #eef1f1; }
.strings-table tr.row-loss td { color: #7d211a; background: #ffe4df; box-shadow: inset 0 1px rgba(216,74,58,.12); }
.strings-table tr.row-warning td { background: #fff8d8; }
.strings-table tr.row-ok:hover td { background: #f2faf6; }
.string-state { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.string-state.row-ok { color: #156b49; background: #dff3e9; }
.string-state.row-loss { color: white; background: var(--red); }
.string-state.row-warning { color: #725b09; background: #ffeb90; }
.string-state.row-absent { color: #617276; background: #dfe5e5; }
.string-state.row-unknown { color: #4e6468; background: #e7efef; }
.string-ok { color: var(--green); font-weight: 800; }
.string-warning { color: #9b6c00; font-weight: 800; }
.string-off { color: var(--muted); }
.mppt-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.mppt-card { min-width: 0; padding: 16px 12px; border: 1px solid var(--line); border-radius: 13px; background: linear-gradient(145deg, #fff, #f5f9f9); text-align: center; }
.mppt-card span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.mppt-card strong { display: block; margin: 7px 0 3px; color: var(--brand-teal); font-size: 20px; }
.mppt-card small { color: var(--muted); }
.source-note { margin: 13px 0 0; color: var(--muted); font-size: 12px; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px 13px; color: var(--muted); font-size: 10px; font-weight: 800; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; background: #dfe5e5; }
.legend-dot.ok { background: var(--green); } .legend-dot.warning { background: var(--brand-yellow); } .legend-dot.loss { background: var(--red); } .legend-dot.absent { background: #aebabc; }

.history-controls { display: grid; grid-template-columns: 190px 190px auto auto; gap: 12px; align-items: end; }
.history-controls label { display: grid; gap: 6px; color: #3c5b60; font-size: 12px; font-weight: 700; }
.button { min-height: 45px; padding: 9px 14px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 800; }
.button.primary { color: white; background: var(--brand-teal); box-shadow: 0 7px 16px rgba(10,90,100,.18); }
.button.secondary { color: var(--brand-teal); background: #e4f0f1; }
.button:disabled { cursor: not-allowed; opacity: .52; }
.history-message { min-height: 21px; margin: 13px 0; color: var(--muted); font-size: 12px; }
.history-message.error { color: var(--red); }
.history-message.success { color: var(--green); }
.history-wrap { max-height: 430px; }

.alert-config-grid { display: grid; grid-template-columns: minmax(230px, .7fr) minmax(340px, 1.4fr) auto auto; gap: 12px; align-items: end; }
.alert-config-grid > label { display: grid; gap: 6px; color: #3c5b60; font-size: 12px; font-weight: 700; }
.switch-label { min-height: 45px; padding: 0 12px; grid-template-columns: auto 1fr !important; align-items: center; border: 1px solid #c8d9da; border-radius: 10px; background: #fbfdfd; }
.switch-label input { width: 18px; min-width: 18px; height: 18px; }
.delivery-state { display: inline-flex; padding: 4px 7px; border-radius: 999px; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.delivery-state.sent { color: #156b49; background: #dff3e9; }
.delivery-state.pending { color: #725b09; background: #ffeb90; }
.delivery-state.failed { color: white; background: var(--red); }
.delivery-state.suppressed { color: #54686b; background: #e4ebeb; }
.alerts-table td small { display: block; color: var(--red); white-space: normal; }

.raw-panel { padding: 0; }
.raw-panel summary { padding: 20px 24px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.raw-panel summary::-webkit-details-marker { display: none; }
.raw-panel summary strong { display: block; font-size: 19px; }
.raw-content { padding: 0 24px 24px; }
.raw-wrap { max-height: 540px; }
.raw-wrap th:nth-child(2), .raw-wrap td:nth-child(2) { text-align: left; }

footer { width: min(1380px, calc(100% - 32px)); margin: 0 auto 30px; padding-top: 14px; display: flex; justify-content: space-between; gap: 18px; border-top: 1px solid rgba(10,90,100,.14); color: #63777a; font-size: 12px; }

.access-page { min-height: 100vh; }
.access-shell { min-height: 100vh; width: min(100% - 28px, 720px); margin: 0 auto; display: grid; place-items: center; padding: 28px 0; }
.access-card { width: 100%; padding: clamp(25px, 5vw, 48px); border: 1px solid rgba(10,90,100,.12); border-top: 5px solid var(--brand-yellow); border-radius: 20px; background: rgba(255,255,255,.98); box-shadow: 0 20px 55px rgba(10,90,100,.14); }
.access-logo { width: min(285px, 75%); height: auto; display: block; margin-bottom: 36px; }
.access-heading { padding-top: 23px; border-top: 1px solid var(--line); }
.access-heading h1 { font-size: clamp(30px, 6vw, 44px); }
.access-heading p:last-child { color: var(--muted); }
.access-form { margin-top: 25px; display: grid; gap: 10px; }
.access-form label { color: #3c5b60; font-size: 13px; font-weight: 800; }
.access-form input { width: 100%; }
.access-form .button { margin-top: 6px; }
.access-error { margin: 0; color: var(--red); font-size: 13px; font-weight: 800; }
.access-expiry { margin: 22px 0 0; padding-top: 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) {
  .status-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mppt-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sensor-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .alert-config-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .hero { position: relative; min-height: auto; padding: 20px; align-items: flex-start; flex-direction: column; gap: 15px; }
  .hero-actions { width: 100%; justify-items: start; }
  .hero-brand { width: 100%; }
  .brand-logo { width: 210px; }
  .hero-title { padding-left: 22px; }
  main { width: min(100% - 18px, 1380px); margin-top: 14px; }
  .history-controls { grid-template-columns: 1fr 1fr; }
  .insulation-panel { align-items: flex-start; }
}
@media (max-width: 560px) {
  .hero-brand { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brand-logo { width: 165px; }
  .hero-title { width: 100%; padding: 8px 0 0; border-left: 0; border-top: 1px solid #d8e4e4; }
  h1 { font-size: 28px; }
  .hero-state { white-space: normal; }
  .status-grid, .kpi-grid { grid-template-columns: 1fr; }
  .panel { padding: 18px 15px; }
  .section-heading { flex-direction: column; }
  .mode-badge, .info-badge { white-space: normal; }
  .mppt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sensor-grid, .alert-config-grid { grid-template-columns: 1fr; }
  .history-controls { grid-template-columns: 1fr; }
  .button { width: 100%; }
  .insulation-panel { flex-direction: column; }
  .raw-panel summary { padding: 18px 15px; }
  .raw-content { padding: 0 15px 18px; }
  footer { flex-direction: column; gap: 4px; }
}
