/* CSS Variables */
:root {
  --transition-theme: 0.35s ease;
  --color-body-bg: #f4f4f4;
  --color-surface: #ffffff;
  --color-surface-muted: #f4f5f7;
  --color-panel: #f4f5f7;
  --color-border: #d7dce8;
  --color-border-strong: #c0c7d6;
  --color-text-primary: #1f2937;
  --color-text-secondary: #414d63;
  --color-text-muted: #6b7280;
  --color-leaderboard-toggle-border: #6be08f;
  --color-accent: #1e88e5;
  --color-accent-rgb: 30, 136, 229;
  --color-table-row-alt: rgba(15, 23, 42, 0.02);
  --color-table-row-hover: rgba(30, 136, 229, 0.08);
  --color-table-group-bg: #e3e7ef;
  --color-frequency-base: var(--color-table-group-bg);
  --color-frequency-y1: rgba(199, 249, 204, 0.85);
  --color-frequency-y2: rgba(128, 237, 153, 0.85);
  --color-frequency-y3: rgba(87, 204, 153, 0.85);
  --color-frequency-y4: rgba(56, 163, 165, 0.85);
  --color-frequency-y5: rgba(34, 87, 122, 0.85);
  --color-frequency-monthly: rgba(218, 242, 170, 0.9);
  --color-input-bg: #ffffff;
  --color-input-border: #cfd3e2;
  --color-input-text: #1f2430;
  --color-button-bg: #ffffff;
  --color-button-text: #1f2430;
  --color-button-border: rgba(17, 24, 39, 0.08);
  --color-nav-bg: rgba(255, 255, 255, 0.95);
  --color-nav-divider: rgba(15, 23, 42, 0.08);
  --color-modal-backdrop: rgba(4, 8, 20, 0.5);
  --shadow-elevated: 0 12px 28px rgba(15, 23, 42, 0.12);
  --color-status-churned: #ffe5e5;
  --color-status-paused: #fffbe5;
  --color-toggle-bg: rgba(15, 23, 42, 0.05);
  --color-toggle-border: rgba(15, 23, 42, 0.15);
  --color-toggle-icon: #1c2434;
  --color-success-strong: #2e7d32;
  --color-danger-strong: #c62828;
}

body.theme-dark,
html.theme-dark {
  --color-body-bg: #050b18;
  --color-surface: #0f1c33;
  --color-surface-muted: #172642;
  --color-panel: #152440;
  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-strong: rgba(255, 255, 255, 0.15);
  --color-text-primary: #f2f6ff;
  --color-text-secondary: #d0dcff;
  --color-text-muted: #9db1d6;
  --color-leaderboard-toggle-border: #f2f6ff;
  --color-table-row-alt: rgba(255, 255, 255, 0.03);
  --color-table-row-hover: rgba(30, 136, 229, 0.32);
  --color-table-group-bg: #0b1628;
  --color-frequency-base: var(--color-table-group-bg);
  --color-input-bg: rgba(14, 24, 45, 0.95);
  --color-input-border: rgba(255, 255, 255, 0.2);
  --color-input-text: #f2f6ff;
  --color-button-bg: rgba(255, 255, 255, 0.08);
  --color-button-text: #f8fbff;
  --color-button-border: rgba(255, 255, 255, 0.2);
  --color-nav-bg: rgba(5, 11, 25, 0.95);
  --color-nav-divider: rgba(255, 255, 255, 0.12);
  --color-modal-backdrop: rgba(0, 4, 19, 0.78);
  --shadow-elevated: 0 20px 40px rgba(2, 6, 23, 0.85);
  --color-status-churned: rgba(255, 82, 82, 0.2);
  --color-status-paused: rgba(255, 213, 79, 0.16);
  --color-toggle-bg: rgba(255, 255, 255, 0.08);
  --color-toggle-border: rgba(255, 255, 255, 0.25);
  --color-toggle-icon: #f2f6ff;
  --color-success-strong: #39d98a;
  --color-danger-strong: #ff6b6b;
}

/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: sans-serif;
}

html {
  background-color: var(--color-body-bg);
  transition: background-color var(--transition-theme);
}

body {
  background-color: var(--color-body-bg);
  color: var(--color-text-primary);
  padding: 20px;
  line-height: 1.5;
  transition: background-color var(--transition-theme), color var(--transition-theme);
  min-height: 100vh;
  position: relative;
}

body .container-fluid {
  background: transparent;
  transition: background-color var(--transition-theme);
}

