:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --text: #e8ecf2;
  --muted: #9aa4b2;
  --accent: #f0a24b;
  --border: #262b35;
  --error: #ff6b6b;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --text: #16181d;
    --muted: #5c6570;
    --accent: #d97a1f;
    --border: #e2e5ea;
    --error: #c0392b;
  }
}

* { box-sizing: border-box; }

/* We supply our own :active press states, so kill the default grey tap flash. */
a, button, .tile, .row, .link-row, .chip-card, .stage-btn { -webkit-tap-highlight-color: transparent; }

/* Top loading bar (see base.html). Hidden at width 0; on navigation it crawls
   toward 90% and never finishes, then the fresh page loads with it reset. */
#nprog {
  position: fixed;
  top: 0; left: 0;
  height: 3px; width: 0;
  background: var(--accent);
  z-index: 9999;
  border-radius: 0 3px 3px 0;
  transition: width 0.2s ease;
}
#nprog.go { width: 90%; transition: width 10s cubic-bezier(0.1, 0.85, 0.2, 1); }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.9rem; margin: 0.2em 0; }

.stack { display: flex; flex-direction: column; gap: 16px; }

.center {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.15rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card.muted { background: var(--surface-2); }
.card h2, .card h3 { margin-top: 0; }
.card p, .card li { color: var(--muted); line-height: 1.5; }
.card ul { padding-left: 18px; margin: 8px 0 0; }

form.stack, .center form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }

input[type="password"], input[type="text"] {
  width: 100%;
  padding: 15px 16px;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: 15px 16px;
  font-size: 16px;
  font-weight: 600;
  color: #10131a;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.error { color: var(--error); margin: 0; }

.mark {
  width: 56px; height: 56px;
  background: var(--accent);
  clip-path: polygon(50% 8%, 92% 88%, 8% 88%);
}
.mark.small { width: 20px; height: 20px; }

/* ---- Navigation + headers ------------------------------------------------ */
.back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 6px 4px;
}
.brand-min { font-weight: 650; }
.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 22px 2px 2px;
  font-weight: 650;
}
.section-label .count {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 4px;
  font-size: 0.8rem;
}
.view-desc { color: var(--muted); margin: 4px 2px 14px; line-height: 1.45; }
.detail-title { margin: 6px 0 8px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }

