/* ================================================================
   Anna | Лиды — Dashboard
   "Industrial Editorial" — paper-tone background, ink-navy accent,
   typographic hierarchy over decoration.
   ================================================================ */

:root {
  /* Surface */
  --bg:           #f6f3ee;          /* warm off-white, paper */
  --bg-elev:     #ffffff;            /* card */
  --bg-sunken:   #efeae3;            /* table-stripe / inputs */
  --bg-rule:     #e3ddd2;            /* borders / hairlines */
  --bg-rule-strong: #c9c1b3;

  /* Ink */
  --fg:           #1b1a17;           /* primary text */
  --fg-muted:    #5b5853;            /* secondary */
  --fg-quiet:    #8b8780;            /* meta / placeholders */

  /* Accents */
  --accent:       #1e3a5f;           /* navy ink — primary action */
  --accent-hover: #14253d;
  --accent-tint:  #e1e7ee;
  --teal:         #0f7173;           /* secondary accent */
  --teal-tint:    #d8eaea;

  /* Status palette (mgr_status) */
  --st-new-fg:        #1e40af;
  --st-new-bg:        #dbeafe;
  --st-new-border:    #93c5fd;

  --st-progress-fg:    #92400e;
  --st-progress-bg:    #fef3c7;
  --st-progress-border:#fcd34d;

  --st-kpsent-fg:      #115e59;
  --st-kpsent-bg:      #ccfbf1;
  --st-kpsent-border:  #5eead4;

  --st-won-fg:         #166534;
  --st-won-bg:         #dcfce7;
  --st-won-border:     #86efac;

  --st-lost-fg:        #991b1b;
  --st-lost-bg:        #fee2e2;
  --st-lost-border:    #fca5a5;

  --st-archived-fg:    #44403c;
  --st-archived-bg:    #e7e5e1;
  --st-archived-border:#c9c5be;

  /* Source badge (subdued) */
  --src-fg:        #44403c;
  --src-bg:        #ece7df;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  --radius-sm: 3px;
  --radius:    6px;
  --radius-lg: 10px;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo,
               Consolas, "Liberation Mono", monospace;

  /* Effects */
  --shadow-sm: 0 1px 0 rgba(27,26,23,.04);
  --shadow:    0 1px 2px rgba(27,26,23,.05), 0 0 0 1px var(--bg-rule);
  --shadow-lg: 0 8px 32px -12px rgba(30,58,95,.18),
               0 0 0 1px var(--bg-rule);

  --dur-fast: 120ms;
  --dur:      180ms;
  --easing:   cubic-bezier(.2,.0,.2,1);
}

/* ----- Reset ----- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11", "tnum";
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--accent); color: #fff; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  padding: 0 var(--sp-6);
  height: 56px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--bg-rule);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
  color: var(--fg);
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.brand-name .brand-divider {
  color: var(--bg-rule-strong);
  margin: 0 6px;
  font-weight: 300;
}
.brand-name .brand-suffix {
  color: var(--fg-muted);
  font-weight: 500;
}

.app-nav {
  display: flex;
  gap: var(--sp-1);
  margin-left: var(--sp-4);
}
.app-nav a {
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--easing),
              color var(--dur-fast) var(--easing);
}
.app-nav a:hover {
  background: var(--bg-sunken);
  color: var(--fg);
  text-decoration: none;
}
.app-nav a.is-active {
  background: var(--accent-tint);
  color: var(--accent);
}

.app-header-spacer { flex: 1; }

.app-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: 13px;
  color: var(--fg-muted);
}
.logout-form { margin: 0; }
.logout-btn {
  background: transparent;
  border: 1px solid var(--bg-rule);
  color: var(--fg-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  transition: all var(--dur-fast) var(--easing);
}
.logout-btn:hover {
  border-color: var(--bg-rule-strong);
  color: var(--fg);
  background: var(--bg-sunken);
}

.app-main {
  flex: 1;
  padding: var(--sp-6) var(--sp-6) var(--sp-7);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--bg-rule);
}
.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.page-title .eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-quiet);
  margin-bottom: 4px;
}
.page-meta {
  font-size: 13px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}

/* ============================================================
   FILTERS BAR
   ============================================================ */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding: var(--sp-4);
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius);
}

