:root {
  color-scheme: dark;
  --bg: #081012;
  --bg-soft: #0d1719;
  --panel: rgba(17, 29, 31, 0.9);
  --panel-strong: #142225;
  --panel-soft: #101c1e;
  --line: rgba(194, 232, 222, 0.12);
  --line-strong: rgba(194, 232, 222, 0.23);
  --text: #f3f8f6;
  --muted: #91a39f;
  --muted-strong: #b8c6c2;
  --mint: #65e5b8;
  --mint-soft: rgba(101, 229, 184, 0.13);
  --blue: #8ebcff;
  --blue-soft: rgba(142, 188, 255, 0.13);
  --sun: #ffd36a;
  --sun-soft: rgba(255, 211, 106, 0.13);
  --danger: #ff7e79;
  --danger-soft: rgba(255, 126, 121, 0.13);
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  --soc: 0deg;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 8% -12%, rgba(101, 229, 184, 0.13), transparent 31rem),
    radial-gradient(circle at 94% 4%, rgba(142, 188, 255, 0.1), transparent 28rem),
    linear-gradient(180deg, #091315 0%, #081012 54%, #070d0f 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 42px 42px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(101, 229, 184, 0.35);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 56px;
}

.app-shell.engineering {
  width: min(1600px, calc(100% - 28px));
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: rgba(11, 20, 22, 0.82);
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(101, 229, 184, 0.32);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(101, 229, 184, 0.18), rgba(142, 188, 255, 0.08));
  color: var(--mint);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.brand-mark::after {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 12px var(--mint);
  content: "";
}

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 760;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.view-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.025);
}

.view-switch a {
  padding: 9px 13px;
  border-radius: 9px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: 160ms ease;
}

.view-switch a:hover {
  color: var(--text);
}

.view-switch a.active {
  background: var(--text);
  color: #0c1719;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.18);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.live-pill,
.tag,
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted-strong);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12px;
  font-weight: 680;
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #65716f;
  transition: 180ms ease;
}

.live-pill[data-state="live"] .live-dot {
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(101, 229, 184, 0.09), 0 0 14px rgba(101, 229, 184, 0.5);
}

.live-pill[data-state="live"].tick .live-dot {
  animation: data-tick 420ms ease-out;
}

.live-pill[data-state="waiting"] .live-dot {
  background: var(--sun);
}

.live-pill[data-state="offline"] .live-dot {
  background: var(--danger);
}

@keyframes data-tick {
  0% { transform: scale(1); }
  42% { transform: scale(1.9); box-shadow: 0 0 0 7px rgba(101, 229, 184, 0.16); }
  100% { transform: scale(1); }
}

.icon-button,
.button,
.mode-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button:hover,
.button:hover,
.mode-button:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.07);
}

.icon-button:active,
.button:active,
.mode-button:active {
  transform: translateY(1px);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border-radius: 11px;
  font-size: 17px;
}

.button {
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 730;
}

.button.primary {
  border-color: rgba(101, 229, 184, 0.3);
  background: var(--mint);
  color: #071411;
}

.button.primary:hover {
  background: #83edc7;
}

.button.danger {
  border-color: rgba(255, 126, 121, 0.24);
  color: #ffaaa6;
  background: var(--danger-soft);
}

.button.compact {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--mint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.page-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 58px 4px 25px;
}

.page-intro h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(34px, 5vw, 66px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.page-intro p:last-child {
  max-width: 460px;
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 211, 106, 0.24);
  border-radius: 15px;
  background: var(--sun-soft);
  color: #ffe6a6;
  font-size: 13px;
}

.banner[hidden] {
  display: none;
}

.banner strong {
  display: block;
  margin-bottom: 2px;
  color: #fff0c8;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(21, 36, 39, 0.94), rgba(13, 24, 26, 0.94));
  box-shadow: var(--shadow);
}

.energy-overview {
  display: grid;
  grid-template-columns: minmax(300px, 1.25fr) minmax(280px, 0.9fr) minmax(250px, 0.75fr);
  gap: 14px;
}

.battery-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 28px;
  min-height: 280px;
  padding: 28px;
}

.soc-ring {
  display: grid;
  width: 170px;
  height: 170px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--mint) var(--soc), rgba(255, 255, 255, 0.075) 0deg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 50px rgba(101, 229, 184, 0.08);
}

