/* ── Notes page overrides & specific styles ── */
/* Base: styles.css provides reset, theme vars, header, nav, password overlay, h-btn */

body { font-size: clamp(15px, 1vw + 10px, 17px); }
.h-btn { font-size: 13px; padding: 4px 10px; text-decoration: none; display: flex; align-items: center; gap: 4px; }
.h-btn:hover { border-color: var(--accent); color: var(--accent); }
.pw-overlay { z-index: 100; }
.pw-overlay.hidden { display: none; }

/* ── Layout ── */
.layout { display: flex; flex: 1; overflow: hidden; }
.layout.locked { filter: blur(8px); pointer-events: none; user-select: none; }

/* ── Sidebar ── */
.sidebar { width: 220px; border-right: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.sidebar-search { padding: 8px; border-bottom: 1px solid var(--border); }
.sidebar-search input { width: 100%; padding: 6px 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; outline: none; }
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text2); }
.doc-list { overflow-y: auto; flex: 1; }
.doc-cat { padding: 8px 14px 4px; font-size: 10px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.doc-item { padding: 7px 14px 7px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); color: var(--text2); transition: background .1s; line-height: 1.4; display: flex; align-items: baseline; gap: 6px; }
.doc-item:hover { background: var(--bg3); color: var(--text); }
.doc-item.active { background: var(--bg3); color: var(--accent); border-left: 3px solid var(--accent); font-weight: 600; }
.doc-num { font-size: 11px; color: var(--text2); opacity: .5; font-weight: 500; min-width: 18px; flex-shrink: 0; }

/* ── Main content ── */
.content-area { flex: 1; overflow-y: auto; padding: 24px 32px; min-width: 0; }
.content-area::-webkit-scrollbar { width: 4px; }
.content-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── TOC ── */
.toc { width: 220px; border-left: 1px solid var(--border); background: var(--bg2); overflow-y: auto; flex-shrink: 0; padding: 12px 0; }
.toc::-webkit-scrollbar { width: 3px; }
.toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.toc-title { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; padding: 4px 14px 8px; }
.toc a { display: block; padding: 3px 14px; font-size: 12px; color: var(--text2); text-decoration: none; line-height: 1.5; transition: color .1s; border-left: 2px solid transparent; }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.toc a.lv2 { padding-left: 24px; }
.toc a.lv3 { padding-left: 34px; font-size: 11px; }

/* ── Markdown rendered content ── */
.md-body { max-width: 900px; line-height: 1.85; font-size: clamp(15px, 0.95vw + 8px, 17px); }
.md-body h1 { font-size: clamp(22px, 1.6vw + 8px, 28px); font-weight: 700; margin: 0 0 18px; padding-bottom: 10px; border-bottom: 2px solid var(--accent); }
.md-body h2 { font-size: clamp(18px, 1.2vw + 6px, 22px); font-weight: 700; margin: 36px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.md-body h3 { font-size: clamp(15px, 1vw + 5px, 18px); font-weight: 600; margin: 28px 0 10px; }
.md-body h4 { font-size: clamp(14px, 0.8vw + 5px, 16px); font-weight: 600; margin: 18px 0 6px; color: var(--text2); }
.md-body p { margin: 0 0 14px; }
.md-body ul, .md-body ol { margin: 0 0 14px 22px; }
.md-body li { margin-bottom: 5px; line-height: 1.75; }
.md-body li > ul, .md-body li > ol { margin-top: 4px; margin-bottom: 4px; }
.md-body strong { color: var(--accent); }
.md-body blockquote { margin: 14px 0; padding: 12px 18px; border-left: 3px solid var(--accent); background: var(--bg3); border-radius: 0 6px 6px 0; color: var(--text2); font-size: 0.93em; }
.md-body code { background: var(--code-bg, var(--bg3)); padding: 2px 6px; border-radius: 4px; font-family: 'Fira Code', monospace; font-size: 0.86em; }
.md-body pre { background: var(--code-bg, var(--bg3)); padding: 14px 18px; border-radius: 8px; overflow-x: auto; margin: 14px 0; border: 1px solid var(--border); }
.md-body pre code { background: none; padding: 0; font-size: 0.86em; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.md-body a { color: var(--accent); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body figure { margin: 24px 0; text-align: center; }
.md-body img { display: inline-block; max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.md-body figcaption { text-align: center; font-size: 13px; color: var(--text2); margin-top: 8px; font-style: italic; }
.md-body table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: clamp(13px, 0.8vw + 6px, 15px); }
.md-body th { background: var(--bg3); font-weight: 600; text-align: left; padding: 8px 14px; border: 1px solid var(--border); white-space: nowrap; }
.md-body td { padding: 7px 14px; border: 1px solid var(--border); line-height: 1.6; }
.md-body tr:nth-child(even) { background: var(--table-stripe, rgba(0,0,0,.02)); }
.md-body tr:hover { background: var(--bg3); }
.md-body input[type="checkbox"] { margin-right: 6px; accent-color: var(--accent); }

/* ── Search highlight ── */
mark { background: rgba(34,197,94,.3); color: inherit; padding: 0 2px; border-radius: 2px; }

/* ── Mobile toggle ── */
.mobile-toggle { display: none; }

/* ── Reading progress bar ── */
.reading-progress { height: 3px; background: var(--bg3); flex-shrink: 0; overflow: hidden; }
.reading-progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .15s ease-out; }

/* ── FAB group (mobile only) ── */
.fab-group { display: none; position: fixed; bottom: 24px; right: 16px; z-index: 30; flex-direction: column; gap: 10px; align-items: center; }
.fab-btn { width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 20px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; transition: transform .15s, opacity .15s; -webkit-tap-highlight-color: transparent; }
.fab-btn:active { transform: scale(.9); }
.fab-btn.secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--border); font-size: 16px; width: 40px; height: 40px; }
.fab-btn.hidden { opacity: 0; pointer-events: none; transform: scale(.6); }
.fab-nav { display: flex; gap: 6px; }
.fab-nav .fab-btn.secondary { width: 36px; height: 36px; font-size: 14px; }

