:root {
  color-scheme: light;
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-soft: #f7f9f9;
  --ink: #172424;
  --muted: #647271;
  --line: #dce5e5;
  --teal: #0f8f85;
  --teal-dark: #0a665f;
  --amber: #c47b14;
  --red: #c94c42;
  --blue: #326bd9;
  --green: #218b51;
  --shadow: 0 24px 70px rgba(34, 50, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.locked {
  overflow: hidden;
}

button,
input,
table {
  font: inherit;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
  align-items: center;
  gap: clamp(24px, 5vw, 74px);
  padding: clamp(24px, 5vw, 72px);
  background:
    linear-gradient(90deg, rgba(5, 20, 18, 0.74) 0%, rgba(8, 42, 37, 0.42) 45%, rgba(8, 18, 25, 0.28) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.32)),
    url("assets/Plant-V.jpg") center / cover no-repeat;
}

.login-screen.show {
  display: grid;
}

.login-hero-copy {
  width: min(860px, 100%);
  color: #f8fffb;
  text-shadow: 0 4px 28px rgba(0, 0, 0, 0.42);
}

.login-hero-copy span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  background: rgba(4, 38, 35, 0.28);
  color: #d9fff0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}

.login-hero-copy h1 {
  max-width: 850px;
  margin: 0;
  color: #ffffff;
  font-size: clamp(42px, 6vw, 86px);
  font-weight: 950;
  line-height: 0.95;
}

.login-hero-copy p {
  margin: 20px 0 0;
  color: #d7fff2;
  font-size: clamp(22px, 3vw, 40px);
  font-weight: 850;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
}

.login-brand {
  color: var(--ink);
}

.login-card h2 {
  margin: 6px 0 2px;
  font-size: 30px;
}

.login-card label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 249, 249, 0.85);
}

.auth-tabs button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.auth-tabs button.active {
  background: var(--teal);
  color: #fff;
}

.auth-field,
.auth-back-button {
  display: none;
}

body[data-auth-mode="login"] .auth-login,
body[data-auth-mode="register"] .auth-register,
body[data-auth-mode="register"] .auth-login,
body[data-auth-mode="forgot"] .auth-forgot,
body[data-auth-mode="recovery"] .auth-recovery {
  display: block;
}

body[data-auth-mode="recovery"] .auth-tabs {
  display: none;
}

body[data-auth-mode="register"] .auth-back-button,
body[data-auth-mode="forgot"] .auth-back-button,
body[data-auth-mode="recovery"] .auth-back-button {
  display: inline-flex;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #132828;
  color: #ecf7f4;
}

.brand,
.sidebar-status,
.topbar,
.panel-header,
.status-row,
.topbar-actions,
.legend {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 34%;
}

.brand p,
.brand strong,
.sidebar-status p,
.sidebar-status strong {
  margin: 0;
}

.brand p,
.sidebar-status p {
  color: #9fc0be;
  font-size: 12px;
}

.brand strong {
  font-size: 18px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-list a {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-radius: 8px;
  color: #bed7d5;
  text-decoration: none;
}

.nav-list a.active,
.nav-list a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

.sidebar-status {
  gap: 12px;
  padding: 14px;
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
}

.pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #73d57f;
  box-shadow: 0 0 0 6px rgba(115, 213, 127, 0.14);
}

.main-content {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

.topbar-actions {
  gap: 10px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--teal-dark);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--teal);
}

.time-chip {
  min-width: 154px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.time-chip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.time-chip strong {
  font-size: 14px;
}

.user-chip {
  max-width: 220px;
}

.user-chip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hero-panel {
  position: relative;
  min-height: 260px;
  display: grid;
  grid-template-columns: 320px 1fr;
  align-items: center;
  gap: 24px;
  padding: 28px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(15, 143, 133, 0.12), rgba(50, 107, 217, 0.06)),
    repeating-linear-gradient(90deg, transparent 0 44px, rgba(19, 40, 40, 0.05) 44px 45px),
    #ffffff;
  box-shadow: var(--shadow);
}

