/* ═══════════════════════════════════════════════
   Ranjan's Notebook — Layout (sidebar, main, toolbar)
   ═══════════════════════════════════════════════ */

#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* iOS dynamic viewport */
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  user-select: none;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease;
}
.auth-bar {
  position: fixed;
  bottom: 8px;
  left: 8px;
  z-index: 100;
}
.auth-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.2);
}
.auth-avatar:hover { border-color: rgba(255,255,255,0.6); }
.auth-name {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}
.sidebar.collapsed ~ .auth-bar { left: -200px; }
.sidebar.collapsed {
  width: 0;
  min-width: 0;
}

/* Sidebar toggle button */
.sidebar-toggle {
  position: fixed;
  top: 10px;
  left: var(--sidebar-w);
  z-index: 100;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  transition: left 0.2s ease, background 0.15s, color 0.15s;
  box-shadow: var(--shadow-sm);
  padding: 0;
}
.sidebar-toggle:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.sidebar.collapsed + .sidebar-toggle {
  left: 6px;
}

.sidebar-brand {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand h1 {
  font-size: 1rem;
  color: white;
  font-weight: 700;
}
.sidebar-brand .btn-add {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.6);
  font-size: 1rem;
  transition: all 0.12s;
}
.sidebar-brand .btn-add:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.sidebar-search {
  padding: 8px 12px;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.82rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: white;
  outline: none;
  transition: border-color 0.15s;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,0.3); }
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

