:root {
  --bg: #0a0d0a;
  --bg2: #11151a;
  --fg: #d4d4d4;
  --dim: #6b7280;
  --dim2: #2d3138;
  --accent: #00ff88;
  --accent-r: 0; --accent-g: 255; --accent-b: 136;
  --danger: #ff4444;
  --border: #1f2937;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, monospace;
}
html[data-theme="green"]  { --accent:#00ff88; --accent-r:0;   --accent-g:255; --accent-b:136; }
html[data-theme="purple"] { --accent:#bf5af2; --accent-r:191; --accent-g:90;  --accent-b:242; }
html[data-theme="blue"]   { --accent:#5ac8fa; --accent-r:90;  --accent-g:200; --accent-b:250; }
html[data-theme="yellow"] { --accent:#ffd60a; --accent-r:255; --accent-g:214; --accent-b:10;  }
html[data-theme="red"]    { --accent:#ff453a; --accent-r:255; --accent-g:69;  --accent-b:58;  }
html[data-theme="pink"]   { --accent:#ff375f; --accent-r:255; --accent-g:55;  --accent-b:95;  }
html[data-theme="white"]  { --accent:#f5f5f7; --accent-r:245; --accent-g:245; --accent-b:247; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.012) 0px,
    rgba(255,255,255,0.012) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  height: 100%;
  overflow: hidden;
}

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

.app {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
  max-width: 900px;
  margin: 0 auto;
}

header.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header.bar img { width: 24px; height: 24px; }
header.bar .title {
  font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; font-size: 12px;
  color: var(--accent);
}
header.bar .grow { flex: 1; }
header.bar .version { font-size: 9px; color: var(--dim); }

.tabs {
  display: none;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tabs.visible { display: flex; }
.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 9px 0;
  border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--fg); }

.view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
}
.view.active { display: flex; }

/* ONBOARDING */
.onboard-wrap {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; padding: 40px 24px; text-align: center; gap: 20px;
}
.onboard-wrap img { width: 64px; height: 64px; opacity: 0.85; }
.onboard-wrap h1 {
  font-size: 16px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); margin: 0;
}
.onboard-wrap p { color: var(--dim); font-size: 11px; line-height: 1.6; max-width: 340px; margin: 0; }
.onboard-wrap .onboard-note {
  font-size: 10px; color: var(--dim); line-height: 1.5;
  background: var(--bg2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 6px; max-width: 360px;
}

/* VAULT */
.list-wrap { flex: 1; overflow-y: auto; }
.list-toolbar {
  display: flex; gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.list-toolbar input[type="search"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--dim2);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 3px;
}
.list-toolbar input[type="search"]:focus { outline: none; border-color: var(--accent); }

.doc-row {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.doc-row:hover { background: var(--bg2); }
.doc-title { font-weight: 700; color: var(--fg); font-size: 12px; margin-bottom: 3px; }
.doc-meta { display: flex; gap: 4px; flex-wrap: wrap; }
.badge {
  background: var(--bg2);
  border: 1px solid var(--dim2);
  padding: 1px 5px; border-radius: 2px;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--dim);
}

.empty {
  padding: 40px 24px; text-align: center;
  color: var(--dim); font-size: 11px; line-height: 1.6;
}

/* CAPTURE ROW */
.capture-row {
  display: none;
  gap: 6px; align-items: center;
  padding: 6px 10px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.capture-row.open { display: flex; }
.capture-row input[type="url"] {
  flex: 1;
  background: var(--bg); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 11px;
  padding: 5px 8px; border-radius: 3px;
}
.capture-row input[type="url"]:focus { outline: none; border-color: var(--accent); }
.capture-row select {
  background: var(--bg); border: 1px solid var(--dim2);
  color: var(--dim); font-family: var(--mono); font-size: 10px;
  padding: 5px 6px; border-radius: 3px; cursor: pointer;
}
.capture-row select:focus { outline: none; border-color: var(--accent); }

/* CHAT MODE TOGGLE */
.chat-mode-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.mode-btn {
  flex: 1;
  background: transparent; border: none;
  color: var(--dim); font-family: var(--mono);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  padding: 7px 0; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.mode-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.mode-btn:hover { color: var(--fg); }

/* ENTRY DETAIL */
.entry-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.entry-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.entry-title {
  font-size: 15px; font-weight: 700; color: var(--accent);
  margin-bottom: 8px; line-height: 1.3;
}
.editable-title {
  cursor: pointer;
}
.editable-title:hover {
  text-decoration: underline;
  opacity: 0.85;
}
.entry-source {
  font-size: 10px; color: var(--dim); margin-bottom: 10px;
  word-break: break-all;
}
.entry-source a { color: var(--accent); }
.entry-content { font-size: 12px; margin-top: 10px; }

/* MARKDOWN BODY — rendered reading view */
.md-body { line-height: 1.7; word-break: break-word; }
.md-body p { margin: 0 0 10px; color: var(--fg); }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  color: var(--accent); margin: 16px 0 6px; font-size: 13px;
  letter-spacing: 0.06em;
}
.md-body h1 { font-size: 15px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-body h2 { font-size: 13px; }
.md-body a { color: var(--accent); word-break: break-all; }
.md-body code {
  background: var(--bg2); border: 1px solid var(--dim2);
  padding: 1px 5px; border-radius: 3px; font-size: 11px;
}
.md-body pre {
  background: var(--bg2); border: 1px solid var(--border);
  padding: 10px; border-radius: 4px; overflow-x: auto; margin: 8px 0;
}
.md-body pre code { background: none; border: none; padding: 0; font-size: 11px; }
.md-body blockquote {
  border-left: 3px solid var(--accent); margin: 8px 0;
  padding: 4px 12px; color: var(--dim);
}
.md-body ul, .md-body ol { margin: 6px 0 10px 18px; padding: 0; }
.md-body li { margin-bottom: 3px; color: var(--fg); }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md-body strong { color: var(--fg); }
.md-body em { color: var(--dim); font-style: italic; }

/* ENTRY EDITOR OVERLAY */
.edit-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  align-items: flex-end; justify-content: center;
}
.edit-overlay.open { display: flex; }
.edit-sheet {
  width: 100%; max-width: 600px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  display: flex; flex-direction: column;
  max-height: 90vh;
  padding-bottom: env(safe-area-inset-bottom);
}
.edit-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.edit-heading {
  flex: 1; text-align: center; font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim);
}
.edit-fields {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px; overflow-y: auto; flex: 1;
}
.edit-label {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--dim); margin-top: 4px;
}
.edit-hint-small { font-size: 9px; color: var(--dim2); text-transform: none; letter-spacing: 0; }
.edit-input {
  background: var(--bg); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 13px;
  padding: 9px 10px; border-radius: 4px; width: 100%; min-height: 44px;
}
.edit-input:focus { outline: none; border-color: var(--accent); }
.edit-textarea {
  background: var(--bg); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 12px;
  padding: 9px 10px; border-radius: 4px; width: 100%;
  min-height: 200px; resize: vertical; line-height: 1.6;
}
.edit-textarea:focus { outline: none; border-color: var(--accent); }

/* BINARY PREVIEWS */
.preview-img { max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 0 auto 12px; }
.preview-pdf-btn { width: 100%; margin-bottom: 12px; }
.preview-video { max-width: 100%; border-radius: 4px; display: block; margin: 0 auto; }
.preview-audio { width: 100%; margin-bottom: 12px; }
.preview-missing { padding: 24px; text-align: center; color: var(--dim); font-size: 11px; }

/* LOCAL SEARCH RESULT CARDS */
.search-results { display: flex; flex-direction: column; gap: 8px; padding: 2px 0; }
.search-count { font-size: 10px; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.search-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 8px 10px;
}
.search-card-title {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; font-weight: 700; font-size: 12px; color: var(--fg);
}
.open-btn { flex-shrink: 0; color: var(--accent); border-color: var(--accent); }
.search-snippet { font-size: 10px; color: var(--dim); margin-top: 4px; line-height: 1.4; }

/* CHAT */
.chat-msgs {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 90%; font-size: 12px; line-height: 1.5; min-width: 0; }
.msg.user { align-self: flex-end; }
.msg.assistant, .msg.error { align-self: flex-start; }
.msg .who { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.msg .body {
  background: var(--bg2); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px; white-space: pre-wrap;
  word-break: break-word; overflow-wrap: anywhere;
}
.msg.user .body {
  background: rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.08);
  border-color: rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.3);
}
.msg.error .body { color: var(--danger); border-color: var(--danger); }

.msg-sources {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-top: 6px; padding-top: 6px;
  border-top: 1px solid var(--dim2);
}
.sources-label { font-size: 9px; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.source-chip {
  font-size: 9px !important; padding: 2px 6px !important;
  min-height: unset !important; color: var(--accent) !important;
  border-color: var(--accent) !important; opacity: 0.8;
}
.source-chip:hover { opacity: 1; }

.thinking-dots {
  display: flex; gap: 5px; align-items: center; padding: 4px 0;
}
.thinking-dots span {
  font-size: 8px; color: var(--accent);
  animation: thinking-pulse 1.2s ease-in-out infinite;
  opacity: 0.2;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.3); }
}

.chat-input-row {
  display: flex; gap: 6px; padding: 10px;
  border-top: 1px solid var(--border); background: var(--bg2); flex-shrink: 0;
}
.chat-input-row textarea {
  flex: 1; background: var(--bg); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 12px;
  padding: 8px; border-radius: 4px; resize: none;
  min-height: 38px; max-height: 120px;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); }