.search-row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.search-input-wrap {
  flex: 1;
  position: relative;
}
.search-input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-quiet);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--bg-rule);
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--easing),
              box-shadow var(--dur-fast) var(--easing);
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr) auto;
  gap: var(--sp-2);
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-quiet);
}

.input, .select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--bg-rule);
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--fg);
  transition: border-color var(--dur-fast) var(--easing),
              box-shadow var(--dur-fast) var(--easing);
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'><path d='M1 1L5 5L9 1' stroke='%235b5853' stroke-width='1.5' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  appearance: none;
  padding-right: 30px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  user-select: none;
}
.checkbox-field input { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  height: 34px;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--easing);
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.btn-secondary {
  background: var(--bg-elev);
  color: var(--fg);
  border-color: var(--bg-rule);
}
.btn-secondary:hover {
  background: var(--bg-sunken);
  border-color: var(--bg-rule-strong);
}
.btn-danger {
  background: var(--bg-elev);
  color: var(--st-lost-fg);
  border-color: var(--st-lost-border);
}
.btn-danger:hover {
  background: var(--st-lost-bg);
}
.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
  padding: 6px 10px;
}
.btn-ghost:hover {
  background: var(--bg-sunken);
  color: var(--fg);
}

/* ============================================================
   TABLE
   ============================================================ */
.table-card {
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}
.leads-table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-quiet);
  padding: 10px 14px;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--bg-rule);
  white-space: nowrap;
}
.leads-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--bg-rule);
  vertical-align: middle;
}
.leads-table tbody tr {
  transition: background var(--dur-fast) var(--easing);
}
.leads-table tbody tr:hover {
  background: var(--bg-sunken);
}
.leads-table tbody tr:last-child td { border-bottom: none; }

/* Row click affordance — whole <tr> becomes a navigation target via JS. */
tr.lead-row { cursor: pointer; }
tr.lead-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cell-mono {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
}
.cell-strong {
  font-weight: 600;
  color: var(--fg);
}
.cell-muted { color: var(--fg-muted); }
.cell-empty { color: var(--fg-quiet); font-style: italic; }
.cell-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-weight: 500;
}
.cell-link svg { transition: transform var(--dur-fast) var(--easing); }
.cell-link:hover svg { transform: translateX(2px); }

/* Contact links (Telegram / tel / mailto) — inline, accent-coloured. */
.contact-link {
  color: var(--accent);
  text-decoration: none;
}
.contact-link:hover { text-decoration: underline; }

/* Small icon-link next to a primary contact-link — used for the t.me deep
   link beside the /users/{id} dashboard link, so operators can still jump
   into Telegram in one click without losing the history page route. */
