/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --nav-h: 52px;
  --sidebar-w: 240px;

  --nav-bg: #0d1117;
  --nav-text: #e6edf3;
  --nav-border: #21262d;

  --sidebar-bg: #1565c0;
  --sidebar-hover: rgba(255,255,255,0.12);
  --sidebar-active: rgba(255,255,255,0.22);
  --sidebar-text: #e3f2fd;
  --sidebar-header: rgba(255,255,255,0.55);

  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #24292f;
  --text-muted: #656d76;
  --accent: #1976d2;
  --accent-dark: #1565c0;
  --accent-light: #e3f2fd;
  --danger: #cf222e;
  --danger-light: #fff1f0;

  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.15);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }

/* ── Top Navbar ────────────────────────────────────────────────────────────── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
}

.topnav-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topnav-center { flex: 1; max-width: 560px; margin: 0 auto; }
.topnav-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.sidebar-toggle {
  background: none; border: none; color: var(--nav-text);
  font-size: 18px; padding: 4px 6px; border-radius: var(--radius);
  opacity: 0.7; transition: opacity .15s;
}
.sidebar-toggle:hover { opacity: 1; background: rgba(255,255,255,.1); }

.topnav-logo {
  display: flex; align-items: center; gap: 8px;
  color: var(--nav-text); font-weight: 600; font-size: 1rem;
  text-decoration: none;
}
.topnav-logo:hover { text-decoration: none; opacity: .85; }
.logo-icon { font-size: 1.3rem; }

.search-form {
  position: relative; display: flex; align-items: center;
}
.search-form .search-icon {
  position: absolute; left: 10px; color: #6e7681; pointer-events: none;
}
.search-form input {
  width: 100%; padding: 7px 12px 7px 36px;
  background: #161b22; border: 1px solid #30363d; border-radius: 6px;
  color: var(--nav-text); font-size: .9rem;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-form input::placeholder { color: #6e7681; }
.search-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(25,118,210,.25); }

.btn-new {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 6px 14px; font-size: .85rem; font-weight: 500;
  text-decoration: none; white-space: nowrap; transition: background .15s;
}
.btn-new:hover { background: var(--accent-dark); text-decoration: none; }

.btn-icon {
  background: none; border: none; color: #8b949e;
  padding: 6px; border-radius: var(--radius); display: flex; align-items: center;
  transition: color .15s, background .15s; text-decoration: none;
}
.btn-icon:hover { color: var(--nav-text); background: rgba(255,255,255,.1); text-decoration: none; }

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

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  display: flex; flex-direction: column;
  position: fixed; top: var(--nav-h); left: 0; bottom: 0;
  overflow-y: auto; overflow-x: hidden;
  transition: transform .2s ease, width .2s ease;
  z-index: 50;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }
.layout.sidebar-collapsed .main { margin-left: 0; }

.sidebar-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px 10px;
  color: var(--sidebar-header);
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-nav { padding: 8px 0; }

.sidebar-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 16px;
  color: var(--sidebar-text); font-size: .875rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .12s;
}
.sidebar-link:hover { background: var(--sidebar-hover); text-decoration: none; }
.sidebar-link.active {
  background: var(--sidebar-active);
  border-left-color: #fff;
  font-weight: 500;
}
.sidebar-link svg { flex-shrink: 0; opacity: .75; }

/* ── Main Content ──────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  transition: margin-left .2s ease;
}

/* ── Page Wrapper ──────────────────────────────────────────────────────────── */
.page-wrapper {
  padding: 28px 32px;
  max-width: 1200px;
}

.page-content-area { width: 100%; }

.page-header { margin-bottom: 24px; }
.page-title {
  font-size: 1.75rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
.page-subtitle { margin-top: 6px; color: var(--text-muted); font-size: .95rem; }

/* ── Home Actions ──────────────────────────────────────────────────────────── */
.home-actions {
  display: flex; gap: 16px; margin-bottom: 32px; flex-wrap: wrap;
}

.action-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  cursor: pointer; font-family: inherit; text-align: left;
  text-decoration: none; color: var(--text);
  transition: box-shadow .15s, border-color .15s;
  min-width: 200px;
}
.action-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); text-decoration: none; }
.action-icon { font-size: 1.6rem; }
.action-card strong { display: block; font-size: .95rem; }
.action-card p { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }

