:root {
  --bg: #1d263b;
  --bg-soft: #101a2f;
  --panel: rgba(17, 28, 46, 0.92);
  --panel-soft: rgba(255, 255, 255, 0.03);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-strong: rgba(84, 177, 255, 0.24);

  --text: #edf4ff;
  --muted: #a8b8d4;
  --accent: #6ec1ff;
  --accent-soft: rgba(84, 177, 255, 0.12);

  --success: #76d39b;
  --warn: #ffd479;
  --danger: #ff8b8b;

  --radius-xs: 10px;
  --radius-sm: 12px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.18);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;

  --page-max: 1500px;
  --content-max: 1380px;

  --kpi-min-h: 70px;
  --chart-min-h: 220px;
  --chart-default-h: 240px;

  --fs-hero: clamp(1.7rem, 1.25rem + 1.4vw, 2.4rem);
  --fs-h2: clamp(1.2rem, 1.05rem + 0.55vw, 1.55rem);
  --fs-h3: clamp(1rem, 0.95rem + 0.25vw, 1.15rem);
  --fs-body: 14px;
  --fs-small: 12px;
  --fs-xs: 11px;
  
  --dashboard-accent: #01a490;
  --dashboard-accent-soft: rgba(1, 164, 144, 0.14);
  --dashboard-accent-border: rgba(1, 164, 144, 0.28);
  --dashboard-accent-bg: rgba(1, 164, 144, 0.08);
  --dashboard-accent-bg-soft: rgba(1, 164, 144, 0.03);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(84, 177, 255, 0.08), transparent 32%),
    linear-gradient(180deg, #0b1220 0%, #0d1528 100%);
  color: var(--text);
  font: 400 var(--fs-body) / 1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

img,
canvas,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

/* ------------------------------------------------ */
/* PAGE LAYOUT                                      */
/* ------------------------------------------------ */

.page-shell {
  width: min(calc(100vw - 24px), var(--page-max));
  margin: 0 auto;
  padding: 14px 0 24px;
}

#app {
  display: grid;
  gap: var(--space-4);
  width: 100%;
}

.hero {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.hero-condensed {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.9fr);
  align-items: start;
}

.hero-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero-copy h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-hero);
  line-height: 1.05;
}

.subtle {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
}

/* ------------------------------------------------ */
/* AUTH                                             */
/* ------------------------------------------------ */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 0;
}

.auth-card {
  width: min(100%, 460px);
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.auth-form label {
  display: grid;
  gap: 6px;
}

.auth-form input {
  width: 100%;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 10px 12px;
}

.auth-form button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

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

.auth-locked {
  color: var(--warn);
}

.auth-rules {
  margin-top: 16px;
  color: var(--muted);
}

/* ------------------------------------------------ */
/* GENERIC CARD / PANEL                             */
/* ------------------------------------------------ */

.card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: var(--space-4);
  overflow: hidden;
}

.card h3 {
  margin: 0 0 6px;
  font-size: var(--fs-h3);
  line-height: 1.2;
}

.small-note {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-small);
  line-height: 1.4;
}

/* ------------------------------------------------ */
/* CONTROL PANEL / UPLOADS                          */
/* ------------------------------------------------ */

  .control-refresh-block {
    display: grid;
    gap: 12px;
  }

  .control-refresh-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    border-radius: var(--radius-md);
    border: 1px solid var(--dashboard-accent-border);
    background: linear-gradient(
      180deg,
      var(--dashboard-accent-soft) 0%,
      rgba(255,255,255,0.03) 100%
    );
    color: var(--text);
    padding: 12px 14px;
  }

  .control-refresh-button:hover {
    border-color: var(--dashboard-accent);
  }

  .control-refresh-button:disabled {
    opacity: 0.85;
    cursor: wait;
  }

  .control-refresh-button.is-loading .control-refresh-icon {
    animation: dashboard-spin 0.9s linear infinite;
  }

  .control-refresh-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--panel-border);
    color: var(--dashboard-accent);
    font-size: 18px;
    font-weight: 700;
  }

  .control-refresh-labels {
    min-width: 0;
    display: grid;
    gap: 2px;
    text-align: left;
  }

  .control-refresh-labels strong {
    font-size: 13px;
    line-height: 1.2;
  }

  .control-refresh-labels span {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
  }

  .control-refresh-meta {
    display: grid;
    gap: 8px;
  }

  .control-refresh-meta-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--muted);
  }

  .control-refresh-meta-item strong {
    color: var(--text);
    font-size: 11px;
  }

  @keyframes dashboard-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

