:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dde5;
  --green: #237456;
  --blue: #2468a2;
  --gold: #b37a16;
  --red: #b4473d;
  --soft-green: #d8ece2;
  --soft-blue: #d9e7f5;
  --focus: #1c6bca;
  --shadow: 0 8px 24px rgba(23, 32, 42, 0.08);
  --brand-bg: #182635;
  --brand-ink: #ffffff;
  --notice-bg: #fff7e1;
  --notice-line: #e9ca83;
  --status-bg: #eef4fb;
  --status-line: #c9daee;
  --input-bg: #ffffff;
  --property-bg: #f8fafc;
  --tooltip-bg: #ffffff;
  --tooltip-line: #b7c0cb;
  --tooltip-heading-bg: #eef2f6;
  --tooltip-alt-bg: #f6f7f9;
  --table-heading-bg: #f8fafc;
  --table-heading-ink: #394454;
  --table-hover: #f7fbff;
  --button-hover: rgba(23, 32, 42, 0.08);
  --chart-bg: #ffffff;
  --chart-label: #17202a;
  --chart-axis: #667085;
  --chart-grid: #d7dde5;
  --chart-inner-label: #ffffff;
  --chart-top-label: #394454;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #171d24;
  --ink: #e9eef5;
  --muted: #a9b4c0;
  --line: #303947;
  --green: #52b788;
  --blue: #78b7ea;
  --gold: #f0b85a;
  --red: #ef7c72;
  --soft-green: #183d31;
  --soft-blue: #193955;
  --focus: #85c5ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.34);
  --brand-bg: #e9eef5;
  --brand-ink: #101820;
  --notice-bg: #3b2f18;
  --notice-line: #8c6a23;
  --status-bg: #142d42;
  --status-line: #275579;
  --input-bg: #111820;
  --property-bg: #111820;
  --tooltip-bg: #111820;
  --tooltip-line: #415066;
  --tooltip-heading-bg: #202a35;
  --tooltip-alt-bg: #18212b;
  --table-heading-bg: #202a35;
  --table-heading-ink: #d4dde8;
  --table-hover: #182638;
  --button-hover: rgba(233, 238, 245, 0.1);
  --chart-bg: #171d24;
  --chart-label: #e9eef5;
  --chart-axis: #a9b4c0;
  --chart-grid: #303947;
  --chart-inner-label: #0f1419;
  --chart-top-label: #d4dde8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

#root {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: var(--brand-bg);
  border-radius: 6px;
  color: var(--brand-ink);
  display: flex;
  font-size: 14px;
  font-weight: 700;
  height: 42px;
  justify-content: center;
  width: 54px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

#dashboardSubtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

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

.session-panel {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  min-width: 260px;
}

#googleSignIn {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  min-height: 40px;
}

.theme-switch {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex: 0 0 auto;
  font-size: 12px;
  gap: 8px;
}

.theme-switch input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.theme-switch-track {
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  height: 24px;
  padding: 2px;
  transition: background 0.18s ease, border-color 0.18s ease;
  width: 46px;
}

.theme-switch-thumb {
  background: var(--panel);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(23, 32, 42, 0.22);
  height: 18px;
  transition: transform 0.18s ease, background 0.18s ease;
  width: 18px;
}

.theme-switch input:checked + .theme-switch-track {
  background: var(--blue);
  border-color: var(--blue);
}

.theme-switch input:checked + .theme-switch-track .theme-switch-thumb {
  transform: translateX(22px);
}

.theme-switch input:focus + .theme-switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.user-badge {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 34px minmax(160px, 1fr) auto;
}

.user-picture {
  border-radius: 50%;
  height: 34px;
  width: 34px;
}