/* ── Section ───────────────────────────────────────────────────────────────── */
.home-section { margin-top: 24px; }
.section-title {
  font-size: 1rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Page Cards Grid ───────────────────────────────────────────────────────── */
.page-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.page-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; color: var(--text);
  transition: box-shadow .15s, border-color .15s;
}
.page-card:hover { box-shadow: var(--shadow); border-color: var(--accent); text-decoration: none; }
.page-card-icon { font-size: 1.2rem; flex-shrink: 0; }
.page-card-title { font-size: .9rem; font-weight: 500; }
.page-card-meta { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Empty State ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 56px 24px;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.2rem; color: var(--text); margin-bottom: 6px; }
.empty-state p { margin-bottom: 20px; }

/* ── Page View ─────────────────────────────────────────────────────────────── */
.page-header-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.meta-date { font-size: .82rem; color: var(--text-muted); }

.page-header-actions { display: flex; align-items: center; gap: 8px; }

.btn-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--radius);
  font-size: .82rem; font-weight: 500; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  text-decoration: none; transition: background .12s, border-color .12s;
  cursor: pointer; font-family: inherit;
}
.btn-action:hover { background: var(--bg); border-color: var(--accent); text-decoration: none; }
.btn-edit { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.btn-edit:hover { background: #bbdefb; }
.btn-danger { color: var(--danger); border-color: #ffc1c1; background: var(--danger-light); }
.btn-danger:hover { background: #ffe4e4; }

.page-body {
  display: flex; gap: 32px; align-items: flex-start;
}
.page-content { flex: 1; min-width: 0; }

.doc-title {
  font-size: 2rem; font-weight: 700; margin-bottom: 24px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
  color: var(--text);
}

/* ── Markdown Body ─────────────────────────────────────────────────────────── */
.markdown-body {
  font-size: .975rem; line-height: 1.75; color: var(--text);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin-top: 1.8em; margin-bottom: .6em; font-weight: 600; line-height: 1.3;
  scroll-margin-top: calc(var(--nav-h) + 16px);
}
.markdown-body h1 { font-size: 1.6rem; border-bottom: 1px solid var(--border); padding-bottom: .4em; }
.markdown-body h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.markdown-body h3 { font-size: 1.1rem; }
.markdown-body p { margin-bottom: 1em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.6em; margin-bottom: 1em; }
.markdown-body li { margin-bottom: .25em; }
.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  padding: .5em 1em; margin: 1em 0;
  background: var(--accent-light); border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
}
.markdown-body code {
  background: #f0f1f3; border: 1px solid var(--border);
  padding: .15em .4em; border-radius: 4px;
  font-family: 'SFMono-Regular', Consolas, monospace; font-size: .88em;
}
.markdown-body pre {
  background: #0d1117; border: 1px solid #30363d; border-radius: var(--radius);
  padding: 16px; overflow-x: auto; margin-bottom: 1em;
}
.markdown-body pre code {
  background: none; border: none; padding: 0; font-size: .875rem;
  color: #e6edf3;
}
.markdown-body table {
  width: 100%; border-collapse: collapse; margin-bottom: 1em; font-size: .9rem;
}
.markdown-body th {
  background: var(--bg); font-weight: 600; text-align: left;
  padding: 8px 12px; border: 1px solid var(--border);
}
.markdown-body td { padding: 8px 12px; border: 1px solid var(--border); }
.markdown-body tr:nth-child(even) td { background: #f9fafb; }
.markdown-body img {
  max-width: 100%; height: auto; border-radius: var(--radius);
  box-shadow: var(--shadow); margin: .5em 0;
}
.markdown-body a { color: var(--accent); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

/* Syntax highlight */
.highlight { background: #0d1117 !important; }
.highlight .hll { background-color: #1c2128; }

/* ── TOC Sidebar ───────────────────────────────────────────────────────────── */
.toc-sidebar {
  width: 200px; flex-shrink: 0;
  position: sticky; top: calc(var(--nav-h) + 20px);
  max-height: calc(100vh - var(--nav-h) - 40px);
  overflow-y: auto;
}
.toc-header {
  display: flex; align-items: center; gap: 6px;
  font-size: .75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.toc-body { font-size: .82rem; }
.toc-body .toc { list-style: none; padding: 0; }
.toc-body .toc li { margin: 0; }
.toc-body .toc a {
  display: block; padding: 3px 6px; border-radius: 4px;
  color: var(--text-muted); text-decoration: none;
  transition: color .12s, background .12s;
  border-left: 2px solid transparent;
}
.toc-body .toc a:hover { color: var(--accent); background: var(--accent-light); }
.toc-body .toc a.toc-active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.toc-body .toc li li a { padding-left: 16px; }
.toc-body .toc li li li a { padding-left: 28px; }

/* ── Floating Edit Button ──────────────────────────────────────────────────── */
.fab-edit {
  position: fixed; bottom: 32px; right: 32px; z-index: 200;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(25,118,210,.5);
  text-decoration: none;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.fab-edit:hover {
  background: var(--accent-dark); text-decoration: none;
  transform: scale(1.08); box-shadow: 0 6px 20px rgba(25,118,210,.6);
}

/* ── Editor ────────────────────────────────────────────────────────────────── */
.editor-wrapper {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--nav-h));
  background: var(--surface);
}

.editor-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.title-input {
  flex: 1; font-size: 1.3rem; font-weight: 600;
  border: none; outline: none; background: transparent;
  color: var(--text); padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: border-color .15s;
}
.title-input:focus { border-bottom-color: var(--accent); }
.title-input::placeholder { color: #c9d1d9; }

.editor-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.editor-image-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px;
  background: #f8f9fa; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.img-upload-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--radius);
  font-size: .82rem; font-weight: 500; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); transition: background .12s, border-color .12s;
}
.img-upload-btn:hover { background: var(--accent-light); border-color: var(--accent); }
.img-bar-hint { font-size: .78rem; color: var(--text-muted); }

/* EasyMDE overrides */
.EasyMDEContainer { flex: 1; display: flex; flex-direction: column; }
.EasyMDEContainer .CodeMirror { flex: 1; border: none; border-radius: 0; font-size: .92rem; }
.EasyMDEContainer .editor-toolbar { border-radius: 0; border-left: none; border-right: none; }
.EasyMDEContainer .editor-statusbar { border-top: 1px solid var(--border); font-size: .78rem; }
.editor-preview { padding: 20px 32px; font-size: .975rem; line-height: 1.75; }

/* ── Search Page ───────────────────────────────────────────────────────────── */
.search-bar-big {
  display: flex; gap: 10px; margin-bottom: 8px;
}
.search-bar-big input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .95rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-bar-big input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(25,118,210,.15); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border: none;
  padding: 8px 18px; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: background .15s;
}
.btn-primary:hover { background: var(--accent-dark); text-decoration: none; }
.btn-full { width: 100%; justify-content: center; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); padding: 7px 16px;
  border-radius: var(--radius); font-size: .875rem; font-weight: 500;
  cursor: pointer; text-decoration: none; transition: background .12s;
}
.btn-secondary:hover { background: var(--bg); text-decoration: none; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface); border-radius: 10px;
  box-shadow: var(--shadow-md); width: 100%; max-width: 480px;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 1.1rem;
  color: var(--text-muted); cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--bg);
}

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-group input[type="text"] {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(25,118,210,.15); }

.file-drop {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center; color: var(--text-muted);
  transition: border-color .15s, background .15s; cursor: default;
}
.file-drop.drag-over { border-color: var(--accent); background: var(--accent-light); }
.file-drop svg { margin-bottom: 10px; opacity: .5; }
.file-drop p { font-size: .88rem; margin: 0; }
.file-chosen { font-size: .85rem; color: var(--accent); margin-top: 8px !important; font-weight: 500; }

/* ── Login Page ────────────────────────────────────────────────────────────── */
.login-body {
  background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); padding: 36px 32px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-icon-lg { font-size: 2.8rem; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 1.6rem; font-weight: 700; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: .88rem; margin-top: 4px; }
.login-form .form-group { margin-bottom: 18px; }
.login-form input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .95rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(25,118,210,.15); }
.login-form .btn-primary { margin-top: 4px; padding: 11px; font-size: 1rem; }

.alert-error {
  background: var(--danger-light); border: 1px solid #ffc1c1;
  color: var(--danger); border-radius: var(--radius);
  padding: 10px 14px; font-size: .875rem; margin-bottom: 16px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .toc-sidebar { display: none; }
  .page-wrapper { padding: 20px 16px; }
}

@media (max-width: 680px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .main { margin-left: 0; }
  .layout.sidebar-open .sidebar { transform: translateX(0); }
  .topnav-center { max-width: none; }
  .btn-new span { display: none; }
}