header {
  margin-bottom: 20px;
}

header h1 {
  font-size: 1.5rem;
  color: var(--color-text-primary);
}

nav {
  margin-bottom: 0.35rem;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 10px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 14px;
  box-shadow: none;
}

.app-topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 32px;
  flex: 1 1 auto;
}

.app-topbar__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--color-text-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.app-topbar__links {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  margin-right: 10px;
  padding: 2px 0;
  flex-wrap: wrap;
}

.app-topbar__switches {
  display: inline-flex;
  gap: 16px;
  align-items: center;
}

.app-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-toggle-bg);
  color: var(--color-text-primary);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: none;
  transition: background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), box-shadow var(--transition-theme), transform 0.2s ease;
}

.app-pill--user {
  letter-spacing: 0.06em;
}

.app-pill--active {
  background: linear-gradient(135deg, rgba(var(--color-accent-rgb), 0.2), rgba(var(--color-accent-rgb), 0.08));
  border-color: var(--color-accent);
  box-shadow: var(--shadow-elevated);
  color: var(--color-text-primary);
}

.app-pill:hover,
.app-pill:focus {
  text-decoration: none;
  color: var(--color-text-primary);
  transform: none;
  box-shadow: none;
}

.app-pill:focus {
  outline: none;
}

.app-pill:active {
  transform: none;
  box-shadow: none;
}

.app-pill[aria-pressed="true"] {
  cursor: default;
}

.app-toplink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.15s ease, box-shadow 0.25s ease, background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), opacity 0.2s ease;
  box-shadow: none;
}

.app-toplink:hover,
.app-toplink:focus {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
  text-decoration: none;
  box-shadow: 0 12px 26px rgba(2, 6, 23, 0.45);
}

.app-toplink--highlight {
  color: #ffffff;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* Top link overrides for light theme readability */
body.theme-light .app-toplink,
html.theme-light .app-toplink {
  color: #1f2937;
}

body.theme-light .app-toplink--highlight,
html.theme-light .app-toplink--highlight {
  color: #1f2937;
}

body.theme-light .app-toplink:hover,
body.theme-light .app-toplink:focus,
html.theme-light .app-toplink:hover,
html.theme-light .app-toplink:focus {
  color: #1f2937;
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.12);
}

.app-toplink[aria-disabled="true"] {
  pointer-events: none;
}

.app-topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 0;
  flex: 0 0 auto;
}

.app-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  line-height: 1.1;
}

.app-user-chip.is-empty {
  display: none;
}

body .nav-tabs {
  border-bottom: none;
  background: var(--color-nav-bg);
  border-radius: 999px;
  padding: 0.3rem;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-elevated);
  position: relative;
  overflow: hidden;
}

body .nav-tabs > div {
  display: flex;
  gap: 0.35rem;
}

body .nav-tabs .nav-link {
  border: none;
  color: var(--color-text-secondary);
  font-weight: 600;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  transition: background-color var(--transition-theme), color var(--transition-theme), box-shadow var(--transition-theme);
  position: relative;
  z-index: 2;
}

body .nav-tabs .nav-link.active,
body .nav-tabs .nav-link:focus,
body .nav-tabs .nav-link:hover {
  color: var(--color-text-primary);
}

body .nav-tabs .nav-link.active {
  background: transparent;
  box-shadow: none;
}

body .nav-tabs li + li {
  border-left: none;
}

body .nav-tabs .nav-tabs-indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-radius: 999px;
  background: var(--color-surface-muted);
  box-shadow: inset 0 0 0 1px var(--color-border-strong);
  transition: transform 0.4s cubic-bezier(0.33, 1, 0.68, 1), width 0.3s ease, height 0.3s ease, opacity 0.2s ease;
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}

body .nav-tabs .nav-tabs-indicator.is-visible {
  opacity: 1;
}

.teamperf-shell {
  margin-top: 6px;
}

.teamperf-nav {
  margin-bottom: 12px;
}

.team-tab-content {
  display: none;
  background: var(--color-surface);
  padding: 18px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-elevated);
  color: var(--color-text-primary);
}

.team-tab-content.active {
  display: block;
}

.team-leaderboard-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.team-leaderboard-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.team-leaderboard-period {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
}

.team-leaderboard-label {
  width: 190px;
  flex: 0 0 190px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-leaderboard-nav {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.team-leaderboard-nav:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.12);
}

.team-leaderboard-nav:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(var(--color-accent-rgb), 0.2);
}

