/* Dreambound CRM stylesheet. Hand-written; tokens first, then base, layout, components. */

/* ---- Fonts (self-hosted) --------------------------------------------- */
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url("/assets/vendor/fonts/figtree-variable.woff2") format("woff2");
}

/* ---- Tokens ----------------------------------------------------------- */
:root {
  --ink: #1C2126;
  --ink-2: #4A5259;
  --ink-3: #7A838B;
  --surface: #FFFFFF;
  --surface-2: #F8F9F7;
  --canvas: #F3F4F2;
  --line: #DDE0DC;
  --line-strong: #C5C9C3;
  --accent: #1F5FBF;        /* placeholder: replace with Dreambound brand colour */
  --accent-ink: #FFFFFF;
  --accent-soft: #E6EEFA;
  --positive: #1E7F4F;
  --positive-soft: #E3F3EA;
  --negative: #B3261E;
  --negative-soft: #F9E5E3;
  --warning: #A86A00;
  --warning-soft: #FBF0DC;
  --focus: #1F5FBF;

  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(20, 24, 28, .06), 0 4px 16px rgba(20, 24, 28, .05);
  --sidebar-w: 224px;
  --topbar-h: 56px;
  --touch: 44px;
  --ease: 160ms ease-out;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E8EAE6;
    --ink-2: #B4B9B3;
    --ink-3: #848A84;
    --surface: #1B1F22;
    --surface-2: #22272B;
    --canvas: #131619;
    --line: #2C3237;
    --line-strong: #3C434A;
    --accent: #7AA7F0;
    --accent-ink: #0F1A2E;
    --accent-soft: #1E2C44;
    --positive: #5FC48F;
    --positive-soft: #163224;
    --negative: #F0847C;
    --negative-soft: #3B1C1A;
    --warning: #E0A84A;
    --warning-soft: #3A2B12;
    --focus: #7AA7F0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

/* ---- Base ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }
.num, td.money, th.money, .money { font-variant-numeric: tabular-nums; }
.money { text-align: right; }

/* ---- Shell layout ----------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 8px 10px;
  color: var(--ink-2); border-radius: var(--radius-sm); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.page { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.search input {
  width: 320px; max-width: 50vw;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); font: inherit;
}
.content { padding: 24px; flex: 1 1 auto; }

/* ---- Minimal layout (login, errors, maintenance) --------------------- */
body.minimal { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.minimal-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
}

/* ---- Components ------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 500;
  cursor: pointer; transition: background var(--ease), border-color var(--ease);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(.95); background: var(--accent); }
.btn-danger { color: var(--negative); border-color: var(--negative); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 18px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge-client { background: var(--positive-soft); color: var(--positive); border-color: transparent; }
.badge-lead { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-contact { background: var(--surface-2); color: var(--ink-2); }
.badge-past_client { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.empty-state { max-width: 520px; padding: 32px 0; color: var(--ink-2); }
.empty-state h2 { color: var(--ink); }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }

label { display: block; font-weight: 500; margin-bottom: 4px; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
.field { margin-bottom: 16px; }
.field-error { color: var(--negative); font-size: 13px; margin-top: 4px; }
.help { color: var(--ink-3); font-size: 13px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--ink); color: var(--surface);
  padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 14px; max-width: 360px;
  animation: toast-in 160ms ease-out;
}
.toast.error { background: var(--negative); color: #fff; }
.toast.success { background: var(--positive); color: #fff; }
.toast.warning { background: var(--warning); color: #fff; }
.toast.is-leaving { opacity: 0; transition: opacity 300ms; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Mobile: sidebar becomes a bottom tab bar ------------------------ */
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    width: auto; height: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
    flex-direction: row; z-index: 20;
  }
  .brand { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; min-height: var(--touch); padding: 6px 4px; font-size: 11px; flex: 1 1 0; }
  .nav-icon { width: 22px; height: 22px; }
  .topbar { padding: 0 16px; }
  .search input { width: 100%; max-width: none; }
  .content { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
  .btn { min-height: var(--touch); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- Phase 2: auth, account, settings -------------------------------- */
.brand-centre { justify-content: center; margin-bottom: 8px; }
.btn-block { width: 100%; }
.btn-small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); margin-bottom: 16px; font-size: 14px; }
.alert-error, .alert-negative { background: var(--negative-soft); border-color: transparent; color: var(--negative); }
.alert-success { background: var(--positive-soft); border-color: transparent; color: var(--positive); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 16px; max-width: 720px; }
.card-narrow { max-width: 560px; margin-bottom: 16px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card-link { color: inherit; display: block; transition: border-color var(--ease); }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.card-link h2 { color: var(--accent); }
.card-muted { color: var(--ink-3); background: var(--surface-2); }
.card-muted h2 { color: var(--ink-2); }
.dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; margin: 0 0 12px; }
.dl dt { color: var(--ink-3); font-size: 13px; }
.dl dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 16px; }
.details { margin-top: 12px; }
.details summary { cursor: pointer; color: var(--accent); font-weight: 500; min-height: 32px; display: flex; align-items: center; }
.inline-form { padding: 12px 0 0; max-width: 360px; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 4px; }
.qr-wrap { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.qr { width: 180px; height: 180px; background: #fff; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); flex: 0 0 auto; }
.qr svg { width: 100%; height: 100%; }
.code-block { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; padding: 6px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); letter-spacing: .04em; user-select: all; }
.recovery-codes { list-style: none; padding: 0; margin: 0 0 16px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.recovery-codes code { display: block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); text-align: center; user-select: all; }
.skip-form { margin-top: 16px; text-align: center; }
.sidebar-user { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.sidebar-user-name { font-weight: 600; }
.sidebar-user-role { color: var(--ink-3); margin-bottom: 8px; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.text-negative { color: var(--negative); }
tr.is-muted td { color: var(--ink-3); }
.table-actions { text-align: right; white-space: nowrap; }
@media (max-width: 800px) {
  .sidebar-user { display: none; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; }
  table.data tr { padding: 8px 12px; border-bottom: 1px solid var(--line); }
  table.data td { padding: 4px 0; border: 0; display: flex; gap: 8px; }
  table.data td[data-label]::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; min-width: 96px; flex: 0 0 auto; }
  table.data td.table-actions { justify-content: flex-start; }
  .recovery-codes { grid-template-columns: 1fr; }
}

/* ---- Phase 3: lists, records, search --------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.filters-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 auto; }
.filters-row select, .filters-row input[type="search"] { width: auto; min-width: 140px; min-height: 38px; }
.filters-search { flex: 1 1 240px; min-width: 200px; }
.filters-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; min-height: 38px; cursor: pointer; }
.check input { width: 18px; height: 18px; min-height: 0; margin: 0; }
.row-title { font-weight: 600; color: var(--ink); }
.sort-link { color: inherit; }
.sort-link.is-active { color: var(--accent); }
.tags-cell { color: var(--ink-3); font-size: 13px; }
.badge-tag { background: var(--surface-2); color: var(--ink-2); }
.stage-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); margin-right: 6px; vertical-align: middle; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; color: var(--ink-3); font-size: 14px; }
.pagination-links { display: flex; gap: 10px; align-items: center; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-3); font-size: 12px; font-weight: 600; text-align: center; line-height: 20px; }

.form-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; max-width: 1000px; }
.form-columns .form-actions { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.form-actions .spacer { flex: 1 1 auto; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1 1 0; min-width: 0; }
.field-row .field-narrow { flex: 0 0 110px; }
.lead-fields { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.inline { display: inline; }
.prewrap { white-space: pre-wrap; }

.record-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 12px; }
.record-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.record-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: 14px; color: var(--ink-2); }
.meta-link { color: var(--ink-2); }
.status-form { display: inline-flex; gap: 6px; align-items: center; }
.status-select { width: auto; min-height: 32px; padding: 2px 28px 2px 10px; border-radius: 999px; font-weight: 600; font-size: 13px; border-color: transparent; }
.status-select.status-client { background: var(--positive-soft); color: var(--positive); }
.status-select.status-lead { background: var(--accent-soft); color: var(--accent); }
.status-select.status-contact { background: var(--surface-2); color: var(--ink-2); }
.status-select.status-past_client { background: var(--warning-soft); color: var(--warning); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; min-height: var(--touch); display: inline-flex; align-items: center; gap: 6px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.card-wide { grid-column: 1 / -1; }

.search { position: relative; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 30; max-height: 70vh; overflow-y: auto; }
.search-group-title { padding: 8px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; }
.search-item { display: block; padding: 8px 12px; color: var(--ink); }
.search-item:hover, .search-item:focus { background: var(--surface-2); text-decoration: none; outline: none; }
.search-item-name { font-weight: 600; }
.search-item-detail { display: block; font-size: 13px; color: var(--ink-3); }
.search-empty { padding: 12px; color: var(--ink-3); font-size: 14px; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.result-list li:last-child { border-bottom: 0; }
.result-list a { font-weight: 600; }

.quick-add { position: relative; }
.quick-add summary { list-style: none; cursor: pointer; }
.quick-add summary::-webkit-details-marker { display: none; }
.quick-add .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; list-style: none; margin: 0; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 30; }
.quick-add .menu a { display: block; padding: 8px 10px; color: var(--ink); border-radius: var(--radius-sm); min-height: 36px; }
.quick-add .menu a:hover { background: var(--surface-2); text-decoration: none; }

@media (max-width: 800px) {
  .filters-row select, .filters-row input[type="search"] { width: 100%; }
  .filters-actions { width: 100%; }
  .filters-actions .btn { flex: 1 1 0; }
  .field-row { flex-direction: column; gap: 0; }
  .field-row .field-narrow { flex: 1 1 auto; }
  .record-header { flex-direction: column; }
  .search-results { position: fixed; left: 8px; right: 8px; top: calc(var(--topbar-h) + 4px); min-width: 0; }
  .topbar-actions { flex: 1 1 auto; justify-content: flex-end; }
  .search { flex: 1 1 auto; }
}