.meter-visual {
  display: grid;
  place-items: center;
}

.dial {
  position: relative;
  width: min(230px, 62vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.dial-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--teal) 0 72%, #d7e8e7 72% 100%);
  box-shadow: inset 0 0 0 18px #fff;
}

.dial-center {
  position: relative;
  z-index: 1;
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background: #132828;
  color: #fff;
}

.dial-center span {
  font-size: 44px;
  font-weight: 850;
}

.dial-center small {
  color: #a9cfcc;
}

.status-row {
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #dff5e7;
  color: var(--green);
  font-size: 12px;
}

.status-pill.warning {
  background: #fff0d7;
  color: var(--amber);
}

.status-pill.danger {
  background: #ffe1de;
  color: var(--red);
}

.hero-copy h2 {
  margin: 16px 0 8px;
  font-size: clamp(26px, 4vw, 48px);
  line-height: 1.05;
}

.hero-copy p {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
}

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

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

.metric-panel {
  min-height: 210px;
}

.metric-rows {
  display: grid;
  gap: 8px;
}

.metric-rows div {
  min-height: 42px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.metric-rows span {
  color: var(--muted);
  font-weight: 850;
}

.metric-rows strong {
  font-size: 20px;
}

.metric-rows small {
  color: var(--muted);
  text-align: right;
}

.metric-rows .metric-total {
  background: #e5f4f2;
}

.plant-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.plant-card {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.plant-card.active {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.plant-card span,
.plant-card small,
.controls-panel span,
.tariff-form span,
.device-form span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.plant-card strong {
  display: block;
  margin: 8px 0;
  font-size: 22px;
}

.controls-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(280px, 0.8fr);
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.monitor-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.monitor-heading > span {
  padding: 8px 10px;
  border-radius: 8px;
  background: #e3f5f3;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 850;
}

.monitor-filter-panel {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.2fr);
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.monitor-filter-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.technical-filter {
  grid-template-columns: minmax(170px, 0.75fr) minmax(260px, 1fr) minmax(260px, 1fr);
}

.selected-meter-chip {
  min-height: 58px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.selected-meter-chip strong,
.selected-meter-chip small {
  display: block;
}

.selected-meter-chip strong {
  margin-top: 4px;
  font-size: 15px;
}

.selected-meter-chip small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 700;
}

.tariff-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.tariff-form .form-message {
  grid-column: 1 / -1;
}

.tariff-form .secondary-button {
  min-width: 98px;
}

select,
input {
  width: 100%;
  min-height: 42px;
  margin-top: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 143, 133, 0.12);
}

.kpi-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.kpi-card {
  min-height: 160px;
  padding: 18px;
}

.kpi-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 8px;
  color: #fff;
}

.kpi-icon.voltage { background: var(--teal); }
.kpi-icon.freq { background: var(--blue); }
.kpi-icon.power { background: var(--amber); }
.kpi-icon.cost { background: #6d5dd3; }

.kpi-card p {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  font-size: 27px;
  line-height: 1.15;
}

.kpi-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(290px, 0.75fr);
  gap: 18px;
  margin-bottom: 18px;
}

.lower-grid {
  grid-template-columns: minmax(290px, 0.75fr) minmax(0, 1.65fr);
}

.manage-grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(280px, 0.65fr);
}

.panel {
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-header h3 {
  margin: 0;
  font-size: 20px;
}

.legend {
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  display: inline-block;
  width: 22px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 99px;
}

.line-a { background: var(--teal); }
.line-b { background: var(--blue); }
.line-c { background: var(--amber); }

canvas {
  width: 100%;
  height: 320px;
  display: block;
}

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

.gateway-form {
  display: grid;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #132828;
}

.secondary-button:hover {
  background: #234343;
}

.compact-button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 12px;
}

