/* elogNG — hand-written stylesheet. Colors are tokens on :root, redefined
   for dark mode. No build step. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2430;
  --text-muted: #5d6878;
  --accent: #1f5fbf;
  --accent-contrast: #ffffff;
  --accent-soft: #e6eefb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --pin: #b35c00;
  --diff-add: #e6ffec;
  --diff-del: #ffebe9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 6px;
  --sidebar: 15.5rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #161c23; --surface-2: #1d252e; --border: #2c3642;
    --text: #e3e8ee; --text-muted: #9aa6b4; --accent: #6ea8ff; --accent-contrast: #0b1220;
    --accent-soft: #1b2a40; --danger: #ff7b72; --danger-soft: #3a1d1d; --ok: #56d364; --ok-soft: #12301d;
    --warn: #e3b341; --warn-soft: #3a2e10; --pin: #f0a35e; --diff-add: #12301d; --diff-del: #3a1d1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #161c23; --surface-2: #1d252e; --border: #2c3642;
  --text: #e3e8ee; --text-muted: #9aa6b4; --accent: #6ea8ff; --accent-contrast: #0b1220;
  --accent-soft: #1b2a40; --danger: #ff7b72; --danger-soft: #3a1d1d; --ok: #56d364; --ok-soft: #12301d;
  --warn: #e3b341; --warn-soft: #3a2e10; --pin: #f0a35e; --diff-add: #12301d; --diff-del: #3a1d1d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, pre, kbd { font-family: var(--mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  height: 3.25rem; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--accent); }
.topbar .search { flex: 1; max-width: 32rem; }
.topbar .search input { width: 100%; }
.topbar nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.menu-toggle { display: none; }

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - 3.25rem); }
.sidebar {
  position: sticky; top: 3.25rem; align-self: start; height: calc(100vh - 3.25rem); overflow-y: auto;
  padding: 1rem .75rem; border-right: 1px solid var(--border); background: var(--surface);
}
.sidebar h2 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: .25rem .5rem .5rem; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: .85rem; }
.tree .group { font-size: .8rem; font-weight: 600; color: var(--text-muted); padding: .5rem .5rem .2rem; }
.tree a {
  display: block; padding: .3rem .5rem; border-radius: var(--radius); color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree a:hover { background: var(--surface-2); text-decoration: none; }
.tree a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.narrow { max-width: 52rem; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: fixed; inset: 3.25rem 0 0 0; width: 100%; z-index: 15; }
  body.nav-open .sidebar { display: block; }
  .menu-toggle { display: inline-flex; }
  .topbar .search { display: none; }
  main { padding: 1rem; }
}

/* --- controls ----------------------------------------------------------------- */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-size: .9rem; line-height: 1.2; cursor: pointer; white-space: nowrap;
  padding: .45rem .8rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover, button.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger, button.danger { color: var(--danger); }
