/* ShiftDesk design system — white surfaces, royal blue bands, purple pill actions.
   Every colour is a token. Light values live on :root; the dark blocks below redefine only the tokens,
   so no component has to know which theme is showing. */

:root {
  --blue: #395cae;
  --blue-dark: #2c4a91;
  --blue-deep: #243d78;
  --blue-50: #eef2fa;
  --blue-100: #dbe4f5;
  --purple: #7e5faa;
  --purple-dark: #664a8f;
  --purple-50: #f4f0fa;
  --purple-100: #e6dcf3;
  --ink-purple: #3d336b;
  --green: #8ac643;
  --green-dark: #4a8c1c;
  --green-text: #3f7a15;
  --green-50: #f0f8e7;
  --green-hover: #3d7716;
  --sky: #6dcff6;
  --sky-50: #e9f8fe;
  --yellow: #fcaf17;
  --yellow-50: #fff5dc;
  --yellow-text: #8a5a00;
  --pink: #f05b72;
  --red: #d63a55;
  --red-dark: #b82a43;
  --red-50: #fdecef;
  --red-text: #b0243d;
  --red-deep: #7d1a2c;

  --ink: #1f2233;
  --text: #3b3f51;
  --muted: #6b7084;
  --faint: #9aa0b1;
  --line: #e3e6ee;
  --line-strong: #cfd4e0;
  --bg: #f4f6fb;
  --card: #ffffff;

  /* Layers on top of a card: sunken table heads, muted input trim, subtle footers, chips. */
  --surface-sunken: #f8f9fc;
  --surface-muted: #f5f6fa;
  --surface-subtle: #fafbfd;
  --chip-bg: #eef0f5;
  --chip-text: #4b5064;
  --card-border: rgba(227, 230, 238, 0.7);
  --overlay: rgba(20, 26, 48, 0.5);
  /* Text that sits on a saturated colour, and the big blue bands themselves. */
  --on-accent: #ffffff;
  --band: #395cae;
  --avatar-ring: #ffffff;
  --alert-warn-text: #6f4a00;
  --alert-warn-line: #f7dc9c;
  --alert-danger-text: #8f1c31;
  --alert-danger-line: #f3c3cc;
  --alert-success-text: #336611;
  --alert-success-line: #cfe7b3;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(22, 32, 64, 0.06);
  --shadow: 0 1px 2px rgba(22, 32, 64, 0.05), 0 6px 20px rgba(22, 32, 64, 0.07);
  --shadow-lg: 0 10px 40px rgba(22, 32, 64, 0.18);
  --focus: 0 0 0 3px rgba(126, 95, 170, 0.35);
  --font: 'Fira Sans', 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
  color-scheme: light;
}

