/*
 * Account pages (sign-in, my courses, admin). Built on the courses' "Night
 * clinic" tokens (tokens.css) so moving between a course and its account
 * feels like one product.
 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 900px;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38rem 26rem at 12% 8%, var(--glow-1), transparent 70%),
    radial-gradient(34rem 24rem at 88% 22%, var(--glow-2), transparent 70%);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  line-height: var(--lh-display);
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.gradient-text {
  background: var(--text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--topbar-height);
  padding-inline: var(--gutter);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--brand-gradient);
  color: var(--on-btn);
  font-size: 0.95rem;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-inline-start: auto;
}

.icon-button,
.lang-button {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  padding: 0 var(--s-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}

.icon-button:hover,
.lang-button:hover {
  border-color: var(--accent-line);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- layout */

.page {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: var(--s-6) var(--gutter) var(--s-8);
}

.page-narrow {
  max-width: 980px;
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: calc(100vh - var(--topbar-height));
  padding: var(--s-6) 16px;
}

.card {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s-5);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  padding: var(--s-6) var(--s-5);
}

.auth-card h1 {
  font-size: var(--fs-xl);
  margin-bottom: var(--s-2);
}

.auth-lead {
  color: var(--ink-2);
  margin-bottom: var(--s-5);
}

.auth-alt {
  margin-top: var(--s-5);
  text-align: center;
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px 12px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-bottom: var(--s-3);
}

/* ---------------------------------------------------------------- forms */

.form {
  display: grid;
  gap: var(--s-4);
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-weight: 600;
  font-size: var(--fs-sm);
}

.field-hint {
  color: var(--ink-3);
  font-size: var(--fs-xs);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.input[dir="ltr"] {
  text-align: left;
}

/* Passwords are typed left-to-right in both editions, so the show/hide button sits on the right edge of the field. */
.password-wrap {
  position: relative;
  direction: ltr;
}

.password-wrap .input {
  padding-right: 64px;
}

.password-toggle {
  position: absolute;
  inset-block: 6px;
  right: 6px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--fs-xs);
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--ink);
  background: var(--surface-3);
}

.form-error {
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent);
  border-radius: var(--r-md);
  background: var(--bad-soft);
  color: var(--bad);
  font-size: var(--fs-sm);
}

.form-ok {
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent);
  border-radius: var(--r-md);
  background: var(--ok-soft);
  color: var(--ok);
  font-size: var(--fs-sm);
}

.privacy-note {
  color: var(--ink-3);
  font-size: var(--fs-xs);
  line-height: 1.7;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease);
}

.btn:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-primary {
  border-color: transparent;
  background: var(--brand-gradient);
  color: var(--on-btn);
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  color: var(--on-btn);
  filter: brightness(1.08);
}

.btn-danger {
  border-color: color-mix(in srgb, var(--bad) 50%, transparent);
  color: var(--bad);
}

.btn-danger:hover {
  background: var(--bad-soft);
  color: var(--bad);
  border-color: var(--bad);
}

.btn-sm {
  min-height: 34px;
  padding: 4px 12px;
  font-size: var(--fs-sm);
}

.btn-block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ---------------------------------------------------------------- my courses */

.hello {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-6);
}

.hello h1 {
  font-size: var(--fs-2xl);
}

.hello p {
  color: var(--ink-2);
}

.section-title {
  font-size: var(--fs-lg);
  margin-bottom: var(--s-4);
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-7);
}

.course-card {
  display: grid;
  gap: var(--s-3);
  align-content: start;
  color: var(--ink);
  text-decoration: none;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.course-card:hover {
  color: var(--ink);
  border-color: var(--accent-line);
  transform: translateY(-2px);
}

.course-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.course-head img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
}

.course-head h3 {
  font-size: var(--fs-md);
}

.course-meta {
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.bar {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--brand-gradient);
  min-width: 0;
}

.course-cta {
  font-weight: 600;
  color: var(--accent);
  font-size: var(--fs-sm);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s-4);
}