.soc-ring::before {
  grid-area: 1 / 1;
  width: 134px;
  height: 134px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #101c1e;
  content: "";
}

.soc-copy {
  z-index: 1;
  grid-area: 1 / 1;
  text-align: center;
}

.soc-value {
  display: block;
  font-size: 38px;
  font-weight: 790;
  letter-spacing: -0.055em;
}

.soc-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.battery-copy h2 {
  margin: 0 0 7px;
  font-size: 21px;
  letter-spacing: -0.025em;
}

.battery-copy > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.primary-metric {
  margin-top: 27px;
}

.metric-value {
  display: block;
  font-size: clamp(32px, 4vw, 48px);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.05em;
}

.metric-caption {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.journey-panel {
  display: flex;
  min-height: 280px;
  padding: 28px;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(circle at 85% 12%, rgba(142, 188, 255, 0.16), transparent 48%),
    linear-gradient(145deg, rgba(20, 36, 41, 0.98), rgba(13, 24, 27, 0.96));
}

.journey-value {
  margin-top: 20px;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 730;
  letter-spacing: -0.065em;
  line-height: 1;
}

.journey-track {
  height: 8px;
  margin: 24px 0 12px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
}

.journey-track span {
  display: block;
  width: 50%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--mint));
  transition: width 400ms ease;
}

.journey-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.source-stack {
  display: grid;
  gap: 14px;
}

.source-card,
.tariff-card {
  display: flex;
  min-height: 84px;
  padding: 17px 19px;
  flex-direction: column;
  justify-content: space-between;
}

.source-top,
.section-heading,
.circuit-top,
.rule-top,
.diag-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.source-name,
.muted-label {
  color: var(--muted);
  font-size: 12px;
}

.source-soc {
  font-size: 28px;
  font-weight: 760;
  letter-spacing: -0.04em;
}

