/*
 * Clarté — Leads redesign (light / warm-paper, violet accent).
 * Plain CSS, no framework — Propshaft serves this file as-is.
 * Drop-in replacement for the existing app/assets/stylesheets/application.css.
 * Every selector the ERB + Stimulus controller rely on is preserved; new
 * selectors (.contacts-more, .lead-drawer*, .app-shell tints) are additive.
 */

:root {
  /* Surfaces — warm paper */
  --bg-page: #f2efe9;
  --sidebar-bg: #f6f3ee;
  --sidebar-hover: #eeeae1;
  --sidebar-border: #e9e5dd;
  --surface: #fffdfa;
  --surface-2: #fbf9f4;
  --border-card: #e7e3db;
  --border-divider: #efebe3;
  --border-divider-2: #f1eee7;
  --fill-subtle: #fbf9f4;
  --fill-subtle-2: #f4f1eb;
  --fill-subtle-3: #efebe2;

  /* Text — warm charcoal */
  --text-primary: #211e18;
  --text-secondary: #3a362e;
  --text-secondary-2: #575249;
  --text-tertiary: #6b665c;
  --text-muted: #a29c8f;
  --text-faint: #b0aa9c;
  --sidebar-text-muted: #6e6a61;
  --sidebar-text-faint: #a29c8f;
  --sidebar-label: #b0aa9c;

  /* Brand — violet */
  --brand: #5b51e0;
  --brand-hover: #4a41cc;
  --brand-tint: #f6f4ff;
  --brand-ring: #b8b2f2;
  --brand-success-bg: #e5f6ec;
  --brand-success-text: #177e43;

  --control-border: #e6e1d7;

  --radius-card: 20px;
  --radius-control: 8px;
  --radius-nav: 10px;

  /* Table density. The header and the rows are separate grids, so their
     horizontal padding has to stay identical or the columns drift apart —
     hence the shared variable rather than a repeated literal. */
  --table-pad-x: 18px;
  --row-height: 46px;
  --table-grid-gap: 16px;

  --shadow-card: 0 1px 2px rgba(40, 35, 25, .04), 0 18px 44px -22px rgba(40, 35, 25, .16);
  --shadow-drawer: -24px 0 52px -24px rgba(40, 35, 25, .32);

  --font-body: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-head: "Schibsted Grotesk", "Hanken Grotesk", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.heading-font { font-family: var(--font-head); }

/* ---------- Page shell ---------- */

/* Fixed viewport height (not min-height) so the leads screen can hand its
   vertical scroll to an inner container: the page title, toolbar and column
   header stay put while only the table body scrolls. Pages without that inner
   scroller (reports, admin) simply scroll #main instead. */
#app { display: flex; width: 100vw; height: 100vh; overflow: hidden; }

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
}

/* ---------- Sidebar (now light) ---------- */

/* Sticky on desktop: the sidebar stays pinned while the page/table scrolls.
   The mobile media query below overrides this with a fixed off-canvas panel. */
#sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  flex-shrink: 0;
}

#sidebar .sidebar-wrapper {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text-faint);
  border-right: 1px solid var(--sidebar-border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: nowrap;
  transition: width .18s ease, padding .18s ease;
}

#sidebar .logo a {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: block;
}

#sidebar .logo h6 {
  margin: 7px 0 0;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--sidebar-text-faint);
  display: flex;
  align-items: center;
  gap: 7px;
}

#sidebar .sidebar-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--sidebar-label);
  padding: 26px 10px 10px;
  list-style: none;
}

#sidebar .menu { list-style: none; margin: 0; padding: 0; }

#sidebar .sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  padding: 9px 11px;
  border-radius: var(--radius-nav);
  color: var(--sidebar-text-muted);
}

#sidebar .sidebar-item:not(.active) .sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--text-secondary);
}

#sidebar .sidebar-item.active .sidebar-link {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

/* menu grows to fill the remaining height, pushing the collapse toggle down */
#sidebar .menu { display: flex; flex-direction: column; flex: 1; }

/* Collapse toggle, pinned below the menu */
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
  padding: 9px 11px;
  border: none;
  background: none;
  border-radius: var(--radius-nav);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--sidebar-text-muted);
  cursor: pointer;
}
.sidebar-collapse-btn:hover { background: var(--sidebar-hover); color: var(--text-secondary); }
.sidebar-collapse-btn svg { flex-shrink: 0; transition: transform .18s ease; }