/* The dark palette, written once and applied in the three states a visitor can be in:
   following the device (no attribute on <html>), or having chosen dark here. An explicit
   light choice always wins over a dark device. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --blue: #6f91de;
    --blue-dark: #89a6e8;
    --blue-deep: #c2d1f6;
    --blue-50: #1b2740;
    --blue-100: #253458;
    --purple: #a583d2;
    --purple-dark: #bda2e2;
    --purple-50: #241f39;
    --purple-100: #33294f;
    --ink-purple: #d4c7ec;
    --green: #8ac643;
    --green-dark: #9ed469;
    --green-text: #a2d76c;
    --green-50: #1a2a12;
    --green-hover: #a2d76c;
    --sky: #6dcff6;
    --sky-50: #122834;
    --yellow: #f7b53a;
    --yellow-50: #2c2411;
    --yellow-text: #f0c46a;
    --pink: #f0708a;
    --red: #e4566e;
    --red-dark: #ef7d92;
    --red-50: #2d161b;
    --red-text: #f3a3b0;
    --red-deep: #8d2033;

    --ink: #eef0f7;
    --text: #c9cfdf;
    --muted: #98a0b5;
    --faint: #7c8499;
    --line: #2a3247;
    --line-strong: #3b4560;
    --bg: #10141e;
    --card: #181e2c;

    --surface-sunken: #1f2637;
    --surface-muted: #222a3d;
    --surface-subtle: #1c2231;
    --chip-bg: #262e42;
    --chip-text: #c3c9d9;
    --card-border: rgba(42, 50, 71, 0.9);
    --overlay: rgba(4, 8, 18, 0.66);
    --on-accent: #ffffff;
    --band: #1e2a49;
    --avatar-ring: #181e2c;
    --alert-warn-text: #f0c46a;
    --alert-warn-line: #5c4714;
    --alert-danger-text: #f3a3b0;
    --alert-danger-line: #5e2732;
    --alert-success-text: #a2d76c;
    --alert-success-line: #33501f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
    --focus: 0 0 0 3px rgba(165, 131, 210, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --blue: #6f91de;
  --blue-dark: #89a6e8;
  --blue-deep: #c2d1f6;
  --blue-50: #1b2740;
  --blue-100: #253458;
  --purple: #a583d2;
  --purple-dark: #bda2e2;
  --purple-50: #241f39;
  --purple-100: #33294f;
  --ink-purple: #d4c7ec;
  --green: #8ac643;
  --green-dark: #9ed469;
  --green-text: #a2d76c;
  --green-50: #1a2a12;
  --green-hover: #a2d76c;
  --sky: #6dcff6;
  --sky-50: #122834;
  --yellow: #f7b53a;
  --yellow-50: #2c2411;
  --yellow-text: #f0c46a;
  --pink: #f0708a;
  --red: #e4566e;
  --red-dark: #ef7d92;
  --red-50: #2d161b;
  --red-text: #f3a3b0;
  --red-deep: #8d2033;

  --ink: #eef0f7;
  --text: #c9cfdf;
  --muted: #98a0b5;
  --faint: #7c8499;
  --line: #2a3247;
  --line-strong: #3b4560;
  --bg: #10141e;
  --card: #181e2c;

  --surface-sunken: #1f2637;
  --surface-muted: #222a3d;
  --surface-subtle: #1c2231;
  --chip-bg: #262e42;
  --chip-text: #c3c9d9;
  --card-border: rgba(42, 50, 71, 0.9);
  --overlay: rgba(4, 8, 18, 0.66);
  --on-accent: #ffffff;
  --band: #1e2a49;
  --avatar-ring: #181e2c;
  --alert-warn-text: #f0c46a;
  --alert-warn-line: #5c4714;
  --alert-danger-text: #f3a3b0;
  --alert-danger-line: #5e2732;
  --alert-success-text: #a2d76c;
  --alert-success-line: #33501f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --focus: 0 0 0 3px rgba(165, 131, 210, 0.45);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  color: var(--ink);
  line-height: 1.25;
  margin: 0;
}

p {
  margin: 0 0 0.75rem;
}

a {
  color: var(--purple-dark);
}

img {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- App shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
  flex-shrink: 1;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--blue);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}

.brand-mark.has-logo {
  background: var(--card);
  border: 1px solid var(--line);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.brand-text small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.mainnav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 100%;
  margin-left: 8px;
}

.mainnav a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  color: var(--ink-purple);
  text-decoration: none;
  font-weight: 500;
  font-size: 14.5px;
  border-bottom: 3px solid transparent;
  border-top: 3px solid transparent;
  white-space: nowrap;
}

.mainnav a svg {
  opacity: 0.75;
}

.mainnav a:hover {
  color: var(--purple);
}

.mainnav a.active {
  color: var(--purple-dark);
  border-bottom-color: var(--purple);
  font-weight: 600;
}

.mainnav a.active svg {
  opacity: 1;
}

.account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-name {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.nav-toggle {
  display: none;
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  place-items: center;
  cursor: pointer;
  color: var(--ink-purple);
}

@media (max-width: 1080px) {
  .mainnav a {
    padding: 0 9px;
  }
  .mainnav a svg {
    display: none;
  }
  .account-name {
    display: none;
  }
}

@media (max-width: 860px) {
  .nav-toggle {
    display: grid;
  }
  .mainnav {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    height: auto;
    flex-direction: column;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 8px 12px 12px;
    margin: 0;
  }
  .mainnav.open {
    display: flex;
  }
  .mainnav a {
    padding: 12px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 0 8px 8px 0;
  }
  .mainnav a svg {
    display: inline;
  }
  .mainnav a.active {
    border-left-color: var(--purple);
    background: var(--purple-50);
  }
  .account {
    margin-left: 0;
  }
  .account .btn-label {
    display: none;
  }
}

.hero {
  position: relative;
  overflow: hidden;
  background: var(--band);
  color: var(--on-accent);
  padding: 30px 0 64px;
}

.hero::before,
.hero::after {
  content: '';
  position: absolute;
  pointer-events: none;
}

/* Playful geometric accents in the Kumon spirit. */
.hero::before {
  width: 96px;
  height: 48px;
  right: 24%;
  bottom: 40px;
  border-radius: 96px 96px 0 0;
  background: var(--yellow);
}