.source-power {
  color: var(--muted-strong);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tariff-card {
  border-color: rgba(255, 211, 106, 0.18);
  background: linear-gradient(145deg, rgba(44, 39, 24, 0.9), rgba(24, 26, 22, 0.95));
}

.tariff-value {
  font-size: 30px;
  font-weight: 780;
  letter-spacing: -0.04em;
}

.tariff-value.nt {
  color: var(--sun);
}

.content-section {
  margin-top: 38px;
}

.section-heading {
  align-items: flex-end;
  margin: 0 3px 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.035em;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-actions {
  display: flex;
  gap: 8px;
}

.circuit-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.circuit-card {
  position: relative;
  min-width: 0;
  padding: 20px;
  overflow: hidden;
  transition: border-color 180ms ease, transform 180ms ease;
}

.circuit-card[data-mode="FV"] {
  border-color: rgba(101, 229, 184, 0.22);
}

.circuit-card[data-mode="DS"] {
  border-color: rgba(142, 188, 255, 0.22);
}

.circuit-card[data-mode="OFF"] {
  opacity: 0.78;
}

.circuit-card.pending {
  animation: pending 1s ease-in-out infinite alternate;
}

@keyframes pending {
  to { border-color: rgba(255, 211, 106, 0.45); }
}

.circuit-name {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.025em;
}

.mode-badge {
  min-width: 44px;
  padding: 6px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 830;
  text-align: center;
}

[data-mode="FV"] .mode-badge,
.mode-badge.fv {
  background: var(--mint-soft);
  color: var(--mint);
}

[data-mode="DS"] .mode-badge,
.mode-badge.ds {
  background: var(--blue-soft);
  color: var(--blue);
}

.circuit-watt {
  display: block;
  margin: 25px 0 4px;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 740;
  letter-spacing: -0.045em;
}

.switch-reason {
  min-height: 19px;
  color: var(--muted);
  font-size: 11px;
}

.mode-control {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 19px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.13);
}

.mode-button {
  min-height: 35px;
  padding: 7px 4px;
  border-color: transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
}

.mode-button.active[data-mode="FV"] {
  background: var(--mint-soft);
  color: var(--mint);
}

.mode-button.active[data-mode="DS"] {
  background: var(--blue-soft);
  color: var(--blue);
}

.mode-button.active[data-mode="OFF"] {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.rule-card {
  padding: 22px;
}

.rule-card h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.rule-card p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.rule-card > .button {
  margin-top: 18px;
}

.rule-count {
  font-size: 30px;
  font-weight: 760;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 42px;
  padding: 17px 4px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

dialog {
  width: min(920px, calc(100% - 26px));
  max-height: min(86vh, 900px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  color: var(--text);
  background: #101a1d;
  box-shadow: 0 35px 120px rgba(0, 0, 0, 0.65);
}

dialog::backdrop {
  background: rgba(2, 8, 9, 0.78);
  backdrop-filter: blur(8px);
}

.dialog-shell {
  display: grid;
  grid-template-rows: auto auto 1fr;
  max-height: inherit;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 21px 22px 16px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.tab-list {
  display: flex;
  gap: 6px;
  padding: 0 22px 15px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  padding: 8px 11px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 730;
}

.tab-button.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.dialog-body {
  padding: 20px 22px 24px;
  overflow: auto;
}

.tab-panel[hidden] {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 19px;
}

.form-grid.quick {
  grid-template-columns: 1.3fr 1fr 1fr auto;
}

.form-grid.weekly > .button {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: #0c1517;
}

.field input:focus,
.field select:focus {
  border-color: rgba(101, 229, 184, 0.42);
}

.subsection-label {
  margin: 24px 0 11px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.data-list {
  display: grid;
  gap: 7px;
}

.data-row {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr 0.85fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.018);
  font-size: 12px;
}

.data-row.hdo {
  grid-template-columns: 1fr 1fr auto;
}

.empty-state {
  padding: 26px;
  border: 1px dashed var(--line-strong);
  border-radius: 13px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  width: min(360px, calc(100% - 36px));
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 13px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(18, 30, 32, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  color: var(--text);
  font-size: 12px;
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-color: rgba(255, 126, 121, 0.35);
  color: #ffc1bd;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* Engineering view */
.engineer-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 38px 3px 18px;
}

.engineer-intro h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: -0.045em;
}

.engineer-intro p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.engineer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.7fr);
  gap: 12px;
  align-items: start;
}

.engineer-main,
.engineer-side {
  display: grid;
  gap: 12px;
}

.diag-panel {
  padding: 18px;
  border-radius: 18px;
  box-shadow: none;
}

.diag-heading {
  margin-bottom: 14px;
}

.diag-heading h2,
.diag-heading h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.diag-heading span {
  color: var(--muted);
  font-size: 11px;
}

.health-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.health-item {
  display: grid;
  min-height: 82px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.018);
  align-content: space-between;
}

.health-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.health-value {
  margin-top: 11px;
  font-size: 14px;
  font-weight: 740;
}

.health-value.ok { color: var(--mint); }
.health-value.warn { color: var(--sun); }
.health-value.bad { color: var(--danger); }

.warning-list {
  display: grid;
  gap: 7px;
}

.warning-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 211, 106, 0.18);
  border-radius: 11px;
  background: var(--sun-soft);
  color: #ffe7ad;
  font-size: 11px;
  line-height: 1.45;
}

.warning-item.bad {
  border-color: rgba(255, 126, 121, 0.2);
  background: var(--danger-soft);
  color: #ffc1bd;
}

.warning-item.ok {
  border-color: rgba(101, 229, 184, 0.18);
  background: var(--mint-soft);
  color: #a6f4d8;
}

.engineering-table-wrap {
  overflow-x: auto;
}

.engineering-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.engineering-table th {
  padding: 0 9px 9px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-align: left;
  text-transform: uppercase;
}

