/* ============================================================
   Startpunkt — Design-Tokens
   ============================================================ */

:root {
  --bg: #14151a;
  --surface: #1b1d24;
  --surface-2: #24272f;
  --surface-3: #2c2f39;
  --border: #2e323c;
  --border-soft: #262933;
  --text: #edeef2;
  --text-muted: #939aac;
  --text-faint: #656c7d;

  --accent: #6c8eef;
  --accent-strong: #8aa4f3;
  --accent-soft: rgba(108, 142, 239, 0.14);
  --accent-glow: rgba(108, 142, 239, 0.25);

  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.14);

  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.4);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f3f2ee;
  --surface: #fdfcfa;
  --surface-2: #f2f0ea;
  --surface-3: #e9e6de;
  --border: #ddd9cf;
  --border-soft: #e6e3da;
  --text: #211f1a;
  --text-muted: #6b6a63;
  --text-faint: #9a988f;

  --accent-soft: rgba(108, 142, 239, 0.12);
  --accent-glow: rgba(108, 142, 239, 0.18);
  --danger-soft: rgba(229, 72, 77, 0.1);
  color-scheme: light;
}

body[data-space="aktiv"] {
  --accent: #ff8a5b;
  --accent-strong: #ffa47d;
  --accent-soft: rgba(255, 138, 91, 0.14);
  --accent-glow: rgba(255, 138, 91, 0.28);
}

body[data-space="archiv"] {
  --accent: #6c8eef;
  --accent-strong: #8aa4f3;
  --accent-soft: rgba(108, 142, 239, 0.14);
  --accent-glow: rgba(108, 142, 239, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

::selection { background: var(--accent-glow); }

a { color: inherit; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================
   App shell
   ============================================================ */

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

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 60px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  background-image: radial-gradient(600px 120px at 15% 0%, var(--accent-glow), transparent 70%);
}

.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -0.01em; flex-shrink: 0; }
.brand-mark { color: var(--accent); font-size: 20px; transition: color 0.25s ease; }

.space-switch { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 999px; padding: 3px; }

.space-tab {
  border: none;
  background: transparent;
  padding: 7px 16px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.space-tab:hover { color: var(--text); }
.space-tab[aria-selected="true"] { background: var(--accent); color: #14151a; }
[data-theme="light"] .space-tab[aria-selected="true"] { color: #fff; }
.space-tab .tab-count { opacity: 0.65; font-weight: 500; margin-left: 5px; }

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

.searchbox { position: relative; display: flex; align-items: center; }
.searchbox-icon { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }
.searchbox input {
  width: 260px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px 8px 32px;
  font-size: 13px;
  transition: width 0.2s ease, border-color 0.15s ease;
}
.searchbox input:focus { width: 320px; border-color: var(--accent); outline: none; }
.searchbox input::placeholder { color: var(--text-faint); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-soft); }

/* ============================================================
   Layout body: sidebar + content
   ============================================================ */

.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 8px;
  flex-shrink: 0;
}
.sidebar-title { font-family: var(--font-display); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

.tree { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.tree:focus { outline: none; }

.sidebar-footer { padding: 10px 14px; border-top: 1px solid var(--border-soft); flex-shrink: 0; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 20px 28px 28px; overflow-y: auto; }

.content-header { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-family: var(--font-display); font-weight: 600; font-size: 19px; letter-spacing: -0.01em; min-width: 0; }
.breadcrumb .crumb { color: var(--text-muted); cursor: pointer; }
.breadcrumb .crumb:hover { color: var(--text); }
.breadcrumb .crumb.current { color: var(--text); cursor: default; }
.breadcrumb .sep { color: var(--text-faint); font-weight: 400; margin: 0 1px; }

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

.primary-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent);
  color: #14151a;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: filter 0.15s ease, transform 0.1s ease;
}
[data-theme="light"] .primary-btn { color: #fff; }
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn svg { width: 14px; height: 14px; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-faint); background: var(--surface-2); }

.danger-btn {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
}
.danger-btn:hover { filter: brightness(1.1); }

.menu-wrap { position: relative; }

/* ============================================================
   Folder tree
   ============================================================ */

.tree-node { position: relative; }
.tree-children { list-style: none; margin: 0; padding-left: 16px; }
.tree-node > .tree-children { border-left: 1px solid var(--border-soft); margin-left: 11px; }
.tree ul.tree-root { list-style: none; margin: 0; padding: 0; }

.tree-row {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  position: relative;
}
.tree-row:hover { background: var(--surface-2); color: var(--text); }
.tree-row.active { background: var(--accent-soft); color: var(--text); }
.tree-row.active .tree-name { color: var(--text); font-weight: 600; }
.tree-row.drop-target { background: var(--accent-glow); outline: 1.5px dashed var(--accent); outline-offset: -2px; }
.tree-row.dragging { opacity: 0.4; }

.tree-toggle {
  width: 16px; height: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text-faint); padding: 0;
  transition: transform 0.15s ease;
}
.tree-toggle svg { width: 10px; height: 10px; }
.tree-toggle.expanded svg { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }

.tree-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}
.tree-name-input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 13px;
  background: var(--surface-3);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 4px;
  padding: 1px 5px;
}

.tree-count { font-size: 11px; color: var(--text-faint); flex-shrink: 0; padding: 0 2px; font-variant-numeric: tabular-nums; }