/* ---------- Collapsed sidebar (desktop only) ---------- */
@media (min-width: 861px) {
  html[data-sidebar="collapsed"] #sidebar .sidebar-wrapper {
    width: 68px;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* hide every text label, keep the icons */
  html[data-sidebar="collapsed"] #sidebar .logo,
  html[data-sidebar="collapsed"] #sidebar .sidebar-title,
  html[data-sidebar="collapsed"] #sidebar .sidebar-link span,
  html[data-sidebar="collapsed"] #sidebar .sidebar-collapse-btn span {
    display: none;
  }

  /* center the icons in their now-square hit areas */
  html[data-sidebar="collapsed"] #sidebar .sidebar-link,
  html[data-sidebar="collapsed"] #sidebar .sidebar-collapse-btn {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
  }

  /* the chevron flips to point the other way (expand) */
  html[data-sidebar="collapsed"] #sidebar .sidebar-collapse-btn svg { transform: rotate(180deg); }
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border-divider);
  padding: 16px 30px 13px;
}

.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.app-header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.export-btn {
  color: var(--brand);
  border-color: var(--brand-border);
  background: var(--brand-tint);
  flex-shrink: 0;
}

.export-btn:hover { background: #ecebff; border-color: var(--brand); }

.export-menu { position: relative; }
.export-menu-caret { margin-left: 2px; }

.export-menu-list {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  padding: 6px;
  z-index: 20;
}

.export-menu-list.is-open { display: block; }

.export-menu-item {
  display: block;
  padding: 8px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.export-menu-item:hover { background: var(--fill-subtle-2); color: var(--brand); }

.app-header h1 {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0;
}

.app-header h1 .accent { color: var(--brand); }

.app-header .meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.app-header .meta .mono { font-family: var(--font-mono); letter-spacing: .01em; }

/* ---------- Content / cards ---------- */

.page-content { padding: 24px 30px 32px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* ---------- Generic buttons / forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-control);
  border: 1px solid var(--control-border);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-secondary { background: var(--fill-subtle-2); border-color: var(--control-border); color: var(--text-secondary); }

.form-control,
.form-select {
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  padding: 8px 11px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface);
  font-family: var(--font-body);
}

.form-control:focus,
.form-select:focus { outline: none; border-color: var(--brand-ring); }

/* ---------- Simple stacked form layout (admin + auth) ---------- */

.form-card { max-width: 520px; }

.card-pad { padding: 22px 24px; }

/* ---------- Reports screen ---------- */

.report-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.report-tab {
  padding: 8px 16px;
  border-radius: var(--radius-control);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: transparent;
}
.report-tab:hover { background: var(--fill-subtle-2); color: var(--text-secondary); }
.report-tab.is-active { background: var(--brand); color: #fff; }

.report-section-title { font-family: var(--font-head); font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 26px 0 12px; }

.report-table-card { overflow-x: auto; }
.report-table-card .table th.num, .report-table-card .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table-card .table th.num .th-inner { flex-direction: row-reverse; }

.report-table-toolbar {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-divider);
  display: flex;
  justify-content: flex-end;
}

.report-table-empty { padding: 28px 22px; text-align: center; font-size: 12.5px; color: var(--text-muted); }

.report-pie-card { padding: 20px 22px; margin-bottom: 18px; }
.report-pie-title { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 16px; }
.report-pie-body { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
.report-pie-svg { width: 200px; height: 200px; flex-shrink: 0; }
.report-pie-legend { display: flex; flex-direction: column; gap: 9px; min-width: 200px; }
.report-pie-legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  width: 100%;
  background: none;
  border: none;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.report-pie-legend-item:hover { background: var(--fill-subtle-2); }
.report-pie-legend-label { color: var(--text-secondary); }
.report-pie-legend-value { margin-left: auto; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.report-pie-legend-item.is-off { opacity: .5; }
.report-pie-legend-item.is-off .report-pie-legend-label { text-decoration: line-through; }

.report-delta { font-weight: 600; }
.report-delta.pos { color: #177e43; }
.report-delta.neg { color: #be1e44; }

.print-only { display: none; }

.report-print-head { margin-bottom: 16px; }
.report-print-head h1 { font-family: var(--font-head); font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.report-print-head p { font-size: 12px; color: var(--text-tertiary); margin: 0; }

/* ---------- Print / PDF export: show only the report content ---------- */
@media print {
  @page { margin: 1.4cm; }

  #sidebar, .mobile-topbar, .nav-backdrop, .report-form, .report-table-toolbar, .app-header, footer.app-footer { display: none !important; }
  .print-only { display: block !important; }

  html, body { height: auto; background: #fff; }
  /* The screen layout caps #app to one viewport (height:100vh + overflow:hidden)
     and scrolls #main internally. For print that clips everything past the first
     page — so unwind the height/overflow here and let the content flow across
     pages. */
  #app { display: block; height: auto; overflow: visible; }
  #main { display: block; height: auto; min-height: 0; overflow: visible; background: #fff; }
  .leads-page, .leads-shell { overflow: visible; height: auto; min-height: 0; }
  .page-content { padding: 0; }

  /* keep colors (KPI dots, chart lines, deltas, status pills) */
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .card, .report-kpi, .report-chart-card, .report-table-card {
    box-shadow: none !important;
    border-color: #e0ddd5 !important;
    break-inside: avoid;
  }
  .report-kpis { break-inside: avoid; }
  .report-section-title { break-after: avoid; }
  .report-chart-svg { height: 260px; }
}

.report-form { padding: 22px 24px; }

.report-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 20px; }
.report-field > label { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }
.report-field .form-select, .report-field .form-control { max-width: 340px; }

.report-range-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.report-range-row .form-select { max-width: 200px; }
.report-range-row .form-control { max-width: 160px; }
.report-range-sep, .report-range-dash { font-size: 12px; color: var(--text-muted); }

.report-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px 18px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 2px;
}

.report-metric-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; }
.report-metric-check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.report-metrics-admin { border: 1px solid var(--control-border); border-radius: var(--radius-control); max-height: 300px; padding: 12px; background: var(--fill-subtle); }

.report-actions { display: flex; gap: 10px; align-items: center; }

.report-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin: 22px 0 18px;
}

.report-kpi { position: relative; background: var(--surface); border: 1px solid var(--border-card); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow-card); }
.report-kpi-dot { position: absolute; top: 16px; right: 16px; width: 9px; height: 9px; border-radius: 50%; }
.report-kpi-value { font-family: var(--font-head); font-size: 23px; font-weight: 700; letter-spacing: -0.02em; color: var(--text-primary); }
.report-kpi-label { font-size: 11.5px; color: var(--text-tertiary); margin-top: 4px; }

.report-chart-card { padding: 20px 22px; }
.report-chart-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 14px; }
.report-legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-secondary); }
.report-legend-swatch { width: 11px; height: 11px; border-radius: 3px; }
.report-chart-svg { width: 100%; height: 300px; display: block; }
.reports-chart-empty { color: var(--text-muted); font-size: 12.5px; text-align: center; padding: 40px 0; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }

.field > label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-tertiary);
}

.field .form-control { width: 100%; }

.field-inline { flex-direction: row; align-items: center; gap: 9px; }

.field-hint { font-size: 11px; color: var(--text-muted); }

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
}

.link-muted { font-size: 12px; color: var(--text-tertiary); font-weight: 500; }
.link-muted:hover { color: var(--brand); }

.form-errors {
  background: #fce8ec;
  border: 1px solid #f5d3db;
  color: #be1e44;
  border-radius: var(--radius-control);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 12px;
}

.form-errors h2 { font-size: 12.5px; margin: 0 0 6px; }
.form-errors ul { margin: 0; padding-left: 18px; }

/* ---------- Flash messages ---------- */

.flash-area { padding: 16px 30px 0; }

.flash {
  border-radius: var(--radius-control);
  padding: 11px 15px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid transparent;
}

.flash + .flash { margin-top: 8px; }

.flash-notice { background: #e5f6ec; color: #177e43; border-color: #cdebd8; }
.flash-alert  { background: #fce8ec; color: #be1e44; border-color: #f5d3db; }

/* ---------- Auth / login screen ---------- */

.auth-shell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.auth-card { width: 100%; max-width: 400px; padding: 32px 30px; }

.auth-card h1 {
  font-family: var(--font-head);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.auth-card .subtitle { font-size: 12.5px; color: var(--text-muted); margin: 0 0 24px; }

.auth-card .btn-primary { width: 100%; justify-content: center; height: 42px; }

.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-divider);
  padding: 13px 16px;
  background: var(--fill-subtle);
}

.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-divider-2);
  color: var(--text-secondary);
}