.team-leaderboard-toggles {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.team-leaderboard-toggle-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.team-leaderboard-toggle {
  width: 100px;
  min-width: 100px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 4px solid transparent;
  background: var(--color-surface-muted);
  color: #ffffff;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.team-leaderboard-toggle:focus,
.team-leaderboard-toggle:focus-visible {
  outline: none;
  box-shadow: none;
}

.team-leaderboard-toggle[data-series="cv"] {
  background: rgba(30, 90, 200, 0.85);
}

.team-leaderboard-toggle[data-series="nrr"] {
  background: rgba(255, 160, 80, 0.85);
}

.team-leaderboard-toggle.is-active {
  border-color: var(--color-leaderboard-toggle-border);
}

.team-leaderboard-chart {
  position: relative;
  min-height: 420px;
}

.team-leaderboard-message {
  padding: 24px;
  border-radius: 12px;
  border: 1px dashed var(--color-border-strong);
  background: var(--color-surface-muted);
  text-align: center;
  color: var(--color-text-muted);
  font-weight: 600;
}

@media (max-width: 768px) {
  .team-leaderboard-head {
    align-items: stretch;
  }

  .team-leaderboard-period,
  .team-leaderboard-toggles {
    width: 100%;
    justify-content: center;
  }

  .team-leaderboard-label {
    width: 160px;
    flex: 0 0 160px;
  }
}

.team-placeholder-card {
  min-height: 150px;
  border: 1px dashed var(--color-border-strong);
  border-radius: 14px;
  background: var(--color-surface-muted);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Auth */
.auth-shell {
  max-width: 1100px;
  margin: 40px auto;
  padding: 28px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  box-shadow: var(--shadow-elevated);
}

.auth-hero {
  margin-bottom: 20px;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: linear-gradient(135deg, rgba(var(--color-accent-rgb), 0.16), rgba(84, 110, 255, 0.18));
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text-primary);
}

.auth-hero h1 {
  margin: 12px 0 6px;
  font-size: 1.8rem;
}

.auth-hero p {
  margin: 0;
  color: var(--color-text-muted);
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.auth-card {
  background: var(--color-surface-muted);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow-elevated);
}

.auth-card__header h2 {
  margin-bottom: 6px;
}

.auth-card__header p {
  margin-bottom: 12px;
  color: var(--color-text-muted);
}

.auth-step {
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px dashed var(--color-border);
}

.auth-step:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.auth-step.is-collapsed {
  display: none;
}

.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
}

.auth-actions .btn-link {
  padding-left: 0;
}

.admin-stack {
  margin-top: 24px;
  padding: 18px;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-elevated);
}

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

.admin-gate__actions {
  display: flex;
  gap: 8px;
}

.admin-panel {
  margin-top: 12px;
  padding: 14px;
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
}

.admin-panel.is-collapsed {
  display: none;
}

.admin-placeholder {
  font-size: 0.9rem;
}

body.admin-console-open {
  padding: 0;
}

.admin-console {
  display: flex;
  min-height: 100vh;
  background: var(--color-body-bg);
}

.admin-sidebar {
  width: 240px;
  padding: 28px 18px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
}

.admin-sidebar__brand {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--color-text-muted);
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.admin-nav__item {
  width: 100%;
  text-align: left;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-secondary);
  font-weight: 700;
  padding: 10px 12px;
  font-size: 0.95rem;
  cursor: pointer;
  appearance: none;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.admin-nav__item:hover,
.admin-nav__item:focus {
  border-color: var(--color-border);
  background: var(--color-surface-muted);
  color: var(--color-text-primary);
  outline: none;
}

.admin-nav__item.is-active {
  border-color: var(--color-border);
  background: var(--color-surface-muted);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-elevated);
}

.admin-main {
  flex: 1;
  padding: 32px 40px;
}

.admin-console__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.admin-console__title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
}

.admin-console__subtitle {
  margin-top: 4px;
  font-size: 0.95rem;
}

.admin-page {
  display: none;
}

.admin-page.is-active {
  display: block;
}

.admin-block {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
}

.admin-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.admin-block__title {
  font-weight: 800;
  color: var(--color-text-primary);
}

