/*
 * TopicAce — shared design system.
 * Design tokens, base typography, the app shell (sidebar), and components
 * reused across Today and Course pages. Page-specific rules live in their own
 * stylesheets (marketing.css, today.css, course.css, session.css).
 */

:root {
  /* Oxblood & aged paper — bookbinding red on a quiet warm ground. The accent
     doubles as the urgency hue (due/fading markers), which red carries naturally. */
  --bg: #f8f6f1;
  --surface: #ffffff;
  --surface-2: #f0ebe2;
  --ink: #211b1b;
  --ink-soft: #4a4444;
  --ink-mute: #8a8484;
  --accent: #7d2b38;
  --accent-soft: #f2dfe1;
  --accent-deep: #561d27;
  --good: #5a7d4f;
  --good-soft: #e3ece0;
  --warn: #b8862a;
  --warn-soft: #f3e8cf;
  --cool: #6b7d9a;
  --cool-soft: #e3e8ef;
  --line: #e7e0d3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.06), 0 16px 40px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Iowan Old Style', 'Charter', 'Georgia', serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.sans { font-family: -apple-system, system-ui, sans-serif; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---- Logo ---- */
.logo {
  font-family: -apple-system, system-ui, sans-serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-mark {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 5px;
  position: relative;
}
.logo-mark::after {
  content: '';
  position: absolute;
  inset: 5px;
  background: var(--bg);
  border-radius: 2px;
}

/* ---- App shell ---- */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

aside {
  border-right: 1px solid var(--line);
  padding: 24px 18px;
  background: var(--bg);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 10px;
}
.sidebar-head .logo { margin-bottom: 0; }
.sidebar-head { flex-shrink: 0; }
/* Hamburger is desktop-hidden; the full nav is always shown. */
.nav-toggle { display: none; }
/* The body fills the remaining height; nav scrolls, the user strip stays pinned. */
.sidebar-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sidebar-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.nav-section { margin-bottom: 24px; }
.nav-section-label {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
  padding: 0 10px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 6px;
  margin-bottom: 1px;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  font-weight: 500;
}
.nav-item .ic {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ink-mute);
}
.nav-item.active .ic { color: var(--accent); }
.nav-item.muted { color: var(--ink-mute); }
.nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-mute);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.nav-item.active .nav-count { background: var(--accent-soft); color: var(--accent-deep); }