.contact-icon {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  color: var(--fg-muted);
  font-size: 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.contact-icon:hover {
  background: var(--bg-sunken);
  color: var(--accent);
  text-decoration: none;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  border: 1px solid;
  white-space: nowrap;
  font-family: var(--font-sans);
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.badge-new        { color: var(--st-new-fg);       background: var(--st-new-bg);       border-color: var(--st-new-border); }
.badge-new::before        { background: var(--st-new-fg); }

.badge-in_progress { color: var(--st-progress-fg);  background: var(--st-progress-bg);  border-color: var(--st-progress-border); }
.badge-in_progress::before { background: var(--st-progress-fg); }

.badge-kp_sent     { color: var(--st-kpsent-fg);    background: var(--st-kpsent-bg);    border-color: var(--st-kpsent-border); }
.badge-kp_sent::before     { background: var(--st-kpsent-fg); }

.badge-won         { color: var(--st-won-fg);       background: var(--st-won-bg);       border-color: var(--st-won-border); }
.badge-won::before         { background: var(--st-won-fg); }

.badge-lost        { color: var(--st-lost-fg);      background: var(--st-lost-bg);      border-color: var(--st-lost-border); }
.badge-lost::before        { background: var(--st-lost-fg); }

.badge-archived    { color: var(--st-archived-fg);  background: var(--st-archived-bg);  border-color: var(--st-archived-border); }
.badge-archived::before    { background: var(--st-archived-fg); }

.badge-source {
  color: var(--src-fg);
  background: var(--src-bg);
  border-color: transparent;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.badge-source::before { display: none; }

/* Activity badge — warm ochre, distinct from .badge-in_progress via dot. */
.badge-active {
  color: #92400e;
  background: #fef3c7;
  border-color: #fcd34d;
}
.badge-active::before { background: #d97706; }

.activity-cell {
  overflow: hidden;
}
.activity-cell > span {
  display: block;
}
.activity-cell-primary {
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.activity-cell-secondary {
  font-size: 11px;
  color: var(--fg-quiet);
}

/* ============================================================
   USER DETAIL — summary panel + leads list
   ============================================================ */
.user-summary {
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.user-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--bg-rule);
  margin-bottom: var(--sp-4);
}
.user-summary-cell { padding: var(--sp-1) 0; }
.user-summary-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--fg-quiet);
  margin-bottom: var(--sp-1);
}
.user-summary-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.user-summary-row {
  display: flex;
  gap: var(--sp-4);
  align-items: baseline;
  padding: var(--sp-2) 0;
}
.user-summary-row + .user-summary-row {
  border-top: 1px dashed var(--bg-rule);
  margin-top: var(--sp-2);
  padding-top: var(--sp-3);
}
.user-summary-row-title {
  flex: 0 0 130px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}
.user-summary-row-body {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.user-leads-list { margin-bottom: var(--sp-5); }

.chat-timeline-section { margin-bottom: var(--sp-5); }
.chat-day-sep {
  text-align: center;
  color: var(--fg-quiet);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--sp-4) 0 var(--sp-2);
}
.chat-bubble {
  max-width: 70%;
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-1) 0;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}
.chat-bubble-in {
  background: var(--bg-sunken);
  color: var(--fg);
  margin-right: auto;
  border-bottom-left-radius: var(--radius-sm);
}
.chat-bubble-out {
  background: var(--accent-tint);
  color: var(--fg);
  margin-left: auto;
  border-bottom-right-radius: var(--radius-sm);
  text-align: left;
}
.chat-time {
  font-size: 10px;
  color: var(--fg-quiet);
  margin-bottom: 2px;
  font-family: var(--font-mono);
}
.chat-text { white-space: pre-wrap; }
.chat-lead-link {
  display: inline-block;
  margin-top: var(--sp-1);
  font-size: 11px;
  color: var(--accent);
}
.chat-load-more {
  display: block;
  margin: var(--sp-4) auto;
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule-strong);
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  transition: background var(--dur-fast) var(--easing);
}
.chat-load-more:hover { background: var(--accent-tint); }

.lead-type {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  letter-spacing: 0;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--fg-muted);
}
.pagination .meta {
  font-family: var(--font-mono);
  font-size: 12px;
}
.pagination .actions {
  display: flex;
  gap: var(--sp-2);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-6);
  color: var(--fg-muted);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--sp-4);
  color: var(--bg-rule-strong);
}
.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin: 0 0 var(--sp-2);
}
.empty-state-text {
  font-size: 14px;
  margin: 0;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.empty-row-cell {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   LEAD DETAIL
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--bg-rule);
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
}
.card-body {
  padding: var(--sp-5);
}

.data-list {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: var(--sp-3) var(--sp-4);
  margin: 0;
}
.data-list dt {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 2px;
}
.data-list dd {
  margin: 0;
  font-size: 14px;
  color: var(--fg);
  word-break: break-word;
}
.data-list dd.mono {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-muted);
}
.data-list dd.empty {
  color: var(--fg-quiet);
  font-style: italic;
}

.kv-block + .kv-block {
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px dashed var(--bg-rule);
}

.kv-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--fg-quiet);
  margin: 0 0 var(--sp-3);
}

/* Manager panel */
.mgr-panel { position: sticky; top: 76px; }