.engineering-table td {
  padding: 10px 9px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.engineering-table .mode-control {
  min-width: 170px;
  margin: 0;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.kv {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.016);
}

.kv-key {
  display: block;
  margin-bottom: 7px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  font-weight: 780;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.kv-value {
  display: block;
  overflow: hidden;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 670;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lock-panel {
  border-color: rgba(255, 211, 106, 0.2);
}

.lock-state {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.lock-symbol {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: var(--sun-soft);
  color: var(--sun);
  font-size: 19px;
}

.lock-copy strong {
  display: block;
  font-size: 14px;
}

.lock-copy span {
  color: var(--muted);
  font-size: 10px;
}

.lock-panel .button {
  width: 100%;
}

.raw-frame {
  max-height: 290px;
  margin: 0;
  padding: 13px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #a9c6bd;
  background: #091113;
  font: 10px/1.55 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Login */
.auth-page {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.auth-shell {
  display: grid;
  width: min(940px, 100%);
  grid-template-columns: 1.1fr 0.9fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(13, 24, 26, 0.91);
  box-shadow: 0 38px 120px rgba(0, 0, 0, 0.46);
}

.auth-story {
  position: relative;
  min-height: 570px;
  padding: 48px;
  overflow: hidden;
  background:
    radial-gradient(circle at 85% 20%, rgba(101, 229, 184, 0.2), transparent 19rem),
    linear-gradient(145deg, #15282a, #0c191b);
}

.auth-story::before,
.auth-story::after {
  position: absolute;
  border: 1px solid rgba(101, 229, 184, 0.14);
  border-radius: 50%;
  content: "";
}

.auth-story::before {
  right: -90px;
  bottom: -120px;
  width: 380px;
  height: 380px;
}

.auth-story::after {
  right: 10px;
  bottom: -20px;
  width: 180px;
  height: 180px;
}

.auth-story h1 {
  max-width: 460px;
  margin: 140px 0 18px;
  font-size: clamp(42px, 6vw, 68px);
  line-height: 0.98;
  letter-spacing: -0.065em;
}

.auth-story p {
  max-width: 410px;
  margin: 0;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.65;
}

.auth-form-wrap {
  display: grid;
  padding: 44px;
  align-content: center;
}

.auth-form-wrap h2 {
  margin: 0;
  font-size: 27px;
  letter-spacing: -0.04em;
}

.auth-lead {
  margin: 8px 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form {
  display: grid;
  gap: 13px;
}

.auth-form .field input {
  height: 50px;
}

.auth-form .button {
  min-height: 50px;
  margin-top: 4px;
}

.auth-details {
  color: var(--muted);
  font-size: 11px;
}

.auth-details summary {
  margin-bottom: 10px;
  cursor: pointer;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: #ffaaa6;
  font-size: 12px;
}

.form-error:empty {
  min-height: 0;
}

.spinner {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(7, 20, 17, 0.3);
  border-top-color: #071411;
  border-radius: 50%;
  animation: spin 750ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1120px) {
  .energy-overview {
    grid-template-columns: 1.1fr 0.9fr;
  }

  .source-stack {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
  }

  .circuit-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .engineer-layout {
    grid-template-columns: 1fr;
  }

  .engineer-side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .engineer-side .raw-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 780px) {
  .app-shell,
  .app-shell.engineering {
    width: min(100% - 20px, 720px);
    padding-top: 10px;
  }

  .topbar {
    top: 7px;
    grid-template-columns: 1fr auto;
    gap: 9px;
    padding: 9px 10px;
  }

  .view-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .view-switch a {
    flex: 1;
    text-align: center;
  }

  .top-actions .live-pill span:last-child {
    display: none;
  }

  .page-intro {
    display: block;
    padding: 40px 3px 20px;
  }

  .page-intro p:last-child {
    margin-top: 14px;
  }

  .energy-overview,
  .rule-grid {
    grid-template-columns: 1fr;
  }

  .battery-panel {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .source-stack {
    grid-column: auto;
    grid-template-columns: 1fr 1fr;
  }

  .tariff-card {
    grid-column: 1 / -1;
  }

  .circuit-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .form-grid.quick {
    grid-template-columns: 1fr 1fr;
  }

  .data-row {
    grid-template-columns: 1fr 1fr auto;
  }

  .data-row > :first-child {
    grid-column: 1 / -1;
  }

  .health-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .engineer-side {
    grid-template-columns: 1fr;
  }

  .engineer-side .raw-panel {
    grid-column: auto;
  }

  .auth-page {
    padding: 12px;
  }

  .auth-shell {
    grid-template-columns: 1fr;
  }

  .auth-story {
    min-height: 260px;
    padding: 28px;
  }

  .auth-story h1 {
    margin: 60px 0 13px;
    font-size: 42px;
  }

  .auth-form-wrap {
    padding: 32px 27px 36px;
  }
}

@media (max-width: 480px) {
  .brand-subtitle,
  .top-actions .icon-button {
    display: none;
  }

  .battery-panel,
  .journey-panel {
    padding: 22px;
  }

  .source-stack,
  .form-grid,
  .form-grid.quick,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .tariff-card {
    grid-column: auto;
  }

  .data-row,
  .data-row.hdo {
    grid-template-columns: 1fr auto;
  }

  .data-row > :first-child {
    grid-column: 1 / -1;
  }

  .footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* WR web v2: pohotovostní rozložení */
.energy-overview {
  grid-template-columns: minmax(0, 1.15fr) minmax(430px, 0.85fr);
  align-items: stretch;
  margin-top: 18px;
  gap: 12px;
}

.energy-overview .source-stack {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.energy-overview .source-card,
.energy-overview .tariff-card {
  min-height: 184px;
  padding: 18px;
}

.battery-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 184px;
  padding: 18px 20px;
  gap: 20px;
}

.battery-panel .primary-metric {
  margin-top: 20px;
}

.battery-panel .metric-value {
  font-size: clamp(30px, 3vw, 42px);
}

.battery-gauge {
  display: grid;
  width: 154px;
  justify-items: center;
  align-content: start;
  gap: 8px;
}

.battery-gauge .soc-ring {
  width: 124px;
  height: 124px;
}

.battery-gauge .soc-ring::before {
  width: 96px;
  height: 96px;
}

.battery-gauge .soc-value {
  font-size: 28px;
}

.battery-gauge .soc-label {
  font-size: 8px;
}

.journey-inline {
  display: grid;
  width: 100%;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 2px 7px;
  text-align: center;
}

.journey-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 780;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.journey-inline strong {
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
}

.journey-inline > span:last-child {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.25;
}

.circuits-section {
  margin-top: 18px;
}

.circuits-section .section-heading {
  margin-bottom: 10px;
}

.circuit-card {
  min-height: 226px;
  padding: 18px;
  background: linear-gradient(145deg, rgba(20, 33, 36, 0.96), rgba(12, 22, 24, 0.96));
}

.circuit-card[data-mode="FV"] {
  border-color: rgba(101, 229, 184, 0.82);
  background: linear-gradient(145deg, rgba(25, 73, 59, 0.98), rgba(13, 37, 33, 0.99));
}

.circuit-card[data-mode="DS"] {
  border-color: rgba(112, 174, 255, 0.84);
  background: linear-gradient(145deg, rgba(27, 60, 94, 0.98), rgba(14, 35, 53, 0.99));
}

.circuit-card[data-mode="OFF"] {
  border-color: rgba(194, 205, 202, 0.13);
  background: linear-gradient(145deg, rgba(23, 30, 31, 0.92), rgba(13, 20, 22, 0.95));
  opacity: 0.76;
}

.circuit-card[data-mode="UNKNOWN"] {
  border-style: dashed;
}

.circuit-card.pending {
  box-shadow: inset 0 0 0 2px rgba(255, 211, 106, 0.55), var(--shadow);
}

.circuit-card-actions {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
}

.quick-rule-button {
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  font-size: 20px;
  font-weight: 430;
  line-height: 1;
}

.quick-rule-button:hover {
  border-color: rgba(101, 229, 184, 0.45);
  color: var(--mint);
  background: var(--mint-soft);
}

.quick-rule-dialog {
  width: min(560px, calc(100% - 26px));
}

.quick-rule-shell {
  display: grid;
}

.quick-rule-shell .dialog-header {
  border-bottom: 1px solid var(--line);
}

.quick-rule-shell .dialog-header .eyebrow {
  margin-bottom: 5px;
}

.quick-rule-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 12px;
  padding: 20px 22px 24px;
}

.quick-rule-body .button {
  grid-column: 1 / -1;
}

.auth-shell.auth-compact {
  width: min(480px, 100%);
  grid-template-columns: 1fr;
}

.auth-compact .auth-form-wrap {
  min-height: 440px;
  padding: 42px;
}

.auth-compact .brand {
  margin-bottom: 54px;
}

.auth-compact h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.engineer-content > .content-section:first-child {
  margin-top: 18px;
}

.engineer-layout {
  grid-template-columns: minmax(0, 1.85fr) minmax(310px, 0.68fr);
}

.diag-heading > div:first-child {
  min-width: 0;
}

.diag-heading > div:first-child > span {
  display: block;
  margin-top: 4px;
}

.diag-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.engineering-table tbody tr {
  transition: background 180ms ease, box-shadow 180ms ease;
}

.engineering-table tbody tr[data-mode="FV"] {
  background: rgba(101, 229, 184, 0.16);
  box-shadow: inset 4px 0 0 rgba(101, 229, 184, 0.96);
}

.engineering-table tbody tr[data-mode="DS"] {
  background: rgba(112, 174, 255, 0.18);
  box-shadow: inset 4px 0 0 rgba(112, 174, 255, 0.96);
}

.circuit-card[data-mode="FV"] .mode-badge,
.engineering-table tbody tr[data-mode="FV"] .mode-badge {
  border: 1px solid rgba(101, 229, 184, 0.62);
  background: rgba(101, 229, 184, 0.3);
  color: #8fffd6;
}

.circuit-card[data-mode="DS"] .mode-badge,
.engineering-table tbody tr[data-mode="DS"] .mode-badge {
  border: 1px solid rgba(112, 174, 255, 0.64);
  background: rgba(112, 174, 255, 0.32);
  color: #c0dcff;
}

.engineering-table tbody tr[data-mode="OFF"] {
  color: var(--muted-strong);
  background: rgba(255, 255, 255, 0.018);
  box-shadow: inset 3px 0 0 rgba(194, 205, 202, 0.18);
}

.engineering-table tbody tr.pending {
  box-shadow: inset 3px 0 0 var(--sun);
}

.engineering-table tbody tr.pending td:last-child {
  background: rgba(255, 211, 106, 0.045);
}

.mode-button.active[data-mode="FV"] {
  border-color: rgba(101, 229, 184, 0.72);
  background: rgba(101, 229, 184, 0.36);
  color: #8fffd6;
}

.mode-button.active[data-mode="DS"] {
  border-color: rgba(112, 174, 255, 0.74);
  background: rgba(112, 174, 255, 0.38);
  color: #c0dcff;
}

.event-panel {
  border-color: rgba(255, 211, 106, 0.3);
  background: linear-gradient(145deg, rgba(46, 40, 23, 0.72), rgba(18, 28, 29, 0.96));
}

.event-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 8px;
}

.event-item {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid rgba(255, 211, 106, 0.16);
  border-radius: 11px;
  background: rgba(5, 12, 13, 0.22);
}

.event-item strong {
  display: block;
  color: var(--text);
  font-size: 12px;
  font-weight: 680;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
}

.health-panel {
  margin-top: 12px;
}

.health-panel .health-item {
  min-height: 68px;
}

@media (max-width: 1120px) {
  .energy-overview {
    grid-template-columns: 1fr;
  }

  .battery-panel {
    order: -1;
  }

  .energy-overview .source-stack {
    grid-column: auto;
  }

  .energy-overview .source-card,
  .energy-overview .tariff-card {
    min-height: 118px;
  }

  .engineer-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .energy-overview .source-stack {
    grid-template-columns: 1fr 1fr;
  }

  .battery-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    justify-items: stretch;
    text-align: left;
  }

  .battery-gauge {
    width: 138px;
  }

  .tariff-card {
    grid-column: 1 / -1;
  }

  .diag-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .diag-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .event-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .auth-compact .auth-form-wrap {
    min-height: auto;
    padding: 30px 24px 34px;
  }

  .auth-compact .brand {
    margin-bottom: 38px;
  }

  .battery-panel {
    grid-template-columns: 1fr auto;
    padding: 17px;
    gap: 12px;
  }

  .battery-copy h2,
  .battery-copy .eyebrow,
  .metric-caption {
    display: none;
  }

  .battery-panel .primary-metric {
    margin-top: 8px;
  }

  .battery-gauge {
    width: 112px;
  }

  .battery-gauge .soc-ring {
    width: 100px;
    height: 100px;
  }

  .battery-gauge .soc-ring::before {
    width: 76px;
    height: 76px;
  }

  .battery-gauge .soc-value {
    font-size: 23px;
  }

  .journey-inline {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .journey-inline > span:last-child {
    display: none;
  }

  .energy-overview .source-stack,
  .quick-rule-body {
    grid-template-columns: 1fr;
  }

  .tariff-card {
    grid-column: auto;
  }
}
