/* leaf notes — application stylesheet
   Consumes assets/css/leaf-tokens.css. No raw colors here: every value is a token.
   Reference patterns: Notion (persistent sidebar, breadcrumbs, hover-revealed row actions, ⌘K),
   Apple Notes / Bear (class list with previews, focused writing page), Craft (calm centered page). */

/* ── 1. Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  color: var(--color-text-primary);
  background: var(--color-canvas);
  font-family: var(--type-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--leaf-color-sage-200) 34%, transparent), transparent 55%),
    radial-gradient(90% 70% at 100% 100%, color-mix(in srgb, var(--leaf-color-cream-300) 70%, transparent), transparent 60%);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img { max-width: 100%; }
::selection { color: var(--color-action-on-primary); background: var(--color-selection); }

:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

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

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: calc(var(--leaf-z-dialog) + 10);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  color: var(--color-action-on-primary);
  background: var(--color-action-primary);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--motion-fast);
}
.skip-link:focus-visible { transform: translateY(0); }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.i {
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.eyebrow {
  margin: 0;
  color: var(--color-text-faint);
  font-family: var(--type-data);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.kbd {
  display: inline-flex;
  align-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: var(--leaf-radius-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  font-family: var(--type-data);
  font-size: 10.5px;
  line-height: 1;
  white-space: nowrap;
}

/* ── 2. Buttons ────────────────────────────────────────────────────── */
.btn-primary,
.btn-secondary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background-color var(--motion-fast),
    border-color var(--motion-fast),
    color var(--motion-fast),
    box-shadow var(--motion-fast),
    transform var(--leaf-motion-instant) var(--leaf-ease-standard);
}

.btn-primary {
  color: var(--button-primary-fg);
  background: var(--button-primary-bg);
  box-shadow: var(--shadow-hairline);
}
.btn-primary:hover:not(:disabled) { background: var(--button-primary-bg-hover); box-shadow: var(--button-primary-shadow); }

.btn-secondary {
  color: var(--button-secondary-fg);
  border-color: var(--button-secondary-border);
  background: var(--color-surface);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--color-rule-strong); background: var(--color-canvas-soft); box-shadow: var(--shadow-hairline); }

.btn-ghost {
  color: var(--color-text-muted);
  background: transparent;
}
.btn-ghost:hover:not(:disabled) { color: var(--color-text-primary); background: var(--color-hover); }

.btn-danger { color: var(--color-action-danger); }
.btn-danger:hover:not(:disabled) { color: var(--color-action-danger); background: var(--color-action-danger-tint); }

.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-ghost:active:not(:disabled),
.icon-btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled { opacity: .55; }

.btn-primary[aria-busy='true'] { position: relative; color: transparent; }
.btn-primary[aria-busy='true']::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--button-primary-fg) 35%, transparent);
  border-top-color: var(--button-primary-fg);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.btn-lg { min-height: 46px; padding: 0 22px; font-size: 14.5px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  transition: background-color var(--motion-fast), color var(--motion-fast), transform var(--leaf-motion-instant);
}
.icon-btn:hover { color: var(--color-text-primary); background: var(--color-hover); }
.icon-btn[aria-pressed='true'],
#btn-focus-mode[aria-expanded='true'] { color: var(--color-action-primary); background: var(--color-action-primary-tint-strong); }
.icon-btn-sm { width: 26px; height: 26px; border-radius: var(--leaf-radius-xs); }

/* ── 3. Fields ─────────────────────────────────────────────────────── */
.field-input,
.library-sort {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--leaf-radius-md);
  color: var(--color-text-primary);
  background: var(--color-surface);
  font-size: 14px;
  outline: none;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast), background-color var(--motion-fast);
}
.field-input::placeholder { color: var(--color-text-faint); }
.field-input:focus-visible,
.library-sort:focus-visible {
  border-color: var(--color-action-primary);
  box-shadow: 0 0 0 3px var(--color-action-primary-tint-strong);
}
textarea.field-input { padding: 10px 12px; resize: vertical; line-height: 1.5; }

select { color: var(--color-text-primary); background-color: var(--color-surface); }

input[type='checkbox'] { accent-color: var(--color-action-primary); }

/* ── 4. Views & page transitions ───────────────────────────────────── */
.view { display: none; position: relative; z-index: 1; min-width: 0; min-height: 0; }
.view.active { display: flex; flex-direction: column; animation: view-in var(--leaf-motion-page) var(--leaf-ease-arrive) backwards; }

#view-signin.active,
#view-notes.active { position: fixed; inset: 0; height: 100dvh; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(.97); }
  to { opacity: 1; transform: none; }
}
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.8); }
}
@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -20% 0; }
}
@keyframes star-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.32) rotate(-8deg); }
  100% { transform: scale(1); }
}
@keyframes leaf-drift {
  from { opacity: 0; transform: translate3d(0, -18px, 0) rotate(-14deg); }
  to { opacity: var(--leaf-opacity, .18); transform: translate3d(0, 0, 0) rotate(var(--leaf-rotate, 0deg)); }
}
@keyframes flash-ring {
  0% { box-shadow: 0 0 0 0 var(--color-action-primary-tint-strong); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

/* Staggered list entrance; JS sets --i on each row (capped). */
.s-card,
.sess-item,
.ctx-file-card,
.library-session-result,
.sidebar-subject {
  animation: rise-in var(--leaf-motion-slow) var(--leaf-ease-arrive) backwards;
  animation-delay: calc(var(--i, 0) * 26ms);
}

/* ── 5. Brand ──────────────────────────────────────────────────────── */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0;
  border: 0;
  color: var(--color-text-primary);
  background: transparent;
  text-decoration: none;
}
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand-mark-lg { width: 44px; height: 44px; }
.brand-word,
.brand-word-sm {
  color: var(--color-action-primary);
  font-family: var(--type-ui);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.035em;
  white-space: nowrap;
}
.brand-word em,
.brand-word-sm em { font-style: normal; font-weight: 450; color: var(--color-text-primary); }
.brand-lockup-lg .brand-word { font-size: 40px; }

/* ── 6. Sign in ────────────────────────────────────────────────────── */
#view-signin { align-items: center; justify-content: center; padding: 24px; overflow: hidden; }
.signin-art { position: absolute; inset: 0; pointer-events: none; }
.signin-leaf { position: absolute; height: auto; filter: saturate(.7); opacity: var(--leaf-opacity, .18); transform: rotate(var(--leaf-rotate, 0deg)); animation: leaf-drift 1.4s var(--leaf-ease-arrive) backwards; }
.signin-leaf-a { top: 12%; left: 10%; --leaf-rotate: -18deg; --leaf-opacity: .16; }
.signin-leaf-b { right: 12%; bottom: 14%; --leaf-rotate: 24deg; --leaf-opacity: .12; animation-delay: .2s; }

.key-card {
  position: relative;
  width: min(100%, 420px);
  padding: 48px 40px 36px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-dialog);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  box-shadow: var(--shadow-popover);
  text-align: center;
  backdrop-filter: blur(10px);
  animation: dialog-in var(--leaf-motion-page) var(--leaf-ease-arrive) backwards .08s;
}
.key-logo { margin: 0 auto; justify-content: center; }
.key-note { margin: 14px 0 30px; color: var(--color-text-muted); font-family: var(--type-display); font-size: 19px; font-style: italic; }
.signin-google { width: 100%; }
.google-mark .g-red { fill: var(--leaf-color-google-red); }
.google-mark .g-blue { fill: var(--leaf-color-google-blue); }
.google-mark .g-yellow { fill: var(--leaf-color-google-yellow); }
.google-mark .g-green { fill: var(--leaf-color-google-green); }
.google-mark { padding: 2px; border-radius: 50%; background: var(--color-on-dark); box-sizing: content-box; }
.signin-fineprint { margin: 14px 0 26px; color: var(--color-text-faint); font-size: 12.5px; }
.signin-discover {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--motion-fast), gap var(--motion-fast);
}
.signin-discover:hover { color: var(--color-action-primary); gap: 9px; }

