/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --header-h: 52px;
  --sidebar-w: 260px;
  --accent: #1a73e8;
  --accent-dark: #1558b0;
  --danger: #d32f2f;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #212121;
  --text-muted: #757575;
  --nav-hover: #e8f0fe;
  --nav-active: #d2e3fc;
  --nav-active-text: #1a73e8;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: #1e3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

#header-left { display: flex; align-items: center; gap: 12px; }

#site-title { font-size: 17px; font-weight: 600; letter-spacing: .2px; }

#burger {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; padding: 4px 6px;
  border-radius: var(--radius);
  display: none;
}
#burger:hover { background: rgba(255,255,255,.15); }

#header-right { display: flex; align-items: center; gap: 8px; }

#user-label { font-size: 13px; color: rgba(255,255,255,.75); }

/* ── Layout ─────────────────────────────────────────────────── */
#layout {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

/* ── Sidebar ─────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--header-h);
  bottom: 0;
  overflow-y: auto;
  padding: 12px 0;
  transition: transform .25s ease;
}

#nav-tree { padding: 0 8px; }

.nav-section { margin-bottom: 4px; }

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.nav-section-header:hover { background: var(--nav-hover); }

.nav-section-header .arrow {
  font-size: 10px;
  transition: transform .2s;
  margin-right: 2px;
  color: var(--text-muted);
}
.nav-section-header.open .arrow { transform: rotate(90deg); }

.nav-section-header .section-actions {
  margin-left: auto;
  display: none;
  gap: 2px;
}
.nav-section-header:hover .section-actions { display: flex; }

.nav-section-articles { padding-left: 16px; }

.nav-article {
  display: flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
  gap: 4px;
}
.nav-article:hover { background: var(--nav-hover); }
.nav-article.active {
  background: var(--nav-active);
  color: var(--nav-active-text);
  font-weight: 500;
}

.nav-article .article-actions {
  margin-left: auto;
  display: none;
  gap: 2px;
}
.nav-article:hover .article-actions { display: flex; }

.nav-subsection { padding-left: 12px; }

.nav-loading { padding: 12px; color: var(--text-muted); font-size: 13px; }

/* ── Main content ─────────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 860px;
}

#content {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 32px 36px;
  min-height: 300px;
}

/* ── Article typography ──────────────────────────────────────── */
.article-header { margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.article-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.article-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.article-body h1, .article-body h2, .article-body h3 { margin: 20px 0 8px; font-weight: 600; }
.article-body h1 { font-size: 20px; }
.article-body h2 { font-size: 17px; }
.article-body h3 { font-size: 15px; }
.article-body p { margin: 0 0 12px; line-height: 1.65; }
.article-body ul, .article-body ol { margin: 0 0 12px 20px; line-height: 1.65; }
.article-body li { margin-bottom: 4px; }
.article-body a { color: var(--accent); text-decoration: none; }
.article-body a:hover { text-decoration: underline; }
.article-body code { background: #f1f3f4; padding: 1px 5px; border-radius: 3px; font-size: 13px; font-family: monospace; }
.article-body pre { background: #f1f3f4; padding: 12px 16px; border-radius: var(--radius); overflow-x: auto; margin-bottom: 12px; }
.article-body pre code { background: none; padding: 0; }
.article-body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-muted); margin: 0 0 12px; }
.article-body strong { font-weight: 600; }
.article-body hr { border: none; border-top: 2px solid var(--border); margin: 16px 0; }
.article-body table { border-collapse: collapse; width: 100%; margin-bottom: 12px; }
.article-body td, .article-body th { border: 1px solid var(--border); padding: 6px 10px; }
.article-body th { background: var(--bg); font-weight: 600; }

.admin-article-actions { display: flex; gap: 8px; margin-left: auto; }

#welcome { padding: 20px 0; }
#welcome h1 { font-size: 22px; margin-bottom: 8px; }
#welcome p { color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: #fff; color: var(--accent);
  border: 1px solid var(--accent);
  padding: 6px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-secondary:hover { background: var(--nav-hover); }

.btn-ghost {
  background: none; border: none; color: rgba(255,255,255,.85);
  padding: 6px 10px; border-radius: var(--radius);
  font-size: 13px; cursor: pointer;
}
.btn-ghost:hover { background: rgba(255,255,255,.15); }

.btn-danger {
  background: var(--danger); color: #fff; border: none;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-danger:hover { background: #b71c1c; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  padding: 2px 5px; border-radius: 4px; font-size: 12px;
  color: var(--text-muted); line-height: 1;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.danger:hover { background: #fdecea; color: var(--danger); }

/* ── Modals ──────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: 10px;
  padding: 28px;
  width: 100%; max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-box--wide { max-width: 760px; }

.modal-box h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }

.modal-box label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text-muted); margin-bottom: 14px;
}

.modal-box label input,
.modal-box label select {
  display: block; width: 100%;
  margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; background: var(--bg);
  outline: none;
}
.modal-box label input:focus,
.modal-box label select:focus { border-color: var(--accent); }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
}
.modal-actions .btn-ghost { color: var(--text-muted); }
.modal-actions .btn-ghost:hover { background: var(--nav-hover); }

.error-msg {
  background: #fdecea; color: var(--danger);
  border-radius: var(--radius); padding: 8px 12px;
  font-size: 13px; margin-bottom: 14px;
}
.error-msg.hidden { display: none; }

/* TipTap toolbar */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg);
}

.tt-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
}
.tt-btn:hover { background: var(--nav-hover); border-color: var(--border); }
.tt-btn.active { background: var(--nav-active); color: var(--nav-active-text); border-color: var(--accent); }