.settings-grid h3 {
  font-size: var(--fs-md);
  margin-bottom: var(--s-3);
}

/* ---------------------------------------------------------------- admin */

.admin-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.admin-head h1 {
  font-size: var(--fs-xl);
}

.tabs {
  display: flex;
  gap: var(--s-1);
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  background: var(--surface);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: var(--s-5);
}

.tab {
  padding: 6px 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.stat {
  padding: var(--s-4);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th,
.table td {
  padding: 10px 14px;
  text-align: start;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
  white-space: nowrap;
}

.table th {
  color: var(--ink-2);
  font-weight: 600;
  background: var(--surface-2);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr.is-clickable {
  cursor: pointer;
}

.table tbody tr.is-clickable:hover td {
  background: var(--accent-soft);
}

.table .num {
  font-variant-numeric: tabular-nums;
}

.cell-user {
  display: grid;
  line-height: 1.4;
}

.cell-user small {
  color: var(--ink-3);
}

.mini-bars {
  display: flex;
  gap: 4px;
}

.mini-bar {
  width: 26px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.mini-bar > span {
  display: block;
  height: 100%;
  background: var(--brand-gradient);
}

.badge {
  display: inline-block;
  padding: 1px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-2xs);
  font-weight: 600;
  border: 1px solid var(--rule-strong);
  color: var(--ink-2);
}

.badge-admin {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

.badge-disabled {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--bad);
  background: var(--bad-soft);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
  margin-bottom: var(--s-3);
}

.toolbar .input {
  flex: 1 1 240px;
  min-height: 40px;
}

.toolbar select.input {
  flex: 0 0 auto;
  width: auto;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-top: var(--s-3);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.empty {
  padding: var(--s-6);
  text-align: center;
  color: var(--ink-3);
}

.chart {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 120px;
  padding-top: var(--s-2);
}

.chart-bar {
  flex: 1;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.85;
}

.chart-bar.is-zero {
  background: var(--surface-3);
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  color: var(--ink-3);
  font-size: var(--fs-2xs);
  margin-top: 6px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}

.two-col h2 {
  font-size: var(--fs-md);
  margin-bottom: var(--s-3);
}

/* ---------------------------------------------------------------- drawer & dialogs */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgb(2 6 23 / 0.55);
}

.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: 41;
  width: min(520px, 100vw);
  overflow-y: auto;
  padding: var(--s-5);
  background: var(--surface);
  border-inline-start: 1px solid var(--rule);
  box-shadow: var(--shadow-2);
}

.drawer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.drawer-head h2 {
  font-size: var(--fs-lg);
  overflow-wrap: anywhere;
}

.drawer-section {
  border-top: 1px solid var(--rule);
  padding-top: var(--s-4);
  margin-top: var(--s-4);
}

.drawer-section h3 {
  font-size: var(--fs-base);
  margin-bottom: var(--s-3);
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px var(--s-4);
  font-size: var(--fs-sm);
}

.kv dt {
  color: var(--ink-2);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.course-row {
  display: grid;
  gap: 6px;
  padding: var(--s-3) 0;
  border-bottom: 1px dashed var(--rule);
}

.course-row:last-child {
  border-bottom: 0;
}

.course-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.link-box {
  display: grid;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.link-box .input {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.dialog {
  max-width: min(440px, calc(100vw - 32px));
  padding: var(--s-5);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-2);
}

.dialog::backdrop {
  background: rgb(2 6 23 / 0.55);
}

.dialog h2 {
  font-size: var(--fs-lg);
  margin-bottom: var(--s-2);
}

.dialog p {
  color: var(--ink-2);
  margin-bottom: var(--s-4);
}

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: 20px;
  z-index: 60;
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
}

.loading {
  padding: var(--s-7) 0;
  text-align: center;
  color: var(--ink-3);
}

@media (max-width: 640px) {
  .brand-text {
    display: none;
  }

  .hello h1 {
    font-size: var(--fs-xl);
  }

  .auth-card {
    padding: var(--s-5) var(--s-4);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