/* ── 7. App shell: sidebar + stage ─────────────────────────────────── */
.app-shell {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100dvh;
}

.library-sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 14px 10px 10px;
  overflow-y: auto;
  border-right: 1px solid var(--color-rule);
  background: var(--color-sidebar);
  scrollbar-width: thin;
}

.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 10px; }
.library-brand { padding: 4px; margin: -4px; border-radius: var(--leaf-radius-sm); }
.library-brand:hover { background: var(--color-hover); }
.sidebar-close { display: none; }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  margin: 2px 0 10px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-md);
  color: var(--color-text-faint);
  background: color-mix(in srgb, var(--color-surface) 70%, transparent);
  text-align: left;
  transition: border-color var(--motion-fast), background-color var(--motion-fast), color var(--motion-fast);
}
.sidebar-search span:not(.kbd) { flex: 1; }
.sidebar-search:hover { color: var(--color-text-muted); border-color: var(--color-rule-strong); background: var(--color-surface); }

.library-primary-nav { display: grid; gap: 1px; }

.library-nav-item,
.library-folder-item,
.sidebar-subject {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background-color var(--motion-fast), color var(--motion-fast);
}
.library-nav-item .i,
.library-folder-item .i { color: var(--color-text-faint); transition: color var(--motion-fast); }
.library-nav-item:hover,
.library-folder-item:hover,
.sidebar-subject:hover { color: var(--color-text-primary); background: var(--color-hover); }
.library-nav-item.is-active,
.library-folder-item.is-active,
.sidebar-subject.is-active {
  color: var(--color-text-primary);
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  box-shadow: var(--shadow-hairline);
  font-weight: 600;
}
.library-nav-item.is-active .i,
.library-folder-item.is-active .i { color: var(--color-action-primary); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { color: var(--color-text-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }

.sidebar-section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; margin-top: 16px; }
.library-primary-nav,
.sidebar-subject-list,
.library-folder-list { grid-template-columns: minmax(0, 1fr); }
.library-sidebar > * { min-width: 0; }
.sidebar-section-hd { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 4px 10px; }
.sidebar-section-title {
  margin: 0;
  color: var(--color-text-faint);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
}
.sidebar-section-hd .icon-btn { opacity: 0; transition: opacity var(--motion-fast), background-color var(--motion-fast); }
.sidebar-section:hover .sidebar-section-hd .icon-btn,
.sidebar-section-hd .icon-btn:focus-visible { opacity: 1; }
.sidebar-subject-list,
.library-folder-list { display: grid; gap: 1px; }
.sidebar-subject { min-height: 30px; padding-left: 8px; font-size: 13px; }
.sidebar-subject .subject-icon { width: 20px; height: 20px; font-size: 11px; border-radius: 5px; }
.sidebar-empty { margin: 2px 10px; color: var(--color-text-faint); font-size: 12.5px; }

.library-sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--color-rule); }
.library-profile-menu { position: relative; }
.library-profile-menu summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 8px;
  border-radius: var(--leaf-radius-sm);
  list-style: none;
  cursor: pointer;
  transition: background-color var(--motion-fast);
}
.library-profile-menu summary::-webkit-details-marker { display: none; }
.library-profile-menu summary:hover { background: var(--color-hover); }
.library-profile-avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
  color: var(--color-action-primary);
  background: var(--leaf-tint-forest);
}
.library-profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.library-profile-name { flex: 1; min-width: 0; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.library-profile-chevron { color: var(--color-text-faint); }
.library-profile-panel { position: absolute; right: 0; bottom: calc(100% + 6px); left: 0; transform-origin: bottom center; }

.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--leaf-z-menu);
  background: var(--color-overlay);
  animation: fade-in var(--motion-normal) backwards;
}

.app-stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; outline: none; }
.app-stage > .view.active { flex: 1; min-height: 0; }

/* ── 8. Topbar & breadcrumbs ───────────────────────────────────────── */
.topbar {
  position: relative;
  z-index: var(--leaf-z-sticky);
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-height);
  flex-shrink: 0;
  padding: 0 20px 0 24px;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--color-canvas) 82%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  transition: border-color var(--motion-normal), box-shadow var(--motion-normal);
}
.topbar.is-scrolled { border-bottom-color: var(--color-rule); }
.sidebar-toggle { display: none; }

