:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #6a737d;
  --border: #e1e4e8;
  --accent: #2962ff;
  --accent-soft: #e8f0fe;
  --danger: #d93025;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

/* The app fills the viewport as a column: topbar on top, main takes the rest.
   This avoids any hardcoded topbar height causing a stray vertical scrollbar. */
body.app-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 380px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login h1 { margin: 0; font-weight: 600; }
.login .subtitle { margin: 0; color: var(--muted); font-weight: 500; }
.login .description { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.login form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.legal-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}
.legal-links a { color: var(--muted); }
.legal-links a:hover { color: var(--accent); }

/* ---------- legal pages ---------- */
.legal-page { padding: 40px 16px; }
.legal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 36px 40px;
  width: 640px;
  max-width: 100%;
  margin: 0 auto;
}
.legal-box h1 { margin: 0 0 4px; font-size: 22px; }
.legal-box .updated { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.legal-box h2 { font-size: 16px; margin: 20px 0 6px; }
.legal-box p { margin: 6px 0; line-height: 1.55; }
.legal-box a { color: var(--accent); }
.login input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.login button {
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
}
.login .error { margin: 0; color: var(--danger); }

/* ---------- project selector ---------- */
.projects-page {
  display: flex;
  align-items: center;
  justify-content: center;
}
.projects-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 360px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.projects-box h1 { margin: 0; font-weight: 600; }
.projects-box .subtitle { margin: 0; color: var(--muted); }
.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.project-row { display: flex; align-items: center; gap: 6px; }
.project-select-form { flex: 1; margin: 0; }
.project-item {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.project-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.project-actions { display: flex; gap: 2px; }
.project-actions .tool { padding: 4px 7px; font-size: 15px; }
.project-rename-form { display: flex; align-items: center; gap: 6px; flex: 1; }
.project-rename-input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--accent); border-radius: 6px; font: inherit; }
.new-project-form { display: flex; gap: 8px; }
.new-project-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.new-project-form button {
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
}
.empty-hint { color: var(--muted); margin: 0; }
.logout-form { margin: 0; }
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; margin-right: auto; }
.search-box { position: relative; flex: 0 1 280px; }
.search-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}
.search-results:empty { display: none; }
.search-hit {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  text-align: left;
}
.search-hit:hover { background: var(--accent-soft); }
.hit-name { font-weight: 600; }
.hit-context { color: var(--muted); font-size: 13px; }
.search-empty { padding: 10px 12px; color: var(--muted); }

.topbar-btn {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.topbar-btn:hover { background: #f3f4f6; }
a.topbar-btn { color: var(--ink); text-decoration: none; }
.btn-icon { display: none; font-size: 16px; line-height: 1; }
.edit-mode-toggle { display: none; font-size: 16px; line-height: 1; }
.edit-mode-toggle.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.logout-form { display: inline; }

/* ---------- board ---------- */
.main { flex: 1 1 0; min-height: 0; overflow: hidden; overflow: clip; position: relative; }
.board {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.entry {
  flex: 0 0 300px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.entry.highlight {
  outline: 3px solid #ffab40;
  outline-offset: 2px;
}

.entry-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.entry-header .name {
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-header .name:hover { color: var(--accent); }
.entry-tools { display: flex; gap: 2px; }
.rename-input { width: 100%; font: inherit; font-weight: 700; border: 1px solid var(--accent); border-radius: 4px; padding: 4px 6px; }

.tool {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 5px;
  line-height: 1;
}
.tool:hover { background: #eef0f2; color: var(--ink); }

.snippets {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.snippet {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  opacity: .85;
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  margin: 0;
}
.snippet.dragging { opacity: .4; }
.snippet.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.entry.drop-target { border-color: var(--accent); }
.snippet .text { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.snippet .text[hx-post] { cursor: pointer; }
.snippet .text[hx-post]:hover { text-decoration: underline; }

.snippet-tools {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  gap: 2px;
}
@media (hover: hover) {
  .snippet:hover .snippet-tools { display: flex; }
}
.edit-mode .snippet .snippet-tools { display: flex; }
.edit-mode .snippet .text[hx-post] { pointer-events: none; }
.edit-mode .snippet { touch-action: auto; }
.snippet-tools .tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 16px;
  line-height: 1;
}

.snippet-editor {
  width: 100%;
  min-height: 80px; /* ~3 lines of text, so editing a paragraph isn't cramped */
  border: 1px solid var(--accent);
  border-radius: 4px;
  font: inherit;
  padding: 6px 8px;
  resize: vertical;
}

/* shared snippet colours (muted) */
.c0  { background: #ffcdd2; } .c1  { background: #f8bbd0; }
.c2  { background: #e1bee7; } .c3  { background: #d1c4e9; }
.c4  { background: #c5cae9; } .c5  { background: #bbdefb; }
.c6  { background: #b2ebf2; } .c7  { background: #b2dfdb; }
.c8  { background: #c8e6c9; } .c9  { background: #f0f4c3; }
.c10 { background: #ffecb3; } .c11 { background: #ffccbc; }

.entry-footer { padding: 8px; border-top: 1px solid var(--border); }
.new-entry-rail {
  flex: 0 0 72px;
  height: 72px;
  border: 2px dashed var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 30px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.new-entry-rail:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.new-entry-rail.drop-target { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.entry-footer .add {
  width: 100%;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 6px;
}
.entry-footer .add:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- empty state ---------- */
.empty-state {
  margin: auto;
  text-align: center;
  max-width: 520px;
  padding: 40px 20px;
}
.empty-state h1 { margin: 0 0 8px; }
.empty-state .tagline { color: var(--muted); margin: 0 0 24px; }
.new-entry {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 600;
}
.empty-state h2 { margin: 32px 0 12px; color: var(--muted); font-size: 15px; }
.recent { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.recent-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
}
.recent-entry:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- suggestions panel ---------- */
.suggestions-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 8px rgba(0,0,0,.06);
  transform: translateX(100%);
  transition: transform .18s ease;
  display: flex;
  flex-direction: column;
  z-index: 15;
}
.suggestions-panel.open { transform: translateX(0); }
.suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.suggestions-header h3 { margin: 0; }
.suggestions-list { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.suggestion {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 10px 12px;
}
.suggestion:hover { border-color: var(--accent); background: var(--accent-soft); }
.suggestions-none { padding: 12px 16px; color: var(--muted); }

/* ---------- dialog ---------- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
.dialog-box {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  width: 380px;
  max-width: 90vw;
}
.dialog-box h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-actions .confirm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 600;
}
.dialog-actions .cancel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
}

/* ---------- portrait (mobile / narrow window) ---------- */
@media (orientation: portrait) {
  .brand { display: none; }
  .search-box { flex: 1; }
  .btn-icon { display: inline; }
  .btn-label { display: none; }
  .edit-mode-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .snippet { touch-action: none; }
}