.table tr:hover td { background: var(--surface-2); }

/* Sortable table headers (generic table controller) */
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable.active { color: var(--brand); }
.table th .th-inner { display: inline-flex; align-items: center; gap: 5px; }

footer.app-footer {
  padding: 10px 30px;
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

footer.app-footer .heart { color: #e11d48; }

/* ===========================================================
   Leads table screen
   =========================================================== */

/* The leads screen is a full-height column. The page title (in .app-header),
   the toolbar and the column header all stay put while only the table body
   scrolls — so the shell itself doesn't scroll, it just lays out the flat table
   to fill the remaining height. .leads-scroll is the single element that
   scrolls, on BOTH axes, so its sticky header (top) and sticky first column
   (left) both resolve against it. */
/* Wraps the header + shell so the leads controller (and thus the search field,
   now in the header) spans both. It's the full-height flex column: header on
   top, scrolling shell filling the rest. */
.leads-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.leads-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Card chrome removed — the table sits flat on the page for more room — and the
   card becomes the full-height flex column that holds the fixed toolbar, the
   scrolling body and the fixed pagination. */
.leads-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 4px 16px 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.leads-footer { flex-shrink: 0; }

.leads-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

/* Always show the horizontal scrollbar: macOS hides overlay scrollbars when a
   trackpad is attached, so mouse users would get no hint that the table
   continues to the right (and nothing to drag).
   NOTE: Chrome ignores ::-webkit-scrollbar as soon as the standard
   scrollbar-width is set — which puts us back on the auto-hiding overlay. So
   the standard properties are scoped to browsers without the webkit
   pseudo-element (i.e. Firefox), and Chrome/Safari get the webkit rules. */
@supports not selector(::-webkit-scrollbar) {
  .leads-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--text-faint) var(--fill-subtle-2);
  }
}

.leads-scroll::-webkit-scrollbar {
  height: 10px;
  width: 10px;
  -webkit-appearance: none;
}

.leads-scroll::-webkit-scrollbar-track {
  background: var(--fill-subtle-2);
  border-top: 1px solid var(--border-divider);
}

.leads-scroll::-webkit-scrollbar-thumb {
  background: #cfc9bd;
  border-radius: 6px;
  border: 2px solid var(--fill-subtle-2); /* inset so the thumb looks slimmer */
}

.leads-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.leads-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 20px 30px 0;
  padding: 12px 15px;
  background: #fbf0e0;
  border: 1px solid #f3e1c4;
  color: #8a5008;
  border-radius: var(--radius-control);
  font-size: 12px;
  line-height: 1.45;
}

