/* Phase 2: subject page layout, index bar, chapter accordion, R/W buttons, menus */

/* ---------- Write-mode visibility ---------- */
.w-only { display: none !important; }
body.write .w-only { display: inline-grid !important; }
body.write .add-bar.w-only { display: block !important; }

/* ---------- Page frame ---------- */
body.subject-view #app {
  max-width: none;
  padding: 0;
  height: 100vh;
}

.shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100%;
}

/* ---------- Index bar ---------- */
.index {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.index-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.home-link {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.home-link:hover { background: var(--surface-hover); color: var(--text); }

.subject-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dots {
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.dots:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

/* ---------- Chapters (accordion) ---------- */
.chapters {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.chapter { margin-bottom: 2px; }

.chapter-row {
  display: flex;
  align-items: center;
  border-radius: 8px;
}
.chapter-row:hover { background: var(--surface-hover); }

.chapter-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.chapter-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chev {
  display: inline-block;
  width: 12px;
  color: var(--text-muted);
  transition: transform 0.22s var(--ease);
}
.chapter.open .chev { transform: rotate(90deg); }

.topics {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s var(--ease);
}
.chapter.open .topics { grid-template-rows: 1fr; }
.topics-inner { overflow: hidden; min-height: 0; }
.topics ul { list-style: none; margin: 2px 0 6px; padding: 0 0 0 20px; }

.topics li { display: flex; align-items: center; border-radius: 6px; }
.topics li:hover { background: var(--surface-hover); }

.topic {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.18s var(--ease);
}
.topic:hover { color: var(--text); }
.topic.active {
  color: var(--accent);
  background: rgba(138, 180, 255, 0.1);
}

/* ---------- R / W buttons ---------- */
.mode-switch {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.mode-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.mode-btn:hover { border-color: var(--border-strong); color: var(--text); }
.mode-btn[aria-pressed="true"] {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- Content panel ---------- */
.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.note-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 48px 48px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.note { max-width: 780px; margin: 0 auto; animation: fade-in 0.3s var(--ease); }

.crumbs { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; }
.note h1 { margin: 0 0 20px; font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }

.note-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  color: var(--text-muted);
}

.note-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.note-nav a {
  display: block;
  max-width: 48%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.note-nav a:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.note-nav small { display: block; color: var(--text-muted); font-size: 12px; }
.note-nav .next { margin-left: auto; text-align: right; }

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
}
.empty-state h2 { color: var(--text); font-size: 20px; margin: 0 0 6px; }
.empty-state p { margin: 0 0 16px; }

.continue-btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  display: inline-block;
  transition: background 0.18s var(--ease);
}
.continue-btn:hover { background: var(--surface-hover); }

/* ---------- Bottom "+" bar ---------- */
.add-bar { padding: 0 24px 20px; }
.add-bar button {
  width: 100%;
  max-width: 780px;
  display: block;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.add-bar button:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }

/* ---------- Dropdown menu ---------- */
.menu {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  padding: 6px;
  background: #1b1b22;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  animation: toast-in 0.15s var(--ease);
}
.menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: rgba(255, 255, 255, 0.08); }
.menu button.danger { color: #ff8a8a; }

/* ---------- Mobile drawer ---------- */
.mobile-bar { display: none; }
.backdrop { display: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }

  .index {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
  }
  .index.open { transform: none; }

  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease);
  }
  .backdrop.open { display: block; opacity: 1; pointer-events: auto; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
  }
  .mobile-bar span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .note-scroll { padding: 28px 18px 18px; }
  .add-bar { padding: 0 14px 14px; }
}
