/* AFTERCLASS — design tokens, base styles and core components.
   Dark-first, cyan-amber accent, calm and editorial. */

:root {
  /* Colour system (dark theme) */
  --bg: #0c0e11;
  --bg-elev: #14171c;
  --bg-elev-2: #191d23;
  --bg-elev-3: #20252c;
  --border: #262c34;
  --border-strong: #333b45;
  --text: #e9ebee;
  --text-dim: #9aa3ad;
  --text-faint: #6b7480;
  --accent: #e5a843;
  --accent-hover: #f0b95c;
  --accent-soft: rgba(229, 168, 67, 0.13);
  --accent-ink: #1a1305;
  --danger: #e5605a;
  --danger-soft: rgba(229, 96, 90, 0.14);
  --success: #4fb477;
  --info: #6cb6ff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8375rem;
  --fs-base: 0.9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.3rem;
  --fs-xl: 1.6rem;
  --fs-2xl: 2.1rem;
  --fs-3xl: 3rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;

  /* Radii & structure */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --sidebar-w: 250px;
  --content-max: 720px;
  --bottomnav-h: 62px;
  --topbar-h: 56px;
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #ffffff;
  --bg-elev-3: #eef0f3;
  --border: #e2e5ea;
  --border-strong: #cfd4db;
  --text: #171a1f;
  --text-dim: #5b636d;
  --text-faint: #8a919c;
  --accent-soft: rgba(190, 130, 30, 0.14);
  --accent: #b1791f;
  --accent-hover: #96660f;
  --accent-ink: #ffffff;
  --shadow-md: 0 6px 20px rgba(20, 25, 40, 0.1);
  --shadow-lg: 0 18px 50px rgba(20, 25, 40, 0.16);
}

/* Sophia's warm variant — applied only to her login screen and onboarding. */
[data-variant="sophia"] {
  --bg: #16120f;
  --bg-elev: #221b17;
  --bg-elev-2: #2a221c;
  --border: #3a2f28;
  --border-strong: #4b3d33;
  --text: #f2e9e2;
  --text-dim: #c2b2a6;
  --text-faint: #94837a;
  --accent: #d98a9e;
  --accent-hover: #e7a1b2;
  --accent-soft: rgba(217, 138, 158, 0.15);
  --accent-ink: #2a1118;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  margin: 0 0 var(--sp-3);
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 640;
}
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* --- Buttons -------------------------------------------------------------- */
.btn {
  --btn-bg: var(--bg-elev-3);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.6rem 1.05rem;
  min-height: 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-base);
  font-weight: 560;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease,
    color 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 18px; height: 18px; }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-border: var(--accent);
  font-weight: 640;
}
.btn-primary:hover { --btn-bg: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { --btn-bg: transparent; --btn-border: transparent; color: var(--text-dim); }
.btn-ghost:hover { --btn-bg: var(--bg-elev-2); color: var(--text); }

.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-border: var(--danger); }
.btn-danger:hover { --btn-bg: var(--danger-soft); }

.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.7rem; min-height: 34px; font-size: var(--fs-sm); }

/* --- Forms ---------------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }
.field > label,
.label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 560;
  color: var(--text-dim);
  margin-bottom: var(--sp-2);
}
.input,
.textarea,
select.input {
  width: 100%;
  padding: 0.68rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--fs-base);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.hint { font-size: var(--fs-xs); color: var(--text-faint); }
.field-error { color: var(--danger); font-size: var(--fs-sm); margin-top: var(--sp-2); }

/* --- Cards, surfaces ------------------------------------------------------ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}
.card-flat { background: var(--bg-elev-2); }
.stack > * + * { margin-top: var(--sp-4); }

/* --- Badges & chips ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--bg-elev-3);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-weight: 560;
}
.badge-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

/* --- Avatars -------------------------------------------------------------- */
.avatar {
  --size: 40px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-elev-3);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-weight: 640;
  font-size: calc(var(--size) * 0.4);
  text-transform: uppercase;
  user-select: none;
}
.avatar-lg { --size: 84px; }
.avatar-xl { --size: 116px; }
.avatar-sm { --size: 32px; }

/* --- Icon --------------------------------------------------------------- */
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }

/* --- Toast --------------------------------------------------------------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--sp-4));
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(92vw, 420px);
  pointer-events: none;
}
@media (min-width: 900px) {
  .toast-region { bottom: var(--sp-5); left: auto; right: var(--sp-5); transform: none; }
}
.toast {
  background: var(--bg-elev-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  animation: toast-in 0.22s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Modal --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; padding: 0; animation: fade-in 0.15s ease;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: var(--sp-4); }
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: var(--sp-5);
  padding-bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal { border-radius: var(--radius-lg); padding: var(--sp-5); }
}
.modal h2 { font-size: var(--fs-lg); }
.modal-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-4); flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } }

/* --- Empty & loading states ---------------------------------------------- */
.empty {
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  color: var(--text-dim);
}
.empty .icon { width: 34px; height: 34px; color: var(--text-faint); margin-bottom: var(--sp-3); }
.empty h3 { color: var(--text); }
.skeleton {
  background: linear-gradient(90deg, var(--bg-elev-2) 25%, var(--bg-elev-3) 37%, var(--bg-elev-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
  height: 1em;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Utility -------------------------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.center { text-align: center; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }
.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); }
.pill-tabs { display: flex; gap: var(--sp-1); background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 3px; }
.pill-tabs button {
  border: 0; background: transparent; color: var(--text-dim); cursor: pointer;
  padding: 0.4rem 0.9rem; border-radius: var(--radius-pill); font-size: var(--fs-sm);
  font-weight: 560; min-height: 34px;
}
.pill-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
[data-motion="reduce"] *, [data-motion="reduce"] *::before, [data-motion="reduce"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}
