:root {
  color-scheme: dark;
  --agoge-bg: #04111d;
  --agoge-bg-elevated: #071a2a;
  --agoge-surface: #0b2235;
  --agoge-surface-raised: #102c43;
  --agoge-surface-hover: #163a56;
  --agoge-border: #284b63;
  --agoge-border-strong: #47738f;
  --agoge-text: #f7f9fb;
  --agoge-text-muted: #bdccd7;
  --agoge-primary: #317db5;
  --agoge-primary-hover: #3f91ca;
  --agoge-accent: #f0b35a;
  --agoge-accent-soft: #3b2d1c;
  --agoge-success: #72d3a3;
  --agoge-warning: #f3c76d;
  --agoge-danger: #ff8e8e;
  --agoge-radius-sm: 8px;
  --agoge-radius-md: 14px;
  --agoge-radius-lg: 20px;
  --agoge-shadow-sm: 0 8px 24px rgb(0 0 0 / 18%);
  --agoge-shadow-lg: 0 24px 64px rgb(0 0 0 / 28%);
  --agoge-patina-a: 18% 24%;
  --agoge-patina-b: 82% 71%;
  --agoge-patina-c: 54% 43%;
  --agoge-microtexture:
    radial-gradient(ellipse at var(--agoge-patina-a), rgb(190 132 67 / 4.2%) 0, transparent 27%),
    radial-gradient(ellipse at var(--agoge-patina-b), rgb(2 10 17 / 8%) 0, transparent 31%),
    radial-gradient(ellipse at var(--agoge-patina-c), transparent 0 18%, rgb(240 179 90 / 1.8%) 37%, transparent 62%);
}

html { background: var(--agoge-bg); }

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 85% -10%, rgb(49 125 181 / 18%), transparent 34rem),
    radial-gradient(circle at 15% 105%, rgb(240 179 90 / 9%), transparent 32rem),
    var(--agoge-bg);
  color: var(--agoge-text);
  font-feature-settings: "kern";
  text-rendering: optimizeLegibility;
}

.app { min-height: 100svh; }

