/* Account widget, login page, dashboards, and shared UI states.
   Tokens come from /style.css; direction in /DESIGN.md. */

/* ---------- nav widget ---------- */
[data-auth-slot] { display: flex; align-items: center; gap: 8px; }
.auth-link { font-size: .9rem; font-weight: 600; color: var(--ink); text-decoration: none; padding: 6px 10px; }
.auth-link:hover { color: var(--mint-ink); }
.auth-btn {
  font-size: .9rem; font-weight: 700; text-decoration: none;
  background: var(--ink); color: #fff;
  padding: 8px 16px; border-radius: var(--r-s);
  transition: background-color .15s ease;
}
.auth-btn:hover { background: #0e2238; color: #fff; }
.auth-chip {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  border: 1px solid var(--line-strong);
  background: var(--card);
  padding: 3px 12px 3px 3px; border-radius: 999px;
  transition: border-color .15s ease;
}
.auth-chip:hover { border-color: var(--ink); }
.auth-chip__avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: .85rem;
}
.auth-chip__name { font-size: .88rem; font-weight: 600; color: var(--ink); }
.auth-logout {
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--ink-2);
  background: none; border: 1px solid transparent; border-radius: var(--r-s);
  padding: 6px 10px; cursor: pointer;
}
.auth-logout:hover { color: var(--danger); border-color: var(--line); }

/* deck top bar is narrow */
.deck-top [data-auth-slot] { margin-left: 8px; }
.deck-top .auth-link, .deck-top .auth-chip__name { display: none; }
.deck-top .auth-chip { padding: 2px; }
.deck-top .auth-logout { padding: 4px 8px; font-size: .78rem; }

/* ---------- login ---------- */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; background: var(--paper); }
.auth-main {
  flex: 1; display: grid; place-items: center;
  padding: 40px 16px 64px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 32px 28px 26px;
}
.auth-card__title { font-size: 1.6rem; font-weight: 800; color: var(--ink); margin: 0 0 6px; }
.auth-card__sub { font-size: .95rem; color: var(--ink-2); margin: 0 0 24px; }

