:root {
  --amber: #f2b84b;
  --blue: #1c4d8f;
  --danger: #c94343;
  --green: #2d8a57;
  --ink: #172033;
  --line: #d9e1eb;
  --muted: #637084;
  --page: #f5f7fb;
  --panel: #ffffff;
  --sidebar: #111827;
  --teal: #1f9d8a;
  --warning-bg: #fff4dd;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-loading {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

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

.sidebar {
  background: var(--sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--amber);
  border-radius: 8px;
  color: #111827;
  display: inline-flex;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.icon {
  height: 18px;
  width: 18px;
}

.icon-22 {
  height: 22px;
  width: 22px;
}

.brand strong {
  display: block;
  font-size: 1.05rem;
}

.brand small,
.sidebar-footer {
  color: #aeb8c7;
  font-size: 0.83rem;
}

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

.nav-list a,
.ghost-button {
  align-items: center;
  border-radius: 8px;
  color: #d8dee9;
  display: flex;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  text-decoration: none;
}

.nav-list a.active,
.nav-list a:hover,
.ghost-button:hover {
  background: #253041;
  color: #ffffff;
}

.sidebar-footer {
  border-top: 1px solid #293244;
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
}

.ghost-button {
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.main-panel {
  display: grid;
  gap: 20px;
  padding: 28px;
}

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

.page-header h1,
.panel h2,
.load-list h3 {
  letter-spacing: 0;
  margin: 0;
}

.page-header h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.05;
}

.kicker {
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  text-decoration: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
  white-space: nowrap;
}

.button:hover {
  box-shadow: 0 12px 24px rgba(23, 32, 51, 0.12);
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.button.primary {
  background: var(--blue);
  color: #ffffff;
}

.button.secondary {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.panel,
.metric-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(23, 32, 51, 0.06);
  min-width: 0;
}

.panel {
  padding: 20px;
}

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

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

.metric-tile {
  display: grid;
  gap: 5px;
  min-height: 138px;
  overflow: hidden;
  padding: 18px;
  position: relative;
}

.metric-icon {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.metric-tile strong {
  font-size: 1.9rem;
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric-tile small {
  color: var(--muted);
}

.inline-stat {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 98px;
  padding: 14px;
}

.inline-stat span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.inline-stat strong {
  font-size: 1.35rem;
  line-height: 1;
}

.inline-stat small {
  color: var(--muted);
}

.tone-blue .metric-icon {
  background: #e8f0fb;
  color: var(--blue);
}

.tone-amber .metric-icon {
  background: var(--warning-bg);
  color: #9b6710;
}

.tone-green .metric-icon,
.tone-teal .metric-icon {
  background: #e5f7f1;
  color: var(--teal);
}

.tone-red .metric-icon {
  background: #feecec;
  color: var(--danger);
}

.dashboard-grid,
.auth-grid,
.solar-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.4fr) minmax(330px, 0.8fr);
}

.dashboard-grid > *,
.auth-grid > *,
.solar-grid > * {
  min-width: 0;
}

.coverage-panel img,
.public-snapshot img {
  aspect-ratio: 13 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  object-fit: cover;
  width: 100%;
}

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

.section-title a,
.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.district-row {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr auto;
  margin-bottom: 18px;
}

.district-row i {
  background: linear-gradient(90deg, var(--amber), var(--danger));
  border-radius: 999px;
  grid-column: 1 / -1;
  height: 9px;
  min-width: 24px;
}

.bar-level-1 {
  width: 12%;
}

.bar-level-2 {
  width: 22%;
}

.bar-level-3 {
  width: 32%;
}

.bar-level-4 {
  width: 42%;
}

.bar-level-5 {
  width: 52%;
}

.bar-level-6 {
  width: 62%;
}

.bar-level-7 {
  width: 72%;
}

.bar-level-8 {
  width: 82%;
}

.bar-level-9,
.bar-level-10 {
  width: 100%;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

td strong,
td span {
  display: block;
}

td span {
  color: var(--muted);
  font-size: 0.86rem;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 5px 9px;
  white-space: nowrap;
}

.status-pending,
.status-caution {
  background: var(--warning-bg);
  color: #8a5c0b;
}

.status-verified,
.status-ready {
  background: #e6f6ed;
  color: var(--green);
}

.status-resolved,
.type-power_on {
  background: #edf2f7;
  color: var(--blue);
}

.status-dismissed,
.status-critical {
  background: #fdecec;
  color: var(--danger);
}

.status-no_load {
  background: #f0f3f7;
  color: var(--muted);
}

.type-loadshedding {
  background: #fff1d6;
  color: #936108;
}

.type-maintenance {
  background: #e9f5ff;
  color: #125183;
}

.form-panel,
.form-grid,
.filter-bar {
  display: grid;
  gap: 16px;
}

.form-grid,
.filter-bar {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.84rem;
  font-weight: 800;
  gap: 7px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
  width: 100%;
}

textarea {
  min-height: 118px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(28, 77, 143, 0.14);
  outline: none;
}

.wide {
  grid-column: 1 / -1;
}

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

.compact-input {
  min-height: 36px;
  padding: 7px 9px;
}

.public-snapshot {
  display: grid;
  gap: 16px;
}

.snapshot-map {
  min-height: 220px;
}

.solar-result {
  align-self: start;
}

.result-top {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.result-top h2 {
  font-size: 2rem;
}

.load-list {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
}

.load-list span,
.estimate-list article {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
}

.advice-list {
  color: var(--muted);
  margin: 16px 0 0;
  padding-left: 18px;
}

.estimate-list {
  display: grid;
  gap: 10px;
}

.estimate-list article span {
  align-items: center;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty-state {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: 96px;
  padding: 18px;
  text-align: center;
}

#toast {
  bottom: 20px;
  position: fixed;
  right: 20px;
  z-index: 20;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(23, 32, 51, 0.2);
  color: #ffffff;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
}

.toast.error {
  background: var(--danger);
}

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

  .sidebar {
    height: auto;
    position: static;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

  .dashboard-grid,
  .auth-grid,
  .solar-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .main-panel {
    padding: 18px;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-header h1 {
    font-size: 2rem;
  }

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

  .metric-grid,
  .metric-grid.compact,
  .form-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .panel {
    padding: 16px;
  }
}
