/* Industry design system — wireframe/blueprint aesthetic.
   Source of truth for every value used here: dashboard/DESIGN_SPEC.md.
   No literal px/hex outside this file — templates only ever reference
   the classes below. */

@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600&family=Barlow+Condensed:wght@500;600;700&display=swap');

:root {
  /* Base colors */
  --color-bg: #f2f2f3;
  --color-surface: #e9e9ea;
  --color-text: #1d1f20;
  --color-accent: #5980a6;
  --color-divider: color-mix(in srgb, #1d1f20 16%, transparent);

  /* Neutral tonal ramp (light -> dark) */
  --color-neutral-100: oklch(97% 0.002 240);
  --color-neutral-200: oklch(93% 0.003 240);
  --color-neutral-300: oklch(87% 0.004 240);
  --color-neutral-400: oklch(78% 0.005 240);
  --color-neutral-500: oklch(68% 0.006 240);
  --color-neutral-600: oklch(56% 0.006 240);
  --color-neutral-700: oklch(44% 0.006 240);
  --color-neutral-800: oklch(32% 0.005 240);
  --color-neutral-900: oklch(20% 0.004 240);

  /* Accent tonal ramp (light -> dark), anchored near --color-accent at 600 */
  --color-accent-100: oklch(94% 0.015 235);
  --color-accent-200: oklch(88% 0.025 235);
  --color-accent-300: oklch(80% 0.035 235);
  --color-accent-400: oklch(72% 0.045 235);
  --color-accent-500: oklch(64% 0.055 235);
  --color-accent-600: oklch(58% 0.06 235);
  --color-accent-700: oklch(50% 0.06 235);
  --color-accent-800: oklch(40% 0.055 235);
  --color-accent-900: oklch(28% 0.045 235);

  /* Type */
  --font-heading: "Barlow Condensed", sans-serif;
  --font-body: "Barlow", sans-serif;

  /* Spacing scale */
  --space-1: 3.4px;
  --space-2: 6.8px;
  --space-3: 10.2px;
  --space-4: 13.6px;
  --space-6: 20.4px;
  --space-8: 27.2px;

  /* Radii */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 7px;

  /* Shadows */
  --shadow-sm: 0 1px 2px color-mix(in srgb, var(--color-neutral-900) 8%, transparent);
  --shadow-md: 0 2px 6px color-mix(in srgb, var(--color-neutral-900) 12%, transparent);
  --shadow-lg: 0 4px 16px color-mix(in srgb, var(--color-neutral-900) 16%, transparent);

  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  margin: 0;
  color: var(--color-text);
}

h1 { font-weight: 600; font-size: 26px; letter-spacing: -0.01em; }
h2 { font-weight: 600; font-size: 17px; margin-bottom: var(--space-4); }

h6.kicker {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent-700);
  margin-bottom: var(--space-1);
}

a { color: var(--color-accent-700); }
a:hover { color: var(--color-accent-900); }

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--color-surface);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

.muted { color: var(--color-neutral-600); font-size: 13px; }

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 224px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-divider);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  padding: var(--space-6) var(--space-4);
}

.sidebar-brand {
  padding: 0 var(--space-2) var(--space-6);
}

/* Standalone (not scoped under .sidebar-brand) so the mobile topbar and
   the login screen can reuse the same brand mark outside the sidebar. */
.brand-name {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.02em;
}

.brand-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-accent-700);
  margin-top: var(--space-1);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  color: var(--color-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
}

.sidebar-nav a svg { flex-shrink: 0; }

.sidebar-nav a:hover {
  background: color-mix(in srgb, var(--color-accent-100) 60%, transparent);
}

.sidebar-nav a[aria-current="page"] {
  color: var(--color-accent-900);
  background: var(--color-accent-100);
  border-left: 2px solid var(--color-accent);
  font-weight: 600;
}

.sidebar-spacer { flex: 1; }

.sidebar-footer {
  padding: var(--space-4) var(--space-2) 0;
  border-top: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-footer .tag-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.sidebar-footer .muted { font-size: 11px; }

/* Hidden checkbox driving the mobile hamburger toggle (see base.html) —
   CSS-only, no JS, matching this app's existing no-client-JS-for-nav-state
   convention. Only shown/relevant at the phone/tablet breakpoint below. */
.nav-toggle-checkbox { display: none; }

.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.main {
  flex: 1;
  overflow: auto;
  padding: calc(var(--space-8) + var(--space-3)) calc(var(--space-8) + var(--space-4)) calc(var(--space-8) + var(--space-6));
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.page-header .titles { min-width: 0; }
.page-header .actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.page-subtitle { color: var(--color-neutral-600); font-size: 13px; margin-top: var(--space-1); }

/* ---------------------------------------------------------------------- */
/* Cards / blueprint                                                      */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--color-bg);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}