.crumbs { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.crumb {
  min-width: 0;
  overflow: hidden;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--leaf-radius-xs);
  color: var(--color-text-muted);
  background: transparent;
  font-size: 13.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb-link { flex-shrink: 0; max-width: 40%; transition: background-color var(--motion-fast), color var(--motion-fast); }
.crumb-link:hover { color: var(--color-text-primary); background: var(--color-hover); }
.crumb-current { color: var(--color-text-primary); font-weight: 600; }
.crumb-divider { color: var(--color-text-faint); opacity: .7; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ── 9. Page layout ────────────────────────────────────────────────── */
.page-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-padding-top: 16px; }
.page { width: min(100%, var(--page-max)); margin: 0 auto; padding: 28px 40px 96px; }

.page-hd { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-hd-text { min-width: 0; }
.page-hd-actions { display: flex; gap: 8px; flex-shrink: 0; }
.page-title {
  margin: 0;
  color: var(--color-text-primary);
  font-family: var(--type-display);
  font-size: clamp(34px, 4vw, 46px);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -.02em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.page-sub { margin: 6px 0 0; color: var(--color-text-muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.page-sub:empty { display: none; }

/* Library tools */
.library-tools { display: flex; gap: 10px; margin-bottom: 18px; }
.library-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.library-search .i { position: absolute; left: 13px; color: var(--color-text-faint); pointer-events: none; }
.library-search input {
  width: 100%;
  min-height: 40px;
  padding: 0 14px 0 38px;
  border: 1px solid var(--color-rule-strong);
  border-radius: var(--leaf-radius-md);
  color: var(--color-text-primary);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}
.library-search input::placeholder { color: var(--color-text-faint); }
.library-search input:focus-visible { border-color: var(--color-action-primary); box-shadow: 0 0 0 3px var(--color-action-primary-tint-strong); }
.library-sort { width: auto; min-width: 150px; padding-right: 32px; border-color: var(--color-rule-strong); cursor: pointer; }

/* Subject table */
.subjects-table-head,
.s-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 140px 40px;
  align-items: center;
  gap: 12px;
}
.subjects-table-head {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--color-rule);
  color: var(--color-text-faint);
  font-size: 11.5px;
  font-weight: 600;
}
.subjects-grid { display: grid; }

.s-card {
  position: relative;
  min-height: 60px;
  padding: 0 12px;
  border-bottom: 1px solid var(--color-rule);
  border-radius: 0;
  cursor: pointer;
  transition: background-color var(--motion-fast);
}
.s-card::before {
  content: '';
  position: absolute;
  inset: 3px -6px;
  z-index: -1;
  border-radius: var(--leaf-radius-md);
  background: transparent;
  transition: background-color var(--motion-fast);
}
.s-card:hover::before,
.s-card:focus-within::before { background: color-mix(in srgb, var(--color-surface) 82%, transparent); }
.s-card:has(.s-card-menu[open]) { z-index: 10; }

.s-card-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.s-card-name {
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  color: var(--color-text-primary);
  background: transparent;
  font-family: var(--type-display);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -.005em;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.s-card-name:focus-visible { outline-offset: 4px; border-radius: 2px; }
.s-card-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--leaf-color-gold-600);
}
.s-card-count,
.s-card-last { color: var(--color-text-muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.s-card-text { display: grid; min-width: 0; }
.s-card-meta-mobile { display: none; color: var(--color-text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

.subject-icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--leaf-radius-sm);
  color: var(--leaf-tint-forest-ink);
  background: var(--leaf-tint-forest);
  font-family: var(--type-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.subject-icon[data-tint='1'] { color: var(--leaf-tint-gold-ink); background: var(--leaf-tint-gold); }
.subject-icon[data-tint='2'] { color: var(--leaf-tint-wine-ink); background: var(--leaf-tint-wine); }
.subject-icon[data-tint='3'] { color: var(--leaf-tint-sky-ink); background: var(--leaf-tint-sky); }
.subject-icon[data-tint='4'] { color: var(--leaf-tint-clay-ink); background: var(--leaf-tint-clay); }
.subject-icon[data-tint='5'] { color: var(--leaf-tint-plum-ink); background: var(--leaf-tint-plum); }
.subject-icon.is-folder { color: var(--color-text-muted); background: var(--color-surface-alt); }
.subject-icon-lg { width: 56px; height: 56px; border-radius: var(--leaf-radius-lg); font-size: 30px; }

/* Overflow menus (details/summary) */
.s-card-menu,
.sess-more,
.ctx-more,
.notes-more { position: relative; justify-self: end; }
.s-card-menu > summary,
.sess-more > summary,
.ctx-more > summary {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-faint);
  list-style: none;
  cursor: pointer;
  transition: background-color var(--motion-fast), color var(--motion-fast), opacity var(--motion-fast);
}
.notes-more > summary { list-style: none; }
.s-card-menu > summary::-webkit-details-marker,
.sess-more > summary::-webkit-details-marker,
.ctx-more > summary::-webkit-details-marker,
.notes-more > summary::-webkit-details-marker,
.notes-editor-more > summary::-webkit-details-marker { display: none; }
.s-card-menu > summary:hover,
.sess-more > summary:hover,
.ctx-more > summary:hover,
details[open] > summary { color: var(--color-text-primary); background: var(--color-hover); }

@media (hover: hover) {
  .s-card .s-card-menu > summary,
  .sess-item .sess-more > summary,
  .ctx-file-card .ctx-more > summary,
  .ctx-file-card .ctx-icon-btn { opacity: 0; }
  .s-card:hover .s-card-menu > summary,
  .s-card:focus-within .s-card-menu > summary,
  .s-card-menu[open] > summary,
  .sess-item:hover .sess-more > summary,
  .sess-item:focus-within .sess-more > summary,
  .sess-more[open] > summary,
  .ctx-file-card:hover .ctx-more > summary,
  .ctx-file-card:focus-within .ctx-more > summary,
  .ctx-more[open] > summary,
  .ctx-file-card:hover .ctx-icon-btn,
  .ctx-file-card:focus-within .ctx-icon-btn { opacity: 1; }
}

.popover,
.s-card-menu-panel,
.sess-more-panel,
.ctx-more-panel {
  z-index: var(--leaf-z-menu);
  min-width: 210px;
  padding: 5px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
}
.s-card-menu-panel,
.sess-more-panel,
.ctx-more-panel,
.notes-more-panel { position: absolute; top: calc(100% + 4px); right: 0; transform-origin: top right; }
details[open] > .popover,
details[open] > .s-card-menu-panel,
details[open] > .sess-more-panel,
details[open] > .ctx-more-panel { animation: pop-in var(--motion-fast) var(--leaf-ease-arrive) backwards; }

.menu-item,
.s-card-menu-panel > button,
.sess-more-panel > button,
.ctx-more-panel > button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-primary);
  background: transparent;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  transition: background-color var(--leaf-motion-instant);
}
.menu-item .i,
.s-card-menu-panel > button .i,
.sess-more-panel > button .i,
.ctx-more-panel > button .i { color: var(--color-text-faint); }
.menu-item:hover,
.s-card-menu-panel > button:hover,
.sess-more-panel > button:hover,
.ctx-more-panel > button:hover { background: var(--color-hover); }
.menu-item-danger,
.s-card-del,
.sess-del,
.ctx-del { color: var(--color-action-danger) !important; }
.menu-item-danger .i,
.s-card-del .i,
.sess-del .i,
.ctx-del .i { color: currentColor !important; }
.menu-item-danger:hover,
.s-card-del:hover,
.sess-del:hover,
.ctx-del:hover { background: var(--color-action-danger-tint) !important; }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--color-rule); }
.s-card-folder-label {
  display: grid;
  gap: 4px;
  padding: 6px 10px 8px;
  color: var(--color-text-faint);
  font-size: 11.5px;
  font-weight: 600;
}
.s-card-folder-select { min-height: 32px; padding: 0 8px; border: 1px solid var(--color-rule-strong); border-radius: var(--leaf-radius-sm); font-size: 13px; }

/* Session search results */
.library-session-results { display: none; }
.library-session-results.is-visible { display: grid; gap: 4px; margin-bottom: 22px; animation: fade-in var(--motion-normal) backwards; }
.library-session-results h3 { margin: 0 0 4px; color: var(--color-text-faint); font-size: 11.5px; font-weight: 600; }
.library-session-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 14px;
  padding: 10px 12px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-md);
  background: color-mix(in srgb, var(--color-surface) 70%, transparent);
  text-align: left;
  transition: border-color var(--motion-fast), background-color var(--motion-fast), transform var(--motion-fast);
}
.library-session-result:hover { border-color: var(--color-rule-strong); background: var(--color-surface); }
.library-session-result-title { font-family: var(--type-display); font-size: 17px; font-weight: 500; }
.library-session-result-subject { color: var(--color-action-primary); font-size: 12px; font-weight: 600; justify-self: end; }
.library-session-result-snippet { grid-column: 1 / -1; overflow: hidden; color: var(--color-text-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.library-session-results-empty { margin: 0; color: var(--color-text-faint); font-size: 13px; }

/* Empty states & skeletons */
.empty-state {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 56px 24px;
  text-align: center;
  animation: rise-in var(--leaf-motion-slow) var(--leaf-ease-arrive) backwards;
}
.empty-art {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--leaf-tint-forest) 70%, transparent);
}
.empty-art img { opacity: .75; }
.empty-state.is-compact { padding: 28px 16px; }
.empty-state.is-compact .empty-art { display: none; }
.empty-title { margin: 0; color: var(--color-text-primary); font-family: var(--type-display); font-size: 22px; font-weight: 500; }
.empty-help { max-width: 360px; margin: 0 0 14px; color: var(--color-text-muted); font-size: 13.5px; }

