:root {
  color-scheme: light;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-3: #E2E8F0;
  --ink: #0F172A;
  --text: #334155;
  --muted: #64748B;
  --subtle: #94A3B8;
  --line: #E2E8F0;
  --line-strong: #CBD5E1;
  --accent: #4F46E5;
  --accent-strong: #4338CA;
  --accent-soft: #EEF2FF;
  --danger: #EF4444;
  --warning: #F59E0B;
  --success: #10B981;
  --focus: rgba(79, 70, 229, 0.2);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

*:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

h1, h2, h3, p {
  margin: 0;
}

/* Typography */
h1 { font-size: 28px; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; color: var(--ink); }

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.compact { margin-top: 4px; font-size: 13px; }

/* Buttons */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-strong);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
  box-shadow: none;
}

.ghost-danger {
  background: transparent;
  border: 1px solid transparent;
  color: var(--danger);
}

.ghost-danger:hover {
  background: rgba(255, 69, 58, 0.1);
  color: var(--danger);
  box-shadow: none;
}

/* Forms */
label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 14px;
  transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

input::placeholder { color: var(--subtle); }

.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-row-tight {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
}

.form-row-small {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* Layout Architecture */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.login-panel {
  margin: auto;
  width: 100%;
  max-width: 400px;
  padding: 40px;
  text-align: center;
}

.login-panel h2 { margin-top: 24px; margin-bottom: 8px; }
.login-panel p { margin-bottom: 32px; }
.login-panel .form-group { text-align: left; }
.login-panel button { width: 100%; margin-top: 8px; }

.brand-mark-large {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  background: var(--accent);
  color: #FFFFFF;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 24px;
  font-weight: 900;
}

.portal-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 32px;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 800; font-size: 16px; color: var(--ink); }

.portal-nav {
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-grow: 1;
}

.nav-tab {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: var(--muted);
  border: none;
  font-weight: 600;
}

.nav-tab:hover {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
}

