:root {
  color-scheme: light;
  --bg: #eef2f0;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --text: #101817;
  --muted: #60706b;
  --line: #dbe4e0;
  --line-strong: #c7d3ce;
  --accent: #16745d;
  --accent-dark: #0f4f42;
  --grid: #2d6cdf;
  --pv: #e0a21b;
  --battery: #19a66a;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(16, 24, 23, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #dfe9e5 0, #eef2f0 360px, #eef2f0 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(14, 32, 29, 0.90);
  color: white;
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--grid) 0 33%, var(--pv) 33% 66%, var(--battery) 66% 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topnav a,
.secondary-link {
  color: rgba(255, 255, 255, 0.84);
  font-weight: 700;
  text-decoration: none;
}

.topnav a:hover,
.secondary-link:hover {
  color: white;
}

.admin-head-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  color: white;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 56px;
}

.login-wrap {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.landing {
  min-height: calc(100vh - 140px);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.75fr);
  gap: 42px;
  align-items: center;
}

.landing-copy {
  display: grid;
  gap: 18px;
  max-width: 680px;
}

.landing-copy h1 {
  max-width: 640px;
}

.landing-copy p:not(.eyebrow) {
  max-width: 560px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.55;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.landing-button {
  min-width: 150px;
}

.landing-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.landing-meter {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.landing-meter span,
.landing-list {
  color: var(--muted);
  font-weight: 800;
}

.landing-meter strong {
  font-size: 34px;
  line-height: 1;
}

.landing-bars {
  height: 150px;
  display: grid;
  grid-template-columns: 1.4fr 2.2fr 1.1fr;
  gap: 10px;
  align-items: end;
  padding-top: 28px;
}

.landing-bars i {
  display: block;
  min-height: 42px;
  border-radius: 6px 6px 0 0;
}

.landing-bars .grid {
  height: 54%;
}

.landing-bars .pv {
  height: 100%;
}

.landing-bars .battery {
  height: 72%;
}

.landing-list {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.landing-list span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-copy {
  color: var(--muted);
  font-weight: 700;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: white;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(22, 116, 93, 0.22);
  border-color: var(--accent);
}

input[type="date"] {
  min-width: 150px;
}

button {
  font: inherit;
}

.primary {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

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

.secondary-submit {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: white;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.secondary-submit:hover {
  border-color: var(--accent);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: white;
  cursor: pointer;
}

.error {
  color: var(--danger);
}

.success-inline {
  color: var(--accent-dark);
  font-weight: 800;
}

.success-panel {
  display: grid;
  gap: 14px;
  max-width: 520px;
}

.action-link {
  min-height: 42px;
}

.dashboard-head {
  min-height: 190px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 28px;
  border: 1px solid rgba(255,255,255,0.26);
  border-radius: 8px;
  background:
    linear-gradient(135deg, #10211f 0%, #183b35 52%, #f2b441 52%, #f2b441 100%);
  color: white;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dashboard-head h1 {
  max-width: 680px;
}

.subhead {
  margin-top: 10px;
  color: rgba(255,255,255,0.72);
  font-weight: 700;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.dashboard-head .eyebrow {
  color: rgba(255,255,255,0.74);
}

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

.status-pill,
.live-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: white;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 5px rgba(74, 222, 128, 0.18);
}

.live-pill.warn .pulse-dot {
  background: #facc15;
  box-shadow: 0 0 0 5px rgba(250, 204, 21, 0.18);
}

.live-pill.offline .pulse-dot {
  background: #ef4444;
  box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.18);
}

.metrics-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  padding: 18px;
  background: rgba(255,255,255,0.86);
  border: 1px solid rgba(255,255,255,0.74);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(16,24,23,0.07);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  font-size: clamp(24px, 3vw, 31px);
  line-height: 1;
  letter-spacing: 0;
}

.metric-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.primary-metric {
  background: #10211f;
  color: white;
  border-color: rgba(255,255,255,0.14);
}

.primary-metric span,
.primary-metric .metric-note {
  color: rgba(255,255,255,0.68);
}

.primary-metric strong {
  font-size: clamp(42px, 6vw, 64px);
}

.content-band,
.insight-panel {
  margin-top: 16px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.72);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(16,24,23,0.07);
}

.admin-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.section-title > span {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.period-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f2f6f4;
}

.period-button {
  min-height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 0 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.period-button:last-child {
  border-right: 0;
}

.period-button:hover {
  background: #e8f0ed;
}

.period-button.active {
  background: var(--accent);
  color: white;
}

.date-range {
  display: flex;
  align-items: end;
  gap: 10px;
}

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

.current-mix-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.mix-donut {
  --grid-pct: 0;
  --pv-pct: 0;
  width: 230px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background:
    radial-gradient(circle at center, var(--panel) 0 49%, transparent 50%),
    conic-gradient(
      var(--grid) 0 calc(var(--grid-pct) * 1%),
      var(--pv) calc(var(--grid-pct) * 1%) calc((var(--grid-pct) + var(--pv-pct)) * 1%),
      var(--battery) calc((var(--grid-pct) + var(--pv-pct)) * 1%) 100%
    );
  box-shadow: inset 0 0 0 1px rgba(16,24,23,0.08), 0 16px 34px rgba(16,24,23,0.10);
}

.mix-donut.offline {
  background:
    radial-gradient(circle at center, var(--panel) 0 49%, transparent 50%),
    conic-gradient(#d9e2de 0 100%);
}

.mix-donut > div {
  width: 118px;
  height: 118px;
  display: grid;
  place-content: center;
  gap: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  text-align: center;
}

.mix-donut strong {
  font-size: 28px;
  line-height: 1;
}

.mix-donut span,
.mix-copy p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mix-copy {
  display: grid;
  gap: 12px;
}

.mix-copy > strong {
  font-size: 26px;
}

.mix-list {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.mix-list span {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 800;
}

.mix-list strong {
  color: var(--text);
  text-align: right;
}

.source-row {
  min-height: 154px;
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.source-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.source-label strong {
  display: block;
  font-size: 17px;
}

.source-label small,
.source-values span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.source-values {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.source-values strong {
  font-size: 23px;
}

.swatch {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 3px;
  margin-top: 3px;
}

.grid { background: var(--grid); }
.pv { background: var(--pv); }
.battery { background: var(--battery); }

.bar-track {
  height: 12px;
  overflow: hidden;
  background: #e7eeeb;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  min-width: 0;
  transition: width 180ms ease;
}

.soft-warning {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #f0d28a;
  border-radius: 8px;
  background: #fff8e7;
  color: #684c0f;
  font-weight: 700;
}

.stacked-chart-wrap {
  height: 340px;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
}

.y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  padding: 2px 0 30px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stacked-chart {
  min-width: 0;
  border-left: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 6px 0;
  overflow-x: auto;
  background:
    repeating-linear-gradient(to top, transparent 0 66px, rgba(219,228,224,0.55) 67px);
}

.stacked-chart.empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  background: var(--panel-soft);
}

.stacked-item {
  height: 100%;
  min-width: 40px;
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 26px;
  align-items: end;
  justify-items: center;
  gap: 5px;
}

.stacked-column {
  width: min(100%, 42px);
  min-height: 2px;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  border-radius: 5px 5px 0 0;
  background: #edf2ee;
  cursor: help;
  box-shadow: 0 8px 18px rgba(16,24,23,0.10);
  transition: transform 140ms ease, filter 140ms ease;
}

.stacked-column:hover {
  transform: translateY(-3px);
  filter: saturate(1.1);
}

.stacked-segment {
  display: block;
  width: 100%;
}

.stacked-item small {
  width: 100%;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.x-axis-label {
  margin: 8px 0 0 80px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chart-legend span,
.tariff-list span,
.system-list span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.insight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tariff-list,
.system-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.tariff-list span,
.system-list span {
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 800;
}

.tariff-list strong,
.system-list strong {
  color: var(--text);
}

.empty-state {
  padding: 32px 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

td a {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.admin-table td:first-child {
  display: grid;
  gap: 3px;
}

.admin-table td:first-child small {
  color: var(--muted);
  font-weight: 700;
}

.mono-chip,
.sender-chip,
.status-badge,
.table-action {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.mono-chip {
  background: #eef4f1;
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.sender-chip {
  background: #e9f0ff;
  color: #1f4ca5;
}

.status-badge.ok {
  background: #e7f8ef;
  color: #0f6b42;
}

.status-badge.off {
  background: #f1f3f2;
  color: var(--muted);
}

.table-action {
  border: 1px solid var(--line);
  background: white;
}

.admin-form {
  display: grid;
  gap: 20px;
}

.form-shell {
  max-width: 920px;
}

.form-section-title {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-top: 4px;
}

.form-section-title p {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.step-number {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 900;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.check-row span {
  display: grid;
  gap: 2px;
  color: var(--text);
  font-weight: 800;
}

.check-row small {
  color: var(--muted);
  font-weight: 700;
}

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

.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

  .source-bars,
  .landing,
  .current-mix-grid,
  .admin-overview-grid,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .mix-donut {
    width: min(230px, 100%);
    justify-self: center;
  }
}

@media (max-width: 760px) {
  main {
    width: min(100% - 24px, 1120px);
    padding-top: 16px;
  }

  .topbar {
    padding: 0 12px;
  }

  .dashboard-head {
    min-height: 220px;
    align-items: flex-start;
    flex-direction: column;
    background: #10211f;
  }

  .head-actions {
    justify-content: flex-start;
  }

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

  .primary-metric strong,
  .metric strong {
    font-size: 30px;
  }

  .period-controls,
  .date-range {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
  }

  .period-button {
    border-right: 1px solid var(--line);
    padding: 0 6px;
    font-size: 12px;
  }

  .section-title {
    flex-direction: column;
  }

  .stacked-chart-wrap {
    grid-template-columns: 50px minmax(0, 1fr);
    height: 300px;
  }

  .stacked-item {
    min-width: 36px;
  }

  .x-axis-label {
    margin-left: 60px;
  }

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

  .landing {
    align-items: start;
    gap: 24px;
  }

  .landing-panel {
    order: -1;
  }
}
