:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c2030;
  --border: #2a2f3d;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #6c8eef;
  --accent-2: #8da4ff;
  --danger: #ef6c6c;
  --ok: #6cef9b;
  --warn: #efc66c;
  --code: #1a1d27;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
header .sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
header .spacer { flex: 1; }
header .stats { color: var(--muted); font-size: 12px; }
header .path { color: var(--muted); font-size: 11px; font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100vh - 49px);
}

aside {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column;
}
.aside-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.aside-head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.aside-head button {
  background: var(--accent); color: #fff; border: none;
  width: 24px; height: 24px; border-radius: 4px; cursor: pointer; font-weight: 600;
}
.aside-head button:hover { background: var(--accent-2); }

#cat-list { list-style: none; margin: 0; padding: 0; flex: 1; }
#cat-list li {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2px;
  font-size: 13px;
}
#cat-list li:hover { background: var(--panel-2); }
#cat-list li.active { background: var(--accent); color: #fff; }
#cat-list li .count {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 6px; border-radius: 10px; font-size: 11px;
}
#cat-list li.active .count { background: rgba(0, 0, 0, 0.25); }
.legend { padding-top: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.legend code { font-size: 11px; word-break: break-all; }

main { overflow: hidden; display: flex; flex-direction: column; }

.tabs {
  display: flex; gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.tabs button {
  background: transparent; color: var(--muted);
  border: none; padding: 10px 16px; cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 500;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent-2); border-bottom-color: var(--accent); }

.tab-pane { display: none; flex: 1; overflow: hidden; flex-direction: column; padding: 16px 20px; }
.tab-pane.active { display: flex; }

.bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.bar .spacer { flex: 1; }
input[type="text"], input[type="number"], select, textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font: inherit;
  outline: none; transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus { border-color: var(--accent); }
#search-q { flex: 1; min-width: 200px; }

button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; font: inherit;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #252a3a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }

.memory-list { flex: 1; overflow-y: auto; padding-right: 4px; }
.memory-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}
.memory-card:hover { border-color: var(--accent); }
.memory-card .doc { margin: 0 0 6px; white-space: pre-wrap; word-break: break-word; }
.memory-card .meta-line {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  font-size: 11px; color: var(--muted);
}
.memory-card .meta-line code { background: var(--code); padding: 1px 6px; border-radius: 4px; }
.memory-card .actions { display: flex; gap: 6px; margin-top: 8px; }
.memory-card .actions button { padding: 4px 10px; font-size: 12px; }

.empty { color: var(--muted); text-align: center; padding: 40px; }

.form { display: flex; flex-direction: column; gap: 12px; max-width: 720px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form input, .form textarea { font-family: inherit; }
.form textarea#add-meta { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 12px; }
.form .row { display: flex; gap: 12px; align-items: center; }
.form .row span { font-size: 12px; }

.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; width: 320px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; }
.modal-card input { width: 100%; }
.modal-card .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 10px 16px; border-radius: 6px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 320px;
  animation: slidein 0.2s ease;
}
.toast.hidden { display: none; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

@keyframes slidein {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

#browse-prev:disabled, #browse-next:disabled { opacity: 0.4; cursor: not-allowed; }
#browse-pos { color: var(--muted); font-size: 12px; min-width: 80px; text-align: center; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a4055; }