.card.blueprint {
  position: relative;
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.card-link:hover { border-color: var(--color-accent-600); }
.card-link.active {
  border-color: var(--color-accent-700);
  background: var(--color-accent-100);
}

.corner {
  position: absolute;
  width: 9px;
  height: 9px;
  pointer-events: none;
}
.corner::before, .corner::after {
  content: "";
  position: absolute;
  background: var(--color-accent-700);
}
.corner::before { width: 100%; height: 1px; top: 50%; left: 0; transform: translateY(-50%); }
.corner::after { width: 1px; height: 100%; left: 50%; top: 0; transform: translateX(-50%); }

.corner.tl { top: -4px; left: -4px; }
.corner.tr { top: -4px; right: -4px; }
.corner.bl { bottom: -4px; left: -4px; }
.corner.br { bottom: -4px; right: -4px; }

.card-kicker {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-neutral-600);
  margin-bottom: var(--space-2);
}

.card-number {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 34px;
  line-height: 1.1;
}

.card-trend {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 11px;
  color: var(--color-accent-700);
  margin-top: var(--space-2);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.tiles .card { margin-bottom: 0; }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-divider);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

.btn svg { flex-shrink: 0; }

.btn-secondary { background: var(--color-bg); border-color: var(--color-divider); color: var(--color-text); }
.btn-secondary:hover { border-color: var(--color-accent-600); color: var(--color-accent-900); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--color-accent-700); }
.btn-ghost:hover { background: var(--color-accent-100); }

.btn-primary {
  background: var(--color-accent-700);
  border-color: var(--color-accent-700);
  color: var(--color-neutral-100);
}
.btn-primary:hover { background: var(--color-accent-800); border-color: var(--color-accent-800); }

.btn-primary.blueprint, .btn-outline-accent.blueprint { position: relative; }
.btn-primary.blueprint .corner::before, .btn-primary.blueprint .corner::after { background: var(--color-neutral-100); }

.btn-outline-accent {
  background: transparent;
  border: 1px solid var(--color-accent-700);
  color: var(--color-accent-900);
}
.btn-outline-accent:hover { background: var(--color-accent-100); }

/* ---------------------------------------------------------------------- */
/* Tags                                                                   */
/* ---------------------------------------------------------------------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  text-transform: uppercase;
  line-height: 1.6;
}

.tag-accent { background: var(--color-accent-700); color: var(--color-neutral-100); }
.tag-outline { background: transparent; border: 1px solid var(--color-accent-600); color: var(--color-accent-800); }
.tag-neutral { background: var(--color-neutral-200); color: var(--color-neutral-700); }

/* ---------------------------------------------------------------------- */
/* Tables                                                                 */
/* ---------------------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table tbody tr { scroll-margin-top: var(--space-4); }
.table th, .table td { text-align: left; padding: var(--space-3) var(--space-3); border-bottom: 1px solid var(--color-divider); }
.table th { color: var(--color-neutral-600); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }

/* Every .table is wrapped in this (see leads.html etc.) — overflow-x lets
   a wide table (Leads' is 11 columns) scroll independently of the page on
   a phone instead of breaking the whole layout. min-width:max-content is
   what actually forces the scroll: without it a width:100% table just
   shrinks to fit the wrapper and never overflows at all. */
.table-wrap { overflow-x: auto; }
.table-wrap .table { min-width: max-content; }

/* ---------------------------------------------------------------------- */
/* Forms                                                                  */
/* ---------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label { font-size: 12px; font-weight: 500; color: var(--color-neutral-700); }

.input, select.input, textarea.input {
  font-family: var(--font-body);
  font-size: 13px;
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--color-accent-600);
  box-shadow: 0 0 0 2px var(--color-accent-100);
}

/* Replaces the browser's native select arrow (OS chrome that doesn't
   match the hairline/blueprint look) with a Lucide chevron-down, same
   glyph family as every icon in _macros.html. CSS custom properties can't
   be interpolated into url()/data-URIs, so the stroke color below is the
   literal oklch() value of --color-neutral-600 copied verbatim — keep it
   in sync if that variable's value ever changes. */
