  11:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --line-soft: #eef2f6;
  --paper: #f1f5f9;
  --paper-2: #e2e8f0;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-strong: #0b5f59;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --warn: #b45309;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.18);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, 0.28);
  --radius: 16px;
  --radius-sm: 10px;
  --ring: 0 0 0 4px var(--accent-soft);
  --sidebar-bg: linear-gradient(195deg, #0b1220 0%, #15233a 60%, #0f1b2e 100%);
  --grid-line: rgba(15, 23, 42, 0.07);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6edf6;
  --muted: #94a3b8;
  --faint: #64748b;
  --line: #25324a;
  --line-soft: #1c2740;
  --paper: #0b1220;
  --paper-2: #0f1830;
  --panel: #111c33;
  --panel-2: #0e1830;
  --accent: #2dd4bf;
  --accent-2: #14b8a6;
  --accent-strong: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.16);
  --warn: #f59e0b;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 14px 40px -16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 30px 70px -24px rgba(0, 0, 0, 0.7);
  --ring: 0 0 0 4px var(--accent-soft);
  --sidebar-bg: linear-gradient(195deg, #060b16 0%, #0c1628 60%, #08111f 100%);
  --grid-line: rgba(226, 232, 240, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 110% -10%, var(--accent-soft), transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "cv05", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 240ms ease, color 240ms ease;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #ffffff;
  cursor: pointer;
  font-weight: 650;
  min-height: 44px;
  padding: 0 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 120ms ease, box-shadow 160ms ease, filter 160ms ease, background 160ms ease;
}

button:hover {
  filter: brightness(1.04);
  box-shadow: var(--shadow);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

input,
select {
  width: 100%;
  min-height: 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 9px 12px;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input::placeholder {
  color: var(--faint);
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: var(--ring);
}

.app-layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 200ms ease;
}

.app-layout.sidebar-collapsed {
  grid-template-columns: 84px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar-bg);
  color: #e6edf6;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-header {
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 12px;
  min-height: 58px;
  overflow: hidden;
  padding: 0 6px 18px;
}

.brand-mark {
  align-items: center;
  border-radius: 12px;
  display: inline-flex;
  flex: 0 0 42px;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  background: linear-gradient(150deg, var(--accent-2), var(--accent));
  box-shadow: 0 12px 26px rgba(20, 184, 166, 0.35);
  letter-spacing: 0.5px;
}

.sidebar-logo {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: #fff url("/logo.png") center / 118% no-repeat;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
}

.nav-icon {
  align-items: center;
  display: inline-flex;
  flex: 0 0 24px;
  height: 24px;
  justify-content: center;
  color: #cbd5e1;
}

.nav-icon svg {
  width: 21px;
  height: 21px;
}

.theme-toggle .nav-icon svg {
  width: 19px;
  height: 19px;
}

.brand-text,
.nav-text {
  overflow: hidden;
  white-space: nowrap;
}

.brand-text {
  display: grid;
  gap: 2px;
}

.brand-text strong {
  letter-spacing: -0.01em;
}

.brand-text span {
  color: #93a4b8;
  font-size: 0.8rem;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
}

.nav-section {
  margin: 10px 0 2px;
  padding: 0 12px;
  color: #6b7a8d;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.nav-section:first-child {
  margin-top: 0;
}

.nav-link,
.sidebar-toggle {
  align-items: center;
  border-radius: 12px;
  color: #cbd5e1;
  display: flex;
  gap: 12px;
  min-height: 54px;
  padding: 8px 12px;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease;
}

.nav-link {
  position: relative;
}

.nav-link::before {
  background: transparent;
  border-radius: 0 4px 4px 0;
  content: "";
  height: 26px;
  left: -16px;
  position: absolute;
  width: 4px;
  transition: background 160ms ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-link.active {
  background: rgba(45, 212, 191, 0.14);
  color: #ffffff;
}

.nav-link.active::before {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.nav-link.active .nav-icon,
.nav-parent.active .nav-icon {
  color: #5eead4;
}

.nav-text {
  display: grid;
  gap: 2px;
}

.nav-text strong {
  font-size: 0.94rem;
}

.nav-text small {
  color: #93a4b8;
  font-size: 0.76rem;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.theme-toggle {
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  color: #cbd5e1;
  display: flex;
  gap: 12px;
  justify-content: flex-start;
  min-height: 48px;
  padding: 8px 12px;
  width: 100%;
  box-shadow: none;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  filter: none;
}

.theme-toggle .nav-icon {
  font-size: 0.95rem;
}

.sidebar-toggle {
  background: rgba(255, 255, 255, 0.06);
  justify-content: flex-start;
  min-height: 48px;
  width: 100%;
  box-shadow: none;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  filter: none;
}

.toggle-icon {
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  display: inline-block;
  flex: 0 0 11px;
  height: 11px;
  margin-left: 13px;
  transform: rotate(45deg);
  transition: transform 200ms ease;
  width: 11px;
}

.app-layout.sidebar-collapsed .brand-text,
.app-layout.sidebar-collapsed .nav-text {
  opacity: 0;
  pointer-events: none;
  width: 0;
}

.app-layout.sidebar-collapsed .nav-link,
.app-layout.sidebar-collapsed .sidebar-toggle,
.app-layout.sidebar-collapsed .theme-toggle {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-layout.sidebar-collapsed .toggle-icon {
  margin-left: 0;
  transform: rotate(225deg);
}

.app-layout.sidebar-collapsed .sidebar-header {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

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

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.toolbar,
.section-heading {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.toolbar {
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2 {
  line-height: 1.08;
  margin: 0;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(1.9rem, 4vw, 2.9rem);
  font-weight: 800;
  background: linear-gradient(120deg, var(--ink), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

h2 {
  font-size: 1.35rem;
  font-weight: 750;
}

.app-view {
  display: none;
  animation: viewfade 280ms ease both;
}

.app-view.active {
  display: block;
}

@keyframes viewfade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-heading {
  margin: 0 0 18px;
}

.panel,
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.billing-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 2fr 3fr;
  align-items: start;
  margin-bottom: 18px;
}

.billing-tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px;
  box-shadow: var(--shadow-sm);
}

.billing-tab {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  box-shadow: none;
  min-height: 38px;
  padding: 0 20px;
}

.billing-tab:hover {
  background: var(--accent-soft);
  color: var(--accent);
  filter: none;
}

.billing-tab.active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.billing-tab-panel {
  display: none;
}

.billing-tab-panel.active {
  display: block;
  animation: viewfade 240ms ease both;
}

.occupant-form {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  padding: 20px;
}

.occupant-form-actions {
  align-items: end;
  display: flex;
  gap: 8px;
}

.occupant-form-actions button {
  white-space: nowrap;
}

.month-panel {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
  padding: 20px;
}

.statement-panel {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 20px;
}

.kwh-audit-panel {
  display: grid;
  gap: 14px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 18px;
}

.audit-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 6px;
  padding: 14px;
}

.audit-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

.audit-card strong {
  font-size: 1.35rem;
  font-weight: 850;
}

.audit-card small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.audit-card.is-warning strong {
  color: var(--warn);
}

.summary-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 18px;
}

.summary-card {
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 6px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.summary-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.summary-card span {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.82rem;
}

.summary-card strong {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.summary-card small {
  color: var(--faint);
  font-size: 0.76rem;
}

.renters-panel,
.occupants-panel,
.summary-panel,
.charts-panel {
  overflow: hidden;
}

.charts-panel {
  margin-bottom: 18px;
  position: relative;
}

.year-filter {
  min-width: 150px;
}

.chart-grid {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  display: grid;
  gap: 14px;
  padding: 18px;
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.chart-card:hover {
  box-shadow: var(--shadow);
}

.chart-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.chart-header h3 {
  font-size: 1.02rem;
  line-height: 1.25;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chart-year {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: middle;
}

.chart-key {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.8rem;
  font-weight: 650;
  gap: 14px;
}

.chart-key span {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.key-box,
.key-line {
  display: inline-block;
}

.key-box {
  border-radius: 4px;
  height: 12px;
  width: 12px;
}

.key-line {
  border-top: 3px solid;
  border-radius: 2px;
  width: 18px;
}

.bill-key {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.rate-key {
  border-color: var(--warn);
}

.chart-card canvas {
  display: block;
  height: 300px;
  width: 100%;
}

.chart-card:last-child canvas {
  height: 360px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-toggle {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: none;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 600;
  gap: 8px;
  min-height: 34px;
  padding: 6px 12px;
  opacity: 0.6;
  transition: border-color 140ms ease, background 140ms ease, opacity 140ms ease, color 140ms ease;
  user-select: none;
}

.legend-toggle:hover {
  border-color: var(--accent);
  filter: none;
  opacity: 1;
}

.legend-toggle.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  opacity: 1;
}

.legend-toggle .legend-swatch {
  flex: 0 0 auto;
}

.legend-swatch {
  border-radius: 4px;
  display: inline-block;
  height: 12px;
  width: 12px;
}

.chart-tooltip {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 16px 38px rgba(2, 6, 23, 0.4);
  color: #ffffff;
  display: none;
  font-size: 0.82rem;
  line-height: 1.4;
  max-width: 260px;
  padding: 9px 12px;
  pointer-events: none;
  position: fixed;
  z-index: 30;
  backdrop-filter: blur(4px);
}

.chart-tooltip strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.section-heading {
  border-bottom: 1px solid var(--line);
  padding: 20px;
}

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

.heading-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
}

.heading-month {
  min-width: 170px;
}

.table-search {
  min-width: 240px;
}

.table-search input[type="search"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cline x1='10.5' y1='10.5' x2='15' y2='15'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 13px center;
  padding-left: 38px;
}

.table-wrap-scroll {
  overflow-y: auto;
}

.table-wrap-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.renters-panel tr.is-filtered-out {
  display: none !important;
}

.table-empty {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
  padding: 22px 20px;
  text-align: center;
}

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

.renters-panel table {
  min-width: 820px;
}

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

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--panel-2);
}

tbody tr {
  transition: background 140ms ease;
}

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

tbody tr:last-child td {
  border-bottom: 0;
}

.computed {
  font-weight: 800;
  white-space: nowrap;
}

.computed small {
  color: var(--muted);
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 3px;
}

.kwh-used.negative {
  color: var(--danger);
  font-weight: 800;
}

.kwh-used.negative::before {
  content: "⚠ ";
}

.payments-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.payments-chart-card {
  overflow: hidden;
}

.payments-table th,
.payments-table td {
  padding: 5px 9px;
  font-size: 0.9rem;
}

.payments-table {
  margin-right: auto;
  max-width: 390px;
  table-layout: auto;
  width: auto;
}

.payments-table th:first-child,
.payments-table td:first-child {
  min-width: 145px;
  width: auto;
}

.payments-table td:first-child {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payments-table th:nth-child(2),
.payments-table td:nth-child(2) {
  padding-right: 28px;
  text-align: right;
  min-width: 105px;
  width: auto;
}

.payments-table th:nth-child(3),
.payments-table td:nth-child(3) {
  text-align: right;
  min-width: 54px;
  width: auto;
}

.heading-inline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.heading-inline .eyebrow {
  margin: 0;
}

.pie-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 300px);
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
}

.payments-chart-card canvas {
  display: block;
  width: 100%;
  max-width: 300px;
  height: 260px;
  cursor: pointer;
  justify-self: center;
}

.pie-legend {
  display: grid;
  gap: 7px;
  width: 100%;
}

.pie-legend-item {
  align-items: center;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 140ms ease, border-color 140ms ease;
  user-select: none;
}

.pie-legend-item:hover,
.pie-legend-item.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pie-legend-item .legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.pie-legend-val {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.payments-table tfoot th {
  background: var(--panel-2);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0;
  border-top: 2px solid var(--line);
}

.payments-table tfoot th:nth-child(2) {
  color: var(--accent);
}

td.renter-bill {
  color: var(--accent);
}

.occupant-name-stack {
  display: grid;
  gap: 3px;
}

.occupant-name-stack strong {
  font-size: 0.96rem;
}

.occupant-name-stack small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.row-actions {
  text-align: right;
  white-space: nowrap;
  width: 140px;
}

.renters-panel th:first-child,
.renters-panel td:first-child {
  width: 190px;
}

.renters-panel th:nth-child(2),
.renters-panel td:nth-child(2),
.renters-panel th:nth-child(3),
.renters-panel td:nth-child(3) {
  width: 26%;
}

.renters-panel th:nth-child(4),
.renters-panel td:nth-child(4) {
  width: 110px;
}

.renters-panel th:nth-child(5),
.renters-panel td:nth-child(5) {
  min-width: 120px;
  width: 150px;
}

.row-actions .secondary-button,
.row-actions .danger-button {
  margin-left: 8px;
}

.secondary-button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
}

.secondary-button:hover {
  background: var(--line);
  filter: none;
}

.danger-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--danger);
  box-shadow: none;
}

.danger-button:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  filter: none;
}

.note {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 18px 0 0;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(4px);
  animation: viewfade 160ms ease both;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: modalpop 180ms ease both;
}

@keyframes modalpop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal h3 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 750;
}

.modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

.modal-actions .danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.modal-actions .danger-button:hover {
  filter: brightness(1.06);
  background: var(--danger);
}

body.modal-open {
  overflow: hidden;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(14px);
  z-index: 90;
  max-width: min(440px, calc(100% - 32px));
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-size: 0.88rem;
  font-weight: 650;
  text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

input.attention {
  border-color: var(--warn);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22);
}

body.no-rate .previous-reading,
body.no-rate .current-reading {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- Auth screen ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 120%, var(--accent-soft), transparent 60%),
    var(--paper);
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: modalpop 220ms ease both;
}

.auth-brand {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.brand-logo {
  width: 92px;
  height: 92px;
  border-radius: 22px;
  background: #fff url("/logo.png") center / 118% no-repeat;
  box-shadow: var(--shadow);
}

.auth-sub {
  color: var(--muted);
  font-size: 0.92rem;
}

.auth-card label {
  color: var(--ink);
}

.auth-card button[type="submit"] {
  margin-top: 4px;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 600;
}

.auth-hint {
  margin: 0;
  text-align: center;
  color: var(--faint);
  font-size: 0.8rem;
}

/* ---------- Sidebar submenu ---------- */
.nav-group {
  display: grid;
  gap: 2px;
}

.nav-parent {
  width: 100%;
  background: transparent;
  box-shadow: none;
  font: inherit;
}

.nav-parent:hover {
  filter: none;
}

.nav-parent.active {
  background: rgba(45, 212, 191, 0.14);
  color: #ffffff;
}

.nav-caret {
  margin-left: auto;
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 200ms ease;
  opacity: 0.7;
}

.nav-group:not(.expanded) .nav-caret {
  transform: rotate(-45deg);
}

.nav-submenu {
  display: grid;
  gap: 2px;
  margin: 2px 0 2px 18px;
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  max-height: 200px;
  transition: max-height 220ms ease, opacity 180ms ease;
}

.nav-group:not(.expanded) .nav-submenu {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  margin-bottom: 0;
}

.nav-sublink {
  position: relative;
  align-items: center;
  border-radius: 8px;
  color: #aebbc8;
  display: flex;
  gap: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 9px 10px;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease;
}

.nav-subicon {
  align-items: center;
  display: inline-flex;
  flex: 0 0 18px;
  height: 18px;
  justify-content: center;
  opacity: 0.85;
}

.nav-subicon svg {
  width: 17px;
  height: 17px;
}

.nav-sublink:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-sublink.active {
  background: rgba(45, 212, 191, 0.16);
  color: #ffffff;
}

.nav-sublink.active .nav-subicon {
  color: #5eead4;
  opacity: 1;
}

.nav-sublink.active::before {
  content: "";
  position: absolute;
  left: -13px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.app-layout.sidebar-collapsed .nav-caret,
.app-layout.sidebar-collapsed .nav-section {
  display: none;
}

.app-layout.sidebar-collapsed .nav-group {
  position: relative;
}

.app-layout.sidebar-collapsed .nav-submenu {
  position: absolute;
  left: 100%;
  top: 0;
  z-index: 40;
  min-width: 198px;
  margin: 0 0 0 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-6px);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms ease;
  max-height: none;
}

.app-layout.sidebar-collapsed .nav-submenu::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 0;
  bottom: 0;
  width: 14px;
}

.app-layout.sidebar-collapsed .nav-group:hover .nav-submenu,
.app-layout.sidebar-collapsed .nav-group:focus-within .nav-submenu {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.app-layout.sidebar-collapsed .nav-submenu .nav-sublink {
  color: var(--muted);
}

.app-layout.sidebar-collapsed .nav-submenu .nav-sublink:hover,
.app-layout.sidebar-collapsed .nav-submenu .nav-sublink.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.app-layout.sidebar-collapsed .nav-submenu .nav-sublink.active .nav-subicon {
  color: var(--accent);
}

.app-layout.sidebar-collapsed .nav-submenu .nav-sublink.active::before {
  display: none;
}

/* ---------- Sidebar user ---------- */
.sidebar-user {
  align-items: center;
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.user-avatar {
  align-items: center;
  background: linear-gradient(150deg, var(--accent-2), var(--accent));
  border-radius: 50%;
  color: #04211d;
  display: inline-flex;
  flex: 0 0 36px;
  font-weight: 800;
  height: 36px;
  justify-content: center;
}

.sidebar-user .nav-text strong {
  font-size: 0.9rem;
}

.app-layout.sidebar-collapsed .sidebar-user {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* ---------- Users page ---------- */
.users-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 2fr 3fr;
  align-items: start;
}

.user-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.permission-set {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin: 0;
  padding: 12px 14px;
}

.permission-set legend {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0 6px;
  text-transform: uppercase;
}

.permission-options {
  display: grid;
  gap: 8px;
}

.permission-option {
  align-items: center;
  display: flex;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.permission-option input {
  width: auto;
  min-height: auto;
  accent-color: var(--accent);
}

.permission-option small {
  color: var(--muted);
  font-weight: 500;
}

.user-form-actions {
  display: flex;
  gap: 10px;
}

.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.role-badge.admin {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.perm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.perm-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 9px;
}

.perm-chip.all {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.you-tag {
  color: var(--faint);
  font-size: 0.76rem;
  font-weight: 600;
}

/* ---------- Permission locks ---------- */
body.lock-billing .billing-grid,
body.lock-billing #currentReadingHeader,
body.lock-billing .current-reading-cell {
  display: none;
}

body.lock-previous .previous-reading {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

body.lock-occupants .occupant-form,
body.lock-occupants .row-actions {
  display: none;
}

@media (max-width: 760px) {
  .sidebar-header {
    display: flex;
  }

  .sidebar-nav {
    display: grid;
  }

  .sidebar-footer {
    margin-top: 12px;
  }

  .brand-text,
  .nav-text,
  .app-layout.sidebar-collapsed .sidebar-toggle .nav-text {
    opacity: 1;
    pointer-events: auto;
    width: auto;
  }

  .nav-link,
  .sidebar-toggle,
  .theme-toggle,
  .app-layout.sidebar-collapsed .sidebar-toggle {
    justify-content: flex-start;
  }

  .toggle-icon,
  .app-layout.sidebar-collapsed .toggle-icon {
    margin-left: 13px;
  }

  .app-layout.sidebar-collapsed .sidebar-header,
  .app-layout.sidebar-collapsed .sidebar-nav {
    display: none;
  }

  .app-shell {
    width: min(100% - 24px, 1180px);
    padding: 16px 0 36px;
  }

  .toolbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .year-filter {
    min-width: 0;
  }

  .heading-controls {
    width: 100%;
  }

  .heading-month,
  .table-search {
    min-width: 0;
    flex: 1 1 160px;
  }

  .billing-grid,
  .month-panel,
  .statement-panel,
  .kwh-audit-panel,
  .occupant-form,
  .summary-grid,
  .users-grid,
  .payments-layout,
  .pie-wrap {
    grid-template-columns: 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  td {
    border: 0;
    padding: 8px 0;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    display: block;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
    text-transform: uppercase;
  }

  .row-actions {
    text-align: left;
    width: auto;
  }

  .row-actions::before {
    content: "";
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  button,
  .sidebar,
  .note {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .panel,
  .summary-card {
    box-shadow: none;
  }
}

/* ---------- Backup & Restore ---------- */
#backupPanel { margin-top: 18px; }
.backup-grid { display: grid; gap: 14px; max-width: 640px; }
.backup-grid > label { display: grid; gap: 6px; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.backup-preview {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.backup-summary { margin: 0 0 8px; color: var(--ink); }
.backup-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.backup-list strong { color: var(--ink); }
.backup-empty { margin: 0; color: var(--muted); }
.backup-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.backup-note { margin: 0; color: var(--faint); font-size: 0.82rem; }

/* ---------- Login activity / monitoring ---------- */
#activityPanel { margin-top: 18px; }
.activity-note { color: var(--faint); font-size: 0.8rem; }
.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: middle;
  background: #94a3b8;
}
.status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}