.skeleton-list { display: grid; gap: 8px; }
.skeleton-row {
  display: block;
  height: 64px;
  border-radius: var(--leaf-radius-md);
  background: linear-gradient(90deg, var(--color-surface-alt) 0%, var(--color-surface) 45%, var(--color-surface-alt) 90%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton-row:nth-child(3) { opacity: .7; }
.skeleton-row:nth-child(4) { opacity: .45; }

/* ── 10. Subject view ──────────────────────────────────────────────── */
.subject-hero { display: flex; align-items: center; gap: 18px; margin: 4px 0 30px; }
.subject-hero-text { min-width: 0; }

.subject-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 32px;
}
.subject-classes-panel,
.subject-context-panel { min-width: 0; }

.subject-section-heading,
.ctx-files-shelf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-rule);
}
.subject-section-heading h3,
.shelf-title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .01em;
}
.subject-stat,
.shelf-count { color: var(--color-text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.shelf-title-row { display: flex; align-items: baseline; gap: 8px; }

/* Class rows (Apple Notes style: title, date, preview) */
.sess-list { display: flex; flex-direction: column; gap: 2px; }
.sess-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 10px;
  padding: 12px 10px 12px 6px;
  border-radius: var(--leaf-radius-md);
  cursor: pointer;
  transition: background-color var(--motion-fast);
}
.sess-item:hover,
.sess-item:focus-within { background: color-mix(in srgb, var(--color-surface) 82%, transparent); }
.sess-item.is-selected { background: var(--color-action-primary-tint); }
.sess-item:has(.sess-more[open]) { z-index: 10; }
.sess-item + .sess-item::after {
  content: '';
  position: absolute;
  top: -1px;
  right: 10px;
  left: 38px;
  height: 1px;
  background: var(--color-rule);
  transition: opacity var(--motion-fast);
}
.sess-item:hover::after,
.sess-item:hover + .sess-item::after { opacity: 0; }

.sess-check {
  width: 16px;
  height: 16px;
  margin: 0 0 0 3px;
  cursor: pointer;
  transition: opacity var(--motion-fast);
}
@media (hover: hover) {
  .sess-list:not(.is-selecting) .sess-check { opacity: 0; }
  .sess-item:hover .sess-check,
  .sess-check:focus-visible { opacity: 1; }
}

.sess-info { display: grid; gap: 2px; min-width: 0; }
.sess-open {
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  color: var(--color-text-primary);
  background: transparent;
  font-family: var(--type-display);
  font-size: 18.5px;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sess-date { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-time { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--color-text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.sess-snippet { margin: 0; overflow: hidden; color: var(--color-text-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.sess-snippet:empty { display: none; }

.sess-study-actions { display: flex; align-items: center; }
.sess-study-action {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-faint);
  background: transparent;
  transition: color var(--motion-fast), background-color var(--motion-fast), opacity var(--motion-fast);
}
.sess-study-action:hover { color: var(--leaf-color-gold-600); background: var(--color-hover); }
.sess-favorite.is-active { color: var(--leaf-color-gold-600); }
.sess-favorite.is-active .i { fill: currentColor; }
.sess-favorite.just-toggled .i { animation: star-pop var(--motion-slow) backwards; }
@media (hover: hover) {
  .sess-item .sess-favorite:not(.is-active) { opacity: 0; }
  .sess-item:hover .sess-favorite,
  .sess-item:focus-within .sess-favorite { opacity: 1; }
}
.sess-arrow { display: none; }

.bulk-bar {
  position: sticky;
  top: 8px;
  z-index: 15;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  animation: pop-in var(--motion-normal) var(--leaf-ease-arrive) backwards;
}
.bulk-count { color: var(--color-text-primary); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bulk-acts { display: flex; gap: 2px; }

/* Materials panel */
.subject-context-panel {
  position: sticky;
  top: 8px;
  padding: 16px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--color-surface) 72%, transparent);
  transition: border-color var(--motion-fast), background-color var(--motion-fast), box-shadow var(--motion-fast);
}
.subject-context-panel.is-dragover {
  border-color: var(--color-action-primary);
  background: var(--color-action-primary-tint);
  box-shadow: 0 0 0 4px var(--color-action-primary-tint);
}
.ctx-files-list { display: grid; }
.ctx-files-shelf { margin-bottom: 6px; }
.ctx-files-shelf .btn-ghost { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.ctx-files-grid { display: grid; gap: 2px; }
.ctx-file-card {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 4px 4px 4px 6px;
  border-radius: var(--leaf-radius-sm);
  transition: background-color var(--motion-fast);
}
.ctx-file-card:hover,
.ctx-file-card:focus-within { background: var(--color-hover); }
.ctx-file-card:has(.ctx-more[open]) { z-index: 10; }
.ctx-type-badge {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 36px;
  border-radius: 5px;
  color: var(--leaf-tint-wine-ink);
  background: var(--leaf-tint-wine);
  font-family: var(--type-data);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .02em;
}
.ctx-badge-txt,
.ctx-badge-md { color: var(--leaf-tint-sky-ink); background: var(--leaf-tint-sky); }
.ctx-type-badge[data-transcribe-state='transcribing'] { color: transparent; position: relative; }
.ctx-type-badge[data-transcribe-state='transcribing']::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in srgb, var(--leaf-tint-wine-ink) 30%, transparent);
  border-top-color: var(--leaf-tint-wine-ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.ctx-type-badge[data-transcribe-state='failed'] {
  width: auto;
  padding: 0 6px;
  color: var(--color-action-danger);
  background: var(--color-action-danger-tint);
  cursor: pointer;
  font-family: var(--type-ui);
  font-size: 10.5px;
}
.ctx-file-text { display: grid; min-width: 0; }
.ctx-file-name {
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  color: var(--color-text-primary);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctx-file-name:hover { color: var(--color-action-primary); }
.ctx-file-meta { color: var(--color-text-faint); font-size: 11.5px; }
.ctx-file-actions { display: flex; align-items: center; gap: 0; }
.ctx-icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-faint);
  background: transparent;
  transition: color var(--motion-fast), background-color var(--motion-fast), opacity var(--motion-fast);
}
.ctx-icon-btn:hover { color: var(--color-text-primary); background: var(--color-hover); }
.ctx-more-panel .ctx-icon-btn { opacity: 1; }

.ctx-dropzone {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
  padding: 20px 14px;
  border: 1.5px dashed var(--color-rule-strong);
  border-radius: var(--leaf-radius-lg);
  color: var(--color-text-muted);
  background: transparent;
  font-size: 13px;
  text-align: center;
  transition: border-color var(--motion-fast), background-color var(--motion-fast), color var(--motion-fast);
}
.ctx-dropzone strong { color: var(--color-text-primary); font-weight: 600; }
.ctx-dropzone small { color: var(--color-text-faint); font-size: 11.5px; }
.ctx-dropzone:hover { border-color: var(--color-action-primary); color: var(--color-action-primary); background: var(--color-action-primary-tint); }
.ctx-files-grid + .ctx-dropzone { padding: 10px; grid-auto-flow: column; justify-content: center; align-items: center; }
.ctx-files-grid + .ctx-dropzone small { display: none; }

.ctx-upload-status { margin: 4px 0 8px; color: var(--color-text-muted); font-size: 12.5px; animation: fade-in var(--motion-fast) backwards; }
.ctx-upload-status.upload-error { color: var(--color-feedback-error); }

/* ── 11. Session (read) view ───────────────────────────────────────── */
.sess-article { width: min(100%, calc(var(--reading-max) + 80px)); margin: 0 auto; padding: 36px 40px 120px; }
.sess-article-hd { margin-bottom: 30px; padding-bottom: 22px; border-bottom: 1px solid var(--color-rule); }
.sess-article-hd .eyebrow { margin-bottom: 10px; }
.session-title {
  margin: 0;
  font-family: var(--type-display);
  font-size: clamp(32px, 4vw, 44px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -.02em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.sess-inner { font-size: 17px; }
.sess-inner > h1:first-child,
.sess-inner > h1:first-child + p:has(strong) { display: none; }
.sess-inner > h1:first-child + p + hr { display: none; }
.loading-msg { color: var(--color-text-faint); font-size: 13px; }

/* ── 12. Markdown (concepts, questions, class view) ────────────────── */
.md { color: var(--color-text-longform); font-family: var(--type-notes-ai-longform); font-size: 16px; line-height: 1.7; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md h1 { margin: 1.4em 0 .5em; font-family: var(--type-display); font-size: 1.9em; font-weight: 500; line-height: 1.15; letter-spacing: -.015em; }
.md h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 1.8em 0 .6em;
  color: var(--color-action-primary);
  font-family: var(--type-ui);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  scroll-margin-top: 80px;
}
.md h2::after { content: ''; flex: 1; height: 1px; background: var(--color-rule); }
.md h3 { margin: 1.3em 0 .35em; font-family: var(--type-display); font-size: 1.25em; font-weight: 500; letter-spacing: -.005em; }
.md h4 { margin: 1.1em 0 .3em; color: var(--color-text-muted); font-family: var(--type-ui); font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.md p { margin: 0 0 .8em; }
.md ul, .md ol { margin: 0 0 .9em; padding-left: 1.3em; }
.md li { margin: .3em 0; }
.md li::marker { color: var(--color-text-faint); }
.md strong { color: var(--color-text-primary); font-weight: 600; }
.md code { padding: .1em .35em; border-radius: var(--leaf-radius-xs); color: var(--color-action-primary); background: var(--color-surface-alt); font-family: var(--type-data); font-size: .82em; }
.md pre { margin: 1em 0; padding: 14px 16px; overflow-x: auto; border-radius: var(--leaf-radius-md); color: var(--color-code-text); background: var(--color-code-surface); }
.md pre code { padding: 0; color: inherit; background: none; }
.md blockquote { margin: 1em 0; padding: 2px 0 2px 16px; border-left: 2px solid var(--color-action-primary); color: var(--color-text-muted); font-style: italic; }
.md a { color: var(--color-action-primary); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--color-action-primary) 35%, transparent); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: currentColor; }
.md hr { margin: 2em 0; border: 0; border-top: 1px solid var(--color-rule); }
.md table { width: 100%; margin: 1em 0; border-collapse: collapse; font-family: var(--type-ui); font-size: 13px; }
.md th, .md td { padding: 8px 10px; border: 1px solid var(--color-rule-strong); text-align: left; vertical-align: top; }
.md th { color: var(--color-text-primary); background: var(--color-surface-alt); font-weight: 650; }
.md td { color: var(--color-text-muted); }
.md img { height: auto; border-radius: var(--leaf-radius-md); }
.mermaid-wrap { margin: 1em 0; padding: 12px; overflow-x: auto; border: 1px solid var(--color-rule); border-radius: var(--leaf-radius-md); background: var(--color-surface); text-align: center; }
.mermaid-err { padding: 10px; border-radius: var(--leaf-radius-sm); color: var(--color-feedback-error); background: var(--color-feedback-error-tint); font-family: var(--type-data); font-size: 12px; }

/* ── 13. Notes workspace ───────────────────────────────────────────── */
#view-notes { background: var(--color-canvas-soft); }

.notes-hdr {
  position: relative;
  z-index: var(--leaf-z-sticky);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  height: var(--topbar-height);
  flex-shrink: 0;
  padding: 0 14px 0 10px;
  border-bottom: 1px solid var(--color-rule);
  background: color-mix(in srgb, var(--color-canvas) 88%, transparent);
  backdrop-filter: blur(10px);
}
.notes-crumbs { display: flex; align-items: center; min-width: 0; }
.btn-brand-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  min-height: 36px;
  padding: 0 12px 0 6px;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  transition: background-color var(--motion-fast), color var(--motion-fast);
}
.btn-brand-back:hover { color: var(--color-text-primary); background: var(--color-hover); }
.btn-brand-back .i { transition: transform var(--motion-fast); }
.btn-brand-back:hover .i { transform: translateX(-2px); }
.badge-subj { min-width: 0; overflow: hidden; font-size: 13.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }

.notes-status-center { display: flex; justify-content: center; min-width: 0; }
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 0 11px 0 9px;
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--motion-normal), color var(--motion-normal);
}
.badge-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-action-primary);
  transition: background-color var(--motion-normal);
}
.badge-typing::before,
.badge-processing::before { background: var(--color-feedback-saving); animation: pulse-dot 1.1s ease-in-out infinite; }
.badge-processing { color: var(--color-text-primary); background: var(--color-surface); }
.badge-error { color: var(--color-feedback-error); background: var(--color-feedback-error-tint); }
.badge-error::before { background: var(--color-feedback-error); }
.badge-offline { color: var(--color-feedback-saving); background: color-mix(in srgb, var(--leaf-color-gold-200) 45%, transparent); }
.badge-offline::before { background: var(--color-feedback-saving); }