.btn-danger:hover, button.danger:hover { background: var(--danger-soft); }
.btn-ghost, button.ghost { border-color: transparent; background: transparent; }
.btn-sm, button.sm { padding: .25rem .55rem; font-size: .82rem; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .42rem .6rem; max-width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
textarea { width: 100%; min-height: 14rem; resize: vertical; font-family: var(--mono); font-size: .9rem; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .3rem; }
.field > label, .field > .label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .8rem; color: var(--text-muted); }
.field input[type="text"], .field input[type="search"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field input[type="datetime-local"], .field select { width: 100%; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.field .error { color: var(--danger); font-size: .85rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.checks { display: flex; flex-wrap: wrap; gap: .35rem 1rem; }
.checks label { display: inline-flex; align-items: center; gap: .35rem; font-weight: normal; }
.form-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .card-body { padding: 1rem 1.25rem; }
.card + .card { margin-top: 1rem; }

.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

.chip {
  display: inline-flex; align-items: center; gap: .25rem; padding: .05rem .5rem;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: .78rem; color: var(--text-muted); white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.badge { display: inline-block; padding: 0 .4rem; border-radius: 4px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--text-muted); }
.badge-pin { background: var(--warn-soft); color: var(--pin); }
.badge-deleted { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a, .tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: .5rem .75rem; color: var(--text-muted); font-weight: 600;
}
.tabs a[aria-selected="true"], .tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: 0; border-radius: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* --- filters & tables ------------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters .field { gap: .15rem; }
.filters .field > label { font-size: .75rem; color: var(--text-muted); font-weight: 600; }
.filters input, .filters select { padding: .35rem .5rem; font-size: .88rem; }
.filters .grow { flex: 1 1 14rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th, table.list td { padding: .45rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.list th { position: sticky; top: 0; background: var(--surface-2); font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: var(--surface-2); }
table.list tr.pinned td:first-child { box-shadow: inset 3px 0 0 var(--pin); }
table.list tr.reply .subject::before { content: "↳ "; color: var(--text-muted); }
table.list .subject a { color: var(--text); font-weight: 500; }
table.list .excerpt { color: var(--text-muted); font-size: .82rem; }
table.list td.id { color: var(--text-muted); font-variant-numeric: tabular-nums; width: 1%; }
.more { display: flex; justify-content: center; padding: 1rem; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); }

/* --- entries ------------------------------------------------------------------------ */

.entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; scroll-margin-top: 4.5rem; }
.entry.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.entry.deleted { opacity: .7; }
.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .75rem; padding: .7rem 1.1rem .5rem; border-bottom: 1px solid var(--border); }
.entry-head .subject { font-size: 1.05rem; font-weight: 650; margin: 0; flex-basis: 100%; }
.entry-head .subject a { color: var(--text); }
.entry-meta { font-size: .82rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center; }
.entry-attrs { display: flex; flex-wrap: wrap; gap: .35rem; padding: .55rem 1.1rem 0; }
.entry-body { padding: .75rem 1.1rem; overflow-wrap: anywhere; }
.entry-foot { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem 1.1rem .75rem; align-items: center; }
.entry-foot form { display: inline; }
.thread .depth-1 { margin-left: 1.5rem; }
.thread .depth-2 { margin-left: 3rem; }
.thread .depth-3 { margin-left: 4.5rem; }
.thread .depth-4 { margin-left: 6rem; }
@media (max-width: 860px) {
  .thread [class*="depth-"] { margin-left: .75rem; }
}

/* rendered Markdown */
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose table, .prose blockquote { margin: 0 0 .8rem; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1.1rem 0 .5rem; }
.prose h1 { font-size: 1.3rem; } .prose h2 { font-size: 1.15rem; } .prose h3 { font-size: 1.02rem; }
.prose ul, .prose ol { padding-left: 1.5rem; }
.prose li.task-list-item { list-style: none; margin-left: -1.3rem; }
.prose blockquote { border-left: 3px solid var(--border); padding-left: .9rem; color: var(--text-muted); }
.prose code { background: var(--surface-2); padding: .1rem .3rem; border-radius: 4px; }
.prose pre { background: var(--surface-2); padding: .75rem 1rem; border-radius: var(--radius); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose pre.plain { background: none; padding: 0; white-space: pre-wrap; font-size: .92rem; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: .3rem .6rem; }
.prose th { background: var(--surface-2); }
.prose img { max-width: 100%; height: auto; border-radius: 4px; }
.prose .math-display { display: block; overflow-x: auto; overflow-y: hidden; margin: .6rem 0; }
.prose .math.unrendered { font-family: var(--mono); color: var(--text-muted); }

.attachments { display: flex; flex-wrap: wrap; gap: .6rem; padding: 0 1.1rem .8rem; }
.attachment { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .85rem; background: var(--surface-2); color: var(--text); max-width: 100%; }
.attachment:hover { text-decoration: none; border-color: var(--accent); }
.attachment.image { padding: .25rem; flex-direction: column; align-items: stretch; }
.attachment.image img { display: block; max-height: 11rem; max-width: 16rem; object-fit: contain; border-radius: 4px; background: var(--surface); }
.attachment.image span { padding: 0 .25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem; }

/* editor (textarea + preview until the live editor lands) */
.editor .tabs { margin-bottom: 0; border-bottom: 0; }
.editor .pane { border: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) var(--radius); background: var(--surface); }
.editor textarea { border: 0; border-radius: 0 var(--radius) var(--radius) var(--radius); min-height: 18rem; }
.editor .preview { min-height: 18rem; padding: .75rem 1rem; }

/* diffs */
.diff { font-family: var(--mono); font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.diff div { padding: 0 .6rem; }
.diff .add { background: var(--diff-add); }
.diff .add::before { content: "+ "; color: var(--ok); }
.diff .del { background: var(--diff-del); }
.diff .del::before { content: "− "; color: var(--danger); }
.diff .ctx::before { content: "  "; }
.diff .gap { color: var(--text-muted); background: var(--surface-2); }

/* login */
.login { max-width: 24rem; margin: 8vh auto; padding: 0 1rem; }
.login .brand { display: block; text-align: center; font-size: 1.6rem; margin-bottom: 1.25rem; }
.login .card-body { display: grid; gap: 1rem; padding: 1.5rem; }
.login .or { display: flex; align-items: center; gap: .75rem; color: var(--text-muted); font-size: .8rem; }
.login .or::before, .login .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login .providers { display: grid; gap: .5rem; }
.login .providers .btn { width: 100%; }

.lang-switch { justify-content: center; margin-top: 1rem; }
.lang-switch button[aria-pressed="true"] { color: var(--accent); font-weight: 600; }
.secret { font-family: var(--mono); word-break: break-all; background: var(--surface-2); padding: .6rem .8rem; border-radius: var(--radius); border: 1px dashed var(--accent); }

/* schema editor */
.schema-row { display: grid; grid-template-columns: 1.1fr 1.1fr .9fr 1.6fr .9fr auto auto; gap: .4rem; align-items: center; }
.schema-row.head { font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
@media (max-width: 860px) {
  .schema-row { grid-template-columns: 1fr 1fr; padding: .5rem 0; border-bottom: 1px solid var(--border); }
  .schema-row.head { display: none; }
}

/* htmx */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-request button[type="submit"] { opacity: .7; }

@media print {
  .topbar, .sidebar, .entry-foot, .filters, .more, .page-head .actions { display: none !important; }
  .shell { display: block; }
  .entry, .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; color: #000; }
}