.tt-sep {
  width: 1px;
  background: var(--border);
  margin: 2px 4px;
  align-self: stretch;
  flex-shrink: 0;
}

.tt-color {
  width: 30px;
  height: 28px;
  padding: 2px 3px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

/* TipTap editor content area */
.tiptap-editor-wrap {
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: #fff;
}
.tiptap-editor-wrap:focus-within { border-color: var(--accent); }

.tiptap-editor-wrap {
  overflow-y: auto;
  height: 280px;
}
.tiptap-editor-wrap .ProseMirror {
  min-height: 100%;
  padding: 14px 16px;
  outline: none;
  font-size: 14px;
  line-height: 1.65;
}
.tiptap-editor-wrap .ProseMirror > * + * { margin-top: 6px; }
.tiptap-editor-wrap .ProseMirror h1 { font-size: 20px; font-weight: 600; margin: 16px 0 6px; }
.tiptap-editor-wrap .ProseMirror h2 { font-size: 17px; font-weight: 600; margin: 14px 0 6px; }
.tiptap-editor-wrap .ProseMirror h3 { font-size: 15px; font-weight: 600; margin: 12px 0 4px; }
.tiptap-editor-wrap .ProseMirror p { margin: 0 0 8px; }
.tiptap-editor-wrap .ProseMirror ul,
.tiptap-editor-wrap .ProseMirror ol { margin: 0 0 8px 20px; }
.tiptap-editor-wrap .ProseMirror blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-muted); margin: 0 0 8px; }
.tiptap-editor-wrap .ProseMirror code { background: #f1f3f4; padding: 1px 5px; border-radius: 3px; font-size: 13px; font-family: monospace; }
.tiptap-editor-wrap .ProseMirror pre { background: #f1f3f4; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 8px; overflow-x: auto; }
.tiptap-editor-wrap .ProseMirror pre code { background: none; padding: 0; }
.tiptap-editor-wrap .ProseMirror a { color: var(--accent); }
.tiptap-editor-wrap .ProseMirror hr { border: none; border-top: 2px solid var(--border); margin: 14px 0; }
.tiptap-editor-wrap .ProseMirror table { border-collapse: collapse; width: 100%; margin-bottom: 8px; }
.tiptap-editor-wrap .ProseMirror td,
.tiptap-editor-wrap .ProseMirror th { border: 1px solid var(--border); padding: 6px 10px; min-width: 60px; }
.tiptap-editor-wrap .ProseMirror th { background: var(--bg); font-weight: 600; }
.tiptap-editor-wrap .ProseMirror .selectedCell { background: var(--nav-active); }

/* ── Overlay (mobile) ────────────────────────────────────────── */
#overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 50;
}

/* ── Color picker ────────────────────────────────────────────── */
.color-picker-popup {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}

.color-swatches { display: flex; gap: 8px; }

.color-swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform .1s, border-color .1s;
}
.color-swatch:hover {
  transform: scale(1.25);
  border-color: rgba(0,0,0,.35);
}

/* ── Hidden article indicators ───────────────────────────────── */
.hidden-badge {
  font-size: 10px;
  background: #f3e8ff;
  color: #7c3aed;
  border-radius: 3px;
  padding: 1px 5px;
  font-weight: 600;
  letter-spacing: .2px;
  vertical-align: middle;
  margin-left: 4px;
}

.article-hidden-notice {
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #854d0e;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.modal-box label.checkbox-row {
  display: flex;
  align-items: center;
  flex-direction: row;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font-weight: 400;
}
.modal-box label.checkbox-row input[type="checkbox"] {
  display: inline;
  width: auto;
  margin: 0;
}

/* ── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 700px) {
  #burger { display: block; }

  #sidebar {
    transform: translateX(-100%);
    z-index: 60;
    width: min(var(--sidebar-w), 85vw);
  }
  #sidebar.open { transform: translateX(0); }

  #overlay.open { display: block; }

  #main { margin-left: 0; padding: 16px; }

  #content { padding: 20px 18px; }

  .modal-box--wide { max-width: 100%; }

  #header-right .btn-secondary { display: none; }
}