.hflex { display: flex; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.btn-ctx { position: relative; max-width: 220px; }
.btn-ctx .badge-ctx { overflow: hidden; text-overflow: ellipsis; }
.btn-ctx[data-count]:not([data-count=''])::after {
  content: attr(data-count);
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  color: var(--color-action-on-primary);
  background: var(--color-action-primary);
  font-size: 10.5px;
  font-weight: 700;
}
.notes-more-panel { min-width: 200px; }
.btn-close-ink { margin-left: 6px; }

.notes-mobile-switcher { display: none; }

.notes-layout { position: relative; display: flex; flex: 1; min-height: 0; }
.panel-left {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 68%;
  min-width: 0;
  background: var(--color-canvas-soft);
  transition: width var(--motion-slow);
}
.panel-right {
  display: flex;
  flex-direction: column;
  width: 32%;
  min-width: 0;
  border-left: 1px solid var(--color-rule);
  background: var(--color-canvas);
}
.notes-layout.is-resizing .panel-left { transition: none; }

.splitter {
  position: relative;
  z-index: 3;
  flex: 0 0 9px;
  margin: 0 -4px;
  cursor: col-resize;
  outline: none;
  touch-action: none;
}
.splitter::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 3px;
  width: 3px;
  height: 36px;
  border-radius: 3px;
  background: var(--color-rule-strong);
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity var(--motion-fast), background-color var(--motion-fast), height var(--motion-fast);
}
.splitter:hover::after,
.splitter:focus-visible::after,
.notes-layout.is-resizing .splitter::after { opacity: 1; height: 56px; background: var(--color-action-primary); }