.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; font-size: .88rem; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.auth-field .opt { color: var(--ink-3); font-weight: 500; }
.auth-field input,
.auth-field select {
  width: 100%;
  padding: 11px 12px; font: inherit; font-size: .95rem; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-field select {
  appearance: none; -webkit-appearance: none;
  padding-right: 36px; cursor: pointer;
  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.5 6 6.5l5-5' fill='none' stroke='%2316324f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.auth-field input::placeholder { color: #8a95a3; }
.auth-field input:hover, .auth-field select:hover { border-color: var(--ink-3); }
.auth-field input:focus, .auth-field select:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(47, 214, 158, .35);
}
.auth-hint { font-size: .82rem; color: var(--ink-3); margin-top: 6px; }

.auth-error {
  background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c1bb;
  border-radius: var(--r-s); padding: 10px 12px; font-size: .9rem; font-weight: 500;
  margin: 0 0 14px;
}
.auth-submit {
  width: 100%; padding: 12px 18px; font: inherit; font-size: 1rem; font-weight: 700;
  background: var(--ink); color: #fff; border: 1px solid var(--ink);
  border-radius: var(--r-s); cursor: pointer;
  transition: background-color .15s ease;
}
.auth-submit:hover:not(:disabled) { background: #0e2238; }
.auth-submit:active:not(:disabled) { background: #0a1a2b; }
.auth-submit:disabled { opacity: .6; cursor: wait; }
.auth-submit--inline { width: auto; }
.auth-submit--danger { background: var(--danger); border-color: var(--danger); }
.auth-submit--danger:hover:not(:disabled) { background: #8f1c13; }
.auth-switch { font-size: .9rem; color: var(--ink-2); margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.auth-switch a { color: var(--mint-ink); font-weight: 600; }

/* secondary action used across dashboards */
.btn-quiet {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: .88rem; font-weight: 600; color: var(--ink);
  background: var(--card); border: 1px solid var(--line-strong);
  border-radius: var(--r-s); padding: 8px 12px; cursor: pointer; text-decoration: none;
  transition: border-color .15s ease, background-color .15s ease;
}
.btn-quiet:hover:not(:disabled) { border-color: var(--ink); }
.btn-quiet:active:not(:disabled) { background: var(--paper-2); }
.btn-quiet:disabled { opacity: .55; cursor: not-allowed; }
.btn-quiet--danger { color: var(--danger); }
.btn-quiet--danger:hover:not(:disabled) { border-color: var(--danger); }

/* ---------- dashboard layout ---------- */
.dash-main { padding: 40px 0 72px; min-height: 80vh; }
.dash-header { margin-bottom: 28px; }
.dash-kicker { font-size: .9rem; font-weight: 600; color: var(--mint-ink); margin: 0 0 4px; }
.dash-header h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 800; color: var(--ink); margin: 0 0 6px; }
.dash-header p { color: var(--ink-2); margin: 0; }
.dash-header__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
.dash-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 22px 24px;
  min-width: 0;
}
.dash-card + .dash-card { margin-top: 20px; }
.dash-grid > .dash-card + .dash-card { margin-top: 0; }
.dash-card h2 { font-size: 1.15rem; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
.dash-card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.dash-card__head h2 { margin: 0; }
.dash-card__desc { color: var(--ink-2); font-size: .93rem; margin: 0 0 16px; max-width: 46rem; }
.dash-empty { color: var(--ink-3); font-size: .93rem; padding: 8px 0; }
.dash-note { font-size: .88rem; color: var(--ink-3); margin-top: 14px; }

/* student: the next step is the focal point */
.dash-next {
  background: var(--ink); color: #fff; border-color: var(--ink);
  padding: 26px 28px;
}
.dash-next h2 { color: #c9f5e4; font-size: .95rem; font-weight: 600; margin-bottom: 8px; }
.dash-next__title { font-size: clamp(1.3rem, 3vw, 1.7rem); font-weight: 800; line-height: 1.25; margin: 0 0 18px; }
.dash-next__title span { color: #9ff0d2; }
.dash-next__msg { color: #dbe5ef; margin: 0; }
.dash-next .btn-next {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--mint); color: var(--ink); font-weight: 800; text-decoration: none;
  padding: 12px 20px; border-radius: var(--r-s);
  transition: background-color .15s ease;
}
.dash-next .btn-next:hover { background: #5ee3b6; }
.dash-next .btn-next:focus-visible { outline-color: #fff; }

.dash-progressbar { height: 10px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.dash-progressbar > div { height: 100%; background: var(--mint); border-radius: 999px; transition: width .4s ease; }

/* top row: next lesson (wide, navy) beside the progress panel */
.dash-top { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 36px; }
@media (min-width: 860px) { .dash-top { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); } }
.dash-top > .dash-card + .dash-card { margin-top: 0; }
.dash-next { display: flex; flex-direction: column; justify-content: center; min-height: 220px; }
.dash-stat h2 { font-size: .95rem; font-weight: 600; color: var(--ink-2); }
.dash-stat__big { font-size: .95rem; color: var(--ink-3); margin: 2px 0 12px; }
.dash-stat__big strong { font-size: 2.6rem; font-weight: 800; color: var(--ink); letter-spacing: -0.03em; line-height: 1; }
.dash-parts { list-style: none; margin-top: 14px; }
.dash-parts li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .9rem; color: var(--ink-2); }
.dash-parts strong { color: var(--ink); font-weight: 700; white-space: nowrap; }

.dash-section__title { font-size: 1.3rem; font-weight: 800; color: var(--ink); margin-bottom: 14px; }

/* 25 lesson tiles; the state changes the tile itself */
.dash-tiles { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.dash-tile {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  height: 100%; min-height: 118px;
  padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-m);
  color: var(--ink); text-decoration: none;
  transition: border-color .15s ease;
}
a.dash-tile:hover { border-color: var(--ink); }
.dash-tile__num { font-family: var(--font-mono); font-size: .82rem; color: var(--ink-3); }
.dash-tile__title { font-weight: 700; font-size: .95rem; line-height: 1.3; }
.dash-tile__state { margin-top: auto; font-size: .78rem; font-weight: 700; color: var(--ink-3); }
.dash-tile.is-done { background: var(--paper); }
.dash-tile.is-done .dash-tile__state { color: var(--mint-ink); }
.dash-tile.is-next { background: var(--mint-soft); border-color: #9fe6c9; }
.dash-tile.is-next .dash-tile__state { color: #0a5c41; }
.dash-tile.is-locked { background: transparent; border-style: dashed; border-color: var(--line-strong); color: var(--ink-3); }
.dash-tile.is-locked .dash-tile__state { color: var(--warn); }
@media (max-width: 640px) {
  .dash-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-tile { min-height: 104px; }
}

/* ---------- teacher ---------- */
.teacher-summary { color: var(--ink-2); }
.teacher-summary strong { color: var(--ink); }
.teacher-sub { display: block; font-size: .84rem; color: var(--ink-3); overflow-wrap: anywhere; }

.dash-section { margin-bottom: 32px; }
.dash-section__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dash-section__head .dash-section__title { margin: 0; }

/* one card per student, plus a dashed "add" tile at the end */
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.student-grid > .dash-empty, .student-grid > .pyc-state { grid-column: 1 / -1; }
.student-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-m);
  min-width: 0;
}
.student-card--skel { height: 220px; }
.student-card__head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.student-card__avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ink); color: #fff; font-weight: 800;
}
.student-card__who { min-width: 0; }
.student-card__name { font-size: 1.08rem; font-weight: 700; color: var(--ink); line-height: 1.25; }
.student-card__count { color: var(--ink-2); font-size: .9rem; }
.student-card__count strong { font-size: 1.6rem; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; margin-right: 2px; }
.student-card__meta { font-size: .84rem; color: var(--ink-3); }
.student-card .teacher-actions { margin-top: auto; padding-top: 4px; }
.student-card--add {
  align-items: center; justify-content: center; gap: 6px;
  min-height: 220px;
  font: inherit; font-weight: 700; color: var(--ink-2);
  background: transparent; border: 1.5px dashed var(--line-strong);
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.student-card--add:hover { border-color: var(--ink); color: var(--ink); }
.student-card__plus { font-size: 2rem; font-weight: 500; line-height: 1; }

.teacher-cells { display: grid; grid-template-columns: repeat(25, minmax(0, 1fr)); gap: 2px; }
.teacher-cell { height: 14px; border-radius: 2px; background: var(--paper-2); border: 1px solid var(--line); }
.teacher-cell.is-done { background: var(--mint); border-color: #1fae7f; }
.teacher-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.teacher-act {
  font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer;
  border-radius: var(--r-s); padding: 6px 10px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
  transition: border-color .15s ease;
}
.teacher-act:hover { border-color: var(--ink); }
.teacher-act--gate { background: var(--ink); color: #fff; border-color: var(--ink); }
.teacher-act--gate:hover { background: #0e2238; }
.teacher-act--del { color: var(--danger); margin-left: auto; }
.teacher-act--del:hover { border-color: var(--danger); }

/* gates panel (wide) beside the add-student panel (narrow) */
.teacher-panels { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 980px) { .teacher-panels { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); } }
.teacher-panels > .dash-card + .dash-card { margin-top: 0; }

/* lesson gates */
.gate-bar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin: 0 0 16px; }
.gate-bar .auth-field { margin: 0; flex: 1 1 240px; max-width: 360px; }
.gate-batch { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.gate-batch[hidden] { display: none; }
.gates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gates-grid > .dash-empty, .gates-grid > .pyc-state { grid-column: 1 / -1; }
.gate-item {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  padding: 10px; background: var(--card);
}
.gate-item--open { border-color: #9fe6c9; background: #f3fcf8; }
.gate-item--closed { border-style: dashed; border-color: var(--line-strong); background: transparent; }
.gate-item__info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.gate-item__num { font-weight: 700; color: var(--ink); font-size: .88rem; }
.gate-item__title { font-size: .8rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gate-toggle {
  font: inherit; font-size: .8rem; font-weight: 700; white-space: nowrap;
  padding: 6px 10px; border-radius: var(--r-s); cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .15s ease, border-color .15s ease;
}
.gate-item--open .gate-toggle { background: var(--mint); color: var(--ink); }
.gate-item--open .gate-toggle:hover:not(:disabled) { background: #5ee3b6; }
.gate-item--closed .gate-toggle { background: var(--card); color: var(--ink-2); border-color: var(--line-strong); }
.gate-item--closed .gate-toggle:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.gate-toggle:disabled { opacity: .6; cursor: wait; }

/* add student panel */
.add-student .auth-field { margin-bottom: 12px; }
.add-student-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.add-student-ok {
  background: var(--mint-soft); border: 1px solid #9fe6c9; color: #0a5c41;
  border-radius: var(--r-s); padding: 12px 14px; font-size: .92rem; margin-top: 14px; line-height: 1.7;
  overflow-wrap: anywhere;
}
.add-student-ok code {
  font-family: var(--font-mono); background: var(--card); border: 1px solid #9fe6c9;
  padding: 1px 6px; border-radius: 4px; font-size: .92em; color: var(--ink);
}

/* modal */
.stu-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; }
.stu-modal[hidden] { display: none; }
.stu-modal__backdrop { position: absolute; inset: 0; background: rgba(15, 29, 46, .5); }
.stu-modal__box {
  position: relative; background: var(--card); border-radius: var(--r-l); padding: 22px;
  width: min(440px, 100%); box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto;
}
.stu-modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stu-modal__head h3 { margin: 0; font-size: 1.2rem; color: var(--ink); }
.stu-modal__x {
  font: inherit; font-size: .88rem; font-weight: 600; color: var(--ink-2);
  background: none; border: 1px solid transparent; border-radius: var(--r-s); padding: 4px 8px; cursor: pointer;
}
.stu-modal__x:hover { border-color: var(--line-strong); color: var(--ink); }
.stu-modal__text { color: var(--ink-2); }
.stu-modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------- shared UI states ---------- */
.pyc-skeleton { background: var(--paper-2); border-radius: var(--r-s); min-height: 16px; }
.pyc-skel-row { height: 44px; margin-bottom: 8px; }

.pyc-spinner {
  display: inline-block; width: 16px; height: 16px; vertical-align: -3px;
  border: 2px solid var(--line-strong); border-top-color: var(--ink);
  border-radius: 50%; animation: pyc-spin .7s linear infinite;
}
@keyframes pyc-spin { 100% { transform: rotate(360deg); } }

.pyc-state { padding: 24px 4px; color: var(--ink-2); font-size: .95rem; }
.pyc-state--error { color: var(--danger); }
.pyc-state__retry { margin-top: 10px; }

#pyc-toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px));
}
.pyc-toast {
  background: var(--ink); color: #fff; border-radius: var(--r-s); padding: 12px 14px;
  box-shadow: var(--shadow-md); font-size: .92rem; font-weight: 500;
  animation: pyc-toast-in .2s ease;
}
.pyc-toast--ok { background: #0a5c41; }
.pyc-toast--err { background: var(--danger); }
.pyc-toast.pyc-toast--out { animation: pyc-toast-out .2s ease forwards; }
@keyframes pyc-toast-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes pyc-toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (max-width: 720px) {
  .dash-card { padding: 18px 16px; }
  .auth-card { padding: 26px 20px 22px; }
  .gate-batch { width: 100%; }
}