.admin-block__actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.admin-block__toggle {
  border-radius: 999px !important;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.admin-block__toggle:not(:hover):not(:focus):not(:active) {
  background-color: transparent !important;
  border-color: transparent !important;
  box-shadow: none;
}

.admin-block__toggle:focus:not(:hover) {
  background-color: transparent !important;
  border-color: transparent !important;
  box-shadow: none;
}

.admin-block__body {
  padding: 16px 18px;
}

.admin-block__hint {
  font-size: 0.9rem;
}

.admin-block__empty {
  padding: 6px 0;
}

.admin-block--collapsed .admin-block__head {
  border-bottom: none;
}

.admin-block--collapsed .admin-block__body {
  display: none;
}

.admin-backup__controls {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.admin-backup__status {
  display: grid;
  gap: 4px;
}

.admin-backup__status-label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--color-text-muted);
}

.admin-backup__status-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

.admin-backup__status-meta {
  font-size: 0.85rem;
}

.admin-backup__status-meta--stale {
  color: var(--color-danger-strong);
  font-weight: 600;
}

.admin-backup__actions {
  display: flex;
  gap: 8px;
}

.admin-backup__table-wrap {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  overflow-x: auto;
}

.admin-backup-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.admin-backup-table th,
.admin-backup-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
  text-align: left;
}

.admin-backup-table th {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  white-space: nowrap;
}

.admin-backup__file {
  font-weight: 600;
  color: var(--color-text-secondary);
}

.admin-backup__row-actions {
  display: inline-flex;
  gap: 8px;
}

.admin-backup__pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--color-surface-muted);
  color: var(--color-text-secondary);
}

.admin-backup__pill--daily {
  background: rgba(var(--color-accent-rgb), 0.12);
  color: var(--color-accent);
}

.admin-backup__pill--weekly {
  background: rgba(46, 125, 50, 0.14);
  color: var(--color-success-strong);
}

.admin-backup__pill--monthly {
  background: rgba(198, 40, 40, 0.12);
  color: var(--color-danger-strong);
}

.admin-backup__pill--manual {
  background: rgba(255, 143, 0, 0.18);
  color: #f57c00;
}

.admin-users__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.admin-users__summary {
  font-size: 0.9rem;
  font-weight: 600;
}

.admin-users__actions {
  display: inline-flex;
  gap: 8px;
}

.admin-users__table-wrap {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  overflow-x: auto;
}

.admin-users-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.admin-users-table th,
.admin-users-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
  text-align: left;
  vertical-align: middle;
}

.admin-users-table th {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  white-space: nowrap;
}

.admin-users__user {
  font-weight: 700;
  color: var(--color-text-primary);
}

.admin-users__meta {
  font-size: 0.8rem;
}

.admin-users__row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* App loader */
.app-loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.app-loader.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.app-loader__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(var(--color-accent-rgb), 0.16), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(var(--color-accent-rgb), 0.12), transparent 60%),
    var(--color-modal-backdrop);
  backdrop-filter: blur(6px);
}

.app-loader__panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  padding: 26px 30px;
  border-radius: 18px;
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-elevated);
  max-width: 360px;
  width: 100%;
}

.app-loader__spinner {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 3px solid rgba(var(--color-accent-rgb), 0.2);
  border-top-color: rgba(var(--color-accent-rgb), 0.9);
  animation: app-loader-spin 0.9s linear infinite;
}

.app-loader__title {
  font-weight: 800;
  letter-spacing: 0.02em;
}

.app-loader__subtitle {
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

@keyframes app-loader-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .auth-shell {
    padding: 20px;
    margin: 20px auto;
  }
  .auth-grid {
    grid-template-columns: 1fr;
  }
  .admin-gate {
    flex-direction: column;
    align-items: flex-start;
  }
  .admin-console {
    flex-direction: column;
  }
  .admin-sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .admin-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .admin-nav__item {
    flex: 1 1 160px;
  }
  .admin-main {
    padding: 24px;
  }
  .admin-console__top {
    align-items: flex-start;
  }
  .admin-block__body .form-row {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-block__body .ml-3 {
    margin-left: 0 !important;
    margin-top: 10px;
  }
  .app-loader__panel {
    padding: 22px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-loader,
  .app-loader__spinner {
    transition: none;
    animation: none;
  }
}

/* Tab content */
body .tab-content {
  display: none;
}

body .tab-content.active {
  display: block;
  background-color: var(--color-surface);
  padding: 20px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-elevated);
  color: var(--color-text-primary);
}

/* Cards */
body .card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-elevated);
}

body .card .card-body {
  color: inherit;
}

/* Tables */
body .table {
  width: 100%;
  margin-bottom: 20px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  border-color: var(--color-border);
}

body .table td,
body .table th {
  border-color: var(--color-border);
}

body .table td.text-right,
body .table th.text-right {
  white-space: nowrap;
}