.user-strip {
  flex-shrink: 0;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.user-strip:hover { background: var(--surface-2); }
.user-strip-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.logout-btn {
  background: none;
  border: none;
  color: var(--ink-mute);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
}
.logout-btn:hover { background: var(--accent-soft); color: var(--accent); }
.avatar {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: -apple-system, system-ui, sans-serif;
  font-weight: 600;
  font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-plan {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  color: var(--ink-mute);
}

/* ---- Main column ---- */
main {
  padding: 36px 44px 80px;
  max-width: 960px;
  width: 100%;
  min-width: 0; /* let the grid column shrink instead of overflowing on narrow screens */
}

/* ---- Buttons ---- */
.btn {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  border: none;
  text-decoration: none;
  display: inline-block;
}
.btn-primary { background: var(--ink); color: white; }
.btn-primary:hover { background: #000; }
.btn-ghost { background: white; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-secondary { background: white; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: white; color: var(--accent-deep); border: 1px solid var(--accent-soft); }
.btn-danger:hover { background: var(--accent-soft); }

/* ---- Section headings ---- */
.section { margin-bottom: 40px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}
.section-head h2, .section-head h3 {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.section-head .meta-link, .section-head .see-all {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink-mute);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
.section-head .meta-link:hover, .section-head .see-all:hover { color: var(--ink); }

/* ---- Forms (shared: course/concept authoring, account) ---- */
.form-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 36px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  max-width: 560px;
}
.form-card h1 { font-size: 28px; font-weight: 500; letter-spacing: -0.015em; margin-bottom: 6px; }
.form-card .form-sub { font-size: 15px; color: var(--ink-soft); margin-bottom: 24px; line-height: 1.5; }
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 12px 14px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); background: white; box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.form-errors {
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 20px; font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px; color: var(--accent-deep);
}
.form-errors ul { margin: 0; padding-left: 18px; }
@media (max-width: 880px) { .field-row { grid-template-columns: 1fr; } }

/* ---- Plan options (account) ---- */
.plan-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.plan-option {
  display: block; padding: 16px 18px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); cursor: pointer; transition: all 0.12s;
}
.plan-option:hover { border-color: var(--accent); }
.plan-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.plan-option input { margin-right: 8px; }
.plan-head { display: flex; justify-content: space-between; align-items: baseline; }
.plan-name { font-weight: 500; font-size: 16px; color: var(--ink); }
.plan-price { font-family: -apple-system, system-ui, sans-serif; font-size: 13px; color: var(--ink-mute); }
.plan-desc { font-size: 13px; color: var(--ink-soft); line-height: 1.5; margin-top: 4px; }
.checkbox-label { font-family: -apple-system, system-ui, sans-serif; font-size: 14px; color: var(--ink-soft); text-transform: none; letter-spacing: 0; font-weight: 400; }

/* ---- Natural-language input bar (shared: add date, course, concept, edge) ---- */
.add-date { margin-top: 14px; }
.date-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px 10px 16px; box-shadow: var(--shadow); transition: border-color 0.15s, box-shadow 0.15s;
}
.date-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.date-bar-icon { color: var(--ink-mute); font-size: 18px; line-height: 1; }
.date-bar-input {
  flex: 1; border: none; background: none; outline: none;
  font-family: 'Iowan Old Style', 'Charter', 'Georgia', serif; font-size: 15px; color: var(--ink);
}
.date-bar-input::placeholder { color: var(--ink-mute); font-style: italic; }
.date-bar-btn {
  font-family: -apple-system, system-ui, sans-serif; font-size: 13px; font-weight: 500;
  background: var(--ink); color: white; border: none; border-radius: 6px; padding: 8px 16px; cursor: pointer;
}
.date-bar-btn:hover { background: #000; }
.date-hint { font-family: -apple-system, system-ui, sans-serif; font-size: 12px; color: var(--ink-mute); margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.date-eg {
  font-family: -apple-system, system-ui, sans-serif; font-size: 12px; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 3px 10px; cursor: pointer;
}
.date-eg:hover { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent-soft); }
.date-help {
  margin-top: 10px; padding: 10px 14px; background: var(--warn-soft); border-radius: 8px;
  font-family: -apple-system, system-ui, sans-serif; font-size: 13px; color: var(--warn); font-weight: 500;
}
.manual-entry { margin-top: 20px; }
.manual-entry summary {
  font-family: -apple-system, system-ui, sans-serif; font-size: 13px; color: var(--ink-mute);
  cursor: pointer; list-style: none; padding: 6px 0;
}
.manual-entry summary::-webkit-details-marker { display: none; }
.manual-entry[open] summary { margin-bottom: 12px; color: var(--ink-soft); }

/* ---- Reflection panel (sessions + review) ---- */
.reflection-panel {
  margin-top: 18px;
  padding: 20px 22px;
  background: var(--surface-2);
  border-radius: 12px;
  border-left: 3px solid var(--cool);
}
.reflection-panel.hidden { display: none; }
.reflection-eyebrow {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cool);
  font-weight: 600;
  margin-bottom: 8px;
}
.reflection-prompt { font-size: 16px; color: var(--ink); line-height: 1.5; margin-bottom: 12px; font-style: italic; }
.reflection-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.reflection-meta { font-family: -apple-system, system-ui, sans-serif; font-size: 12px; color: var(--ink-mute); }
.reflection-saved-body { font-size: 14px; color: var(--ink-soft); line-height: 1.5; }

/* ---- Flash messages (shared across layouts) ---- */
.flash {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
}
.flash-notice { background: var(--good-soft); color: var(--good); border: 1px solid var(--good-soft); }
.flash-alert { background: var(--accent-soft); color: var(--accent-deep); border: 1px solid var(--accent-soft); }
.flash-banner { max-width: 1100px; margin: 16px auto 0; padding: 0 28px; }

/* Inline success line for in-place (Turbo Stream) mutations; auto-fades. */
.inline-notice { background: var(--good-soft); color: var(--good); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 8px; animation: inlineNoticeFade 5s ease forwards; }
@keyframes inlineNoticeFade { 0%, 78% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  aside {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 14px 18px;
    background: var(--bg);
  }
  .sidebar-head { margin-bottom: 0; }
  .nav-toggle {
    display: block;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    color: var(--ink-soft);
    padding: 6px 10px;
    border-radius: 6px;
    user-select: none;
  }
  .nav-toggle:hover { background: var(--surface-2); color: var(--ink); }
  /* Collapsed by default on mobile; the menu button reveals it. */
  .sidebar-body { display: none; }
  aside.nav-open .sidebar-body { display: block; margin-top: 14px; }
  .sidebar-scroll { overflow: visible; min-height: 0; }
  .user-strip { margin-top: 12px; }
  main { padding: 24px 22px 60px; }
}

/* ---- Global learner tools: selection toolbar + command palette ------------- */

/* The `display` rules below outrank the UA [hidden] rule (class beats bare attribute
   selector), so restore hiding explicitly — otherwise the overlay paints full-screen
   even while hidden. */
.sel-tools[hidden], .cmdk[hidden] { display: none !important; }

/* Selection toolbar — floats over a text selection anywhere in the app. */
.sel-tools {
  position: absolute;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-family: -apple-system, system-ui, sans-serif;
  animation: selToolsIn 0.12s ease-out;
}
@keyframes selToolsIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
.sel-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
}
.sel-tool:hover { background: var(--surface-2); color: var(--accent-deep); }
.sel-tool-ic { font-size: 13px; color: var(--ink-mute); }
.sel-tool:hover .sel-tool-ic { color: var(--accent); }
.sel-tool-status { display: none; padding: 0 10px; font-size: 13px; font-weight: 500; color: var(--accent-deep); }
/* While a save is in flight / confirmed, swap the buttons for the status line. */
.sel-tools.is-status .sel-tool { display: none; }
.sel-tools.is-status .sel-tool-status { display: inline; }

/* Command palette — Cmd/Ctrl-K overlay. */
.cmdk {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(26, 26, 26, 0.28);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
  animation: cmdkFade 0.12s ease-out;
}
@keyframes cmdkFade { from { opacity: 0; } to { opacity: 1; } }
.cmdk-panel {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  font-family: -apple-system, system-ui, sans-serif;
}
.cmdk-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 16px 18px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
.cmdk-input::placeholder { color: var(--ink-mute); }
.cmdk-results { list-style: none; margin: 0; padding: 6px; max-height: 46vh; overflow-y: auto; }
.cmdk-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.cmdk-row.is-active { background: var(--surface-2); }
.cmdk-row-label { font-size: 14px; color: var(--ink); font-weight: 500; }
.cmdk-row-sub { font-size: 12px; color: var(--ink-mute); white-space: nowrap; }
.cmdk-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-mute);
}
.cmdk-hint kbd {
  font-family: inherit;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 3px;
  font-size: 11px;
}
.cmdk-hint-capture { color: var(--accent-deep); font-weight: 500; }