.advanced-fields {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.advanced-fields summary {
  cursor: pointer;
  color: var(--teal-dark);
  font-weight: 850;
}

.advanced-fields label {
  display: block;
  margin-top: 12px;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.form-message.success {
  color: var(--green);
  font-weight: 800;
}

.form-message.error {
  color: var(--red);
  font-weight: 800;
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.gateway-list {
  display: grid;
  gap: 12px;
}

.gateway-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.gateway-item strong,
.gateway-item span {
  display: block;
}

.gateway-item span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.gateway-item code,
.device-item code {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  overflow-x: auto;
  border: 1px solid #cfe4e1;
  border-radius: 8px;
  background: #eef8f6;
  color: var(--teal-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.gateway-item small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.gateway-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.gateway-actions button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.gateway-actions button.danger {
  border-color: #ffd6d6;
  background: #fff4f4;
  color: var(--red);
}

.device-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.device-item strong,
.device-item span {
  display: block;
}

.device-item span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.poll-order {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  margin-bottom: 10px;
  border-radius: 8px;
  background: #132828;
  color: #fff;
  font-weight: 850;
}

.meter-type {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  margin-top: 10px;
  margin-right: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e3f5f3;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.device-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  margin-top: 10px;
  padding: 0 8px;
  border-radius: 999px;
  background: #dff5e7;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.device-status.offline {
  background: #ffe1de;
  color: var(--red);
}

.device-status.maintenance {
  background: #fff0d7;
  color: var(--amber);
}

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

.device-actions button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
}

.device-actions button:hover {
  border-color: var(--teal);
  background: #e3f5f3;
}

.device-actions button.danger {
  color: var(--red);
}

.device-actions button.danger:hover {
  border-color: #ffc8c1;
  background: #fff2f0;
}

.register-list-panel {
  display: none;
  margin-bottom: 18px;
}

.register-reading-panel {
  margin-bottom: 18px;
}

.register-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.register-groups article {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.register-groups article strong {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.register-groups article div {
  min-height: 36px;
  display: grid;
  grid-template-columns: 48px 48px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
}

.register-groups span {
  font-weight: 900;
}

.register-groups b {
  display: inline-grid;
  min-height: 24px;
  place-items: center;
  border-radius: 999px;
  background: #dff3f0;
  color: var(--teal-dark);
  font-size: 12px;
}

.register-groups small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.register-reading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}

.register-device-card {
  display: grid;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(21, 45, 45, 0.06);
}

.register-device-card:nth-child(odd) {
  border-top: 4px solid var(--teal);
}

.register-device-card:nth-child(even) {
  border-top: 4px solid var(--blue);
}

.register-device-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.register-device-title strong,
.register-device-title span,
.register-device-meta span,
.register-device-meta em {
  display: block;
}

.register-device-title span {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f5f3;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.register-device-title strong {
  margin-top: 8px;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.2;
}

.register-device-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  max-width: 420px;
}

.register-device-meta span {
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.register-device-meta em {
  padding: 5px 9px;
  border-radius: 999px;
  background: #e6f7ef;
  color: var(--green);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.register-device-card.is-empty .register-device-meta em {
  background: #ffe6e2;
  color: var(--red);
}

.register-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
  gap: 10px;
}

.register-reading-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.register-reading-group h4 {
  margin: 0;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.register-reading-group > div {
  display: grid;
  gap: 8px;
}

.register-reading-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(58px, auto) 42px;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
}

.register-reading-row b {
  display: inline-grid;
  min-height: 26px;
  place-items: center;
  border-radius: 999px;
  background: #dff3f0;
  color: var(--teal-dark);
  font-size: 12px;
}

.register-reading-row span {
  min-width: 0;
}

.register-reading-row strong,
.register-reading-row small,
.register-reading-row em {
  display: block;
}

.register-reading-row strong {
  overflow: hidden;
  font-size: 17px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.register-reading-row small {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.register-reading-row p {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.register-reading-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.register-reading-row.is-empty {
  opacity: .72;
}

.register-reading-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "info address"
    "value unit";
  gap: 10px;
  min-height: 108px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.register-reading-card div {
  grid-area: info;
  min-width: 0;
}

.register-reading-card span,
.register-reading-card small,
.register-reading-card em {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.register-reading-card span {
  color: var(--teal-dark);
  text-transform: uppercase;
}

.register-reading-card strong {
  display: block;
  margin: 3px 0;
  overflow: hidden;
  font-size: 20px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.register-reading-card b {
  grid-area: address;
  display: inline-grid;
  min-width: 44px;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #dff3f0;
  color: var(--teal-dark);
  font-size: 12px;
}

.register-reading-card p {
  grid-area: value;
  align-self: end;
  margin: 0;
  overflow: hidden;
  font-size: 26px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.register-reading-card em {
  grid-area: unit;
  align-self: end;
  justify-self: end;
  font-size: 13px;
}

.register-reading-card.is-empty {
  background: var(--surface-soft);
}

meter {
  width: 100%;
  height: 12px;
}

.table-panel {
  margin-bottom: 24px;
}

body:not(.show-log) .log-page {
  display: none;
}

body:not(.show-settings) .setting-page {
  display: none;
}

body:not(.show-plants) .plant-page {
  display: none;
}

body:not(.show-alarms) .alarm-page {
  display: none;
}

body:not(.show-reports) .report-page {
  display: none;
}

body:not(.show-technical) .technical-page {
  display: none;
}

body.show-log .dashboard-page,
body.show-log .alarm-page,
body.show-log .plant-page,
body.show-log .report-page,
body.show-log .setting-page,
body.show-log .technical-page,
body.show-plants .dashboard-page,
body.show-plants .alarm-page,
body.show-plants .log-page,
body.show-plants .report-page,
body.show-plants .setting-page,
body.show-plants .technical-page,
body.show-alarms .dashboard-page,
body.show-alarms .plant-page,
body.show-alarms .log-page,
body.show-alarms .report-page,
body.show-alarms .setting-page,
body.show-alarms .technical-page,
body.show-reports .dashboard-page,
body.show-reports .alarm-page,
body.show-reports .plant-page,
body.show-reports .log-page,
body.show-reports .setting-page,
body.show-reports .technical-page,
body.show-settings .dashboard-page,
body.show-settings .alarm-page,
body.show-settings .plant-page,
body.show-settings .log-page,
body.show-settings .report-page,
body.show-settings .technical-page,
body.show-technical .dashboard-page,
body.show-technical .alarm-page,
body.show-technical .plant-page,
body.show-technical .log-page,
body.show-technical .report-page,
body.show-technical .setting-page {
  display: none;
}

.energy-chart-grid {
  grid-template-columns: 1fr;
}

.energy-chart-grid .trend-panel {
  min-height: 420px;
}

.energy-recap {
  display: grid;
  grid-template-columns: 1.25fr repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.recap-card {
  display: grid;
  align-content: space-between;
  min-height: 142px;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(30, 54, 54, 0.08);
}

.recap-card.primary {
  background:
    linear-gradient(135deg, rgba(15, 143, 133, 0.14), rgba(50, 107, 217, 0.08)),
    var(--surface);
  border-color: rgba(15, 143, 133, 0.36);
}

.recap-card span {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.recap-card strong {
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
}

.recap-card small {
  color: var(--muted);
  font-weight: 800;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 4px 0 0;
  font-size: clamp(30px, 4vw, 46px);
}

.page-context {
  display: block;
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.log-filter-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.alarm-page {
  display: grid;
  gap: 18px;
}

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

.alarm-card {
  min-height: 132px;
  display: grid;
  gap: 10px;
  align-content: space-between;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.alarm-card span {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.alarm-card strong {
  font-size: 40px;
  line-height: 1;
}

.alarm-card small {
  color: var(--muted);
  font-weight: 750;
}

.alarm-card.normal span,
.alarm-card.normal strong {
  color: var(--green);
}

.alarm-card.warning span,
.alarm-card.warning strong {
  color: var(--amber);
}

.alarm-card.danger span,
.alarm-card.danger strong {
  color: var(--red);
}

.alarm-card.muted span,
.alarm-card.muted strong {
  color: var(--muted);
}

.alarm-filter-panel {
  margin-top: 0;
}

.report-page {
  display: grid;
  gap: 18px;
}

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

.chart-card {
  min-height: 300px;
}

.usage-bars {
  height: 210px;
  display: flex;
  align-items: end;
  gap: 8px;
  padding: 14px 8px 4px;
  overflow-x: auto;
}

.usage-bar-column {
  min-width: 34px;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  justify-items: center;
}

.usage-bar-column span {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: end;
  border-radius: 8px;
  background: var(--surface-soft);
  overflow: hidden;
}

.usage-bar-column i {
  width: 100%;
  display: block;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, #17a398, #0f766e);
}

.usage-bar-column small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.log-filter-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.export-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.export-actions #recordCount {
  color: var(--muted);
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
}

.table-action:hover {
  border-color: var(--teal);
  background: #e3f5f3;
}

tbody tr:hover {
  background: var(--surface-soft);
}

.state-normal {
  color: var(--green);
  font-weight: 800;
}

.state-warning {
  color: var(--amber);
  font-weight: 800;
}

.state-danger {
  color: var(--red);
  font-weight: 800;
}

.error-box {
  padding: 14px;
  border: 1px solid #ffd4cd;
  border-radius: 8px;
  background: #fff2f0;
  color: #8e2f27;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px 12px;
    align-items: center;
  }

  .brand div:last-child,
  .nav-list span,
  .sidebar-status div {
    display: none;
  }

  .sidebar-status {
    padding: 14px;
  }

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

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

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

  .plant-strip,
  .device-list,
  .alarm-recap,
  .report-recap,
  .report-chart-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
  }

  .nav-list {
    grid-auto-flow: column;
  }

  .sidebar-status {
    display: none;
  }

  .main-content {
    padding: 18px;
  }

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

  .hero-panel {
    grid-template-columns: 1fr;
    padding: 20px;
  }

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

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

  .controls-panel,
  .monitor-filter-panel,
  .technical-filter,
  .form-row {
    grid-template-columns: 1fr;
  }

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

  .legend {
    display: none;
  }
}

/* Responsive polish */
html {
  scroll-behavior: smooth;
}

body {
  background:
    linear-gradient(135deg, rgba(15, 143, 133, 0.08), rgba(255, 255, 255, 0) 34%),
    linear-gradient(180deg, #f3f7f7 0%, #e8f0f0 100%);
}

input,
select,
button {
  min-width: 0;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
}

.app-shell {
  grid-template-columns: clamp(228px, 18vw, 280px) minmax(0, 1fr);
}

.main-content {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 2.3vw, 34px);
}

.sidebar {
  box-shadow: 18px 0 50px rgba(16, 37, 37, 0.14);
}

.topbar {
  gap: 18px;
  justify-content: space-between;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.time-chip {
  min-width: 150px;
}

.controls-panel {
  grid-template-columns: minmax(170px, 0.8fr) minmax(190px, 0.9fr) minmax(320px, 1.4fr);
  align-items: end;
}

.controls-panel.setting-page {
  grid-template-columns: minmax(300px, 640px);
}

.tariff-form {
  align-items: end;
}

.hero-panel {
  grid-template-columns: minmax(220px, 0.38fr) minmax(0, 1fr);
  overflow: hidden;
}

.kpi-grid,
.metrics-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.content-grid,
.manage-grid,
.lower-grid {
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

.trend-panel {
  min-width: 0;
}

#voltageChart {
  width: 100%;
  max-width: 100%;
  height: 320px;
  display: block;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table {
  min-width: 900px;
}

.compact-button {
  min-height: 40px;
  white-space: nowrap;
}

.export-actions {
  row-gap: 8px;
}

@media (max-width: 1100px) {
  .energy-recap {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .meter-visual {
    justify-content: center;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 12;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 16px;
  }

  .sidebar .brand div:last-child,
  .sidebar-status {
    display: none;
  }

  .nav-list {
    width: auto;
    grid-auto-flow: column;
    grid-auto-columns: minmax(56px, auto);
    gap: 8px;
  }

  .nav-list a {
    min-height: 44px;
    justify-content: center;
    padding: 10px 12px;
  }

  .nav-list span {
    display: none;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 78px;
  }

  body.locked {
    padding-bottom: 0;
  }

  .login-screen {
    padding: 16px;
  }

  .login-card {
    padding: 22px;
  }

  .login-card h2 {
    font-size: 28px;
    line-height: 1.1;
  }

  .login-brand div:last-child {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .sidebar .brand {
    display: none;
  }

  .nav-list {
    width: 100%;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-flow: unset;
    gap: 6px;
  }

  .nav-list a {
    min-height: 56px;
    flex-direction: column;
    gap: 5px;
    padding: 8px 3px;
    border-radius: 8px;
    font-size: 10px;
  }

  .nav-list span {
    display: inline;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-list svg {
    width: 20px;
    height: 20px;
  }

  .main-content {
    padding: 16px 14px 26px;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar h1 {
    font-size: clamp(34px, 11vw, 46px);
    line-height: 0.98;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 54px;
    align-items: stretch;
  }

  .topbar-actions .time-chip:last-child {
    grid-column: 1 / -1;
  }

  .icon-button,
  .time-chip {
    width: 100%;
  }

  .time-chip {
    min-width: 0;
  }

  .plant-strip {
    grid-auto-flow: column;
    grid-auto-columns: minmax(210px, 82vw);
    grid-template-columns: none;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .controls-panel,
  .log-filter-panel,
  .tariff-form,
  .form-row {
    grid-template-columns: 1fr;
  }

  .report-chart-grid,
  .report-recap {
    grid-template-columns: 1fr;
  }

  .usage-bars {
    height: 180px;
  }

  .controls-panel,
  .hero-panel,
  .panel,
  .kpi-card {
    border-radius: 8px;
  }

  .dial {
    width: min(214px, 70vw);
    height: min(214px, 70vw);
  }

  .hero-copy h2 {
    font-size: clamp(34px, 10vw, 44px);
  }

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

  .register-groups {
    grid-template-columns: 1fr;
  }

  .register-groups article div {
    grid-template-columns: 42px 44px minmax(0, 1fr);
  }

  .register-reading-grid {
    grid-template-columns: 1fr;
  }

  .register-device-header {
    grid-template-columns: 1fr;
  }

  .register-device-meta {
    justify-content: flex-start;
    max-width: none;
  }

  .register-group-grid {
    grid-template-columns: 1fr;
  }

  .register-reading-group {
    padding: 12px;
  }

  .register-reading-row {
    grid-template-columns: 40px minmax(0, 1fr) minmax(52px, auto) 36px;
    gap: 8px;
    padding: 8px;
  }

  .register-reading-row strong {
    font-size: 15px;
  }

  .register-reading-row p {
    font-size: 18px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

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

  .export-actions #recordCount {
    width: 100%;
  }

  .export-actions .compact-button {
    flex: 1 1 132px;
  }

  #voltageChart {
    height: 260px;
  }

  .table-wrap {
    margin-inline: -14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  table {
    min-width: 930px;
  }

  th,
  td {
    padding: 11px 10px;
  }
}

@media (max-width: 420px) {
  .topbar-actions {
    grid-template-columns: 50px minmax(0, 1fr) 50px;
  }

  .compact-button {
    padding-inline: 10px;
  }

  .metric-rows {
    grid-template-columns: 1fr;
  }

  .register-reading-row {
    grid-template-columns: 38px minmax(0, 1fr) minmax(48px, auto) 34px;
  }

  .register-reading-row b {
    min-width: 38px;
    min-height: 24px;
  }

  .register-reading-row p {
    font-size: 17px;
  }
}

.login-brand div:last-child {
  display: block !important;
}

/* Energy dashboard */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-shell,
.main-content,
.topbar,
.topbar-actions,
section,
.panel {
  min-width: 0;
}

.usage-overview {
  align-items: stretch;
}

.usage-card {
  display: grid;
  gap: 8px;
  min-height: 184px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.usage-card:hover,
.usage-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(15, 143, 133, 0.55);
  outline: none;
  box-shadow: 0 16px 36px rgba(25, 58, 58, 0.12);
}

.usage-card b {
  display: block;
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1;
}

.usage-card em,
.meter-detail-card em {
  width: fit-content;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: #e3f5f3;
  color: var(--teal-dark);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.card-hint {
  color: var(--teal-dark) !important;
}

.usage-card.warning em {
  background: #fff0d7;
  color: var(--amber);
}

.usage-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeee;
}

.usage-bar i {
  display: block;
  height: 100%;
  min-width: 6px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.plant-detail-panel {
  margin-bottom: 18px;
}

.detail-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.plant-detail-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.empty-detail,
.detail-summary-row,
.meter-detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.empty-detail {
  padding: 16px;
  color: var(--muted);
  font-weight: 700;
}

.detail-summary-row {
  display: grid;
  gap: 6px;
  padding: 14px;
  cursor: pointer;
}

.detail-summary-row strong,
.meter-detail-card strong {
  font-size: 18px;
}

.detail-summary-row span {
  font-size: 24px;
  font-weight: 900;
}

.detail-summary-row small,
.meter-detail-card small {
  color: var(--muted);
  font-weight: 700;
}

.meter-detail-card {
  display: grid;
  gap: 10px;
  padding: 15px;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.meter-detail-card:hover,
.meter-detail-card:focus-visible,
.meter-detail-card.active {
  border-color: var(--teal);
  background: #f2fbfa;
  outline: none;
}

.meter-detail-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter-detail-card b {
  font-size: 30px;
  line-height: 1;
}

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

.meter-actions button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
}

.meter-actions button:hover {
  border-color: var(--teal);
  background: #e3f5f3;
}

.time-chip strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .login-card {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }

  .login-screen {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 22px;
    background-position: center top;
  }

  .login-hero-copy {
    text-align: center;
  }

  .login-hero-copy h1 {
    max-width: 360px;
    margin: 0 auto;
    font-size: clamp(30px, 9vw, 42px);
    line-height: 1;
  }

  .login-hero-copy p {
    margin-top: 10px;
    font-size: clamp(18px, 6vw, 26px);
  }

  .login-card input,
  .login-card button {
    width: 100%;
  }

  .plant-strip {
    grid-auto-flow: unset;
    grid-auto-columns: unset;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .energy-recap {
    grid-template-columns: 1fr;
  }

  .recap-card {
    min-height: 118px;
  }

  .usage-card {
    min-height: 158px;
    padding: 16px;
  }

  .plant-detail-body {
    grid-template-columns: 1fr;
  }

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

  .detail-meta {
    width: 100%;
    text-align: left;
  }

  .controls-panel {
    margin-top: 10px;
  }

  .topbar-actions {
    gap: 8px;
    overflow: hidden;
  }

  .time-chip {
    padding-inline: 12px;
  }

  .hero-panel {
    padding: 18px;
  }

  .hero-copy h2 {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 380px) {
  .main-content {
    padding-inline: 10px;
  }

  .login-screen {
    padding: 12px;
  }

  .login-card {
    max-width: calc(100vw - 24px);
    padding: 20px 16px;
  }

  .topbar h1 {
    font-size: 32px;
  }
}