aside {
  position: sticky;
  top: 0;
  height: 100svh;
  border-right: 1px solid rgb(71 115 143 / 45%);
  background: linear-gradient(180deg, rgb(7 26 42 / 98%), rgb(4 17 29 / 96%));
  box-shadow: 12px 0 36px rgb(0 0 0 / 14%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 4px 4px 26px;
  color: var(--agoge-accent);
  text-shadow: 0 0 28px rgb(240 179 90 / 20%);
}

.brand img {
  flex: 0 0 46px;
  border-radius: 12px;
  filter: drop-shadow(0 7px 16px rgb(0 0 0 / 24%));
}

.brand-copy {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.brand-copy span {
  font-size: 1.32rem;
  font-weight: 850;
  line-height: 1;
  letter-spacing: .14em;
}

.brand-copy small {
  color: var(--agoge-text-muted);
  font-size: .58rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .17em;
  white-space: nowrap;
}

nav { gap: 8px; }

.nav-btn {
  position: relative;
  min-height: 44px;
  padding: 7px 11px;
  border-color: transparent;
  font-size: .9rem;
  font-weight: 650;
  letter-spacing: .01em;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.nav-btn::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 10px;
  border: 1px solid currentColor;
  border-radius: 50%;
  vertical-align: .08em;
  opacity: .55;
}

.nav-btn[aria-current="page"] {
  border-color: rgb(71 115 143 / 55%);
  background: linear-gradient(90deg, rgb(49 125 181 / 28%), rgb(16 44 67 / 80%));
  box-shadow: inset 3px 0 0 var(--agoge-accent);
}

.nav-btn[aria-current="page"]::before {
  border-color: var(--agoge-accent);
  background: var(--agoge-accent);
  box-shadow: 0 0 10px rgb(240 179 90 / 55%);
  opacity: 1;
}

main { padding: clamp(18px, 3vw, 42px); }

.navigation-toolbar {
  position: sticky;
  top: 12px;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 14px auto;
  padding: 7px;
  border: 1px solid rgb(240 179 90 / 27%);
  border-radius: var(--agoge-radius-md);
  background: rgb(7 26 42 / 92%);
  box-shadow: 0 10px 28px rgb(0 0 0 / 24%);
  backdrop-filter: blur(14px);
}

.navigation-toolbar .compact-action {
  min-width: 5.75rem;
  box-shadow: none;
}

.view-picker {
  display: grid;
  grid-template-columns: auto minmax(9rem, 13rem);
  align-items: center;
  gap: 8px;
}

.view-picker label {
  margin: 0;
  color: var(--agoge-text-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .09em;
}

.view-picker select {
  min-height: 44px;
  padding-block: 7px;
}

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin-bottom: clamp(20px, 3vw, 34px);
  padding: clamp(16px, 2.4vw, 26px);
  border: 1px solid rgb(71 115 143 / 42%);
  border-radius: var(--agoge-radius-lg);
  background-color: rgb(7 26 42 / 92%);
  background-image: var(--agoge-microtexture), linear-gradient(135deg, rgb(16 44 67 / 92%), rgb(7 26 42 / 84%));
  background-size: 100% 100%, 100% 100%, 100% 100%, auto;
  background-repeat: no-repeat;
  box-shadow: var(--agoge-shadow-sm);
}

.page-heading { min-width: 0; }

.page-heading > .muted { margin: 0; }

.status-cluster {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: min(36rem, 100%);
}

.auth-controls {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
  padding-top: 13px;
  border-top: 1px solid rgb(240 179 90 / 14%);
}

.auth-controls #authStatus {
  margin-right: auto;
  overflow-wrap: anywhere;
}

.top h1 {
  margin: 3px 0 0;
  font-size: clamp(1.75rem, 4vw, 2.55rem);
  line-height: 1.1;
  letter-spacing: -.035em;
}

.top .muted {
  color: var(--agoge-accent);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.card {
  border-color: rgb(71 115 143 / 46%);
  border-radius: var(--agoge-radius-lg);
  background-color: rgb(7 26 42 / 96%);
  background-image: var(--agoge-microtexture), linear-gradient(145deg, rgb(11 34 53 / 97%), rgb(7 26 42 / 96%));
  background-size: 100% 100%, 100% 100%, 100% 100%, auto;
  background-repeat: no-repeat;
  box-shadow: var(--agoge-shadow-sm);
}

.dashboard-grid { grid-template-columns: repeat(auto-fit, minmax(min(16.5rem, 100%), 1fr)); }

.quick-action-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 13.5rem;
  overflow: hidden;
}

.quick-action-card:nth-child(2n),
.exercise-card:nth-child(2n),
.phase-card:nth-child(2n),
.feedback-card:nth-child(2n) {
  --agoge-patina-a: 76% 18%;
  --agoge-patina-b: 21% 79%;
  --agoge-patina-c: 39% 58%;
}

.quick-action-card:nth-child(3n),
.exercise-card:nth-child(3n),
.phase-card:nth-child(3n),
.feedback-card:nth-child(3n) {
  --agoge-patina-a: 41% 82%;
  --agoge-patina-b: 88% 37%;
  --agoge-patina-c: 14% 46%;
}

.quick-action-card::after {
  content: "";
  position: absolute;
  top: -28px;
  right: -28px;
  width: 88px;
  height: 88px;
  border: 1px solid rgb(240 179 90 / 16%);
  border-radius: 50%;
  box-shadow: 0 0 0 13px rgb(240 179 90 / 3%);
  pointer-events: none;
}

.quick-action-card .muted { flex: 1; }

.card-kicker {
  margin: 0 0 8px;
  color: var(--agoge-accent);
  font-size: .7rem;
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.card h2 {
  margin-top: 0;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  line-height: 1.25;
  letter-spacing: -.02em;
}

.card h3, .card h4 { line-height: 1.3; }

.muted { color: var(--agoge-text-muted); }

.badge {
  min-height: 32px;
  align-items: center;
  border: 1px solid rgb(71 115 143 / 55%);
  background: rgb(16 44 67 / 88%);
  color: var(--agoge-text);
  font-size: .82rem;
}

#safetyStatus { border-color: rgb(114 211 163 / 42%); }

.badge[data-role]::before,
.badge[data-safety]::before,
#authStatus[data-auth-state]::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--agoge-text-muted);
  box-shadow: 0 0 0 3px rgb(189 204 215 / 10%);
}

.badge[data-role="ADMIN"] { border-color: rgb(240 179 90 / 52%); }
.badge[data-role="ADMIN"]::before { background: var(--agoge-accent); }
.badge[data-role="COACH"]::before { background: #7fc4ee; }
.badge[data-role="PARENT"]::before,
.badge[data-role="SPECIALIST"]::before { background: #b6a8ee; }

.badge[data-safety="clear"] { border-color: rgb(114 211 163 / 62%); color: #dff8eb; }
.badge[data-safety="clear"]::before,
#authStatus[data-auth-state="active"]::before { background: var(--agoge-success); }
.badge[data-safety="review"] { border-color: rgb(243 199 109 / 64%); color: #fff0c9; }
.badge[data-safety="review"]::before { background: var(--agoge-warning); }
.badge[data-safety="blocked"] { border-color: rgb(255 142 142 / 68%); color: #ffe1e1; }
.badge[data-safety="blocked"]::before,
#authStatus[data-auth-state="error"]::before { background: var(--agoge-danger); }

#authStatus[data-auth-state] {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
}

.action {
  width: fit-content;
  min-width: 7.5rem;
  min-height: 44px;
  padding: 8px 13px;
  border-color: #76b5df;
  background: linear-gradient(180deg, var(--agoge-primary-hover), var(--agoge-primary));
  box-shadow: 0 7px 18px rgb(49 125 181 / 24%);
  font-size: .9rem;
  font-weight: 720;
  line-height: 1.2;
  letter-spacing: .005em;
  transition: filter .16s ease, transform .16s ease, box-shadow .16s ease;
}

.action.secondary {
  border-color: var(--agoge-border-strong);
  background: var(--agoge-surface-raised);
  box-shadow: none;
}

.action:not(:disabled):active { transform: translateY(1px); }

button:disabled { box-shadow: none; }

input, select, textarea {
  border-color: var(--agoge-border-strong);
  background: rgb(4 17 29 / 78%);
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

input:hover, select:hover, textarea:hover { border-color: #6190aa; }

input:focus, select:focus, textarea:focus {
  border-color: var(--agoge-accent);
  background: var(--agoge-bg-elevated);
  box-shadow: 0 0 0 4px rgb(240 179 90 / 13%);
}

label { margin-bottom: 5px; color: #e8eef3; font-size: .91rem; }

form > label:not(:first-child) { margin-top: 2px; }

.field {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px 14px;
  padding-top: 4px;
}

.form-span { grid-column: 1 / -1; }

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  min-width: 0;
  padding-top: 3px;
}

form > .action { justify-self: start; }

.auth-controls .action { min-width: auto; }

.session-option .action,
.athlete .action { min-width: 6.5rem; }

#planOut,
#calendarOut,
#generationOut,
#wellbeingOut,
#mediaAdminOut,
#exerciseResults,
#sessionList,
#athletePhaseStates {
  margin-top: 14px;
}

[data-state] {
  position: relative;
  min-height: 44px;
  padding: 11px 13px 11px 40px;
  border: 1px solid var(--agoge-border);
  border-radius: var(--agoge-radius-sm);
  background: rgb(7 26 42 / 76%);
}

[data-state]::before {
  position: absolute;
  top: 10px;
  left: 13px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 900;
}

[data-state="loading"] {
  border-color: rgb(168 215 245 / 44%);
  color: #dceef9;
}

[data-state="loading"]::before { content: "···"; letter-spacing: -2px; }

[data-state="empty"] {
  border-color: rgb(240 179 90 / 34%);
  color: var(--agoge-text-muted);
}

[data-state="empty"]::before { content: "—"; color: var(--agoge-accent); }

[data-state="error"] {
  border-color: rgb(255 142 142 / 62%);
  background: rgb(74 25 31 / 54%);
  color: #ffe1e1;
}

[data-state="error"]::before { content: "!"; color: var(--agoge-danger); }

[data-state="ready"] {
  border-color: rgb(114 211 163 / 42%);
  color: #dff8eb;
}

[data-state="ready"]::before { content: "✓"; color: var(--agoge-success); }

[data-state] > :first-child { margin-top: 0; }
[data-state] > :last-child { margin-bottom: 0; }

[aria-busy="true"] { cursor: progress; }

.block {
  border: 1px solid rgb(71 115 143 / 36%);
  border-left: 4px solid var(--agoge-accent);
  background: linear-gradient(90deg, rgb(59 45 28 / 38%), rgb(13 38 59 / 82%) 34%);
}

#exerciseResults,
#athletePhaseStates,
#feedbackAssignments {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr));
  gap: 13px;
}

#exerciseResults > .muted:first-child,
#exerciseResults > [data-state],
#athletePhaseStates > [data-state],
#feedbackAssignments > [data-state] {
  grid-column: 1 / -1;
}

.exercise-card,
.phase-card,
.feedback-card,
.session-card {
  margin: 0;
  border: 1px solid rgb(240 179 90 / 22%);
  border-left: 3px solid var(--agoge-accent);
  border-radius: var(--agoge-radius-md);
  background-color: rgb(7 26 42 / 88%);
  background-image: var(--agoge-microtexture), linear-gradient(145deg, rgb(13 38 59 / 88%), rgb(7 26 42 / 84%));
  background-size: 100% 100%, 100% 100%, 100% 100%, auto;
  background-repeat: no-repeat;
}

.exercise-card,
.phase-card,
.feedback-card { padding: 15px; }

.exercise-card h3,
.phase-card h3,
.feedback-card legend {
  margin: 0 0 8px;
  color: var(--agoge-text);
  font-size: 1.04rem;
  font-weight: 800;
  letter-spacing: -.01em;
}

.meta-line {
  margin: 0 0 10px;
  font-size: .82rem;
  line-height: 1.45;
}

.exercise-detail {
  margin-top: 11px;
  border-radius: var(--agoge-radius-sm);
}

.exercise-detail:not(:empty) {
  padding: 12px;
  border: 1px solid rgb(71 115 143 / 38%);
  background: rgb(4 17 29 / 48%);
}

.session-card {
  grid-template-columns: minmax(9rem, .45fr) minmax(15rem, 1fr) auto;
  margin-bottom: 9px;
  padding: 12px 13px;
}

.session-card > strong { color: var(--agoge-accent); }

.feedback-card .grid { margin-bottom: 12px; }

.feedback-card > label:not(.check-label) {
  display: grid;
  gap: 5px;
  margin-top: 10px;
}

.athlete, .session-option { border-bottom-color: rgb(71 115 143 / 34%); }

a { color: #a8d7f5; }

::selection { background: var(--agoge-accent); color: #1c1409; }

@media (max-width: 800px) {
  aside {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid rgb(71 115 143 / 45%);
    box-shadow: 0 10px 30px rgb(0 0 0 / 14%);
  }

  .brand { margin: 4px 4px 14px; }
  .brand img { width: 40px; height: 40px; flex-basis: 40px; }
  .brand-copy { display: flex; align-items: baseline; gap: 10px; }

  nav {
    margin-inline: -3px;
    padding-bottom: 7px;
    scrollbar-color: var(--agoge-border-strong) transparent;
  }

  .nav-btn {
    width: auto;
    padding-inline: 10px;
    border-color: rgb(71 115 143 / 26%);
  }

  .action {
    width: fit-content;
    min-width: 7rem;
    max-width: 100%;
  }

  .nav-btn[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--agoge-accent); }

  main { padding: clamp(12px, 3.5vw, 24px); }

  .top { grid-template-columns: minmax(0, 1fr); }
  .status-cluster { justify-content: flex-start; max-width: 100%; }
  .auth-controls { grid-column: 1; flex-wrap: wrap; justify-content: flex-start; }
  .auth-controls #authStatus { flex: 1 1 100%; width: 100%; }

  .navigation-toolbar {
    top: 8px;
    width: 100%;
    margin-left: 0;
  }

  .view-picker {
    grid-template-columns: auto minmax(0, 1fr);
    flex: 1;
  }

  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .session-card { grid-template-columns: minmax(0, 1fr); }
  .form-span, .form-actions { grid-column: 1; }
}

@media (max-width: 380px) {
  .brand-copy { display: grid; gap: 6px; }
  .action { width: fit-content; min-width: 7rem; }
  .status-cluster { align-items: stretch; flex-direction: column; }
  .status-cluster .badge { width: 100%; }
  .auth-controls .action { min-width: 6.5rem; }
  .navigation-toolbar { gap: 7px; padding: 6px; }
  .navigation-toolbar .compact-action { min-width: 4.8rem; padding-inline: 9px; }
  .view-picker { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .view-picker label { display: none; }
  .form-actions { align-items: stretch; flex-direction: column; gap: 8px; }
  .form-actions .action { align-self: flex-start; }
  .top { border-radius: var(--agoge-radius-md); }
  .card { border-radius: var(--agoge-radius-md); }
}

@media (prefers-contrast: more) {
  :root {
    --agoge-border: #7ba3bb;
    --agoge-border-strong: #9fc3d8;
    --agoge-text-muted: #dbe6ed;
    --agoge-microtexture: none, none, none;
  }

  .card, .top, .badge { border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .nav-btn, .action, input, select, textarea { transition: none; }
}