/* UTILITY */
.hidden { display: none !important; }
.grow { flex: 1; }

/* SETTINGS */
.config-box { padding: 14px 16px; overflow-y: auto; }
.settings-hint { font-size: 10px; color: var(--dim); margin: 0 0 4px; line-height: 1.5; }
.settings-save-row { margin-top: 16px; }
.settings-save-btn { width: 100%; }
.settings-footer { margin-top: 20px; font-size: 10px; color: var(--dim); line-height: 1.5; }
.chat-clear-btn { margin-left: auto; padding: 4px 7px !important; min-height: unset !important; }
.config-box h3 {
  font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 10px;
  border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.config-box h3:not(:first-child) { margin-top: 20px; }
.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.field input, .field select {
  background: var(--bg2); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 11px;
  padding: 7px 10px; border-radius: 3px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field input[type="password"] { letter-spacing: 0.08em; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.swatch {
  width: 28px; height: 28px; border-radius: 4px; cursor: pointer;
  border: 2px solid var(--dim2); transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--fg); box-shadow: 0 0 8px var(--accent); }
.swatch[data-t="green"]  { background: #00ff88; }
.swatch[data-t="purple"] { background: #bf5af2; }
.swatch[data-t="blue"]   { background: #5ac8fa; }
.swatch[data-t="yellow"] { background: #ffd60a; }
.swatch[data-t="red"]    { background: #ff453a; }
.swatch[data-t="pink"]   { background: #ff375f; }
.swatch[data-t="white"]  { background: #f5f5f7; }

.vault-dir-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--bg2); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 4px; margin-bottom: 6px;
}
.vault-dir-name {
  flex: 1 1 100%; color: var(--accent); font-size: 11px;
  word-break: break-word; overflow-wrap: anywhere;
  line-height: 1.3; padding-bottom: 2px;
}

/* SHARED BUTTONS */
button.btn {
  background: var(--bg); border: 1px solid var(--dim2);
  color: var(--fg); font-family: var(--mono); font-size: 11px;
  font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 6px 12px; cursor: pointer; border-radius: 4px;
}
button.btn:hover { border-color: var(--accent); color: var(--accent); }
button.btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
button.btn.primary:hover { filter: brightness(1.1); }
button.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.btn:disabled { opacity: 0.45; cursor: not-allowed; }
button.btn.sm { padding: 4px 8px; font-size: 10px; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* RENAME MODAL */
.rename-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  align-items: flex-end; justify-content: center;
}
.rename-overlay.open { display: flex; }
.rename-dialog {
  width: 100%; max-width: 520px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.rename-filename { font-size: 10px; color: var(--dim); word-break: break-all; }
.rename-label { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.rename-input {
  background: var(--bg); border: 1px solid var(--accent);
  color: var(--fg); font-family: var(--mono); font-size: 14px;
  padding: 10px 12px; border-radius: 4px; width: 100%;
}
.rename-input:focus { outline: none; }
.rename-actions { display: flex; gap: 8px; }
.rename-actions .btn { flex: 1; min-height: 44px; }

/* TOAST */
.toast-mini {
  position: fixed; bottom: 12px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--accent);
  color: var(--accent); padding: 7px 16px; border-radius: 4px;
  font-size: 11px; z-index: 1000; display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  white-space: nowrap;
}
.toast-mini.show { display: block; }

/* Refresh button — header icon button (desktop + mobile) */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 20px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-icon:hover { color: var(--accent); }

/* RESPONSIVE */
@media (max-width: 480px) {
  .app { max-width: 100%; }
  header.bar { padding: 8px 10px; }
  .onboard-wrap { padding: 30px 16px; }
}

/* ─── MOBILE PWA (≤ 768px) ──────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Base font */
  html, body { font-size: 14px; }

  /* ── Header ── */
  header.bar { padding: 10px 14px; height: 52px; }
  header.bar .version { display: none; }

  /* ── Bottom tab bar ── */
  .app { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .tabs.visible {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    min-height: 60px;
    z-index: 100;
    border-top: 1px solid var(--border);
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs button {
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
    gap: 2px;
    padding: 6px 0;
    font-size: 9px;
  }
  .tab-icon { font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
  .tab-icon svg { display: block; }
  .tab-label { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; }

  /* ── Touch targets — global ── */
  button.btn { min-height: 44px; padding: 10px 16px; font-size: 13px; }
  button.btn.sm { min-height: 44px; padding: 8px 12px; font-size: 12px; }
  .field input,
  .field select,
  .chat-input-row textarea { min-height: 44px; font-size: 14px; padding: 10px 12px; }

  /* ── Vault toolbar — icon row ── */
  .list-toolbar { flex-wrap: wrap; padding: 8px; gap: 6px; }
  .list-toolbar input[type="search"] {
    flex-basis: 100%;
    order: -1;
    font-size: 14px;
    padding: 10px 12px;
    min-height: 44px;
  }
  .list-toolbar button.btn.sm {
    flex: 1;
    min-width: 44px;
    min-height: 44px;
    font-size: 16px;
    padding: 0;
  }

  /* ── Capture row ── */
  .capture-row.open { flex-wrap: wrap; }
  .capture-row input[type="url"] {
    flex-basis: 100%;
    min-height: 44px;
    font-size: 14px;
    padding: 10px 12px;
  }
  .capture-row select { min-height: 44px; font-size: 13px; flex: 1; }
  .capture-row .btn { min-height: 44px; }

  /* ── Chat ── */
  .chat-msgs { padding: 12px 12px 16px; }
  .chat-input-row {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .chat-mode-bar { flex-shrink: 0; }
  .mode-btn { padding: 10px 0; font-size: 11px; min-height: 44px; }

  /* ── Settings cards ── */
  .config-box { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
  .settings-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
  }
  .settings-card h3 { margin-top: 0; }
  .config-box h3:not(:first-child) { margin-top: 0; }
  .field { margin-bottom: 14px; }
  .field label { font-size: 11px; }
  .swatches { gap: 12px; }
  .swatch { width: 36px; height: 36px; }

  /* ── Entry detail ── */
  .entry-body { padding: 14px 14px 24px; }

  /* ── Onboarding ── */
  .onboard-wrap { padding: 30px 20px; gap: 16px; }
}