body .table thead th {
  background: var(--color-surface-muted);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

body .table-striped tbody tr:nth-of-type(odd) {
  background-color: var(--color-table-row-alt);
}

#excelImportBlock {
  position: relative;
}

#excelImportBlock.is-locked {
  opacity: 0.6;
  pointer-events: none;
}

#excelImportHelp {
  transition: opacity var(--transition-theme);
}

#excelImportBlock.is-locked #excelImportHelp {
  opacity: 0;
  height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

#excelImportBlock .excel-import-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#excelImportBlock.is-locked .excel-import-overlay {
  display: flex;
}

.modal-success .modal-header {
  background-color: #e8f5e9;
  color: #0f5132;
}

.modal-error .modal-header {
  background-color: #fdecea;
  color: #842029;
}

.modal-warning .modal-header {
  background-color: #fff8e1;
  color: #664d03;
}

body .table-striped tbody tr:hover {
  background-color: var(--color-table-row-hover);
}

body .table .table-group-row td {
  background-color: var(--color-table-group-bg) !important;
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-top: 1px solid var(--color-border);
  /*border-bottom: 1px solid var(--color-border);*/
  cursor: default;
  padding-top: 4px;
  padding-bottom: 4px;
}

body .table .table-group-row:hover td {
  background-color: var(--color-table-group-bg) !important;
}

body .table .table-group-row--year td {
  background-color: var(--color-table-group-bg) !important;
  color: var(--color-text-primary);
  font-weight: 700;
}

body .table .table-group-row--month td {
  background-color: var(--color-table-group-bg) !important;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  border-top: 3px solid var(--color-border-strong);
  padding-top: 5px;
  padding-bottom: 5px;
}

body .table .table-group-row--day td {
  background-color: var(--color-table-group-bg) !important;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  border-top: 2px solid var(--color-border-strong);
  padding-top: 4px;
  padding-bottom: 4px;
}

body .table .table-group-row--year + .table-group-row--day td,
body .table .table-group-row--month + .table-group-row--day td,
body .table .table-group-row--frequency + .table-group-row--day td {
  border-top: none;
}

body .table .table-group-row__value {
  text-align: right;
  white-space: nowrap;
}

body .table .table-group-row--frequency td {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  border-top: 3px solid var(--color-border-strong);
  padding-top: 5px;
  padding-bottom: 5px;
  --frequency-accent: var(--color-frequency-y1);
  background-color: var(--color-frequency-base) !important;
  background-image: linear-gradient(140deg, var(--frequency-accent) 0%, var(--frequency-accent) 30%, rgba(0, 0, 0, 0) 40%);
  background-repeat: no-repeat;
}

body .table .table-group-row--frequency:hover td {
  background-color: var(--color-frequency-base) !important;
  background-image: linear-gradient(140deg, var(--frequency-accent) 0%, var(--frequency-accent) 30%, rgba(0, 0, 0, 0) 40%);
}

body .table .table-group-row--freq-y1 td {
  --frequency-accent: var(--color-frequency-y1);
  color: #0f172a;
}

body .table .table-group-row--freq-y2 td {
  --frequency-accent: var(--color-frequency-y2);
  color: #0f172a;
}

body .table .table-group-row--freq-y3 td {
  --frequency-accent: var(--color-frequency-y3);
  color: #0f172a;
}

body .table .table-group-row--freq-y4 td {
  --frequency-accent: var(--color-frequency-y4);
  color: #0f172a;
}

body .table .table-group-row--freq-y5 td {
  --frequency-accent: var(--color-frequency-y5);
  color: #f8fafc;
}

body .table .table-group-row--freq-monthly td,
body .table .table-group-row--freq-other td {
  --frequency-accent: var(--color-frequency-monthly);
  color: #0f172a;
}

/* Forms */
body .form-control,
body select.form-control {
  background-color: var(--color-input-bg);
  border: 1px solid var(--color-input-border);
  color: var(--color-input-text);
  transition: background-color var(--transition-theme), border-color var(--transition-theme), color var(--transition-theme);
}

body .form-control:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 0.15rem rgba(30, 136, 229, 0.3);
  background-color: var(--color-input-bg);
  color: var(--color-input-text);
}

::placeholder {
  color: var(--color-text-muted);
}

.masked-input {
  -webkit-text-security: disc;
  text-security: disc;
}

/* Modal override */
body .modal .modal-dialog {
  max-width: 600px;
}

body .modal-content {
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-elevated);
}