.leads-notice svg { flex-shrink: 0; margin-top: 1px; color: #b4690e; }

/* Bottom bar: "Zeige N Einträge" on the left, pagination on the right. */
.leads-footer {
  padding: 10px var(--table-pad-x);
  border-top: 1px solid var(--border-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.show-entries { display: flex; align-items: center; gap: 8px; }
.show-entries label { font-size: 12px; color: var(--text-muted); }

.meta-refresh {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  vertical-align: middle;
}

.meta-refresh svg { opacity: .8; }

.meta-refresh:hover { color: var(--brand); }

.show-entries select.page-size {
  padding: 7px 26px 7px 11px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-control);
  background: var(--fill-subtle-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b0aba1' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 9px center;
  appearance: none;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.leads-search { display: flex; align-items: center; gap: 8px; }

.leads-search .search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--fill-subtle-2);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 9px 12px;
  width: 270px;
}

.leads-search .search-box:focus-within { border-color: var(--brand-ring); background: var(--surface); }
.leads-search .search-box svg { flex-shrink: 0; color: var(--text-muted); }

.leads-search .search-box input {
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 12.5px;
  width: 100%;
  color: var(--text-secondary);
}

/* Grid: Company | Status | Contacts | Created | Meeting | Client | Note.
   minmax(0, …) is essential: without it a wide cell (e.g. the note input +
   save button) grows its track in the row grid but not in the header grid,
   and the two drift out of alignment. The min-width keeps every column
   readable — below it the card scrolls horizontally instead of squeezing. */
.leads-grid {
  display: grid;
  /* the minmax floors keep a track from being squeezed below its content; the
     0-floors let the rest shrink so the tracks stay driven by the template
     rather than by whatever text a row happens to hold */
  grid-template-columns:
    minmax(0, 1.4fr) minmax(0, 1.2fr) minmax(0, 1.3fr)
    minmax(0, 0.8fr) minmax(140px, 1fr) minmax(0, 0.7fr) minmax(0, 2.2fr);
  gap: var(--table-grid-gap);
  align-items: center;
  min-width: 1240px;
}

.leads-grid > * { min-width: 0; }

.leads-grid-header {
  position: sticky;
  top: 0;
  background: var(--fill-subtle);
  border-top: 1px solid var(--border-divider);
  border-bottom: 1px solid var(--border-divider);
  padding: 8px var(--table-pad-x);
  z-index: 3;
}

.leads-grid-header .col {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.leads-grid-header .col.sortable { cursor: pointer; user-select: none; }
.leads-grid-header .col.active { color: var(--brand); }

.sort-chevrons { display: flex; flex-direction: column; gap: 1px; }
.sort-chevrons svg { width: 9px; height: 6px; color: var(--text-faint); }
.sort-chevrons svg.active { color: var(--brand); }

.leads-row {
  height: var(--row-height);
  padding: 0 var(--table-pad-x);
  border-bottom: 1px solid var(--border-divider-2);
  /* clip (not hidden) so the sticky first column still resolves against
     .leads-scroll — overflow:hidden would turn each row into its own scroll
     container and kill the horizontal freeze. */
  overflow: clip;
  box-sizing: border-box;
  cursor: pointer;
  transition: background .12s;
}

.leads-row:hover { background: var(--surface-2); }
.leads-row.is-selected { background: var(--brand-tint); box-shadow: inset 3px 0 0 var(--brand); }
.leads-row.hidden { display: none; }

/* ---- Frozen first column (stays pinned on horizontal scroll) ----
   The card behind the table is gone, so each frozen cell needs its own opaque
   background (and matching hover/selected tint) or scrolled-under content shows
   through. The ::after masks the grid gap to the cell's right so column 2 can't
   peek through the gutter while it slides underneath. The divider shadow is
   toggled on only while actually scrolled (see .is-scrolled-x below). */
.company-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  /* fill the full row height (the grid centers items) so the opaque background
     covers the whole cell — otherwise scrolled content bleeds through the thin
     strips above and below a content-height cell. */
  align-self: stretch;
}

.leads-row:hover .company-cell { background: var(--surface-2); }
.leads-row.is-selected .company-cell { background: var(--brand-tint); }

.leads-grid-header .col:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--fill-subtle);
  align-self: stretch; /* fill full header height (see .company-cell) */
}

.company-cell::after,
.leads-grid-header .col:first-child::after {
  content: "";
  position: absolute;
  top: 0;
  right: calc(-1 * var(--table-grid-gap));
  width: var(--table-grid-gap);
  height: 100%;
  background: inherit; /* mirror the cell's (state-dependent) fill */
}

.leads-scroll.is-scrolled-x .company-cell,
.leads-scroll.is-scrolled-x .leads-grid-header .col:first-child {
  box-shadow: 8px 0 9px -6px rgba(40, 35, 25, .16);
}

.company-tile {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--fill-subtle-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  flex-shrink: 0;
}

.company-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-name:hover { color: var(--brand); text-decoration: underline; }

/* Status pill/select */
.lead-status {
  width: 100%;
  padding: 8px 28px 8px 12px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  appearance: none;
  cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b0aba1' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Contacts: first contact visible + "+N" chip; full list lives in a hidden node for the drawer */
.contacts-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }

.contacts-cell .avatar { width: 24px; height: 24px; font-size: 9.5px; }

.contacts-cell .contact-name {
  font-size: 12px;
  color: var(--text-secondary-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contacts-more {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--fill-subtle-3);
  border-radius: 20px;
  padding: 2px 9px;
  white-space: nowrap;
}

.contacts-full { display: none; } /* cloned into the drawer by Stimulus */

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.contact-cell { display: flex; align-items: center; gap: 8px; }
.contact-name { font-size: 12.5px; color: var(--text-secondary); }

.date-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; /* keep date and time on one line */
}

