/* Planning Cnam - no external resources (CSP 'self' only). Course colours come from data via --c. */

:root {
  --bg: #E8EDF1;
  --surface: #F8FAFB;
  --field: #FFFFFF;
  --ink: #18232E;
  --muted: #5B6875;
  --line: #D3DBE2;
  --line-strong: #B6C2CC;
  --exam: #F0BE2C;
  --stripe: #18232E;
  --focus: #1F5FD6;
  --focus-ring: rgb(31 95 214 / 0.22);
  --danger: #B3261E;
  --shadow-pop: 0 14px 36px rgb(24 35 46 / 0.16), 0 2px 6px rgb(24 35 46 / 0.08);
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 8px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171E;
    --surface: #18212A;
    --field: #0E151C;
    --ink: #E4EBF1;
    --muted: #93A1AE;
    --line: #2B3742;
    --line-strong: #3B4956;
    --exam: #E8B828;
    --focus: #7FA8FF;
    --focus-ring: rgb(127 168 255 / 0.3);
    --danger: #FF8A80;
    --shadow-pop: 0 14px 36px rgb(0 0 0 / 0.45), 0 2px 6px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { -webkit-appearance: none; appearance: none; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }

.app {
  max-width: 34rem;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* ---------- header ---------- */

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; margin-bottom: 8px; }
.app.is-login .top, .app.is-login .foot { display: none; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; }
.brand-text { display: grid; min-width: 0; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.brand-sub { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* app mark: the two half-day bars */
.mark { display: grid; align-content: center; gap: 3px; flex: none; width: 32px; height: 32px; padding: 0 7px; border-radius: 9px; background: #18232E; box-shadow: inset 0 0 0 1px var(--line); }
.mark span { height: 5px; border-radius: 3px; background: #2496AA; }
.mark span + span { background: var(--exam); }
.mark-lg { width: 56px; height: 56px; gap: 6px; padding: 0 12px; border-radius: 15px; }
.mark-lg span { height: 9px; border-radius: 5px; }

/* account menu */
.account { position: relative; flex: none; }
.account-btn {
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 4px 10px 4px 4px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  cursor: pointer;
}
.account-btn[aria-expanded="true"] { border-color: var(--line-strong); }
.account-btn .chevron { width: 16px; height: 16px; color: var(--muted); transition: transform 150ms ease; }
.account-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.account-name { font-size: 0.875rem; font-weight: 600; max-width: 9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: var(--bg);
  font-family: var(--font-display); font-weight: 700; font-size: 0.9375rem;
}
.avatar.is-admin { background: var(--exam); color: #18232E; }

.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  min-width: 15rem; padding: 6px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-pop);
  transform-origin: top right;
  animation: pop 120ms ease-out;
}
.menu-head { padding: 10px 12px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.menu-name { margin: 0; font-weight: 600; }
.menu-role { margin: 0; font-size: 0.8125rem; color: var(--muted); }
.menu-item {
  display: block; width: 100%; min-height: 44px; padding: 10px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent;
  text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); outline: none; }
.menu-item.danger { color: var(--danger); }

@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(-4px); } }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 0.9375rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: progress; transform: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 4px 12px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--ink);
  font-size: 0.8125rem; font-weight: 500; cursor: pointer;
}

.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--bg); color: var(--ink); cursor: pointer;
}

.link-btn {
  padding: 0; border: 0; background: none; color: var(--ink);
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn.strong { font-weight: 600; text-decoration-color: currentColor; }

/* ---------- forms (reset native looks, iOS included) ---------- */

.form { display: grid; gap: 16px; }
.form-body, .form-group { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > label { font-size: 0.875rem; font-weight: 600; }

.field input, .field textarea, .field select {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--field);
  color: var(--ink);
  font-size: 16px; /* below 16px iOS zooms on focus */
  line-height: 1.3;
  box-shadow: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field textarea { min-height: 76px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: 0.8; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 4px var(--focus-ring);
}
.field input:disabled, .field select:disabled { color: var(--muted); background: var(--bg); }

.field input[type="number"] { -moz-appearance: textfield; }
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.field input[type="color"] { padding: 5px; cursor: pointer; }
.field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 8px; }

/* select with a CSS chevron */
.select { position: relative; }
.select select { padding-right: 42px; cursor: pointer; }
.select::after {
  content: ""; position: absolute; right: 18px; top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); pointer-events: none;
}

/* password with show/hide */
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 44px; height: 40px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--ink); }