.flash {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(110, 193, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: var(--fs-small);
}

/* ------------------------------------------------ */
/* NAV TABS                                         */
/* ------------------------------------------------ */

.tab-bar,
.subtab-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-bar {
  margin-bottom: 4px;
}

.subtab-bar {
  margin: 0 0 4px;
}

.tab-bar button,
.subtab-bar button,
.secondary-button {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  min-height: 38px;
  padding: 8px 14px;
  line-height: 1.15;
}

.tab-bar button.active,
.subtab-bar button.active {
  background: var(--dashboard-accent-soft);
  border-color: var(--dashboard-accent-border);
  color: var(--dashboard-accent);
}

.secondary-button:hover,
.tab-bar button:hover,
.subtab-bar button:hover {
  border-color: rgba(110, 193, 255, 0.22);
}

/* ------------------------------------------------ */
/* DASHBOARD SECTIONS                               */
/* ------------------------------------------------ */

.dashboard-section {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
}

.dashboard-section-focused {
  background: linear-gradient(
    180deg,
    var(--dashboard-accent-bg) 0%,
    var(--dashboard-accent-bg-soft) 14%,
    rgba(17, 28, 46, 0) 100%
  );
  border-color: var(--dashboard-accent-border);
}

.dashboard-section-annual {
  background: linear-gradient(
    180deg,
    var(--dashboard-accent-bg) 0%,
    var(--dashboard-accent-bg-soft) 14%,
    rgba(17, 28, 46, 0) 100%
  );
  border-color: var(--dashboard-accent-border);
}

.dashboard-section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.dashboard-section-header h2 {
  margin: 2px 0 4px;
  font-size: var(--fs-h2);
  line-height: 1.12;
}

.dashboard-section-eyebrow {
  margin: 0;
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.dashboard-section-header-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.dashboard-section-filter {
  min-width: 180px;
  max-width: 240px;
}

/* ------------------------------------------------ */
/* FORM CONTROLS                                    */
/* ------------------------------------------------ */

.month-filter select {
  -webkit-appearance: none;
  appearance: none;
  background-color: rgba(17, 28, 46, 0.92);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--dashboard-accent) 50%),
    linear-gradient(135deg, var(--dashboard-accent) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;

  color: var(--text);
  border: 1px solid var(--dashboard-accent-border);
  border-radius: 12px;
  min-height: 38px;
  width: 100%;
  padding: 8px 34px 8px 12px;
  line-height: 1.2;
  box-shadow: none;
  outline: none;
}

.month-filter select:hover {
  border-color: var(--dashboard-accent);
}

.month-filter select:focus {
  border-color: var(--dashboard-accent);
  box-shadow: 0 0 0 3px var(--dashboard-accent-soft);
}

.month-filter select::-ms-expand {
  display: none;
}

.month-filter select option {
  background: #16233a;
  color: var(--text);
}

/* ------------------------------------------------ */
/* PROGRAM PANELS                                   */
/* ------------------------------------------------ */

.program-panel-stack {
  display: grid;
  gap: 14px;
}

.kpi-panel {
  padding: 0;
  border-radius: var(--radius-lg);
}

.kpi-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.kpi-section-eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 4px 9px;
  margin: 0 0 6px;
  border-radius: 999px;

  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;

  color: var(--dashboard-accent);
  background: var(--dashboard-accent-soft);
  border: 1px solid var(--dashboard-accent-border);
}

.kpi-panel-heading {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.kpi-panel-heading h3 {
  margin: 0;
}

.kpi-panel-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: flex-start;
}

.kpi-panel-body {
  display: grid;
  gap: 12px;
  padding: 12px 14px 14px;
}

.kpi-grid-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.kpi-tile {
  min-width: 0;
  min-height: var(--kpi-min-h);
  padding: 10px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.035) 0%,
    rgba(255, 255, 255, 0.015) 100%
  );
  display: grid;
  gap: 4px;
  align-content: start;
}

.kpi-tile.kpi-focus {
  border-color: var(--dashboard-accent-border);
}

