:root {
  --bg: #fbfaf8;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --muted: #6d6a65;
  --line: #e6e2dc;
  --accent: #b4541f;
  --accent-soft: #fdf1e9;
  --danger: #a3301f;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --panel: #1f1e23;
    --ink: #eceaea;
    --muted: #9b9791;
    --line: #322f36;
    --accent: #e8874f;
    --accent-soft: #2a211d;
    --danger: #e0705c;
  }
}

* { box-sizing: border-box; }

/* A class with its own display would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.ai { background: var(--accent-soft); border-color: transparent; }

input, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.01em; }
.searchbar { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.searchbar input { flex: 1; }
.actions { display: flex; gap: 8px; }

.banner {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
}
.banner code { font-family: var(--mono); font-size: 12px; }

/* ----------------------------------------------------------------- layout */

main { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 310px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tagbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.tagbar button {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--muted);
}
.tagbar button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.notelist { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.notelist li {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.notelist li:hover { background: var(--panel); }
.notelist li.active { background: var(--panel); border-color: var(--accent); }
.notelist .n-title { font-weight: 560; display: flex; gap: 6px; align-items: baseline; }
.notelist .n-snip { color: var(--muted); font-size: 13px; margin-top: 2px; }
.notelist .n-meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.notelist .n-reason { color: var(--accent); font-size: 12px; margin-top: 4px; }
.notelist .empty { color: var(--muted); padding: 20px 10px; text-align: center; font-size: 13px; }

/* ----------------------------------------------------------------- editor */

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  min-width: 0;
}
.title-input { font-size: 20px; font-weight: 620; border-color: transparent; background: transparent; padding-left: 2px; }
.body-input {
  flex: 1;
  resize: none;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  min-height: 180px;
}
.summary {
  font-size: 13px;
  color: var(--muted);
  border-left: 3px solid var(--accent);
  padding: 4px 10px;
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.tags-input { width: 100%; font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.status { color: var(--muted); font-size: 13px; }
.status.err { color: var(--danger); }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel);
  font-size: 13.5px;
}
.panel h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.panel a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 550; }
.panel a:hover { text-decoration: underline; }
.panel li { margin-bottom: 5px; }
.panel ul { margin: 0; padding-left: 18px; }

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.dialog {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(720px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.ask-form { display: flex; gap: 8px; }
.ask-form input { flex: 1; }
.dialog-body {
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  min-height: 60px;
}
.dialog-body .cite {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}
.dialog-body ul { white-space: normal; }

@media (max-width: 760px) {
  main { flex-direction: column; }
  .sidebar { width: 100%; max-height: 38vh; border-right: none; border-bottom: 1px solid var(--line); }
}
