/* =================================================================
   REVISION RAIL — shared collapsible icon-rail + topic tree
   Reusable across notes.html (public) and app.html (in-app).
   Depends only on theme.css tokens (--card,--ink,--muted,--border,
   --green,--green-l,--bg). Themes light + dark automatically.
================================================================= */

.rr-layout {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: 480px;
}

/* ── RAIL TRACK (holds space in flow) ─────────────────────────── */
.rrail {
  /* Collapsed strip is sized to the icon and nothing more: 6px list padding +
     10px item padding + 26px icon + 10px + 6px = 58px, which puts the icon dead
     centre. It was 66px, which left a band of empty space beside every icon. */
  --rail-collapsed: 58px;
  --rail-expanded: 260px;
  position: relative;
  flex: 0 0 var(--rail-collapsed);
  width: var(--rail-collapsed);
}

/* ── RAIL PANEL (overlays content when expanded, no reflow) ──── */
.rrail-panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: var(--rail-collapsed);
  background: var(--card);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  z-index: 20;
  display: flex;
  flex-direction: column;
  /* Opening eases out of the gate and settles; closing is quicker and plainer,
     so dismissing never feels like it is dawdling. */
  transition: width .34s cubic-bezier(.16,1,.3,1),
              box-shadow .34s ease;
  will-change: width;
}
.rrail.expanded .rrail-panel {
  width: var(--rail-expanded);
  box-shadow: 0 18px 50px rgba(0,0,0,.18);
}
.rrail:not(.expanded) .rrail-panel {
  transition: width .2s cubic-bezier(.4,0,1,1), box-shadow .2s ease;
}

/* The contents keep the EXPANDED width at all times and are cropped by the
   panel's overflow:hidden. Previously they were sized by the panel, so every
   frame of the width animation re-laid-out the header, the list and every item —
   labels rewrapping mid-transition is what made it look jumpy. Holding the
   layout still turns the animation into a straight reveal. */
.rrail-head,
.rrail-list,
.rrail-item,
.rrail-section {
  width: var(--rail-expanded);
  box-sizing: border-box;
}
.rrail-item-txt,
.rrail-section-txt,
.rrail-head-txt { white-space: nowrap; }
/* Scrollbar belongs to the expanded layout; keep it off the collapsed strip. */
.rrail:not(.expanded) .rrail-list { overflow-y: hidden; }

/* Labels wait for the panel to be part-way open before fading in, so text never
   appears against a panel that is still narrow. Only on the way OUT — closing
   drops them immediately, which reads as decisive rather than laggy. */
.rrail.expanded .rrail-head-txt,
.rrail.expanded .rrail-item-txt,
.rrail.expanded .rrail-section-txt { transition-delay: .10s; }
.rrail.opening .rrail-head-txt,
.rrail.opening .rrail-item-txt,
.rrail.opening .rrail-section-txt { transition-duration: .26s; }

@media (prefers-reduced-motion: reduce) {
  .rrail-panel,
  .rrail .rrail-head-txt,
  .rrail .rrail-item-txt,
  .rrail .rrail-section-txt { transition: none !important; }
}
[data-theme="dark"] .rrail.expanded .rrail-panel {
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
}

/* ── RAIL HEADER ──────────────────────────────────────────────── */
.rrail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 16px 21px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  min-height: 56px;
  white-space: nowrap;
}
.rrail-head .rrail-head-ico {
  font-size: 20px;
  color: var(--green);
  flex: 0 0 auto;
  line-height: 1;
}
.rrail-head .rrail-head-txt {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.01em;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity .2s ease, transform .22s ease;
}
.rrail.expanded .rrail-head-txt { opacity: 1; transform: none; }

/* ── RAIL ITEMS ───────────────────────────────────────────────── */
.rrail-list {
  list-style: none;
  margin: 0; padding: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
}

/* WebKit/Chromium — thin, transparent track, subtle thumb.
   NOTE: do NOT set scrollbar-width/scrollbar-color here — in Chromium those
   standard props make the ::-webkit-scrollbar rules below be ignored, and
   Chrome's own "thin" is wider (10px) than what we want. Firefox is handled
   in the @supports block underneath. */
.rrail-list::-webkit-scrollbar { width: 5px; }
.rrail-list::-webkit-scrollbar-track { background: transparent; }
.rrail-list::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.16);
  border-radius: 999px;
}
.rrail-list:hover::-webkit-scrollbar-thumb { background: rgba(0,0,0,.28); }
[data-theme="dark"] .rrail-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); }
[data-theme="dark"] .rrail-list:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,.26); }

/* Firefox — no ::-webkit-scrollbar support, use the standard properties */
@supports not selector(::-webkit-scrollbar) {
  .rrail-list { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.20) transparent; }
  [data-theme="dark"] .rrail-list { scrollbar-color: rgba(255,255,255,.16) transparent; }
}