body .modal-header,
body .modal-footer {
  border-color: var(--color-border);
}

body .modal-header {
  background: var(--color-surface-muted);
  color: var(--color-text-primary);
}

body .modal-header .close {
  color: var(--color-text-primary);
  opacity: 0.9;
  text-shadow: none;
  transition: color var(--transition-theme), opacity var(--transition-theme);
}

body.theme-dark .modal-header .close,
html.theme-dark .modal-header .close {
  color: #fdfdfd;
  opacity: 1;
}

body .modal-header .close:hover,
body .modal-header .close:focus {
  color: var(--color-accent);
  opacity: 1;
  outline: none;
}

body .modal-backdrop.show {
  opacity: 1;
  background-color: var(--color-modal-backdrop);
}

/* Buttons */
body .btn {
  transition: background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), box-shadow var(--transition-theme);
}

body .btn-light,
body .btn-outline-secondary,
body .dashboard-month-nav-btn {
  background: var(--color-button-bg);
  color: var(--color-button-text);
  border-color: var(--color-button-border);
}

/* Minimal styling for action buttons in tables */
#clientTableBody .btn-warning,
#clientTableBody .btn-danger,
#upsellTableBody .btn-warning,
#upsellTableBody .btn-danger,
#successPackTableBody .btn-warning,
#successPackTableBody .btn-danger,
#renewTableBody .btn-warning,
#renewTableBody .btn-danger,
#clientTableBody .btn-success {
  background-color: transparent;
  border: none;
}

/* Theme toggle */
.theme-toggle-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--color-toggle-border);
  background: var(--color-toggle-bg);
  color: var(--color-toggle-icon);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  z-index: 1500;
  box-shadow: var(--shadow-elevated);
  transition: background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), box-shadow var(--transition-theme), transform 0.2s ease;
}

.theme-toggle-btn:hover {
  transform: translateY(-2px);
}

.theme-toggle-btn:focus,
.theme-toggle-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-elevated);
}

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

/* Shared transitions */
body,
body .tab-content,
body .card,
body .table,
body .modal-content,
body .nav-tabs,
body .nav-tabs .nav-link,
.dashboard-panel,
.dashboard-month-selector,
.dashboard-month-nav-btn,
.quarter-card,
.commission-summary-card {
  transition: background-color var(--transition-theme), color var(--transition-theme), border-color var(--transition-theme), box-shadow var(--transition-theme);
}

.tracking-row--deleted,
.upsell-row-deleted,
.successpack-row-deleted,
.renew-row-deleted {
  color: #893F45;
  opacity: 0.92;
}

.upsell-row-deleted td,
.successpack-row-deleted td,
.renew-row-deleted td {
  color: #893F45;
}

.tracking-row--deleted .tracking-row__client .badge-warning,
.upsell-row-deleted .badge-warning,
.successpack-row-deleted .badge-warning,
.renew-row-deleted .badge-warning {
  background-color: rgba(137, 63, 69, 0.15);
  color: #893F45;
}

/* Settings: Deleted & Orphans list visuals (light/dark) */
#deletedDataList .list-group-item,
#orphanList .list-group-item {
  background: var(--color-surface-muted);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}

body.theme-dark #deletedDataList .list-group-item,
body.theme-dark #orphanList .list-group-item {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--color-border);
}

#deletedDataList .badge-secondary,
#orphanList .badge-warning {
  color: #1f2937;
}

body.theme-dark #deletedDataList .badge-secondary {
  background-color: rgba(255, 255, 255, 0.14);
  color: #f2f6ff;
}

body.theme-dark #orphanList .badge-warning {
  background-color: rgba(255, 213, 79, 0.22);
  color: #fdf6d3;
}

body.theme-dark #orphanSummary.alert-warning {
  background-color: rgba(255, 213, 79, 0.12);
  border-color: rgba(255, 213, 79, 0.35);
  color: #fdf6d3;
}

@media (max-width: 576px) {
  .app-topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 6px 0 10px 0;
  }

  .app-topbar__links {
    width: 100%;
    margin: 2px 0 0 0;
    justify-content: flex-start;
    gap: 8px;
  }

  .app-toplink {
    padding: 6px 10px;
  }

  .app-topbar__right {
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
  }

  .app-topbar__title {
    font-size: 1.2rem;
    justify-content: flex-start;
  }

  .app-user-chip {
    justify-content: center;
    width: 100%;
  }

  .theme-toggle-btn {
    width: 44px;
    height: 44px;
  }
}