/* switch */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--field);
}
.switch-label { display: grid; gap: 2px; font-weight: 600; font-size: 0.9375rem; cursor: pointer; }
.switch-label .hint { font-weight: 400; }
.switch-row input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  position: relative; flex: none; width: 46px; height: 28px; margin: 0;
  border-radius: 999px; background: var(--line-strong); cursor: pointer;
  transition: background-color 150ms ease;
}
.switch-row input[type="checkbox"]::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 150ms ease;
}
.switch-row input[type="checkbox"]:checked { background: var(--ink); }
.switch-row input[type="checkbox"]:checked::before { transform: translateX(18px); }
@media (prefers-color-scheme: dark) {
  .switch-row input[type="checkbox"]:checked { background: var(--focus); }
}

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { margin: 0; font-size: 0.8125rem; color: var(--muted); }
.form-error {
  margin: 0; padding: 10px 14px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); font-size: 0.9375rem;
}
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.form-actions .danger { margin-right: auto; padding-left: 4px; }

/* ---------- dialog: centered card, bottom sheet on phones ---------- */

.dialog {
  width: min(30rem, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  overflow: auto;
}
.dialog[open] { animation: pop 140ms ease-out; }
.dialog::backdrop { background: rgb(16 23 30 / 0.5); }
.dialog .form { padding: 4px 20px 20px; }
.dialog-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 16px 12px 20px; background: var(--surface);
}
.dialog-title { margin: 0; font-family: var(--font-display); font-size: 1.25rem; line-height: 1.2; }
.dialog-title::first-letter { text-transform: uppercase; }