/* ── SECTION HEADERS (grouped rail) ───────────────────────────── */
.rrail-section {
  padding: 14px 12px 6px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  position: relative;
}
.rrail-section:first-child { padding-top: 6px; }
.rrail-section .rrail-section-txt {
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity .18s ease, transform .2s ease;
  display: inline-block;
}
.rrail.expanded .rrail-section-txt { opacity: 1; transform: none; }
/* collapsed: show a short divider rule in place of the label text */
.rrail-section::after {
  content: '';
  position: absolute;
  left: 16px; right: 16px; top: 50%;
  height: 1px;
  background: var(--border);
  opacity: 1;
  transition: opacity .18s ease;
}
.rrail.expanded .rrail-section::after { opacity: 0; }
.rrail-section:first-child::after { display: none; }
.rrail-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px;
  margin-bottom: 4px;
  border: none;
  background: none;
  border-radius: 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.rrail-item-ico {
  flex: 0 0 26px;
  width: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  line-height: 1;
  color: var(--muted);
  transition: color .15s ease;
}
.rrail-item-txt {
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity .2s ease, transform .22s ease;
}
.rrail.expanded .rrail-item-txt { opacity: 1; transform: none; }
.rrail-item:hover { background: var(--green-l); }
.rrail-item:hover .rrail-item-ico { color: var(--green-d); }
.rrail-item.active {
  background: var(--green);
  color: #fff;
}
.rrail-item.active .rrail-item-ico { color: #fff; }

/* ── MAIN PANEL (content to the right) ────────────────────────── */
.rr-main {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 24px;
}

/* ── TOPIC TREE (SaveMyExams-style accordion cards) ───────────── */
.rtree {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 16px;
  align-content: start;
}
@media (max-width: 900px) { .rtree { grid-template-columns: 1fr; } }

.rtree-topic {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  align-self: start;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.rtree-topic:hover { border-color: var(--border-m); }
.rtree-topic.open { border-color: var(--green); box-shadow: 0 6px 24px rgba(13,200,138,.10); }

.rtree-topic-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--ink);
}
.rtree-topic-num {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--green-l);
  color: var(--green-d);
  font-size: 13px; font-weight: 800;
}
.rtree-topic.open .rtree-topic-num { background: var(--green); color: #fff; }
.rtree-topic-title {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-width: 0;
}
.rtree-topic-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex: 0 0 auto;
}
.rtree-chev {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 18px;
  transition: transform .25s ease, color .2s ease;
  display: flex;
}
.rtree-topic.open .rtree-chev { transform: rotate(180deg); color: var(--green-d); }

.rtree-notes {
  list-style: none;
  margin: 0;
  padding: 0 12px;
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease, padding .3s ease;
}
.rtree-topic.open .rtree-notes { padding: 0 12px 12px; }
.rtree-note {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink-mid);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.rtree-note::before {
  content: '';
  flex: 0 0 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  border: 2px solid var(--border-m);
  transition: border-color .14s ease, background .14s ease;
}
.rtree-note:hover {
  background: var(--green-l);
  color: var(--green-d);
}
.rtree-note:hover::before { border-color: var(--green); }
.rtree-note.active { color: var(--green-d); }
.rtree-note.active::before { border-color: var(--green); background: var(--green); }

/* ── CARD SURFACE (empty state + reading view) ───────────────── */
.rr-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  min-height: 340px;
}
.rr-subject-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 2px 0 18px;
}

/* ── READING VIEW ─────────────────────────────────────────────── */
.rr-reading .rr-back {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--green-d); font-weight: 700; font-size: 13px;
  font-family: inherit; padding: 0; margin-bottom: 16px;
}
.rr-reading .rr-back:hover { text-decoration: underline; }

/* ── MOBILE (no hover) → horizontal chip strip ───────────────── */
@media (max-width: 760px) {
  .rr-layout { flex-direction: column; }
  .rrail {
    flex: none;
    width: 100%;
    height: auto;
  }
  .rrail-panel {
    position: static;
    width: 100%;
    flex-direction: column;
    border-radius: 14px;
  }
  .rrail-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .rrail-head .rrail-head-txt { opacity: 1; transform: none; }
  .rrail-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 10px;
    gap: 8px;
  }
  .rrail-item {
    flex: 0 0 auto;
    width: auto;
    margin-bottom: 0;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
  }
  .rrail-item-ico { flex: 0 0 auto; width: auto; font-size: 16px; }
  .rrail-item-txt { opacity: 1; transform: none; }
  .rr-main { padding-left: 0; padding-top: 18px; }
}