.kpi-value {
  font-size: clamp(1rem, 0.95rem + 0.38vw, 1.28rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.kpi-label {
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

.kpi-detail {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.help-icon {
  font-size: 11px;
  color: var(--dashboard-accent);
  vertical-align: middle;
}

.panel-disclaimer {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--dashboard-accent-border);
  background: var(--dashboard-accent-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.membership-insights-section {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

/* ------------------------------------------------ */
/* GRID HELPERS                                     */
/* ------------------------------------------------ */

.section-grid {
  display: grid;
  gap: 12px;
}

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

.embedded-panel-grid {
  margin-top: 2px;
}

/* ------------------------------------------------ */
/* CHARTS                                           */
/* ------------------------------------------------ */

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: var(--chart-min-h);
  height: var(--chart-default-h);
  overflow: hidden;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ------------------------------------------------ */
/* TABLES                                           */
/* ------------------------------------------------ */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.015);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(11, 18, 32, 0.96);
  color: var(--muted);
  font-size: var(--fs-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

th,
td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: top;
}

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

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--dashboard-accent-soft);
  border: 1px solid var(--dashboard-accent-border);
  color: var(--text);
  font-size: 11px;
  line-height: 1.2;
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------ */
/* EMPTY STATE                                      */
/* ------------------------------------------------ */

.empty-state {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  padding: 28px 20px;
  border-radius: var(--radius-lg);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.empty-state h2 {
  margin: 0;
  font-size: var(--fs-h2);
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

/* ------------------------------------------------ */
/* MODAL                                            */
/* ------------------------------------------------ */

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 10, 20, 0.72);
  backdrop-filter: blur(6px);
  z-index: 999;
}

.modal-card {
  width: min(1200px, 100%);
  max-height: min(88vh, 100%);
  background: rgba(17, 28, 46, 0.98);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.modal-card-xl {
  width: min(1240px, 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

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

.modal-body {
  overflow: auto;
  padding: 14px 16px 16px;
}

.balance-paid-row td {
  background: rgba(118, 211, 155, 0.05);
}

.balance-paid-cell {
  color: var(--success);
  font-weight: 700;
}

.balance-due-cell {
  color: var(--text);
  font-weight: 700;
}

/* ------------------------------------------------ */
/* PREVIEW STATS / TABS                             */
/* ------------------------------------------------ */

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

.preview-stat-card {
  display: grid;
  gap: 4px;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--panel-border);
}

.preview-stat-card-wide {
  grid-column: span 3;
}

.preview-stats-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.preview-stats-value {
  font-size: 17px;
  font-weight: 700;
}

.preview-stats-detail {
  font-size: var(--fs-small);
  line-height: 1.35;
}

.preview-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.preview-tab {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  min-height: 34px;
  padding: 7px 12px;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.preview-tab.active {
  background: var(--accent-soft);
  border-color: rgba(110, 193, 255, 0.28);
  color: var(--accent);
}

.preview-tab-count {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 11px;
  font-weight: 700;
}

/* ------------------------------------------------ */
/* RESPONSIVE                                       */
/* ------------------------------------------------ */

@media (max-width: 1280px) {
  .hero-condensed {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .page-shell {
    width: min(calc(100vw - 20px), 100%);
  }

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

@media (max-width: 900px) {
  .page-shell {
    width: min(calc(100vw - 16px), 100%);
    padding-top: 10px;
  }

  .dashboard-section {
    padding: 10px;
    gap: 12px;
  }

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

  .dashboard-section-header-actions {
    align-items: stretch;
  }

  .dashboard-section-filter {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .section-grid.two-up {
    grid-template-columns: 1fr;
  }

  .preview-stats {
    grid-template-columns: 1fr 1fr;
  }

  .preview-stat-card-wide {
    grid-column: span 2;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .modal-header,
  .modal-body {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 13px;
  }

  .page-shell {
    width: min(calc(100vw - 12px), 100%);
    padding-top: 8px;
    padding-bottom: 16px;
  }

  .card {
    padding: 12px;
    border-radius: 15px;
  }

  .dashboard-section {
    padding: 8px;
    margin-bottom: 12px;
    border-radius: 15px;
  }

  .tab-bar button,
  .subtab-bar button,
  .secondary-button {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .kpi-panel-header {
    padding: 10px 11px 9px;
  }

  .kpi-panel-body {
    padding: 10px 11px 11px;
    gap: 10px;
  }

  .kpi-grid-panel {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .kpi-tile {
    min-height: 64px;
    padding: 9px 10px;
    border-radius: 12px;
  }

  .kpi-value {
    font-size: 1rem;
  }

  .kpi-label,
  .kpi-detail {
    font-size: 10px;
  }

  .chart-wrap {
    min-height: 200px;
    height: 220px;
  }

  .preview-stats {
    grid-template-columns: 1fr;
  }

  .preview-stat-card-wide {
    grid-column: span 1;
  }

  .modal-card {
    max-height: 94vh;
    border-radius: 16px;
  }

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

  .modal-actions {
    width: 100%;
  }

  .modal-actions .secondary-button {
    width: 100%;
  }

  table {
    min-width: 560px;
  }
}