/* ── Bottom sheet TOC ── */
.toc-sheet-backdrop { display: none; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); opacity: 0; transition: opacity .25s; }
.toc-sheet-backdrop.open { display: block; opacity: 1; }
.toc-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg2); border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; max-height: 60vh; transform: translateY(100%); transition: transform .3s cubic-bezier(.32,.72,0,1); display: flex; flex-direction: column; box-shadow: 0 -4px 24px rgba(0,0,0,.15); }
.toc-sheet.open { transform: translateY(0); }
.toc-sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto 0; flex-shrink: 0; }
.toc-sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; flex-shrink: 0; }
.toc-sheet-header span { font-size: 14px; font-weight: 700; color: var(--text2); }
.toc-sheet-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 4px 8px; line-height: 1; }
.toc-sheet-body { overflow-y: auto; padding: 0 8px 20px; flex: 1; -webkit-overflow-scrolling: touch; }
.toc-sheet-body a { display: block; padding: 10px 12px; font-size: 14px; color: var(--text); text-decoration: none; border-radius: 8px; transition: background .1s; line-height: 1.4; }
.toc-sheet-body a:active { background: var(--bg3); }
.toc-sheet-body a.active { color: var(--accent); font-weight: 600; background: rgba(22,163,74,.06); }
.toc-sheet-body a.lv2 { padding-left: 28px; font-size: 13px; }
.toc-sheet-body a.lv3 { padding-left: 44px; font-size: 12px; color: var(--text2); }

/* ── Chat panel ── */
.chat-panel { position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 100vw; background: var(--bg2); border-left: 1px solid var(--border); z-index: 50; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .25s cubic-bezier(.32,.72,0,1); box-shadow: -4px 0 20px rgba(0,0,0,.1); }
.chat-panel.open { transform: translateX(0); }
.chat-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-panel-header h3 { font-size: 14px; font-weight: 700; }
.chat-panel-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 2px 6px; line-height: 1; }
.chat-panel-close:hover { color: var(--text); }

