:root {
  --text: #1f2328;
  --muted: #6a737d;
  --border: #d8dee4;
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --accent: #0969da;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

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

h1, h2, h3, h4 { line-height: 1.25; margin-top: 1.5em; margin-bottom: 0.5em; }
h1:first-child { margin-top: 0; }

.muted { color: var(--muted); }

/* Tables (file browser, dashboard) */
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Markdown body */
.markdown-body img { max-width: 100%; }
.markdown-body pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
}
.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-subtle);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.markdown-body pre code { background: none; padding: 0; font-size: 0.85rem; }
.markdown-body blockquote {
  margin: 1rem 0;
  padding: 0.1rem 1rem;
  border-left: 4px solid var(--border);
  color: var(--muted);
}
.markdown-body table { width: auto; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* Landing */
.landing { text-align: center; padding-top: 20vh; }
.landing h1 { font-weight: 500; letter-spacing: 0.02em; }

/* Editor */
.container-wide { max-width: 1000px; }
.editor-wrap { position: relative; }
/* Textarea and highlight mirror must share identical text metrics —
   any drift between the two misaligns the caret from the colored text. */
.editor-wrap textarea,
.editor-wrap pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  tab-size: 8;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}
.editor-wrap textarea {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 65vh;
  resize: vertical;
}
.editor-wrap pre {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 0.3rem 0.5rem;          /* match global textarea padding */
  border: 1px solid transparent;   /* match global textarea border width */
  border-radius: 6px;
  background: var(--bg);
}
.editor-wrap.is-highlighted pre { display: block; }
.editor-wrap.is-highlighted textarea {
  color: transparent;
  caret-color: var(--text);
  background: transparent;
}
.editor-actions { display: flex; gap: 1rem; align-items: center; margin-top: 0.75rem; }

/* Editor syntax tokens (GitHub-light-ish) */
.tok-comment { color: #6a737d; }
.tok-string { color: #0a3069; }
.tok-tag { color: #116329; }
.tok-attr { color: #0550ae; }
.tok-key { color: #cf222e; }
.tok-num { color: #0550ae; }
.tok-prop { color: #0550ae; }
.md-heading { color: #0550ae; font-weight: 600; }
.md-bold { font-weight: 600; }
.md-italic { font-style: italic; }
.md-code { color: #953800; }
.md-link { color: #0969da; }
.md-quote { color: #6a737d; }
.md-punct { color: #cf222e; }

/* Forms */
.panel {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 1rem 0.75rem;
  margin: 1rem 0;
}
.panel h2 { margin-top: 0.75rem; font-size: 1.1rem; }
.panel form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.panel label { font-size: 0.9rem; }
.panel label.inline { display: inline-flex; align-items: center; gap: 0.3rem; }
.panel .muted { font-size: 0.8rem; margin: 0.5rem 0 0.25rem; }
select, input[type="text"], textarea {
  font: inherit;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
button[type="submit"] {
  font: inherit;
  padding: 0.3rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.1); }

/* Manager / dashboard chrome */
.topnav { font-size: 0.9rem; margin-bottom: 1rem; }
.flash { padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid; }
.flash-ok { background: #dafbe1; border-color: #aceebb; }
.flash-err { background: #ffebe9; border-color: #ffc1bc; }
td.actions form { display: inline; margin: 0 0 0 0.25rem; }
td.actions button, .linklike {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer;
}
td.actions button:hover { text-decoration: underline; }
td.actions { white-space: nowrap; font-size: 0.85rem; }
td.actions .rename-form input, td.actions .rename-form select {
  font-size: 0.8rem; padding: 0.15rem 0.3rem;
}
td.actions button.danger { color: #cf222e; }

/* Dashboard */
.stat-big { font-size: 2rem; font-weight: 600; margin: 0.5rem 0 1.5rem; }
.stat-big .muted { font-size: 1rem; font-weight: 400; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
  padding: 0.5rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.chart-col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart-bar { width: 100%; min-height: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.chart-range { font-size: 0.8rem; margin-top: 0.25rem; }
