/* ---- design tokens: light default, dark via media query AND [data-theme] ---- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e6ec;
  --text: #14181d;
  --text-dim: #5b6672;
  --accent: #3b6ef5;
  --accent-soft: #e6edff;
  --danger: #d0402b;
  --ok: #1f9d5b;
  --warn: #c98a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 29, 0.06), 0 4px 16px rgba(20, 24, 29, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --surface: #14181d;
    --surface-2: #1b2027;
    --border: #262d36;
    --text: #e6e9ee;
    --text-dim: #8b95a1;
    --accent: #5b86ff;
    --accent-soft: #17233f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}
/* explicit toggle wins over the media query, both directions */
:root[data-theme="light"] {
  --bg: #f7f8fa; --surface: #fff; --surface-2: #f0f2f5; --border: #e2e6ec;
  --text: #14181d; --text-dim: #5b6672; --accent: #3b6ef5; --accent-soft: #e6edff;
}
:root[data-theme="dark"] {
  --bg: #0b0d10; --surface: #14181d; --surface-2: #1b2027; --border: #262d36;
  --text: #e6e9ee; --text-dim: #8b95a1; --accent: #5b86ff; --accent-soft: #17233f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { padding: 24px 28px; max-width: 900px; width: 100%; }
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
}

.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; padding: 4px 8px 14px; display: flex; align-items: center; gap: 8px; }
.nav-group { margin-bottom: 14px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); padding: 6px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px;
  color: var(--text); width: 100%; border: none; background: none; text-align: left; font-size: 14px;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--text-dim); }
.nav-item .badge { margin-left: auto; background: var(--warn); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }

.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-sub { color: var(--text-dim); margin: 0 0 20px; }

/* ---- cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); display: flex; gap: 12px;
}
.card:hover { border-color: var(--accent); }
.card .thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.card .kind { font-size: 18px; flex: none; width: 24px; text-align: center; }
.card .body { min-width: 0; flex: 1; cursor: pointer; }
.card .title { font-weight: 600; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .snippet { color: var(--text-dim); font-size: 13.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .meta { display: flex; gap: 8px; align-items: center; margin-top: 7px; flex-wrap: wrap; }
.chip { font-size: 11.5px; padding: 1px 8px; border-radius: 20px; background: var(--surface-2); color: var(--text-dim); }
.chip.space { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.time { color: var(--text-dim); font-size: 12px; margin-left: auto; }

/* ---- controls ---- */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 8px; font-size: 14px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 84px; }
label { font-size: 12.5px; color: var(--text-dim); display: block; margin: 10px 0 4px; }

/* ---- quick capture (fixed) ---- */
.qc-fab { position: fixed; right: 22px; bottom: 22px; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff; border: none; font-size: 26px; box-shadow: var(--shadow); z-index: 40; }
.qc-panel { position: fixed; right: 22px; bottom: 22px; width: min(420px, calc(100vw - 44px)); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; z-index: 41; }
.qc-drop { border: 1.5px dashed var(--border); border-radius: 8px; }
.qc-drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---- modal ---- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: min(760px, 100%); padding: 22px 24px; }
.modal img.full { max-width: 100%; border-radius: 8px; }
.prose { line-height: 1.6; word-wrap: break-word; }
.prose pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.prose code { font-family: var(--mono); font-size: 13px; }
.prose img { max-width: 100%; }
.prose blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 12px; color: var(--text-dim); }

/* ---- search + gallery ---- */
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { font-size: 15px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; background: var(--surface-2); }

/* ---- misc ---- */
.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); font-size: 13.5px; }
.keygate { max-width: 420px; margin: 12vh auto; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
kbd { font-family: var(--mono); font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
table.research { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.research th, table.research td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
table.research th { color: var(--text-dim); font-weight: 600; }