select.input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='oklch(56%25%200.006%20240)'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpolyline%20points='6%209%2012%2015%2018%209'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px;
  padding-right: calc(var(--space-8) + var(--space-2));
}

.filter-bar {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.filter-bar .push-right { margin-left: auto; }

.form-row { display: flex; gap: var(--space-3); align-items: flex-end; flex-wrap: wrap; }
.form-stack { display: flex; flex-direction: column; gap: var(--space-4); max-width: 480px; }

/* Narrow-field utilities — replace ad hoc inline style="width:...px" on
   short-value inputs (country code, language code, row cap) so those
   values compose from --space-* instead of being literal px in a
   template. See targets.html. */
.field-narrow { max-width: calc(var(--space-8) * 6); }
.field-country-code .input { width: calc(var(--space-8) * 2 + var(--space-4)); text-transform: uppercase; }
.field-grow { flex: 1; }

/* Multiple per-row action buttons in one table cell (Targets' cities
   table) — wraps instead of overflowing the cell on a narrow screen. */
.cell-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ---------------------------------------------------------------------- */
/* Bar charts                                                             */
/* ---------------------------------------------------------------------- */

.bar-row { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-2) 0; font-size: 12.5px; }
.bar-label { width: 150px; flex-shrink: 0; color: var(--color-neutral-700); }
.bar-track { flex: 1; background: var(--color-neutral-200); border-radius: var(--radius-sm); overflow: hidden; height: 12px; }
.bar-fill { background: var(--color-accent); height: 100%; }
.bar-count { width: 46px; text-align: right; flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* Pipeline workflow                                                      */
/* ---------------------------------------------------------------------- */

.workflow {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: stretch;
  margin-bottom: var(--space-4);
}

.workflow-step {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  background: var(--color-surface);
}

.workflow-step .step-name {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: var(--space-2);
}

.stage-grid { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-6); }

/* ---------------------------------------------------------------------- */
/* Notices (blueprint, mono-accent — no red/yellow)                       */
/* ---------------------------------------------------------------------- */

.notice { display: flex; gap: var(--space-3); align-items: flex-start; }
.notice svg { flex-shrink: 0; color: var(--color-accent-700); margin-top: 2px; }

/* ---------------------------------------------------------------------- */
/* Log panel (dark, on the light Industry surface elsewhere)              */
/* ---------------------------------------------------------------------- */

.log-panel {
  --color-text: var(--color-neutral-100);
  background: var(--color-neutral-900);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  position: relative;
}
.log-panel .corner::before, .log-panel .corner::after { background: var(--color-accent-400); }

.log-panel pre {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--color-neutral-200);
  white-space: pre-wrap;
  max-height: 60vh;
  overflow-y: auto;
}

/* ---------------------------------------------------------------------- */
/* Pagination                                                             */
/* ---------------------------------------------------------------------- */

.pagination { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: var(--space-4); }

/* ---------------------------------------------------------------------- */
/* Lead notes list (lead detail page)                                     */
/* ---------------------------------------------------------------------- */

.note { padding: var(--space-3) 0; border-bottom: 1px solid var(--color-divider); }
.note:last-child { border-bottom: none; }

/* ---------------------------------------------------------------------- */
/* Login (standalone screen, no sidebar)                                  */
/* ---------------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--color-bg);
}
.login-card { width: 100%; max-width: calc(var(--space-8) * 14); }

/* ---------------------------------------------------------------------- */
/* Misc                                                                   */
/* ---------------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: var(--space-6); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

/* Tablet/compact: two-col panels stack, and the sidebar hides behind the
   hamburger toggle in .mobile-topbar instead of the old behavior of just
   stacking the full 224px-padded sidebar above the content (which pushed
   every page's content down by a full nav's height before you saw
   anything). Opening the nav pushes content down — no overlay/drawer,
   simplest thing that works for a single-operator tool. */
@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .mobile-topbar { display: flex; }
  .sidebar { width: auto; border-right: none; border-bottom: 1px solid var(--color-divider); display: none; }
  .nav-toggle-checkbox:checked ~ .sidebar { display: flex; }
}