/* ---- Home tiles ---------------------------------------------------------- */
.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
}
.tile-primary { background: var(--accent); color: #10131a; border-color: transparent; }
.tile-primary .tile-sub { color: #10131a; opacity: 0.75; }
.tile-title { display: block; font-size: 1.15rem; font-weight: 650; }
.tile-sub { display: block; color: var(--muted); margin-top: 2px; font-size: 0.92rem; }

/* ---- Link list ----------------------------------------------------------- */
.link-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 16px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.link-row:last-child { border-bottom: none; }
.link-row .arrow { color: var(--muted); }

/* ---- Rows (list layout) -------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  text-decoration: none;
  color: var(--text);
}
.row.static { cursor: default; }
.row-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row-title { font-weight: 620; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-summary { color: var(--muted); font-size: 0.9rem; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; white-space: nowrap; }

/* ---- Board (kanban) ------------------------------------------------------ */
.board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}
.board-col {
  flex: 0 0 78%;
  max-width: 300px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px;
}
.board-col-head {
  font-weight: 650;
  font-size: 0.9rem;
  margin: 2px 4px 10px;
  display: flex;
  justify-content: space-between;
}
.board-col-head .count { color: var(--muted); }
.board-col-body { display: flex; flex-direction: column; gap: 8px; }
.chip-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  text-decoration: none;
  color: var(--text);
}
.chip-card-title { display: block; font-weight: 620; }
.chip-card-meta { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

/* ---- Chips, tags, money, due dates -------------------------------------- */
.chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 620;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.tag {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 8px;
  text-decoration: none;
}
.money { font-weight: 650; color: var(--text); }
.due { font-size: 0.85rem; color: var(--muted); }
.due.overdue { color: var(--error); font-weight: 620; }

/* status chip accents (subtle left-tint by lifecycle stage) */
.chip-cold-lead    { background: #2a3340; }
.chip-researching  { background: #2e3a2f; }
.chip-contacted    { background: #33372a; }
.chip-in-talks     { background: #3a3320; }
.chip-client       { background: #2c3a2c; color: #d6f5d6; }
.chip-past-client  { background: #2a2f38; }
.chip-not-a-fit    { background: #382a2a; }
.chip-suppressed   { background: #4a2020; color: #ffd6d6; }
.chip-inquiry      { background: #2a3340; }
.chip-quoted       { background: #33372a; }
.chip-booked       { background: #3a3320; }
.chip-in-progress  { background: #2e3a3a; }
.chip-delivered    { background: #2c3550; }
.chip-paid         { background: #2c3a2c; color: #d6f5d6; }
@media (prefers-color-scheme: light) {
  .chip-cold-lead    { background: #e4ebf3; }
  .chip-researching  { background: #e2f0e4; }
  .chip-contacted    { background: #eef0dd; }
  .chip-in-talks     { background: #f6eccf; }
  .chip-client       { background: #d8f0d8; color: #1c4d1c; }
  .chip-past-client  { background: #e6e9ee; }
  .chip-not-a-fit    { background: #f5dede; }
  .chip-suppressed   { background: #f7d4d4; color: #7a1c1c; }
  .chip-inquiry      { background: #e4ebf3; }
  .chip-quoted       { background: #eef0dd; }
  .chip-booked       { background: #f6eccf; }
  .chip-in-progress  { background: #d9eeee; }
  .chip-delivered    { background: #dbe4f7; }
  .chip-paid         { background: #d8f0d8; color: #1c4d1c; }
}

/* ---- Metrics ------------------------------------------------------------- */
.metric-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.metric {
  flex: 1 1 30%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-weight: 620;
}
.metric-label { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 500; margin-bottom: 3px; }

/* ---- Stage / status picker ---------------------------------------------- */
.stage-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.stage-btn {
  flex: 1 1 auto;
  padding: 12px 10px;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  min-height: 44px;
}
.stage-btn.current { background: var(--accent); color: #10131a; border-color: transparent; }
.stage-btn:disabled { opacity: 1; cursor: default; }

/* ---- Details, fields, forms --------------------------------------------- */
.field { padding: 6px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field-label { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 2px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.link-pill {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}
.notion-link { text-align: center; margin-top: 24px; }
.notion-link a { color: var(--muted); font-size: 0.85rem; }

.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.form select, .form textarea, .form input[type="date"], .form input[type="text"] {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.form .fixed-field {
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 620;
}
.form textarea { font-family: inherit; resize: vertical; }

/* ---- Rendered markdown --------------------------------------------------- */
.prose { line-height: 1.55; }
.prose p { color: var(--text); }
.prose h1, .prose h2, .prose h3 { margin: 0.6em 0 0.3em; }
.prose ul, .prose ol { padding-left: 20px; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; font-size: 0.9em; }
.prose a { color: var(--accent); }

.empty p { margin: 0; }

/* ---- Instant tap feedback ------------------------------------------------ */
/* Pressed states fire immediately on touch, before the page navigates, so a
   tap always feels acknowledged even while the server round-trip is in flight. */
.tile, .row, .link-row, .chip-card, .stage-btn, button, .link-pill {
  transition: transform 0.06s ease, filter 0.06s ease, background 0.12s ease;
}
.tile:active, .chip-card:active, .link-pill:active {
  transform: scale(0.985);
  filter: brightness(0.94);
}
.row:active, .link-row:active { background: var(--surface-2); transform: scale(0.995); }
button:active, .stage-btn:active { transform: scale(0.97); filter: brightness(0.93); }
@media (prefers-color-scheme: dark) {
  .tile:active, .chip-card:active { filter: brightness(1.12); }
}