.user-badge strong,
.user-badge span {
  display: block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge span {
  color: var(--muted);
  font-size: 12px;
}

main {
  margin: 0 auto;
  max-width: 1440px;
  padding: 22px 28px 36px;
}

.notice {
  align-items: center;
  background: var(--notice-bg);
  border: 1px solid var(--notice-line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  min-height: 46px;
  padding: 11px 14px;
}

.notice.muted {
  background: var(--status-bg);
  border-color: var(--status-line);
}

.notice-close {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  display: flex;
  flex: 0 0 auto;
  font-size: 20px;
  height: 28px;
  justify-content: center;
  line-height: 1;
  margin-left: auto;
  padding: 0;
  width: 28px;
}

.notice-close:hover {
  background: var(--button-hover);
  color: var(--ink);
}

.dashboard-grid {
  display: grid;
  gap: 16px;
}

.controls-bar {
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  padding: 14px;
}

.admin-controls-bar {
  grid-template-columns: minmax(260px, 1fr) auto;
}

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

input,
select {
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  height: 38px;
  min-width: 0;
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-button,
.ghost-button {
  border-radius: 6px;
  height: 38px;
  padding: 0 14px;
}

.primary-button {
  background: var(--green);
  border: 1px solid var(--green);
  color: #ffffff;
  font-weight: 700;
}

.ghost-button {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--ink);
}

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

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

.property-panel {
  overflow: visible;
}

.property-panel.is-collapsed {
  overflow: hidden;
}

.property-panel.is-collapsed .checkbox-grid,
.property-panel.is-collapsed .admin-actions {
  display: none;
}

.property-panel.is-collapsed .panel-heading {
  border-bottom: 0;
}

.admin-actions {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
}

.checkbox-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  padding: 14px;
}

.property-check {
  align-items: center;
  background: var(--property-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: flex;
  font-size: 13px;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
}

.property-check input {
  height: 16px;
  width: 16px;
}

.property-check small {
  color: var(--muted);
  font-size: 11px;
  margin-left: auto;
}

.group-checkbox-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.section-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 4px 2px 0;
}

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

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

.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 16px;
}

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

.metric-card strong {
  font-size: 26px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.accent-blue {
  border-left-color: var(--blue);
}

.accent-gold {
  border-left-color: var(--gold);
}

.accent-red {
  border-left-color: var(--red);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px 14px;
}

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

.panel-heading-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.panel-collapse-button {
  height: 30px;
  min-width: 54px;
  padding: 0 10px;
}

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

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

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

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

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

.chart-tooltip {
  background: var(--tooltip-bg);
  border: 1px solid var(--tooltip-line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(23, 32, 42, 0.18);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  max-width: 360px;
  min-width: 240px;
  padding: 12px;
  pointer-events: none;
  position: fixed;
  z-index: 20;
}

.tooltip-title {
  font-weight: 700;
  margin-bottom: 7px;
}

.tooltip-line {
  color: var(--muted);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 3px 0;
}

.tooltip-line strong {
  color: var(--ink);
  font-weight: 700;
}

.tooltip-table {
  border-collapse: collapse;
  margin-top: 8px;
  min-width: 0;
  width: 100%;
}

.tooltip-table th,
.tooltip-table td {
  border: 0;
  font-size: 12px;
  padding: 4px 6px;
}

.tooltip-table th {
  background: var(--tooltip-heading-bg);
  color: var(--table-heading-ink);
  cursor: default;
  position: static;
}

.tooltip-table tr:nth-child(even) td {
  background: var(--tooltip-alt-bg);
}

.tooltip-table td:last-child,
.tooltip-table th:last-child {
  text-align: right;
}

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

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

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

th {
  background: var(--table-heading-bg);
  color: var(--table-heading-ink);
  cursor: pointer;
  font-weight: 700;
  position: sticky;
  top: 0;
}

td.numeric,
th.numeric {
  text-align: right;
}

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

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

.table-actions .ghost-button {
  height: 32px;
  padding: 0 10px;
}

.empty-row td {
  color: var(--muted);
  padding: 28px 14px;
  text-align: center;
}

.empty-selector {
  color: var(--muted);
  font-size: 13px;
  grid-column: 1 / -1;
  padding: 8px 2px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-panel,
  .user-badge {
    width: 100%;
  }

  .controls-bar,
  .kpi-grid,
  .chart-grid,
  .monthly-chart-grid {
    grid-template-columns: 1fr;
  }

  .selector-actions {
    justify-content: stretch;
  }

  .selector-actions button {
    flex: 1;
  }

  main {
    padding: 16px;
  }
}