.client-cell { font-size: 12px; color: var(--text-tertiary); }

.desc-cell { display: flex; gap: 8px; align-items: center; }

.desc-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  padding: 8px 11px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface);
}

.desc-input:focus { outline: none; border-color: var(--brand-ring); }

.save-btn {
  border: none;
  border-radius: var(--radius-control);
  height: 34px;
  padding: 0 14px;
  /* fixed width so switching between "Speichern" and "Gespeichert" doesn't
     resize the button and shift the row */
  min-width: 122px;
  flex-shrink: 0;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.save-btn.is-clean { background: var(--fill-subtle-3); color: var(--text-faint); cursor: default; }
.save-btn.is-dirty { background: var(--brand); color: #fff; cursor: pointer; box-shadow: 0 1px 2px rgba(91, 81, 224, .33); }
.save-btn.is-dirty:hover { background: var(--brand-hover); }
.save-btn.is-saved { background: var(--brand-success-bg); color: var(--brand-success-text); cursor: default; }

.leads-empty { text-align: center; padding: 64px 20px; }

.leads-empty .tile {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-control);
  background: var(--fill-subtle-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin: 0 auto 14px;
}

.leads-empty p { font-size: 13px; font-weight: 600; color: var(--text-secondary-2); margin: 0; }

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

.leads-pagination:empty { display: none; }

/* border + padding now live on .leads-footer; the pagination just groups its
   info + controls to the right of "Zeige N Einträge" */
.leads-pagination {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pagination-info { font-size: 12px; color: var(--text-muted); }

.pagination-controls { display: flex; align-items: center; gap: 4px; }

.pagination-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-card);
  background: var(--surface);
  border-radius: var(--radius-control);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.pagination-btn:hover:not(:disabled):not(.is-active) { background: var(--fill-subtle-2); }

.pagination-btn.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  cursor: default;
}

.pagination-btn:disabled { opacity: .45; cursor: default; }

.pagination-ellipsis { padding: 0 4px; color: var(--text-muted); font-size: 12px; }

/* ===========================================================
   Lead detail drawer (split-view on row click)
   =========================================================== */

.lead-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 35, 25, .14);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.lead-drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

.lead-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 434px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--sidebar-border);
  box-shadow: var(--shadow-drawer);
  z-index: 41;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .24s cubic-bezier(.22, 1, .36, 1);
}

.lead-drawer.is-open { transform: translateX(0); }

.lead-drawer-inner { padding: 26px 30px 44px; }

.lead-drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }

.lead-drawer-title {
  font-family: var(--font-head);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.12;
  min-width: 0;
}

.lead-drawer-close {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-card);
  background: var(--fill-subtle-2);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
}

.lead-drawer-close:hover { background: var(--fill-subtle-3); color: var(--text-secondary); }

.lead-drawer-facts { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 16px 34px; }
.lead-drawer-fact { display: flex; flex-direction: column; gap: 5px; }
/* .lead-drawer-fact's display:flex would otherwise beat the UA [hidden] rule */
.lead-drawer-fact[hidden] { display: none; }

.lead-drawer-fact .label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .13em;
  color: var(--text-faint);
}

.lead-drawer-fact .value { font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
.lead-drawer-fact .value.mono { font-family: var(--font-mono); }

/* Meeting gebucht — the screen's success signal, so it gets prominence: green
   label plus a filled pill matching the "Meeting gebucht" status in the table. */
.lead-drawer-meeting .label { color: var(--brand-success-text); }
.lead-drawer-meeting .value.meeting-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-success-text);
  background: var(--brand-success-bg);
  border-radius: 999px;
  padding: 5px 12px 5px 10px;
}
.lead-drawer-meeting .meeting-pill svg { flex-shrink: 0; }

/* lead id is long — give it its own line and let it wrap */
.lead-drawer-id { margin-top: 16px; }
.lead-drawer-id .value { font-size: 11.5px; color: var(--text-tertiary); word-break: break-all; user-select: all; }

.lead-drawer-divider { height: 1px; background: var(--border-divider); margin: 24px 0; }