.nav-tab.active {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-icon { margin-right: 8px; font-size: 16px; }

.sidebar-footer {
  padding: 24px 16px;
  border-top: 1px solid var(--line);
}

.auth-status {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.auth-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.auth-info span { font-size: 13px; font-weight: 600; }

.account-kicker {
  color: var(--muted);
  font-size: 10px !important;
  font-weight: 800 !important;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#userLabel {
  max-width: 185px;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-status .ghost-danger {
  width: 100%;
  justify-content: center;
  border-color: var(--line);
  background: var(--surface);
}

.role-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 3px 9px;
  background: var(--surface-3);
  border-radius: 999px;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
}
.role-badge.superadmin { background: var(--ink); color: #FFFFFF; font-weight: 800; }
.role-badge.gym_admin { background: #E8F7EF; color: #047857; font-weight: 800; }
.role-badge.admin { background: var(--surface-3); color: var(--ink); font-weight: 700; }

/* Content Area */
.content-area {
  flex-grow: 1;
  overflow-y: auto;
  padding: 40px 48px;
  background: var(--bg);
}

.scope-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.scope-bar strong {
  color: var(--ink);
  font-size: 15px;
}

.scope-bar label {
  width: min(280px, 100%);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

/* Dashboard Grids */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.metric-card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.metric-card span { color: var(--muted); font-size: 13px; font-weight: 600; }
.metric-card strong { display: block; font-size: 32px; font-weight: 800; color: var(--ink); margin: 8px 0; }
.metric-card small { color: var(--subtle); font-size: 12px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 300px;
  gap: 16px;
}

.platform-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 16px;
}

.migration-panel {
  margin-top: 16px;
}

.migration-gym-field {
  max-width: 360px;
  margin-bottom: 16px;
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.action-row.clickable {
  cursor: pointer;
}

.action-row.clickable:hover {
  background: var(--surface-3);
}

.action-row strong { color: var(--ink); font-size: 14px; }
.action-row span { color: var(--muted); font-size: 13px; margin-top: 4px; display: block; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.delete-confirmation {
  display: grid;
  gap: 14px;
  margin-top: -4px;
  margin-bottom: 12px;
  padding: 16px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius-md);
}

.delete-confirmation strong {
  color: var(--ink);
  font-size: 14px;
}

.delete-confirmation span {
  display: block;
  margin-top: 4px;
  color: #991B1B;
  font-size: 13px;
}

.readout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.readout:last-child { border-bottom: none; }
.readout span { color: var(--muted); font-size: 13px; font-weight: 500;}
.readout strong { color: var(--ink); font-size: 15px; font-weight: 600;}

/* Tables (Clients, Assignment) */
.client-controls {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-filter {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
}

.status-filter.active {
  background: var(--accent-soft);
  border-color: rgba(208, 255, 0, 0.3);
  color: var(--accent);
}

.client-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.client-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.client-table th {
  text-align: left;
  padding: 16px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.client-table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

.client-table tr:last-child td { border-bottom: none; }

.client-table tbody tr {
  transition: background 0.15s ease;
  cursor: pointer;
}

.client-table tbody tr:hover { background: var(--surface-2); }
.client-table tbody tr.selected { background: var(--accent-soft); }

.client-name strong { display: block; color: var(--ink); font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.client-name span { color: var(--muted); font-size: 13px; }

.loading-state {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.loading-state strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
  margin-bottom: 4px;
}

.loading-state span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-skeleton {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.loading-skeleton div {
  height: 54px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent),
    var(--surface-2);
  background-size: 220px 100%;
  animation: shimmer 1.15s ease-in-out infinite;
}

.table-loading-cell {
  padding: 0 !important;
}

.table-loading-cell .loading-state {
  border-bottom: 1px solid var(--line);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  0% { background-position: -220px 0; }
  100% { background-position: calc(100% + 220px) 0; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  .loading-skeleton div {
    animation: none;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.badge.active {
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}
.badge.recent { background: rgba(255, 159, 10, 0.1); color: var(--warning); }

.sort-button {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  padding: 0;
  text-transform: inherit;
}
.sort-button:hover { color: var(--ink); box-shadow: none; background: transparent; }

/* Plans & Staff Layout */
.plans-layout, .staff-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
}

.assignment-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.item {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: left;
  display: block;
  width: 100%;
}
.item:hover { background: var(--surface-3); }
.item.selected { background: var(--accent-soft); border-color: rgba(208, 255, 0, 0.3); }
.item strong { color: var(--ink); font-size: 14px; display: block; margin-bottom: 4px; }
.item span { color: var(--muted); font-size: 13px; display: block; }

.section-divider {
  height: 1px;
  background: var(--line);
  margin: 24px 0;
}

/* Builder */
.builder {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 24px;
}

.day-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.day-tab {
  flex: 1;
  border: none;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.day-tab:last-child { border-right: none; }
.day-tab:hover { background: var(--surface-3); box-shadow: none; }
.day-tab.active { background: var(--accent-soft); color: var(--accent); }

.builder-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  padding: 24px;
}

.day-overview { display: flex; flex-direction: column; gap: 24px; }

.add-exercise-form {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  align-self: start;
}

.exercises-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.exercise-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: all 0.2s ease;
}

.exercise-card:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.exercise-index {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  color: var(--ink);
  border-radius: 50%;
  font-weight: 700;
  font-size: 16px;
}

.exercise-info { flex-grow: 1; }
.exercise-info strong { display: block; font-size: 15px; font-weight: 700; text-transform: uppercase; margin-bottom: 4px; color: var(--ink); }
.exercise-info span { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }

.remove-btn { background: transparent; color: var(--danger); min-height: auto; padding: 8px; font-size: 12px; opacity: 0.6; }
.remove-btn:hover { background: rgba(255, 69, 58, 0.1); color: var(--danger); opacity: 1; box-shadow: none; }

/* Utilities */
.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: min(400px, calc(100vw - 48px));
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
  z-index: 100;
}

.toast.error { border-left-color: var(--danger); }

/* Custom Checkbox */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.mt-16 { margin-top: 16px; width: 100%; }

/* Responsive */
@media (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .plans-layout, .staff-layout { grid-template-columns: 1fr; }
  .builder-layout { grid-template-columns: 1fr; }
  .content-area { padding: 24px; }
}

@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); padding: 16px; }
  .portal-nav { flex-direction: row; overflow-x: auto; }
  .nav-tab { width: auto; white-space: nowrap; }
}

/* ── Chart Grid ────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.chart-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}

.chart-wrap--donut {
  height: 270px;
  display: flex;
  justify-content: center;
  align-items: center;
}

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