#notes-input {
  flex: 1;
  width: 100%;
  padding: 40px max(24px, calc((100% - var(--reading-max)) / 2));
  border: 0;
  outline: none;
  resize: none;
  color: var(--editor-text);
  background: transparent;
  font-family: var(--type-notes-editor-body);
  font-size: var(--editor-body-size);
  line-height: var(--editor-body-leading);
}

/* AI panel */
.panel-hdr { display: flex; align-items: center; flex-shrink: 0; }
.panel-ai-hdr { justify-content: space-between; gap: 10px; min-height: 52px; padding: 0 14px 0 18px; border-bottom: 1px solid var(--color-rule); }
.ai-title { display: inline-flex; align-items: center; gap: 7px; color: var(--color-action-primary); font-size: 13px; font-weight: 700; letter-spacing: -.01em; }
.tabs {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
}
.tab {
  position: relative;
  z-index: 1;
  min-height: 28px;
  padding: 0 13px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  background: transparent;
  font-size: 12.5px;
  font-weight: 600;
  transition: color var(--motion-fast);
}
.tab:hover { color: var(--color-text-primary); }
.tab.active { color: var(--color-text-primary); }
.tabs-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--tab-w, 50%);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-hairline);
  transform: translateX(var(--tab-x, 3px));
  transition: transform var(--motion-normal), width var(--motion-normal);
}
.tab-pane { display: none; flex: 1; flex-direction: column; min-height: 0; }
.tab-pane.active { display: flex; animation: fade-in var(--motion-normal) backwards; }
.output-scroll { flex: 1; min-height: 0; padding: 22px 22px 80px; overflow-y: auto; overscroll-behavior: contain; font-size: 15.5px; }
.q-actions { padding: 14px 18px 0; }
.btn-gen-q { width: 100%; }

.placeholder {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 48px auto 0;
  max-width: 260px;
  color: var(--color-text-faint);
  font-family: var(--type-display);
  font-size: 17px;
  font-style: italic;
  text-align: center;
}
.placeholder-art {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--color-action-primary);
  background: var(--color-action-primary-tint-strong);
  font-style: normal;
}

.block-result {
  position: relative;
  margin-bottom: 14px;
  padding: 14px 16px 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-lg);
  background: var(--color-surface);
  animation: rise-in var(--leaf-motion-slow) var(--leaf-ease-arrive) backwards;
}
.block-result:empty { min-height: 72px; background: linear-gradient(90deg, var(--color-surface-alt) 0%, var(--color-surface) 45%, var(--color-surface-alt) 90%); background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite; }
.block-actions { display: flex; justify-content: flex-end; margin-top: 4px; opacity: 0; transition: opacity var(--motion-fast); }
.block-result:hover .block-actions,
.block-actions:focus-within { opacity: 1; }
.block-dismiss,
.block-restore {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-text-faint);
  background: transparent;
  font-family: var(--type-ui);
  font-size: 12px;
  font-weight: 600;
  transition: color var(--motion-fast), background-color var(--motion-fast);
}
.block-dismiss:hover,
.block-restore:hover { color: var(--color-text-primary); background: var(--color-hover); }

.api-error {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--leaf-radius-md);
  color: var(--color-feedback-error);
  background: var(--color-feedback-error-tint);
  font-family: var(--type-ui);
  font-size: 13px;
  line-height: 1.45;
  animation: rise-in var(--motion-normal) backwards;
}