.tree-row-actions { display: none; align-items: center; gap: 1px; flex-shrink: 0; }
.tree-row:hover .tree-row-actions,
.tree-row:focus-within .tree-row-actions { display: flex; }
.tree-row-actions button {
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 4px; color: var(--text-faint);
}
.tree-row-actions button:hover { background: var(--surface-3); color: var(--text); }
.tree-row-actions svg { width: 12px; height: 12px; }

.tree-context-menu {
  position: absolute; z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  min-width: 180px;
  padding: 5px;
}
.tree-context-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; text-align: left;
  padding: 7px 9px; border-radius: 6px; font-size: 13px; color: var(--text);
}
.tree-context-menu button:hover { background: var(--surface-3); }
.tree-context-menu button.danger { color: var(--danger); }
.tree-context-menu hr { border: none; border-top: 1px solid var(--border-soft); margin: 4px 0; }

/* ============================================================
   Link list
   ============================================================ */

.link-list { display: flex; flex-direction: column; gap: 6px; }

.link-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.link-row:hover { border-color: var(--border); background: var(--surface-2); }
.link-row.dragging { opacity: 0.4; }

.link-favicon { width: 20px; height: 20px; border-radius: 4px; flex-shrink: 0; background: var(--surface-3); }

.link-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.link-title-link { text-decoration: none; }
.link-title {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-title-link:hover .link-title { color: var(--accent-strong); text-decoration: underline; }
.link-url { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-notes { font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 2px; }

.link-actions { display: flex; align-items: center; gap: 2px; opacity: 0; flex-shrink: 0; transition: opacity 0.15s ease; }
.link-row:hover .link-actions, .link-row:focus-within .link-actions { opacity: 1; }
.link-actions button {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px; color: var(--text-faint);
}
.link-actions button:hover { background: var(--surface-3); color: var(--text); }
.link-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }
.link-actions svg { width: 14px; height: 14px; }
.link-drag-handle { cursor: grab; color: var(--text-faint); flex-shrink: 0; }
.link-drag-handle:active { cursor: grabbing; }

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 40px 4px; color: var(--text-muted); max-width: 420px;
}
.empty-state h3 { font-family: var(--font-display); font-size: 16px; color: var(--text); margin: 0; }
.empty-state p { margin: 0; font-size: 13px; }

/* ============================================================
   Search results
   ============================================================ */

.search-result-meta { font-size: 11px; color: var(--text-faint); display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.search-result-meta .badge {
  padding: 2px 7px; border-radius: 999px; background: var(--surface-3); font-weight: 600;
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px;
}

/* ============================================================
   Dialogs
   ============================================================ */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-2);
}
dialog::backdrop { background: rgba(10, 10, 12, 0.55); backdrop-filter: blur(2px); }

.dlg-form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg-form h2 { font-family: var(--font-display); font-size: 17px; margin: 0 0 2px; }

.dlg-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.dlg-form input, .dlg-form textarea, .dlg-form select {
  font: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-weight: 400;
  resize: vertical;
}
.dlg-form input:focus, .dlg-form textarea:focus, .dlg-form select:focus { outline: none; border-color: var(--accent); }

.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.confirm-body { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }

.space-manage-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.space-manage-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); background: var(--surface-2); }
.space-manage-row input { flex: 1; background: transparent; border: none; color: var(--text); font-size: 13px; padding: 4px; }
.space-manage-row input:focus { outline: none; background: var(--surface-3); border-radius: 4px; }
.space-manage-row .lock-note { font-size: 10.5px; color: var(--text-faint); flex-shrink: 0; }
.space-manage-row button { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; background: none; border: none; border-radius: 6px; color: var(--text-faint); flex-shrink: 0; }
.space-manage-row button:hover { background: var(--surface-3); color: var(--danger); }
.space-add-form { display: flex; gap: 8px; }
.space-add-form input { flex: 1; }

/* ============================================================
   Toasts
   ============================================================ */

.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.2s ease;
  max-width: 320px;
}
.toast.error { border-color: var(--danger); color: #ffb3b5; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 860px) {
  .searchbox input, .searchbox input:focus { width: 160px; }
  .sidebar { width: 240px; }
  .content { padding: 16px; }
}

@media (max-width: 680px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .brand-name { display: none; }
  .body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .breadcrumb { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================================================
   Auth-Seiten (Login/Registrierung/Passwort)
   ============================================================ */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(700px 320px at 50% 0%, var(--accent-glow), transparent 70%);
  padding: 24px;
}
.auth-page { width: 100%; max-width: 400px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: -0.01em; }
.auth-brand .brand-mark { color: var(--accent); font-size: 24px; }
.auth-card { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); padding: 28px; box-sizing: border-box; }
.auth-card h2 { font-family: var(--font-display); font-size: 17px; margin: 0 0 4px; }
.auth-hint { font-size: 13px; color: var(--text-muted); line-height: 1.55; margin: 0 0 18px; }
.auth-status { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text); font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.auth-error { color: var(--danger); font-size: 12px; margin-top: -9px; }
.dlg-form label.auth-remember { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); font-weight: 400; cursor: pointer; }
.auth-remember input { margin: 0; width: auto; }
.auth-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.auth-actions.center { justify-content: flex-end; }
.auth-link { font-size: 13px; color: var(--text-muted); text-decoration: none; }
.auth-link:hover { color: var(--accent-strong); text-decoration: underline; }
.auth-foot { font-size: 13px; color: var(--text-faint); text-align: center; }
.auth-foot a { color: var(--text-muted); text-decoration: none; }
.auth-foot a:hover { color: var(--accent-strong); text-decoration: underline; }