.mgr-form-block {
  margin-bottom: var(--sp-5);
}
.mgr-form-block:last-child { margin-bottom: 0; }
.mgr-form-block label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-quiet);
  margin-bottom: 6px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.status-row .select { flex: 1; }

.notes-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--bg-rule);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  line-height: 1.55;
  resize: vertical;
  min-height: 140px;
  transition: border-color var(--dur-fast) var(--easing),
              box-shadow var(--dur-fast) var(--easing);
}
.notes-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.notes-status {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--st-won-fg);
  min-height: 18px;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}
.notes-status:empty::before {
  content: "Изменения сохраняются при потере фокуса";
  color: var(--fg-quiet);
  font-style: italic;
}

.archive-form { margin-top: var(--sp-2); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--sp-4);
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 500;
}
.back-link:hover { color: var(--accent); text-decoration: none; }
.back-link svg { transition: transform var(--dur-fast) var(--easing); }
.back-link:hover svg { transform: translateX(-3px); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(30,58,95,.04), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(15,113,115,.04), transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius-lg);
  padding: var(--sp-7) var(--sp-6) var(--sp-6);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}
.login-brand .brand-mark {
  width: 36px; height: 36px;
  font-size: 16px;
}
.login-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.login-brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.login-brand-tag {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--fg-quiet);
}

.login-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 var(--sp-2);
  color: var(--fg);
}
.login-subtitle {
  font-size: 13px;
  color: var(--fg-muted);
  margin: 0 0 var(--sp-5);
  line-height: 1.5;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.login-form .field-label {
  margin-bottom: 4px;
}
.login-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--bg-rule);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--easing),
              box-shadow var(--dur-fast) var(--easing);
}
.login-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.login-submit {
  width: 100%;
  height: 40px;
  margin-top: var(--sp-2);
  font-weight: 600;
}

.login-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--st-lost-border);
  background: var(--st-lost-bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--st-lost-fg);
  margin-bottom: var(--sp-3);
}
.login-error svg { flex-shrink: 0; margin-top: 2px; }

.login-footer {
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--bg-rule);
  font-size: 11px;
  color: var(--fg-quiet);
  text-align: center;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.app-main > * { animation: fadeIn 240ms var(--easing) both; }
.login-card { animation: fadeIn 280ms var(--easing) both; }

/* HTMX swap pulse */
.htmx-swapping { opacity: .5; transition: opacity 100ms; }
.htmx-settling { opacity: 1; }
#leads-table-body tr {
  animation: fadeIn 180ms var(--easing) both;
}

/* Subtle indicator for HTMX requests */
.htmx-request .search-input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'><circle cx='7' cy='7' r='5' fill='none' stroke='%231e3a5f' stroke-width='1.5' stroke-linecap='round' stroke-dasharray='5 20'><animateTransform attributeName='transform' type='rotate' from='0 7 7' to='360 7 7' dur='800ms' repeatCount='indefinite'/></circle></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ============================================================
   RESPONSIVE — desktop-first; basic mobile fallbacks
   ============================================================ */