/* Annotations */
.annot-tooltip {
  position: fixed;
  z-index: var(--leaf-z-overlay);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-pill);
  color: var(--color-action-on-primary);
  background: var(--color-text-primary);
  box-shadow: var(--shadow-popover);
  font-size: 12.5px;
  font-weight: 600;
  transform: translateX(-50%);
  animation: pop-in var(--motion-fast) var(--leaf-ease-arrive) backwards;
}
.annot-popover {
  position: fixed;
  z-index: var(--leaf-z-overlay);
  width: 300px;
  padding: 12px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  animation: pop-in var(--motion-fast) var(--leaf-ease-arrive) backwards;
}
.annot-ref { margin-bottom: 8px; padding-left: 10px; border-left: 2px solid var(--color-action-primary); color: var(--color-text-muted); font-family: var(--type-display); font-size: 14px; font-style: italic; }
.annot-input { min-height: 72px; }
.annot-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.annot-btns button { min-height: 32px; padding: 0 12px; font-size: 12.5px; }
.annot-result { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--color-rule); border-left: 3px solid var(--color-action-primary); border-radius: var(--leaf-radius-md); background: var(--color-surface); animation: rise-in var(--motion-slow) backwards; }
.annot-question { margin: 0 0 8px; color: var(--color-text-primary); font-family: var(--type-ui); font-size: 13px; font-weight: 650; }
.annot-badge { margin-right: 4px; color: var(--color-action-primary); font-family: var(--type-data); font-size: 11px; letter-spacing: .04em; white-space: nowrap; }

.editor-flash { animation: flash-ring .6s var(--leaf-ease-arrive); }

/* ── 14. Dialogs ───────────────────────────────────────────────────── */
.modal-bg,
.ui-dialog {
  position: fixed;
  inset: 0;
  z-index: var(--leaf-z-dialog);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--dialog-overlay);
  backdrop-filter: blur(3px);
  animation: fade-in var(--motion-normal) backwards;
}
.ui-dialog { display: none; }
.ui-dialog.active { display: flex; }

.modal {
  display: flex;
  flex-direction: column;
  width: min(100%, 640px);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
  border: 1px solid var(--dialog-border);
  border-radius: var(--dialog-radius);
  background: var(--dialog-bg);
  box-shadow: var(--dialog-shadow);
  outline: none;
  animation: dialog-in var(--leaf-motion-page) var(--leaf-ease-arrive) backwards;
}
.modal-sm { width: min(100%, 460px); }
#modal-bg .modal-sm { width: min(100%, 540px); }
.modal-hdr { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 22px 6px 26px; }
.modal-hdr h3 { margin: 0; font-family: var(--type-display); font-size: 26px; font-weight: 500; line-height: 1.15; letter-spacing: -.01em; overflow-wrap: anywhere; }
.modal-hdr > button:not(.icon-btn) {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-muted);
  background: transparent;
}
.modal-hdr > button:not(.icon-btn):hover { background: var(--color-hover); }
.modal-heading { display: grid; gap: 6px; min-width: 0; }
.ui-dialog-kicker { color: var(--color-action-primary); font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ui-dialog-heading { display: grid; gap: 6px; min-width: 0; }
.ui-dialog-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--leaf-radius-sm);
  color: var(--color-text-muted);
  background: transparent;
  transition: background-color var(--motion-fast);
}
.ui-dialog-close:hover { background: var(--color-hover); }
.modal-body { display: grid; gap: 16px; padding: 12px 26px 8px; overflow-y: auto; overscroll-behavior: contain; }
.modal-body > p { margin: 0; color: var(--color-text-muted); font-size: 14px; line-height: 1.55; white-space: pre-line; }
.modal-ftr { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 16px 22px 20px; }
.modal-ftr-start { margin-right: auto; }
.ui-dialog[data-intent='danger'] .modal-ftr .btn-primary { background: var(--color-action-danger); }
.ui-dialog[data-intent='danger'] .modal-ftr .btn-primary:hover { background: color-mix(in srgb, var(--color-action-danger) 88%, var(--color-text-primary)); box-shadow: none; }
.ui-dialog[data-mode='alert'] .modal-body:has(> p[hidden]):has(> input[hidden]) { display: none; }

.modal-title-field { display: grid; gap: 6px; }
.modal-field-label { color: var(--color-text-muted); font-size: 12.5px; font-weight: 600; }
.modal-gen-options { display: grid; gap: 8px; }
.modal-gen-label { display: flex; align-items: center; gap: 7px; margin: 4px 0 0; color: var(--color-action-primary); font-size: 12.5px; font-weight: 650; }
.modal-check-row { display: grid; gap: 6px; }
.modal-check-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--color-rule-strong);
  border-radius: var(--leaf-radius-md);
  cursor: pointer;
  transition: border-color var(--motion-fast), background-color var(--motion-fast);
}
.modal-check-item:hover { border-color: color-mix(in srgb, var(--color-action-primary) 45%, transparent); }
.modal-check-item:has(input:checked) { border-color: var(--color-action-primary); background: var(--color-action-primary-tint); }
.modal-check-item input { width: 16px; height: 16px; margin: 2px 0 0; }
.modal-check-text { display: grid; gap: 1px; }
.modal-check-title { font-size: 13.5px; font-weight: 600; }
.modal-check-help { color: var(--color-text-muted); font-size: 12.5px; }
.modal-note { margin: 4px 0 0; color: var(--color-text-faint); font-size: 12px; }