/* Collapsible sections (Leads' "Browse by city" grid / filter bar) — a
   CSS-only checkbox-hack, same shape as the hamburger nav. The checkbox
   itself is always hidden, at every width — it's purely a toggle
   mechanism, never meant to render. The toggle label (and the actual
   collapse behavior) only turn on at the phone breakpoint below;
   desktop/tablet always show the content open with no toggle chrome. */
.collapsible-checkbox { display: none; }
.collapsible-toggle { display: none; }

/* Leads' Stage cell (leads.html): a plain read-only .tag on desktop/
   tablet, swapped for a quick-edit <select> (auto-submits via a one-line
   onchange, the only bit of real JS in this app) on phone — editing a
   lead's stage from the list, not just its detail page, matters more
   there since a tap-through round trip costs more on a small screen. */
.stage-quick-edit { display: none; }

/* Phone: reclaim width eaten by .main's desktop padding, and stack
   controls that would otherwise cram into an unreadable narrow row. */
@media (max-width: 480px) {
  .main { padding: var(--space-6) var(--space-4); }

  .stage-view { display: none; }
  .stage-quick-edit { display: block; }

  /* Tighter than the default .input padding — the table-card's STAGE row
     sits next to plain-text values (CATEGORY, CITY, ...) so the standard
     control padding reads as oversized next to them. Font-size stays at
     16px (below, shared with every field) rather than shrinking — that's
     the iOS auto-zoom fix and isn't safe to override per-field. */
  .stage-quick-edit select {
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
  }

  /* iOS Safari auto-zooms the page on focus for any input/select/textarea
     with font-size under 16px (it assumes you need help reading it) — the
     desktop type scale's 13px triggers this on every text field in the
     app, login included. Bumped to 16px only at this breakpoint so the
     desktop scale (dashboard/DESIGN_SPEC.md's stated 13px) is untouched. */
  .input, select.input, textarea.input { font-size: 16px; }

  .bar-row { flex-wrap: wrap; row-gap: var(--space-1); }
  .bar-label { width: 100%; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .btn { justify-content: center; }

  .collapsible-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
    margin-bottom: var(--space-4);
  }
  .collapsible-toggle .chevron { display: inline-flex; transition: transform 0.15s ease; }

  /* Each accordion instance MUST be scoped by its checkbox's own #id on
     both sides of the selector, not a class shared between sections. Two
     bugs came from that sharing: (1) a generic
     ".collapsible-checkbox:not(:checked) ~ .collapsible-content" matches
     as soon as ANY earlier checkbox on the page is unchecked, regardless
     of which panel it belongs to; (2) even after scoping the checkbox
     side by #id, .filter-bar also carried the generic ".collapsible-
     content" class so #cities-toggle's own rule still matched it and hid
     it whenever the (unrelated, untouched) city panel was collapsed. Fix
     for both: each panel gets its own unique content class (.filter-bar
     is already unique on its own — it doesn't need "collapsible-content"
     too) and each rule pairs one #checkbox-id with that one unique class,
     nothing shared. Add one more such pair for every future collapsible
     section — copy-paste, don't genericize. */
  #cities-toggle:checked ~ label[for="cities-toggle"] .chevron { transform: rotate(90deg); }
  #cities-toggle:not(:checked) ~ .collapsible-content { display: none; }
  #filters-toggle:checked ~ label[for="filters-toggle"] .chevron { transform: rotate(90deg); }
  #filters-toggle:not(:checked) ~ .filter-bar { display: none; }

  /* .table-cards (opt-in modifier, e.g. Leads' 11-column table): turns
     each row into a stacked label/value card instead of a shrunk table
     you scroll sideways through. Each <td> needs data-label="..." — that
     attribute is what the ::before below renders as the row's field
     label. Plain .table elsewhere (fewer columns, already read fine on
     a phone) is untouched — this only applies where a template opts in
     with the second class. */
  .table-cards thead { display: none; }
  .table-wrap .table-cards { min-width: 0; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    margin-bottom: var(--space-3);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-md);
    padding: var(--space-3);
  }
  .table-cards tr:last-child { margin-bottom: 0; }
  .table-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-1) 0;
    border-bottom: none;
    text-align: right;
  }
  .table-cards td[colspan] { display: block; text-align: left; }
  .table-cards td::before {
    content: attr(data-label);
    flex-shrink: 0;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-neutral-600);
  }
}