@media (max-width: 40rem) {
  .dialog {
    width: 100%; max-width: 100%;
    margin: auto 0 0;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
  .dialog[open] { animation: sheet 200ms ease-out; }
  .dialog .form { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .form-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .form-actions .danger { grid-column: 1 / -1; order: 3; margin: 0; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

/* ---------- boot screen (before the app renders, or if it fails to start) ---------- */

.boot { display: grid; justify-items: center; gap: 14px; margin: 28vh auto 0; max-width: 22rem; text-align: center; }
.boot-msg { margin: 0; color: var(--muted); }
.boot .btn { display: none; }
.boot.is-failed .boot-msg { color: var(--ink); }
.boot.is-failed .btn { display: inline-flex; }

/* ---------- login ---------- */

.login { display: grid; place-items: center; min-height: calc(100dvh - 48px); padding: 24px 0; }
.login-card {
  display: grid; gap: 12px; width: 100%; max-width: 24rem;
  padding: 28px 24px 24px;
  border: 1px solid var(--line); border-radius: 24px; background: var(--surface);
}
.login-title { margin: 10px 0 0; font-family: var(--font-display); font-size: 1.875rem; line-height: 1.1; }
.login-title::first-letter { text-transform: none; }
.login-lead { margin: 0 0 8px; color: var(--muted); }
.login-card .form { gap: 14px; }
.login-links {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px;
  margin-top: 6px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 0.9375rem;
}

/* ---------- week strip: two bars per day, one per half-day ---------- */

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 4px 0 20px; }
.wd {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 44px; padding: 8px 0 7px;
  border: 0; border-radius: var(--r-md); background: transparent; cursor: pointer;
}
.wd-name { font-size: 0.75rem; color: var(--muted); }
.wd-num { font-family: var(--font-display); font-size: 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.wd-bars { display: grid; gap: 2px; width: 22px; margin-top: 2px; }
.wd-bar { height: 4px; border-radius: 2px; background: var(--line); }
.wd-bar.on { background: var(--c); }
.wd-bar.exam { background: repeating-linear-gradient(-45deg, var(--exam) 0 3px, var(--stripe) 3px 5px); }
.wd.is-today .wd-num { color: var(--focus); }
.wd.is-selected { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.wd.is-off .wd-num { color: var(--muted); font-weight: 400; }

/* ---------- day header ---------- */

.dayhead { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; margin-bottom: 16px; }
.dayhead-text { min-width: 0; }
h1 { margin: 0; font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
h1::first-letter { text-transform: uppercase; }
.rel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 4px 0 0; min-height: 1.3em; font-size: 0.875rem; color: var(--muted); }
.arrow {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface); cursor: pointer;
}

/* ---------- day content ---------- */

.day { display: grid; gap: 12px; }
.banner { margin: 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); font-size: 0.9375rem; }

.slot {
  position: relative; display: grid; gap: 2px;
  padding: 14px 16px 16px 22px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  overflow: hidden;
}
.slot::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 7px; background: var(--c, var(--line)); }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; margin-bottom: 4px; }
.slot-time { margin: 0; font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.slot-code {
  margin: 0;
  font-family: var(--font-display); font-size: 2.5rem; font-weight: 700;
  line-height: 1.05; letter-spacing: -0.015em;
  color: var(--c-text, var(--ink));
  overflow-wrap: anywhere;
}
.slot.event .slot-code { font-size: 1.625rem; line-height: 1.15; }
.slot-title { margin: 4px 0 0; font-size: 1.0625rem; font-weight: 500; max-width: 36ch; }
.slot-teacher { margin: 2px 0 0; color: var(--muted); }
.slot-note { margin: 10px 0 0; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 0.9375rem; }

.slot.exam::before { width: 10px; background: repeating-linear-gradient(-45deg, var(--exam) 0 6px, var(--stripe) 6px 10px); }
.badge { justify-self: start; margin: 0 0 6px; padding: 2px 10px; border-radius: 999px; background: var(--exam); color: #18232E; font-size: 0.8125rem; font-weight: 700; }

.slot.empty { padding-left: 16px; background: transparent; border-style: dashed; border-color: var(--line-strong); }
.slot.empty::before { display: none; }
.slot-empty-text { margin: 0; color: var(--muted); }
.day > .btn { justify-self: start; }
.day-tools { display: flex; justify-content: flex-end; }

.slot[data-ue] { --c-text: var(--c); }
@media (prefers-color-scheme: dark) {
  .slot[data-ue], .code { --c-text: color-mix(in srgb, var(--c) 62%, white); }
}

/* ---------- admin ---------- */

.back {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; margin-left: -6px; padding: 4px 10px 4px 6px;
  border-radius: 999px; color: var(--muted); font-size: 0.9375rem; text-decoration: none;
}
.back:hover { color: var(--ink); background: var(--surface); }
.page-title { margin: 4px 0 16px; }

.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  margin-bottom: 20px; padding: 3px;
  border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line);
}
.segment {
  display: grid; place-items: center; min-height: 40px; padding: 6px 4px;
  border-radius: 9px; color: var(--muted);
  font-size: 0.875rem; font-weight: 600; text-decoration: none; text-align: center;
}
.segment[aria-current="page"] { background: var(--ink); color: var(--bg); }

.panel { display: grid; gap: 12px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 8px; }
.section-head:first-child { margin-top: 0; }
.section-title { margin: 0; font-family: var(--font-display); font-size: 1.125rem; }
.section-sub { margin: 2px 0 0; font-size: 0.875rem; color: var(--muted); }

.list {
  list-style: none; margin: 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  overflow: hidden;
}
.list > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 12px 14px;
  border: 0; background: transparent; text-align: left; cursor: pointer;
}
.row:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.row:focus-visible { outline-offset: -3px; }
.row-main { display: grid; flex: 1; min-width: 0; gap: 2px; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { margin: 0; font-size: 0.8125rem; color: var(--muted); overflow-wrap: anywhere; }
.chevron-right { width: 18px; height: 18px; color: var(--muted); }
.swatch { flex: none; width: 6px; align-self: stretch; min-height: 36px; border-radius: 3px; background: var(--c); }
.code { --c-text: var(--c); color: var(--c-text); font-family: var(--font-display); }
.tag {
  display: inline-block; margin-left: 8px; padding: 1px 8px; vertical-align: 1px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 0.75rem; font-weight: 500; color: var(--muted);
}
.tag.accent { border-color: var(--exam); color: var(--ink); background: color-mix(in srgb, var(--exam) 22%, transparent); }

.log-item { display: grid; grid-template-columns: 5.5rem 1fr; gap: 12px; padding: 10px 14px; }
.log-time { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.log-main { min-width: 0; }
.log-action { margin: 0; font-weight: 600; font-size: 0.9375rem; }
.log-item.is-fail .log-action { color: var(--danger); }

.card { display: grid; gap: 12px; justify-items: start; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.card p { margin: 0; }
.code-block {
  justify-self: stretch; margin: 0; padding: 12px 14px;
  border-radius: var(--r-md); background: var(--bg);
  font-family: var(--font-mono); font-size: 0.8125rem; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---------- footer ---------- */

.foot { display: grid; gap: 6px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.next-exam, .muted-line { margin: 0; font-size: 0.875rem; color: var(--muted); }

.noscript { padding: 16px; text-align: center; }

/* One orchestrated motion: the day slides in the direction you moved */
.day.from-right { animation: from-right 180ms ease-out; }
.day.from-left { animation: from-left 180ms ease-out; }
@keyframes from-right { from { opacity: 0; transform: translateX(18px); } }
@keyframes from-left { from { opacity: 0; transform: translateX(-18px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 26rem) {
  .account-name { display: none; }
}

@media (min-width: 40rem) {
  .app { padding-top: 28px; }
  h1 { font-size: 2.125rem; }
  .slot-code { font-size: 3rem; }
}