@media (max-width: 1080px) {
  .filter-row { grid-template-columns: repeat(3, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .mgr-panel { position: static; }
}
@media (max-width: 720px) {
  .app-main { padding: var(--sp-4); }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .data-list { grid-template-columns: 1fr; gap: 4px var(--sp-2); }
  .data-list dt { padding-top: var(--sp-2); }
  .leads-table thead { display: none; }
  .leads-table, .leads-table tbody, .leads-table tr, .leads-table td { display: block; width: 100%; }
  .leads-table tr { padding: var(--sp-3); border-bottom: 1px solid var(--bg-rule); }
  .leads-table tbody td { padding: 4px 0; border: none; }
  .app-header { padding: 0 var(--sp-3); gap: var(--sp-3); }
  .brand-name .brand-suffix { display: none; }
}

/* ============================================================
   SETTINGS PAGE — sections, forms, recipients table, flash
   ============================================================ */
.settings-section {
  background: var(--bg-elev);
  border: 1px solid var(--bg-rule);
  border-radius: 4px;
  padding: var(--sp-5) var(--sp-6);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow);
}
.settings-section + .settings-section { margin-top: var(--sp-5); }
.settings-section-header { margin-bottom: var(--sp-4); }
.settings-section-header h2 {
  margin: 0 0 var(--sp-2);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.settings-help {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.5;
  max-width: 64ch;
}
.settings-warning {
  margin: var(--sp-3) 0 0;
  padding: var(--sp-2) var(--sp-3);
  background: #fff8e1;
  border-left: 3px solid #c89400;
  color: #5a4400;
  font-size: 13px;
  line-height: 1.5;
}
.settings-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--sp-4);
}
.settings-table th,
.settings-table td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--bg-rule);
  vertical-align: middle;
}
.settings-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  background: var(--bg-sunken);
}
.settings-table tr:last-child td { border-bottom: none; }
.settings-form {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px dashed var(--bg-rule);
}
.settings-form h3 {
  margin: 0 0 var(--sp-3);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-3);
  align-items: end;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: 13px;
}
.form-row label > span {
  font-weight: 500;
  color: var(--fg-muted);
}
.form-row input[type="text"],
.form-row input[type="email"],
.form-row input[type="number"],
.form-row input[type="time"] {
  padding: 8px 10px;
  border: 1px solid var(--bg-rule);
  border-radius: 3px;
  background: var(--bg-elev);
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
}
.form-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-tint);
}
.inline-form { display: inline; }
.toggle-btn {
  border: 1px solid var(--bg-rule);
  background: var(--bg-elev);
  border-radius: 3px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.toggle-btn.is-on {
  background: var(--accent-tint);
  color: var(--accent);
  border-color: var(--accent);
}
.toggle-btn.is-off {
  background: var(--bg-sunken);
  color: var(--fg-muted);
}
.empty-state {
  margin: 0 0 var(--sp-4);
  padding: var(--sp-4);
  background: var(--bg-sunken);
  border: 1px dashed var(--bg-rule);
  border-radius: 3px;
  color: var(--fg-muted);
  font-size: 14px;
  text-align: center;
}
.flash {
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-4);
  border-radius: 3px;
  font-size: 14px;
  border-left: 3px solid currentColor;
}
.flash-ok { background: #eef6ee; color: #2c5e2c; }
.flash-err { background: #fdecec; color: #8a1f1f; }

/* Settings Sweep 2 — secret masking + verify result spans */
.secret-current {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: var(--sp-1);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.form-row-wide { grid-column: 1 / -1; }
.form-row textarea {
  padding: 8px 10px;
  border: 1px solid var(--bg-rule);
  border-radius: 3px;
  background: var(--bg-elev);
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  resize: vertical;
}
.verify-slot {
  display: inline-block;
  min-height: 1.5em;
  align-self: center;
}
.verify-result {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.verify-ok { background: #eef6ee; color: #2c5e2c; border: 1px solid #b0d4b0; }
.verify-err { background: #fdecec; color: #8a1f1f; border: 1px solid #e0a0a0; }

/* ============================================================
   LEAD EDIT FORM (lead_fields_partial.html)
   ============================================================ */
.lead-edit-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.edit-fieldset {
  border: none;
  margin: 0;
  padding: 0;
}
.edit-fieldset + .edit-fieldset {
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px dashed var(--bg-rule);
}
.edit-fieldset legend {
  padding: 0;
  margin-bottom: var(--sp-3);
}
.edit-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3) var(--sp-4);
}
.edit-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.edit-field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.edit-field-with-action {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}
.edit-field-with-action .input {
  flex: 1;
  min-width: 0;
}
.edit-field-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--bg-rule);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--easing);
}
.edit-field-action:hover {
  background: var(--accent-tint);
  color: var(--accent);
  border-color: var(--accent);
}
.edit-actions {
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--bg-rule);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.edit-actions-hint {
  font-size: 12px;
  color: var(--fg-quiet);
}
.fields-flash {
  margin-bottom: var(--sp-4);
}

@media (max-width: 640px) {
  .edit-fields-grid {
    grid-template-columns: 1fr;
  }
}

/* Utility */
.hidden { display: none !important; }

/* Icon button (pencil etc.) */
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
}

