/* ===========================================================
   Sammlung — theme tokens (light default, dark override below)
   =========================================================== */
:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-sidebar: #1f2a44;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
  --text: #1c2430;
  --text-muted: #6b7280;
  --text-on-sidebar: #dfe4f0;
  --text-on-sidebar-muted: #9aa5c2;
  --border: #e2e5eb;
  --accent: #3b6ef6;
  --accent-hover: #2e5bd6;
  --accent-contrast: #ffffff;
  --danger: #d64545;
  --danger-hover: #b93636;
  --success: #2f9e5b;
  --chip-bg: #eef1fb;
  --chip-text: #3b4a8b;
  --shadow: 0 1px 3px rgba(20, 24, 33, 0.08), 0 1px 2px rgba(20, 24, 33, 0.06);
  --radius: 10px;
  --code-bg: #eef0f4;
}

:root[data-theme="dark"] {
  --bg: #14181f;
  --bg-elevated: #1c212b;
  --bg-sidebar: #10141c;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
  --text: #e7e9ee;
  --text-muted: #97a0b3;
  --text-on-sidebar: #d7dcec;
  --text-on-sidebar-muted: #7c869e;
  --border: #2a3140;
  --accent: #6f92ff;
  --accent-hover: #85a2ff;
  --accent-contrast: #0d1117;
  --danger: #e2685f;
  --danger-hover: #ea8079;
  --success: #4fbd80;
  --chip-bg: #232a3b;
  --chip-text: #aeb9ee;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --code-bg: #232a3b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f;
    --bg-elevated: #1c212b;
    --bg-sidebar: #10141c;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
    --text: #e7e9ee;
    --text-muted: #97a0b3;
    --text-on-sidebar: #d7dcec;
    --text-on-sidebar-muted: #7c869e;
    --border: #2a3140;
    --accent: #6f92ff;
    --accent-hover: #85a2ff;
    --accent-contrast: #0d1117;
    --danger: #e2685f;
    --danger-hover: #ea8079;
    --success: #4fbd80;
    --chip-bg: #232a3b;
    --chip-text: #aeb9ee;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --code-bg: #232a3b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 56px;
  padding: 0 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.search-box { flex: 1; max-width: 480px; }
.search-box input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}
.search-box input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }

.only-mobile { display: none; }

/* ---------------- Buttons ---------------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon {
  width: 32px; height: 32px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem;
}

/* ---------------- Layout ---------------- */
.body-layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  color: var(--text-on-sidebar);
  overflow-y: auto;
  padding: 14px 10px 30px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.sidebar-nav a, .sidebar-home-link, .sidebar-trash-link {
  color: var(--text-on-sidebar);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
}
.sidebar-nav a:hover { background: var(--bg-sidebar-hover); text-decoration: none; }

.sidebar-section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-on-sidebar-muted);
  margin: 18px 10px 6px;
  font-weight: 600;
}

.folder-tree { font-size: 0.9rem; }
.folder-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  padding: 2px 4px;
}
.folder-row:hover { background: var(--bg-sidebar-hover); }
.folder-toggle {
  background: none; border: none; color: var(--text-on-sidebar-muted);
  cursor: pointer; width: 18px; flex-shrink: 0; font-size: 0.7rem;
  transform: rotate(0deg); transition: transform .12s ease;
}
.folder-node.expanded > .folder-row > .folder-toggle { transform: rotate(90deg); }
.folder-toggle.leaf { visibility: hidden; }
.folder-link { color: var(--text-on-sidebar); flex: 1; padding: 6px 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-link:hover { text-decoration: none; color: #fff; }
.folder-link.active { color: var(--accent); font-weight: 600; }
.folder-count { color: var(--text-on-sidebar-muted); font-size: 0.76rem; margin-right: 4px; }
.folder-children { margin-left: 16px; display: none; border-left: 1px solid rgba(255,255,255,0.08); padding-left: 4px; }
.folder-node.expanded > .folder-children { display: block; }
.folder-empty-hint { color: var(--text-on-sidebar-muted); font-size: 0.82rem; padding: 4px 10px; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px; }
.tag-pill {
  background: rgba(255,255,255,0.08);
  color: var(--text-on-sidebar);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
}
.tag-pill:hover { background: rgba(255,255,255,0.16); text-decoration: none; }
.tag-pill .count { color: var(--text-on-sidebar-muted); margin-left: 3px; }

.sidebar-backdrop { display: none; }

.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 60px;
}

.main-inner { max-width: 980px; margin: 0 auto; }

/* ---------------- Breadcrumb ---------------- */
.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { color: var(--border); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

/* ---------------- Page list / folder view ---------------- */
.list-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}
.list-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.sort-toggle { display: flex; gap: 4px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.sort-toggle button {
  border: none; background: transparent; color: var(--text-muted);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.82rem; font-weight: 500;
}
.sort-toggle button.active { background: var(--accent); color: var(--accent-contrast); }

.folder-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.folder-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow); font-weight: 600; font-size: 0.9rem;
}
.folder-chip .muted { color: var(--text-muted); font-weight: 400; font-size: 0.8rem; }