/* Tree items */
.tree-notebook {
  margin-top: 4px;
}
.tree-nb-body {
  overflow: hidden;
  transition: max-height 0.25s ease;
  max-height: 0;
}
.tree-notebook.open .tree-nb-body { max-height: 2000px; }
.nb-chevron {
  font-size: 0.5rem;
  color: rgba(255,255,255,0.3);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.tree-notebook.open .nb-chevron { transform: rotate(90deg); }
.nb-label { flex: 1; min-width: 0; }
.tree-notebook-header {
  padding: 8px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tree-notebook-header:hover { color: rgba(255,255,255,0.7); }
.tree-notebook-header .tree-actions {
  display: none;
  gap: 2px;
}
.tree-notebook-header:hover .tree-actions { display: flex; }
.tree-action {
  font-size: 0.7rem;
  padding: 1px 4px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  border-radius: 3px;
  cursor: pointer;
}
.tree-action:hover { background: rgba(255,255,255,0.1); color: white; }

.tree-section {
  padding: 7px 14px 7px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.1s;
}
.tree-section:hover { background: var(--sidebar-hover); }
.tree-section.active { background: var(--sidebar-active); border-left-color: var(--accent); }
.tree-section-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-actions { display: none; }
.tree-section:hover .sec-actions { display: inline-flex; gap: 2px; }
.tree-section .chevron {
  font-size: 0.55rem;
  color: rgba(255,255,255,0.25);
  transition: transform 0.15s;
  flex-shrink: 0;
  cursor: pointer;
}
.tree-section.open .chevron { transform: rotate(90deg); }

.tree-pages {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.tree-pages.open { max-height: 500px; }

.tree-page {
  padding: 5px 14px 5px 36px;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.1s;
}
.tree-page:hover { background: var(--sidebar-hover); color: white; }
.tree-page.active { color: var(--accent); font-weight: 600; }
.tree-page-actions {
  display: none;
  gap: 1px;
  flex-shrink: 0;
  margin-left: auto;
}
.tree-page:hover .tree-page-actions { display: inline-flex; }
.tree-page-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  font-size: 0.6rem;
  cursor: pointer;
  padding: 0 3px;
}
.tree-page-btn:hover { color: white; }
.tree-page-btn.del:hover { color: #ef4444; }
.tree-page .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: auto;
}
.tree-page .dot.done { background: var(--green); }
.tree-page .dot.wip { background: var(--orange); }
.tree-page .dot.todo { background: rgba(255,255,255,0.15); }

.tree-add-page {
  padding: 5px 14px 5px 36px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
}
.tree-add-page:hover { color: var(--accent); }

/* ─── Sidebar section labels & quick lists ─── */
.sidebar-section-label {
  padding: 10px 14px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.35);
}
.sidebar-section-label.collapsible {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-section-label.collapsible:hover { color: rgba(255,255,255,0.55); }
.ql-chevron { font-size: 0.7rem; }
.sidebar-quick-list {
  padding: 0 0 4px;
}
.sidebar-quick-list .quick-page {
  padding-left: 20px;
  font-size: 0.8rem;
}
.sidebar-quick-list .quick-page .tree-page-btn { display: none; }
.sidebar-quick-list .quick-page:hover .tree-page-btn { display: inline; }
.tree-page-btn.fav-active { color: #eab308 !important; display: inline !important; font-size: 0.65rem; }

/* ─── Main Area ─── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Toolbar toggle FAB (floating action button) */
.toolbar-fab {
  position: fixed;
  top: 50px;
  right: 10px;
  z-index: 300;
  width: 28px;
  height: 28px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
  box-shadow: var(--shadow-sm);
}
.toolbar-fab:hover { opacity: 1; background: var(--accent); color: white; border-color: var(--accent); }

/* Toolbar */
.toolbar {
  height: var(--toolbar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.toolbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.toolbar-breadcrumb {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-left: 8px;
}
.toolbar-breadcrumb .crumb-link {
  color: var(--accent);
  cursor: pointer;
}
.toolbar-breadcrumb .crumb-sep { margin: 0 5px; color: var(--text-muted); }

.toolbar-spacer { flex: 1; }

.toolbar-modes {
  display: flex;
  padding: 3px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  gap: 2px;
}
.toolbar-modes .btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  border-radius: 4px;
}
.toolbar-modes .btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Progress indicator */
.progress-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
}
.progress-bar {
  width: 60px;
  height: 5px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Search bar */
#search-bar {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
}
#search-input {
  width: 100%;
  max-width: 420px;
  padding: 7px 14px;
  font-size: 0.84rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  background: var(--bg);
  color: var(--text-primary);
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.08); }
#search-results {
  max-height: 320px;
  overflow-y: auto;
  margin-top: 6px;
  width: 100%;
  max-width: 420px;
}
.search-result {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result:hover { background: var(--accent-light); }
.sr-path {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.sr-title {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}
.sr-snippet {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sr-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* Page Area */
.page-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 32px 60px;
  overscroll-behavior: contain;
}

/* Centered content */
.page-content {
  max-width: 1100px;
  margin: 0 auto;
}

/* Welcome */
.welcome-screen {
  text-align: center;
  padding: 100px 20px;
}
.welcome-screen h2 {
  font-size: 1.4rem;
  margin-bottom: 6px;
}
.welcome-screen p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Teach mode split */
.page-area.teach-mode {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  height: calc(100vh - var(--toolbar-h));
  height: calc(100dvh - var(--toolbar-h)); /* iOS dynamic viewport */
}
.teach-split {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0; /* Allow flex shrinking */
}
.teach-content {
  width: 42%;
  min-width: 200px;
  max-width: 80%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px;
  background: var(--bg);
  flex-shrink: 0;
  transition: width 0.2s ease;
}
.teach-blocks {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Full-board mode: hide content & divider */
.page-area.teach-mode.full-board .teach-content,
.page-area.teach-mode.full-board .teach-divider {
  display: none;
}
.page-area.teach-mode.full-board .teach-canvas {
  width: 100%;
}

/* Resizable divider */
.teach-divider {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}
.teach-divider:hover,
.teach-divider.dragging {
  background: var(--accent);
}
.teach-divider::after {
  content: '⋮';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  pointer-events: none;
}
.teach-divider:hover::after,
.teach-divider.dragging::after {
  color: white;
}

.teach-canvas {
  flex: 1;
  position: relative;
  background: white;
  overflow: hidden;
  min-width: 200px;
  min-height: 0; /* Allow flex to shrink */
}
.teach-canvas canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 5;
}
/* Grid background */
.teach-canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 1;
}

/* ─── Tablet / Small Screen Responsive ─── */

/* Landscape tablet (short height) */
@media (max-height: 600px) {
  :root { --toolbar-h: 36px; }
  .toolbar { padding: 0 10px; gap: 4px; }
  .toolbar .btn { font-size: 0.7rem; padding: 3px 8px; }
  .sidebar { width: 200px; min-width: 200px; }
}

/* Tablet widths */
@media (max-width: 1024px) {
  .sidebar { width: 220px; min-width: 220px; }
  .page-area { padding: 16px 18px 40px; }
  .teach-content { width: 35%; }
}

/* Small tablets / phones */
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 200; height: 100vh; }
  .sidebar.collapsed { width: 0; min-width: 0; }
  .sidebar-toggle { position: fixed; z-index: 201; left: 0; }
  .sidebar:not(.collapsed) ~ .sidebar-toggle { left: 220px; }
  .page-area { padding: 12px 10px 30px; }
  .teach-content { width: 100%; max-width: 100%; }
  .teach-split { flex-direction: column; }
  .teach-divider { width: 100%; height: 6px; cursor: row-resize; }
  .teach-canvas { min-height: 50vh; }
}

/* ─── Drag & Drop page move ─── */
.tree-page[draggable="true"] { cursor: grab; }
.tree-page.dragging { opacity: 0.35; }
.tree-pages.drag-over {
  background: rgba(99, 102, 241, 0.08);
  border-radius: 6px;
  outline: 2px dashed rgba(99, 102, 241, 0.4);
  outline-offset: -2px;
}
.tree-page.drag-insert-above {
  box-shadow: 0 -2px 0 0 #6366f1;
}
.tree-page.drag-insert-below {
  box-shadow: 0 2px 0 0 #6366f1;
}

/* ─── Timer (used in teach nav) ─── */
.ftn-timer {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary, #6366f1);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: center;
}

/* ─── Sidebar multi-select mode ─── */
.select-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(99,102,241,0.12);
  border-bottom: 1px solid rgba(99,102,241,0.25);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.8);
}
.select-bar button {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: #e0e0e0;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.select-bar button:hover { background: rgba(255,255,255,0.1); }
.select-bar button.danger { border-color: #ef4444; color: #fca5a5; }
.select-bar button.danger:hover { background: rgba(239,68,68,0.2); }
.select-bar .sel-count { flex: 1; }
.tree-page .page-checkbox {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  accent-color: #6366f1;
  cursor: pointer;
  flex-shrink: 0;
}