.lead-drawer-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .13em;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.lead-drawer .lead-status { min-width: 230px; width: auto; font-size: 12px; padding: 10px 36px 10px 14px; border-radius: 9px; }

.lead-drawer-contacts { display: flex; flex-direction: column; gap: 2px; margin-top: -2px; }

.lead-drawer-contacts .contact-cell { padding: 9px 8px; border-radius: 10px; }
.lead-drawer-contacts .contact-cell:hover { background: var(--fill-subtle); }
.lead-drawer-contacts .avatar { width: 34px; height: 34px; border-radius: 50%; font-size: 11.5px; }
.lead-drawer-contacts .contact-name { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }

.lead-drawer-note {
  width: 100%;
  min-height: 98px;
  resize: none;
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 11px;
  padding: 13px 15px;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--text-secondary);
  outline: none;
  line-height: 1.5;
}

.lead-drawer-note:focus { border-color: var(--brand-ring); }

.lead-drawer-save-row { display: flex; justify-content: flex-end; margin-top: 14px; }

.lead-drawer .save-btn { height: 40px; padding: 0 20px; font-size: 12px; }

/* ---------- Status palette (Clarté tints; slugs generated by lead_status_css_class) ---------- */

.status-potential        { color: #3b4fd6; background-color: #e9edff; border-color: #d6deff; }
.status-warm             { color: #b4690e; background-color: #fbf0e0; border-color: #f3e1c4; }
.status-meeting-gebucht  { color: #177e43; background-color: #e5f6ec; border-color: #cdebd8; }
.status-on-hold          { color: #5a6577; background-color: #eef0f3; border-color: #e1e5ea; }
.status-disqualifiziert  { color: #be1e44; background-color: #fce8ec; border-color: #f5d3db; }

/* ---------- Avatar palette (cycled by lead_avatar_class) ---------- */

.avatar-0 { background: #6366f1; }
.avatar-1 { background: #0ea5e9; }
.avatar-2 { background: #14b8a6; }
.avatar-3 { background: #f59e0b; }
.avatar-4 { background: #ec4899; }
.avatar-5 { background: #8b5cf6; }
.avatar-6 { background: #ef4444; }

/* ===========================================================
   Responsive
   =========================================================== */

/* Mobile top bar + off-canvas backdrop are desktop-hidden by default */
.mobile-topbar { display: none; }

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(40, 35, 25, .28);
  z-index: 50;
  opacity: 0;
  transition: opacity .2s ease;
}

.nav-backdrop.is-open { opacity: 1; }

/* ---------- Tablet / narrow: let the wide table scroll horizontally ---------- */
@media (max-width: 1080px) {
  .app-header { padding: 16px 22px 13px; }
  .page-content { padding: 20px 22px 28px; }
  .leads-card { margin: 6px 16px 0; }
  /* horizontal scroll + min-widths now live in the base rules (they apply at
     every width), so nothing table-specific is needed here */
}

/* ---------- Mobile: off-canvas sidebar + top bar ---------- */
@media (max-width: 860px) {
  #app { flex-direction: column; height: 100vh; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    height: 56px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-divider);
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .mobile-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-card);
    background: var(--fill-subtle-2);
    border-radius: 9px;
    color: var(--text-secondary);
    cursor: pointer;
  }

  .mobile-topbar-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }

  #main { min-height: 0; flex: 1; }

  .nav-backdrop { display: block; pointer-events: none; }
  .nav-backdrop.is-open { pointer-events: auto; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.22, 1, .36, 1);
  }

  #sidebar.is-open { transform: translateX(0); }

  #sidebar .sidebar-wrapper { box-shadow: 8px 0 40px -18px rgba(40, 35, 25, .4); }

  /* collapse is a desktop affordance; on mobile the panel is off-canvas + full */
  .sidebar-collapse-btn { display: none; }

  .app-header { position: static; }
}

/* ---------- Small phones ---------- */
@media (max-width: 560px) {
  .app-header { padding: 20px 16px 16px; }
  .app-header h1 { font-size: 18px; }
  .page-content { padding: 16px; }
  .leads-card { margin: 6px 14px 0; }

  /* the search now sits in the header actions — let it fill the row on mobile */
  .leads-search .search-box { width: 100%; }
  .leads-search { flex: 1; }

  footer.app-footer { flex-direction: column; gap: 4px; padding: 16px; }
}