/* Note selector */
.note-selector { border-bottom: 1px solid var(--border); flex-shrink: 0; padding: 8px 0; }
.ns-current { padding: 2px 12px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.ns-current label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); font-weight: 600; cursor: pointer; }
.ns-current input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.ns-group { padding: 2px 12px; }
.ns-group-header { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; font-size: 11px; font-weight: 700; color: var(--text2); user-select: none; text-transform: uppercase; letter-spacing: .3px; }
.ns-group-header:hover { color: var(--text); }
.ns-group-header input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.ns-group-items { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; padding-left: 18px; }
.ns-item { display: flex; align-items: center; gap: 4px; padding: 1px 0; font-size: 11px; color: var(--text2); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ns-item:hover { color: var(--text); }
.ns-item input[type="checkbox"] { accent-color: var(--accent); margin: 0; flex-shrink: 0; }
.ns-item .ns-num { color: var(--text2); font-size: 10px; opacity: .6; font-weight: 500; min-width: 16px; }
.ns-item.current-doc { color: var(--accent); font-weight: 500; }
.ns-meta { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px; font-size: 11px; color: var(--text2); border-bottom: 1px solid var(--border); flex-shrink: 0; }

/* Chat messages */
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msgs::-webkit-scrollbar { width: 3px; }
.chat-msgs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-msg { padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.6; max-width: 90%; word-break: break-word; white-space: pre-wrap; }
.chat-msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
.chat-msg.assistant { background: var(--bg3); color: var(--text); align-self: flex-start; border-bottom-left-radius: 2px; white-space: normal; }
.chat-msg.assistant h4 { font-size: 13px; font-weight: 700; margin: 10px 0 4px; color: var(--accent); }
.chat-msg.assistant h4:first-child { margin-top: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 4px 0 8px 18px; padding: 0; }
.chat-msg.assistant li { margin-bottom: 2px; }
.chat-msg.assistant strong { color: var(--accent); font-weight: 600; }
.chat-msg.assistant table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 12px; }
.chat-msg.assistant th { background: rgba(0,0,0,.06); font-weight: 600; text-align: left; padding: 4px 8px; border: 1px solid var(--border); white-space: nowrap; }
[data-theme="dark"] .chat-msg.assistant th { background: rgba(255,255,255,.06); }
.chat-msg.assistant td { padding: 3px 8px; border: 1px solid var(--border); }
.chat-msg.assistant p { margin: 0 0 6px; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.chat-msg.system-info { background: transparent; color: var(--text2); font-size: 12px; text-align: center; align-self: center; }
.chat-typing span { display: inline-block; width: 6px; height: 6px; background: var(--text2); border-radius: 50%; margin: 0 2px; animation: chatDot .6s infinite alternate; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatDot { to { opacity: .2; transform: translateY(-4px); } }

/* Suggested questions */
.chat-suggestions { padding: 8px 12px 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.chat-suggestions-title { width: 100%; font-size: 11px; color: var(--text2); margin-bottom: 2px; }
.chat-chip { background: var(--bg3); border: 1px solid var(--border); border-radius: 16px; padding: 5px 12px; font-size: 12px; color: var(--text); cursor: pointer; transition: all .15s; line-height: 1.3; white-space: nowrap; }
.chat-chip:hover { border-color: var(--accent); color: var(--accent); background: rgba(22,163,74,.06); }
[data-theme="dark"] .chat-chip:hover { background: rgba(34,197,94,.08); }

/* Chat input */
.chat-input-area { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); flex-shrink: 0; align-items: flex-end; }
.chat-input-area textarea { flex: 1; padding: 8px 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; font-family: inherit; resize: none; outline: none; min-height: 36px; max-height: 100px; }
.chat-input-area textarea:focus { border-color: var(--accent); }
.chat-input-area button { padding: 8px 14px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; flex-shrink: 0; transition: opacity .15s; }
.chat-input-area button:hover { opacity: .85; }
.chat-input-area button:disabled { opacity: .4; cursor: not-allowed; }

/* Chat backdrop (mobile) */
.chat-backdrop { display: none; position: fixed; inset: 0; z-index: 49; background: rgba(0,0,0,.4); }
.chat-backdrop.open { display: block; }

/* ── Notes theme extras ── */
:root { --code-bg: #F1F5F9; --table-stripe: rgba(0,0,0,.02); }
[data-theme="dark"] { --code-bg: #0F172A; --table-stripe: rgba(255,255,255,.03); }

/* ── Responsive ── */
@media (min-width: 1400px) {
  .content-area { padding: 28px 48px; }
  .md-body { max-width: 960px; }
}
@media (max-width: 900px) {
  .toc { display: none; }
  .content-area { padding: 18px 20px; }
  .fab-group { display: flex; }
  .chat-panel { width: 340px; }
}
@media (max-width: 700px) {
  .sidebar { display: none; position: fixed; top: 44px; left: 0; bottom: 0; width: 260px; z-index: 20; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .sidebar.open { display: flex; }
  .mobile-toggle { display: flex; }
  .header-nav { margin-left: 6px; padding-left: 6px; }
  .nav-link { font-size: 11px; padding: 3px 6px; }
  .content-area { padding: 14px 12px; }
  .md-body { font-size: 15px; line-height: 1.8; }
  .md-body h1 { font-size: 20px; }
  .md-body h2 { font-size: 17px; margin: 28px 0 10px; }
  .md-body h3 { font-size: 15px; }
  .md-body table { font-size: 12px; }
  .md-body th, .md-body td { padding: 5px 8px; }
  .md-body blockquote { padding: 8px 12px; }
  .chat-panel { width: 100vw; }
  .ns-group-items { grid-template-columns: 1fr; }
}