/* Material selector / drawer */
.ctx-sel-subtitle { margin: 0; color: var(--color-text-muted); font-size: 13.5px; }
.ctx-sel-list { display: grid; gap: 4px; max-height: 320px; overflow-y: auto; overscroll-behavior: contain; }
.ctx-sel-row {
  display: grid;
  grid-template-columns: 18px 32px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--leaf-radius-md);
  cursor: pointer;
  transition: border-color var(--motion-fast), background-color var(--motion-fast);
}
.ctx-sel-row:hover { border-color: var(--color-rule-strong); }
.ctx-sel-row:has(input:checked) { border-color: color-mix(in srgb, var(--color-action-primary) 55%, transparent); background: var(--color-action-primary-tint); }
.ctx-sel-check { width: 16px; height: 16px; margin: 0; }
.ctx-sel-name { overflow: hidden; font-size: 13.5px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.ctx-sel-toggle { justify-self: start; min-height: 30px; font-size: 12.5px; }
.ctx-sel-empty { margin: 0; color: var(--color-text-muted); }
.ctx-sel-upload-row { display: flex; }
.ctx-preview-content { max-height: 55vh; overflow-y: auto; padding: 14px 16px; border-radius: var(--leaf-radius-md); color: var(--color-text-longform); background: var(--color-surface-alt); font-family: var(--type-display); font-size: 15px; line-height: 1.6; white-space: pre-wrap; }
.ctx-preview-note { margin: 0; color: var(--color-text-faint); font-size: 12px; }

/* Command palette */
.palette-bg {
  position: fixed;
  inset: 0;
  z-index: var(--leaf-z-dialog);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
  background: var(--dialog-overlay);
  backdrop-filter: blur(3px);
  animation: fade-in var(--motion-fast) backwards;
}
.palette {
  display: flex;
  flex-direction: column;
  width: min(100%, 580px);
  max-height: 70vh;
  overflow: hidden;
  border: 1px solid var(--dialog-border);
  border-radius: var(--leaf-radius-xl);
  background: var(--dialog-bg);
  box-shadow: var(--dialog-shadow);
  animation: dialog-in var(--motion-normal) backwards;
}
.palette-input-row { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--color-rule); color: var(--color-text-faint); }
.palette-input-row input { flex: 1; min-width: 0; height: 54px; border: 0; outline: none; color: var(--color-text-primary); background: transparent; font-size: 16px; }
.palette-input-row input::placeholder { color: var(--color-text-faint); }
.palette-list { flex: 1; min-height: 0; padding: 6px; overflow-y: auto; overscroll-behavior: contain; }
.palette-group { margin: 8px 10px 4px; color: var(--color-text-faint); font-size: 11.5px; font-weight: 600; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--leaf-radius-md);
  color: var(--color-text-primary);
  background: transparent;
  font-size: 14px;
  text-align: left;
}
.palette-item .subject-icon { width: 26px; height: 26px; font-size: 14px; border-radius: 6px; }
.palette-item-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; color: var(--color-text-muted); background: var(--color-surface-alt); }
.palette-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-hint { color: var(--color-text-faint); font-size: 12px; }
.palette-item[aria-selected='true'] { background: var(--color-action-primary-tint-strong); }
.palette-item[aria-selected='true'] .palette-item-hint { color: var(--color-action-primary); }
.palette-empty { margin: 20px; color: var(--color-text-faint); text-align: center; }
.palette-ftr { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--color-rule); color: var(--color-text-faint); font-size: 12px; }
.palette-ftr .kbd { margin-right: 2px; }

/* ── 15. Responsive ────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .subject-workspace { grid-template-columns: minmax(0, 1fr); }
  .subject-context-panel { position: static; }
}

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .library-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: calc(var(--leaf-z-menu) + 1);
    width: min(86vw, 300px);
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-dialog);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform var(--motion-slow), visibility 0s linear var(--leaf-motion-slow);
  }
  body.sidebar-open .library-sidebar { transform: none; visibility: visible; transition: transform var(--motion-slow), visibility 0s; }
  .sidebar-close,
  .sidebar-toggle { display: inline-grid; }
  .sidebar-section-hd .icon-btn { opacity: 1; }
  .topbar { padding: 0 12px 0 8px; }
}

@media (max-width: 900px) {
  .notes-hdr { grid-template-columns: minmax(0, 1fr) auto; padding: 0 8px 0 4px; }
  .notes-status-center { display: none; }
  .btn-ctx .badge-ctx { display: none; }
  #btn-focus-mode { display: none !important; }

  .notes-mobile-switcher {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin: 8px 12px 0;
    padding: 3px;
    border-radius: var(--radius-pill);
    background: var(--color-surface-alt);
  }
  .notes-mobile-switcher button {
    min-height: 36px;
    border: 0;
    border-radius: var(--radius-pill);
    color: var(--color-text-muted);
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    transition: background-color var(--motion-fast), color var(--motion-fast);
  }
  .notes-mobile-switcher button.active { color: var(--color-text-primary); background: var(--color-surface); box-shadow: var(--shadow-hairline); }
  body:not(.editor-v2-enabled) .notes-mobile-switcher { display: none !important; }

  .notes-layout .panel-left,
  .notes-layout .panel-right { width: 100% !important; border-left: 0; }
  .splitter { display: none; }
  body.notes-mobile-ai .notes-layout .panel-left { display: none; }
  body:not(.notes-mobile-ai) .notes-layout .panel-right { display: none; }
  .panel-right { animation: fade-in var(--motion-normal) backwards; }
  .panel-ai-hdr .ai-title { display: none; }
  .panel-ai-hdr { justify-content: center; }
}

@media (max-width: 720px) {
  .page { padding: 18px 16px 88px; }
  .page-hd { align-items: flex-start; flex-direction: column; gap: 14px; }
  .page-hd-actions { width: 100%; }
  .page-hd-actions .btn-primary { flex: 1; min-height: 44px; }
  .library-tools { flex-direction: column; }
  .library-sort { width: 100%; min-height: 44px; }
  .library-search input { min-height: 44px; }
  .subjects-table-head { display: none; }
  .s-card { grid-template-columns: minmax(0, 1fr) 40px; min-height: 64px; gap: 4px 10px; }
  .s-card-main { grid-row: span 2; }
  .s-card-count,
  .s-card-last { display: none; }
  .s-card-meta-mobile { display: block !important; }
  .s-card-menu { grid-row: 1 / span 2; grid-column: 2; }
  .subject-hero { gap: 14px; margin-bottom: 20px; }
  .subject-icon-lg { width: 46px; height: 46px; font-size: 24px; }
  .sess-item { grid-template-columns: minmax(0, 1fr) auto auto; padding-left: 10px; }
  .sess-check { display: none; }
  .sess-item + .sess-item::after { left: 10px; }
  .sess-article { padding: 22px 18px 96px; }
  .topbar-actions .btn-primary span,
  .session-header-actions .btn-secondary span,
  .session-header-actions .btn-ghost span:not(:only-of-type) { display: none; }
  .topbar-actions .btn-primary,
  .session-header-actions .btn-secondary,
  .session-header-actions .btn-ghost { min-width: 40px; min-height: 40px; padding: 0 11px; }
  .btn-close-ink span { display: none; }
  .btn-close-ink { min-width: 40px; padding: 0 12px; }
  .modal-hdr { padding: 20px 18px 4px 20px; }
  .modal-body { padding: 10px 20px 6px; }
  .modal-ftr { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
  .modal-ftr .btn-primary { flex: 1; min-height: 44px; }
  .modal-bg, .ui-dialog { align-items: flex-end; padding: 0; }
  .modal, .modal-sm { width: 100%; max-height: 92dvh; border-radius: var(--dialog-radius) var(--dialog-radius) 0 0; }
  .palette-bg { padding-top: 8vh; }
  .key-card { padding: 40px 24px 28px; }
  .brand-lockup-lg .brand-word { font-size: 34px; }
}

@media (max-width: 380px) {
  .crumb-link { max-width: 34%; }
  .btn-ctx { display: none; }
}

@media (hover: none) {
  .sidebar-search .kbd { display: none; }
  .s-card-menu > summary,
  .sess-more > summary,
  .ctx-more > summary,
  .icon-btn { min-width: 44px; min-height: 44px; }
}

/* ── 16. Motion preferences ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton-row,
  .block-result:empty { animation: none !important; }
}