.hero::after {
  width: 84px;
  height: 84px;
  right: calc(24% + 130px);
  top: 14px;
  border-radius: 50%;
  border: 13px solid rgba(109, 207, 246, 0.3);
}

@media (max-width: 760px) {
  .hero::before,
  .hero::after {
    display: none;
  }
}

.hero-inner {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.hero h1 {
  color: var(--on-accent);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hero .hero-sub {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.85);
  font-size: 15px;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.page {
  max-width: 1240px;
  margin: -40px auto 0;
  padding: 0 20px 48px;
  position: relative;
  z-index: 2;
}

.page-loading {
  display: grid;
  place-items: center;
  min-height: 240px;
}

/* ---------- Cards & layout ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--card-border);
  min-width: 0;
}

.card + .card {
  margin-top: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.card-header.plain {
  border-bottom: 0;
  padding-bottom: 4px;
}

.card-title {
  font-size: 16.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-sub {
  font-size: 13.5px;
  color: var(--muted);
  margin-top: 2px;
}

.card-body {
  padding: 18px 20px;
}

.card-body.tight {
  padding: 8px 20px;
}

.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 20px;
}

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

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

.grid-main-side {
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
}

@media (max-width: 960px) {
  .grid-2,
  .grid-3,
  .grid-main-side {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stack > * + * {
  margin-top: 20px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 960px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .stats {
    gap: 10px;
  }
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 16px 20px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.stat::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--accent, var(--blue));
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

@media (max-width: 420px) {
  .stat-value {
    font-size: 22px;
  }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--purple);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--purple-dark);
}

.btn-secondary {
  background: var(--card);
  color: var(--purple-dark);
  border-color: var(--purple-100);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--purple);
  background: var(--purple-50);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-purple);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--purple-50);
}

.btn-danger {
  background: var(--red);
  color: var(--on-accent);
}

.btn-danger:hover:not(:disabled) {
  background: var(--red-dark);
}

.btn-danger-outline {
  background: var(--card);
  color: var(--red-text);
  border-color: var(--alert-danger-line);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--red-50);
  border-color: var(--red);
}

.btn-success {
  background: var(--green-dark);
  color: var(--on-accent);
}

.btn-success:hover:not(:disabled) {
  background: var(--green-hover);
}

.btn-on-dark {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.55);
}

.btn-on-dark:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
  border-color: #fff;
}

.btn-light {
  background: var(--card);
  color: var(--blue-dark);
}

.btn-light:hover:not(:disabled) {
  background: var(--blue-50);
}

.btn-sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13.5px;
}

.btn-icon {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.btn-icon.btn-sm {
  width: 32px;
  min-height: 32px;
}

.btn.is-busy {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-busy::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: rgba(255, 255, 255, 0.9) rgba(255, 255, 255, 0.9) rgba(255, 255, 255, 0.9) transparent;
  animation: spin 0.7s linear infinite;
}

.btn-secondary.is-busy::after,
.btn-ghost.is-busy::after,
.btn-light.is-busy::after,
.btn-danger-outline.is-busy::after {
  border-color: var(--purple) var(--purple) var(--purple) transparent;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--purple-dark);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--purple-100);
  border-top-color: var(--purple);
  animation: spin 0.8s linear infinite;
}

/* ---------- Forms ---------- */

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

.form-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid .span-2 {
  grid-column: span 2;
}

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

@media (max-width: 620px) {
  .form-grid,
  .form-grid.cols-3 {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-grid .span-2 {
    grid-column: auto;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field > label,
.field-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.field .req {
  color: var(--red);
  margin-left: 2px;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

.input,
.field input:not([type='checkbox']):not([type='radio']):not([type='file']),
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: var(--focus);
}

.field input:disabled,
/* Shown but not editable here, e.g. a student's name that comes from the CRM. */
.field input[readonly] {
  background: var(--surface-muted);
  color: var(--muted);
  cursor: default;
}

.field select:disabled {
  background: var(--surface-muted);
  color: var(--muted);
}

select.input,
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7084' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.input-affix {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  overflow: hidden;
}

.input-affix:focus-within {
  border-color: var(--purple);
  box-shadow: var(--focus);
}

.field .input-affix input {
  border: 0 !important;
  box-shadow: none !important;
  border-radius: 0;
  min-width: 0;
}

.input-affix span {
  display: grid;
  place-items: center;
  padding: 0 11px;
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 14.5px;
  color: var(--ink);
}

.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--purple);
  flex-shrink: 0;
}

.check .hint {
  display: block;
}

.fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.fieldset + .fieldset {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.fieldset-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--blue);
  margin: 0 0 12px;
}

.day-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.day-picker label {
  position: relative;
}

.day-picker input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.day-picker span {
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 36px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1.5px solid var(--line-strong);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.day-picker input:checked + span {
  background: var(--purple);
  border-color: var(--purple);
  color: var(--on-accent);
}

.day-picker input:focus-visible + span {
  box-shadow: var(--focus);
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-picker label {
  position: relative;
}

.color-picker input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.color-picker span {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--avatar-ring);
  box-shadow: 0 0 0 1.5px var(--line-strong);
  cursor: pointer;
}

.color-picker input:checked + span {
  box-shadow: 0 0 0 2.5px var(--ink);
}

.color-picker input:focus-visible + span {
  box-shadow: 0 0 0 2.5px var(--ink), var(--focus);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

.table th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

/* On a phone, rows of a .stack-sm table become small cards: one cell under another, full width. */
@media (max-width: 640px) {
  .table.stack-sm thead {
    display: none;
  }
  .table.stack-sm,
  .table.stack-sm tbody,
  .table.stack-sm tr,
  .table.stack-sm td {
    display: block;
    width: 100%;
  }
  .table.stack-sm tr {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
  }
  .table.stack-sm tbody tr:last-child {
    border-bottom: 0;
  }
  .table.stack-sm td,
  .table.stack-sm tbody tr:last-child td {
    padding: 3px 0;
    border-bottom: 0;
    white-space: normal !important;
  }
  .table.stack-sm select {
    max-width: none !important;
    width: 100%;
  }
}

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

.table tfoot td {
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-sunken);
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table .nowrap {
  white-space: nowrap;
}

.table .actions {
  text-align: right;
  white-space: nowrap;
}

.table tr.clickable {
  cursor: pointer;
}

.table tr.clickable:hover td {
  background: var(--purple-50);
}

.table tr.subtotal td {
  background: var(--surface-subtle);
  font-weight: 600;
  color: var(--ink);
}

.table tr.day-row td {
  background: var(--blue-50);
  color: var(--blue-deep);
  font-weight: 600;
  font-size: 13.5px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.table tr.is-muted td {
  color: var(--faint);
}

.table-compact td {
  padding: 9px 12px;
}

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.person-name {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-sub {
  font-size: 12.5px;
  color: var(--muted);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--on-accent);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  background: var(--blue);
  letter-spacing: 0.02em;
}

.avatar.sm {
  width: 26px;
  height: 26px;
  font-size: 11px;
}

.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
}

/* ---------- Badges, alerts, empty states ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  background: var(--chip-bg);
  color: var(--chip-text);
  white-space: nowrap;
}

.badge-green {
  background: var(--green-50);
  color: var(--green-text);
}

.badge-yellow {
  background: var(--yellow-50);
  color: var(--yellow-text);
}

.badge-red {
  background: var(--red-50);
  color: var(--red-text);
}

.badge-blue {
  background: var(--blue-50);
  color: var(--blue-dark);
}

.badge-purple {
  background: var(--purple-50);
  color: var(--purple-dark);
}

.badge .pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  background: var(--blue-50);
  color: var(--blue-deep);
  border: 1px solid var(--blue-100);
}

.alert > svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.alert strong {
  color: inherit;
}

.alert-warn {
  background: var(--yellow-50);
  color: var(--alert-warn-text);
  border-color: var(--alert-warn-line);
}

.alert-danger {
  background: var(--red-50);
  color: var(--alert-danger-text);
  border-color: var(--alert-danger-line);
}

.alert-success {
  background: var(--green-50);
  color: var(--alert-success-text);
  border-color: var(--alert-success-line);
}

.alert + .alert,
.alert + .card,
.card + .alert,
.alert-stack {
  margin-top: 14px;
}

.alert-list {
  margin: 4px 0 0;
  padding-left: 18px;
}

.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--muted);
}

.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  background: var(--purple-50);
  color: var(--purple);
}

.empty h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.empty p {
  margin: 0 auto 14px;
  max-width: 420px;
}

/* ---------- Toolbars ---------- */

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

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.period-label {
  font-weight: 700;
  color: var(--ink);
  font-size: 16px;
  min-width: 0;
  padding: 0 4px;
}

.segmented {
  display: inline-flex;
  background: var(--chip-bg);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0 14px;
  min-height: 32px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.segmented button[aria-pressed='true'] {
  background: var(--card);
  color: var(--purple-dark);
  box-shadow: var(--shadow-sm);
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  overflow-x: auto;
}

.tabs button {
  border: 0;
  background: none;
  padding: 14px 12px 12px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.tabs button[aria-selected='true'] {
  color: var(--purple-dark);
  border-bottom-color: var(--purple);
}

/* ---------- Lists ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  border-bottom: 0;
}

.list-main {
  flex: 1;
  min-width: 0;
}

.list-side {
  text-align: right;
  flex-shrink: 0;
}

.meta {
  font-size: 13px;
  color: var(--muted);
}

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

.small {
  font-size: 13px;
}

.strong {
  font-weight: 600;
  color: var(--ink);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.text-right {
  text-align: right;
}

.mt-0 {
  margin-top: 0 !important;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mt-3 {
  margin-top: 24px;
}

.mb-2 {
  margin-bottom: 16px;
}

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

.flex-wrap {
  flex-wrap: wrap;
}

.between {
  justify-content: space-between;
}

@media (max-width: 620px) {
  .hide-sm {
    display: none !important;
  }
}

/* ---------- Modal ---------- */

dialog.modal {
  border: 0;
  padding: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  color: var(--text);
  overflow: hidden;
}

dialog.modal.wide {
  width: min(760px, calc(100vw - 24px));
}

dialog.modal.narrow {
  width: min(420px, calc(100vw - 24px));
}

dialog.modal[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in 0.16s ease-out;
}

/* A browser that freezes animations (a hidden or backgrounded page) must still show the dialog. */
@media (prefers-reduced-motion: reduce) {
  dialog.modal[open] {
    animation: none;
  }
}

dialog.modal::backdrop {
  background: var(--overlay);
}

@keyframes modal-in {
  from {
    transform: translateY(8px);
  }
}

.modal form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Never flex-basis: 0 here. Safari gives the dialog no height at all, so it opens invisible. */
  flex: 1 1 auto;
}

.modal-header,
.modal-footer {
  flex: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-subtle);
  flex-wrap: wrap;
}

.modal-footer .left {
  margin-right: auto;
}

.form-error {
  margin-bottom: 14px;
}

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(420px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--on-accent);
  box-shadow: var(--shadow-lg);
  font-size: 14.5px;
  animation: modal-in 0.2s ease-out;
}

.toast svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-success svg {
  color: var(--green);
}

.toast-error {
  background: var(--red-deep);
}

.toast-warn svg {
  color: var(--yellow);
}

/* ---------- Auth pages ---------- */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background: var(--band);
  position: relative;
  overflow: hidden;
}

.auth-wrap::before {
  content: '';
  position: absolute;
  width: 180px;
  height: 90px;
  border-radius: 180px 180px 0 0;
  background: var(--yellow);
  left: 6%;
  bottom: 0;
}

.auth-wrap::after {
  content: '';
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 26px solid var(--sky);
  opacity: 0.22;
  right: -40px;
  top: 40px;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 28px;
}

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

.auth-card h1 {
  font-size: 24px;
  margin: 14px 0 4px;
}

.auth-card .lead {
  color: var(--muted);
  margin-bottom: 20px;
}

.auth-footer {
  text-align: center;
  margin-top: 18px;
  font-size: 14px;
}

.auth-footer a {
  color: var(--on-accent);
}

/* ---------- Calendar ---------- */

.cal-scroll {
  overflow: auto;
  max-height: 72vh;
  position: relative;
}

.cal {
  display: grid;
  min-width: 720px;
  position: relative;
}

.cal.days-1 {
  min-width: 0;
}

.cal-corner,
.cal-dayhead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.cal-corner {
  left: 0;
  z-index: 4;
}

.cal-dayhead {
  padding: 10px 6px;
  text-align: center;
  border-left: 1px solid var(--line);
  cursor: pointer;
}

.cal-dayhead .dow {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.cal-dayhead .dom {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.cal-dayhead.today .dom {
  background: var(--purple);
  color: var(--on-accent);
}

.cal-dayhead .hrs {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.cal-times {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
}

.cal-time {
  position: relative;
  font-size: 11.5px;
  color: var(--muted);
  text-align: right;
  padding-right: 8px;
}

.cal-time span {
  position: relative;
  top: -8px;
}

.cal-col {
  position: relative;
  border-left: 1px solid var(--line);
  cursor: copy;
}

.cal-col.today {
  background: rgba(126, 95, 170, 0.035);
}

.cal-hour {
  border-top: 1px solid var(--line);
}

.cal-hour.half {
  border-top: 1px dashed var(--chip-bg);
}

.cal-shift {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  border-radius: 8px;
  padding: 4px 7px;
  font-size: 12.5px;
  line-height: 1.25;
  color: var(--on-accent);
  overflow: hidden;
  cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 3px rgba(22, 32, 64, 0.18);
  text-align: left;
  font-family: inherit;
}

.cal-shift:hover {
  filter: brightness(1.06);
  z-index: 2;
}

.cal-shift strong {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-shift span {
  display: block;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-shift.is-past {
  opacity: 0.62;
}

.cal-shift .initials {
  display: none;
  text-align: center;
  letter-spacing: 0.02em;
}

.cal-shift.is-narrow {
  padding: 4px 1px;
}

.cal-shift.is-narrow .full {
  display: none;
}

.cal-shift.is-narrow .initials {
  display: block;
  overflow: visible;
  text-overflow: clip;
}

.cal-now {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--red);
  z-index: 2;
  pointer-events: none;
}

.cal-now::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}

.month {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.month-dow {
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.month-cell {
  min-height: 112px;
  padding: 6px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  cursor: copy;
}

.month-cell:nth-child(7n) {
  border-right: 0;
}

.month-cell.other {
  background: var(--surface-subtle);
}

.month-cell.other .month-date {
  color: var(--faint);
}

.month-date {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0 4px;
}

.month-cell.today .month-date {
  background: var(--purple);
  color: var(--on-accent);
}

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  border: 0;
  background: none;
  padding: 2px 4px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip:hover {
  background: var(--purple-50);
}

.chip .dot {
  width: 8px;
  height: 8px;
}

.chip-more {
  font-size: 12px;
  font-weight: 600;
  color: var(--purple-dark);
  background: none;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
}

@media (max-width: 700px) {
  .month-cell {
    min-height: 74px;
    padding: 3px;
  }
  .chip {
    padding: 1px 2px;
    font-size: 11px;
  }
  .chip .chip-time {
    display: none;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

/* ---------- Misc components ---------- */

.timeline-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  overflow: hidden;
  min-width: 60px;
}

.timeline-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 14.5px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  color: var(--ink);
  font-weight: 500;
}

.logo-preview {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  border: 1.5px dashed var(--line-strong);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-subtle);
  color: var(--faint);
  flex-shrink: 0;
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.error-card {
  text-align: center;
  padding: 40px 20px;
}

.footer-note {
  text-align: center;
  font-size: 12.5px;
  color: var(--faint);
  margin-top: 28px;
}

/* Settings → Texts: one box per moment (start / finish, students / staff). */
.text-rules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 12px;
}
.text-rule {
  margin: 0;
  min-width: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-subtle);
}
.text-rule legend {
  padding: 0 4px;
  font-weight: 600;
  color: var(--ink);
}
.text-rules > .flex {
  grid-column: 1 / -1;
}
