/* ─────────────────────────────────────────────────────────────
   solidoc design pass
   Warm minimal, narrow column, confident type, calm motion.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #111111;
  --ink-2: #4a4a4a;
  --ink-3: #8a8a86;
  --ink-4: #b8b6b0;
  --accent: #5a3ec8;
  --accent-2: #4226a9;
  --accent-soft: #f1edff;
  --danger: #c63a3a;
  --hairline: #ece9e1;
  --hairline-2: #f3f1ea;
  --radius: 10px;
  --shadow-1: 0 1px 2px rgba(20, 14, 50, 0.04);
  --shadow-2: 0 8px 32px -8px rgba(20, 14, 50, 0.10);
  --duration: 160ms;
  --ease: cubic-bezier(.2,.6,.2,1);
}

* { box-sizing: border-box }
html { background: var(--bg) }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  max-width: 680px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 6rem;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--hairline);
}
header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
header h1 a {
  color: inherit;
  text-decoration: none;
  background: linear-gradient(135deg, var(--ink) 0%, var(--accent) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header h1 a::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 0.35em;
}
.hint {
  color: var(--ink-3);
  font-size: 0.92rem;
  margin: 0;
}

/* ── Buttons ──────────────────────────────────────────────── */
button { font: inherit; cursor: pointer }

#new {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem 0.55rem 0.9rem;
  margin-bottom: 1.5rem;
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 999px;
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: -0.005em;
  box-shadow: var(--shadow-1);
  transition: transform var(--duration) var(--ease),
              background var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}
#new::before {
  content: "+";
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  line-height: 1.05;
  text-align: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  font-weight: 500;
  font-size: 0.95em;
}
#new:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px -4px rgba(90, 62, 200, 0.4);
}
#new:active { transform: translateY(0) }
#new[disabled] { background: var(--ink-4); cursor: not-allowed }

/* ── List ─────────────────────────────────────────────────── */
#msg {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: -0.75rem 0 0.75rem;
}

#doclist {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--hairline);
}
#doclist li {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 1rem 1.25rem;
  border-bottom: 1px solid var(--hairline);
  transition: background var(--duration) var(--ease);
}
#doclist li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.05rem;
  bottom: 1.05rem;
  width: 3px;
  border-radius: 2px;
  background: transparent;
  transition: background var(--duration) var(--ease);
}
#doclist li:hover {
  background: var(--accent-soft);
}
#doclist li:hover::before {
  background: var(--accent);
}
#doclist li .row-main {
  min-width: 0;
}
#doclist li a {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.005em;
  margin-bottom: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#doclist li:hover a { color: var(--accent-2) }
#doclist li .meta {
  color: var(--ink-3);
  font-size: 0.82rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
#doclist li .meta .filename {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--ink-4);
}
#doclist li .meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ink-4);
  display: inline-block;
}
#doclist li .row-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
#doclist li .action {
  background: none;
  border: none;
  color: var(--ink-4);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--duration) var(--ease),
              background var(--duration) var(--ease),
              color var(--duration) var(--ease);
}
#doclist li:hover .action { opacity: 1 }
#doclist li .action:focus { opacity: 1 }
#doclist li .action:hover {
  color: var(--accent-2);
  background: var(--accent-soft);
}
#doclist li .action.copy.done {
  opacity: 1;
  color: #2a8e3a;
  background: rgba(42, 142, 58, 0.10);
}
#doclist li .action.del { font-size: 1.3rem; line-height: 1; padding: 0 0.6rem }
#doclist li .action.del:hover {
  color: var(--danger);
  background: rgba(198, 58, 58, 0.08);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--ink-3);
}
.empty-state .emoji {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}
.empty-state p {
  margin: 0;
  font-size: 0.95rem;
}

.empty {
  padding: 1rem 0;
  color: var(--ink-3);
  font-style: italic;
}

/* ── Editor view ──────────────────────────────────────────── */
.back {
  color: var(--ink-3);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  margin: 0 0 0.5rem -0.6rem;
  border-radius: 6px;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.back:hover { color: var(--accent-2); background: var(--accent-soft) }

#status {
  color: var(--ink-3);
  font-size: 0.8rem;
  min-height: 1.2em;
  margin: 0 0 0.5rem;
  font-variant-numeric: tabular-nums;
}

#editor {
  min-height: 60vh;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  margin: 0 0 1rem;
}

/* ── Crepe editor inner polish ────────────────────────────── */
/* Use body-level specificity + font-family on every typed element so
   Crepe's theme can't quietly serve serif headings. */
body #editor,
body #editor .milkdown,
body #editor .ProseMirror,
body #editor .ProseMirror h1,
body #editor .ProseMirror h2,
body #editor .ProseMirror h3,
body #editor .ProseMirror h4,
body #editor .ProseMirror h5,
body #editor .ProseMirror h6,
body #editor .ProseMirror p,
body #editor .ProseMirror li,
body #editor .ProseMirror blockquote {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               system-ui, "Helvetica Neue", Arial, sans-serif;
}
#editor .milkdown,
#editor .ProseMirror { color: var(--ink) }

/* Pin padding/margins with !important so Crepe focus/active states can't
   silently swap them and reflow the document vertically. */
#editor .ProseMirror {
  padding: 1.75rem 2rem !important;
  line-height: 1.65;
  font-size: 16px;
  outline: none;
}
#editor .ProseMirror > * { margin: 0.4rem 0 !important }
#editor .ProseMirror > *:first-child { margin-top: 0 !important }
/* Defensively hide any empty paragraph wrappers Crepe might insert above
   the first real block (suspected cause of vertical jiggle). */
#editor .ProseMirror > p:empty:first-child,
#editor .ProseMirror > p:first-child:has(br:only-child) {
  display: none;
}
/* Prevent the browser from auto-scrolling focused content into view,
   which can read as the heading shifting up/down when clicked. */
html { scroll-padding-top: 0; scroll-behavior: auto }
#editor, #editor * { scroll-margin: 0 !important }

#editor .ProseMirror h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 0.6rem !important;
}
/* Suppress empty siblings before the first heading. ProseMirror often
   inserts a hidden trailing paragraph / placeholder once it goes editable,
   which pushes the actual content down by one line-height. */
#editor .ProseMirror > *:first-child:empty,
#editor .ProseMirror > br:first-child,
#editor .ProseMirror > p:first-child:not(:has(*)):not(:not(:empty)) {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
}
#editor .ProseMirror h2 {
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 1.4rem 0 0.4rem;
}
#editor .ProseMirror h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 1.1rem 0 0.3rem;
}
#editor .ProseMirror p { margin: 0.4rem 0 }
#editor .ProseMirror ul,
#editor .ProseMirror ol { padding-left: 1.5rem; margin: 0.4rem 0 }
#editor .ProseMirror li { margin: 0.15rem 0 }
#editor .ProseMirror li > p { margin: 0 }
#editor .ProseMirror blockquote {
  border-left: 3px solid var(--accent-soft);
  padding: 0.1rem 0 0.1rem 1rem;
  color: var(--ink-2);
  margin: 0.6rem 0;
}
#editor .ProseMirror code {
  background: var(--accent-soft);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font: 0.9em ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent-2);
}
#editor .ProseMirror pre {
  background: #faf9f5;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  margin: 0.6rem 0;
  overflow-x: auto;
}
#editor .ProseMirror pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.9em;
}
#editor .ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#editor .ProseMirror hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 1.5rem 0;
}