.home-tags { margin-bottom: 18px; }

.page-card-list { display: flex; flex-direction: column; gap: 10px; }
.page-card {
  display: block;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  color: var(--text);
}
.page-card:hover { border-color: var(--accent); text-decoration: none; }
.page-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.page-card-meta { font-size: 0.78rem; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.page-card-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }

.empty-state {
  text-align: center; color: var(--text-muted); padding: 60px 20px;
}
.empty-state .big { font-size: 2.4rem; margin-bottom: 8px; }

/* ---------------- Tag chips (generic) ---------------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--chip-bg); color: var(--chip-text);
  border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; font-weight: 500;
}
.chip a { color: inherit; }

/* ---------------- Page detail ---------------- */
.page-detail-grid { display: grid; grid-template-columns: 1fr 260px; gap: 24px; align-items: start; }

.page-header { margin-bottom: 10px; }
.page-header h1 { margin: 0 0 6px; font-size: 1.9rem; }

.markdown-body { line-height: 1.65; font-size: 1rem; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { line-height: 1.3; }
.markdown-body h1 { font-size: 1.5rem; margin-top: 1.6em; }
.markdown-body h2 { font-size: 1.25rem; margin-top: 1.4em; }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body p { margin: 0.9em 0; }
.markdown-body a { color: var(--accent); }
.markdown-body code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body pre {
  background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent); margin: 1em 0; padding: 2px 14px; color: var(--text-muted);
}
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; }
.markdown-body img { max-width: 100%; border-radius: 6px; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.6em 0; }

.side-panel { display: flex; flex-direction: column; gap: 14px; }
.side-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.side-card-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 700; margin-bottom: 8px;
}
.side-card .chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.side-card .meta-name { font-weight: 600; }
.side-card .meta-date { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }
.side-card .actions { display: flex; flex-direction: column; gap: 8px; }
.side-card .actions .btn { width: 100%; text-align: center; }
.side-card .actions .btn.btn-icon { width: 32px; align-self: center; }

/* ---------------- Forms ---------------- */
.form-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow);
}
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.form-row .hint { color: var(--text-muted); font-size: 0.78rem; margin-top: 4px; }
.form-row input[type=text], .form-row input[type=search] {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.92rem;
}
.form-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-row-flex { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row-flex > .form-row { flex: 1; min-width: 220px; }

.editor-toolbar { display: flex; gap: 6px; margin-bottom: 8px; }
.editor-toolbar button {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 0.8rem;
}
.editor-toolbar button.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.md-toolbar { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.md-toolbar button {
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
}
.md-toolbar button:hover { background: var(--bg); }

.editor-area { display: grid; gap: 14px; }
.editor-area.split { grid-template-columns: 1fr 1fr; }
#contentInput {
  width: 100%; min-height: 420px; resize: vertical; padding: 12px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92rem; line-height: 1.55;
}
#contentInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#contentInput.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.preview-pane {
  border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px;
  background: var(--bg); min-height: 420px; overflow-y: auto;
}

.form-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: space-between; align-items: center; }
.form-actions-left { display: flex; gap: 10px; }

/* ---------------- Trash ---------------- */
.trash-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 10px; box-shadow: var(--shadow); flex-wrap: wrap;
}
.trash-item-info .title { font-weight: 600; }
.trash-item-info .meta { font-size: 0.78rem; color: var(--text-muted); }
.trash-actions { display: flex; gap: 8px; }

/* ---------------- Modal (confirm dialogs) ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 18, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-box {
  background: var(--bg-elevated); border-radius: var(--radius); padding: 22px 24px;
  max-width: 420px; width: 100%; box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0 0 10px; }
.modal-box p { color: var(--text-muted); font-size: 0.92rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast-container { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: 8px; padding: 10px 16px; font-size: 0.88rem; color: var(--text);
  animation: toast-in .15s ease-out;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .page-detail-grid { grid-template-columns: 1fr; }
  .side-panel { order: -1; }
}

@media (max-width: 720px) {
  .only-mobile { display: flex; }
  .brand span { display: none; }
  .main { padding: 18px 16px 50px; }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,0.4); z-index: 30;
  }
  .sidebar-backdrop.open { display: block; }
  .editor-area.split { grid-template-columns: 1fr; }
}
