*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --nav-bg: #0f172a;
  --nav-text: #94a3b8;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Navigation ──────────────────────────────────────────────────────────────── */
nav {
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 1.5rem;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,0.05);
}

.nav-brand {
  color: #f8fafc;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  letter-spacing: -0.01em;
  margin-right: 1rem;
  flex-shrink: 0;
}

.nav-brand em {
  font-style: normal;
  color: #60a5fa;
}

nav a:not(.nav-brand) {
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

nav a:not(.nav-brand):hover { color: #f8fafc; background: rgba(255,255,255,0.08); }
nav a.active { color: #f8fafc !important; background: var(--primary) !important; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.75rem 2.5rem 3rem;
}

/* ── Page title ──────────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; }
.page-header p { color: var(--muted); font-size: 0.875rem; margin-top: 0.25rem; }

/* ── Hero banner ─────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  margin-bottom: 1.5rem;
  color: #f8fafc;
  border: 1px solid #1e3a5f;
}

.hero h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.375rem; }
.hero h1 span { color: #60a5fa; }
.hero p { color: #94a3b8; font-size: 0.875rem; }

/* ── Stat cards ──────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  box-shadow: var(--shadow);
}

.stat-card .lbl {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.stat-card .val {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 { font-size: 0.9375rem; font-weight: 600; }

.card-link {
  font-size: 0.8125rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.card-link:hover { text-decoration: underline; }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead tr {
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
}

th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

td {
  padding: 0.75rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-new        { background: #dbeafe; color: #1e40af; }
.badge-qualified  { background: #d1fae5; color: #065f46; }
.badge-disqualified { background: #fee2e2; color: #991b1b; }
.badge-inoutreach { background: #fef3c7; color: #92400e; }
.badge-converted  { background: #dcfce7; color: #14532d; }
.badge-dead       { background: #f1f5f9; color: #475569; }
.badge-success    { background: #d1fae5; color: #065f46; }
.badge-failed     { background: #fee2e2; color: #991b1b; }

/* ── Toolbar (search + filters) ──────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  min-width: 220px;
  flex: 1;
  max-width: 380px;
}

.search-box svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  padding: 0.5625rem 0.875rem 0.5625rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.pill {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--card);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  line-height: 1;
}

.pill:hover { border-color: var(--primary); color: var(--primary); }
.pill.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.price-range-filter {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: nowrap;
}

.price-range-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.price-range-sep {
  color: var(--muted);
  font-size: 0.8125rem;
}

.price-range-filter input[type="number"] {
  width: 110px;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
}

.price-range-filter input[type="number"]::-webkit-inner-spin-button,
.price-range-filter input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

.price-range-filter input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.price-clear-btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-color: var(--border);
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pager-info { color: var(--muted); font-size: 0.8125rem; }

.pager-btns { display: flex; align-items: center; gap: 0.25rem; }

.pbtn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pbtn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pbtn:disabled { opacity: 0.35; cursor: not-allowed; }
.pbtn.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.pager-ellipsis { color: var(--muted); padding: 0 0.25rem; font-size: 0.875rem; }

/* ── States ──────────────────────────────────────────────────────────────────── */
.state-loading, .state-empty, .state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--muted);
  gap: 0.5rem;
  text-align: center;
}

.state-loading { flex-direction: row; }
.state-empty h3, .state-error h3 { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.state-empty p, .state-error p { font-size: 0.8125rem; }
.state-error h3 { color: #991b1b; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

/* ── Worker run summary metrics ──────────────────────────────────────────────── */
.run-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0;
}

.run-metric {
  padding: 1.125rem 1.25rem;
  border-right: 1px solid var(--border);
  text-align: center;
}
.run-metric:last-child { border-right: none; }
.run-metric .num { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.03em; color: var(--text); }
.run-metric .lbl { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 0.25rem; }

/* ── Inline link ─────────────────────────────────────────────────────────────── */
a.text-link { color: var(--primary); text-decoration: none; }
a.text-link:hover { text-decoration: underline; }

/* ── Action buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5625rem 1.125rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: #94a3b8; }

.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ── Code/mono text ──────────────────────────────────────────────────────────── */
code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.8125em;
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  color: #475569;
}

/* ── Stub banner ─────────────────────────────────────────────────────────────── */
.stub-banner {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.badge-stub {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.05em;
  vertical-align: middle;
  margin-left: 4px;
}

/* ── Form section (used in Settings CRM card) ───────────────────────────────── */
.form-section { padding: 1.25rem; }
.form-section + .form-section { border-top: 1px solid var(--border); }
.form-section-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1.125rem;
}
.form-section-title { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.form-hint {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ── CRM config badge ────────────────────────────────────────────────────────── */
.crm-config-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.crm-config-on  { background: #d1fae5; color: #065f46; }
.crm-config-off { background: #fee2e2; color: #991b1b; }

/* ── CRM push action buttons in leads table ──────────────────────────────────── */
.tbl-action-sm:hover { color: #7c3aed !important; border-color: #c4b5fd !important; background: #f5f3ff !important; }
.tbl-action-st:hover { color: #0369a1 !important; border-color: #7dd3fc !important; background: #e0f2fe !important; }
.tbl-action-sm.pushing, .tbl-action-st.pushing { opacity: 0.5; cursor: not-allowed; }

/* ── "Sent to CRM" status badges in leads table ──────────────────────────────── */
.crm-sent-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.crm-sent-sm { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.crm-sent-st { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }

/* ── Run Now button ──────────────────────────────────────────────────────────── */
.btn-run {
  background: #059669;
  color: #fff;
  border-color: #059669;
}
.btn-run:hover { background: #047857; border-color: #047857; }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Toast notification ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Settings form ───────────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  padding: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.field .hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.125rem;
}

.field input[type="number"] {
  width: 100%;
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.settings-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.status-cell {
  padding: 1rem 1.25rem;
  border-right: 1px solid var(--border);
}
.status-cell:last-child { border-right: none; }
.status-cell .lbl { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.375rem; }
.status-cell .val { font-size: 0.9375rem; font-weight: 600; }

/* ── Architecture page ───────────────────────────────────────────────────────── */
.arch-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
  overflow-x: auto;
}

.arch-svg { display: block; max-width: 100%; height: auto; }

.arch-legend {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.arch-legend-item { display: flex; align-items: center; gap: 0.5rem; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}

/* ── Sortable column headers ─────────────────────────────────────────────────── */
th.sortable { cursor: pointer; transition: color 0.15s; }
th.sortable:hover { color: var(--primary); }
th.sort-active { color: var(--primary); }
.sort-icon { font-style: normal; font-size: 0.85em; margin-left: 3px; opacity: 0.35; }
th.sort-active .sort-icon,
th.sortable:hover .sort-icon { opacity: 1; }

/* ── Lead detail modal ───────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem); overflow-y: auto;
  transform: translateY(12px); transition: transform 0.2s;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1rem; font-weight: 600; flex: 1; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 1.25rem; line-height: 1; padding: 0.25rem;
  border-radius: 4px; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-foot {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  display: flex; gap: 0.75rem; justify-content: flex-end;
}
.modal-field { display: flex; flex-direction: column; gap: 0.25rem; }
.modal-field label {
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.modal-field select, .modal-field textarea {
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9375rem; font-family: inherit; background: #fff; color: var(--text);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-field select:focus, .modal-field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.modal-field textarea { resize: vertical; min-height: 80px; }
.modal-info-row { display: flex; gap: 2rem; font-size: 0.875rem; flex-wrap: wrap; }
.modal-info-item { display: flex; flex-direction: column; gap: 0.25rem; }
.modal-info-item .lbl {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.lead-row { cursor: pointer; }
.lead-row:hover td { background: #f8fafc; }

/* ── Nav end (user name + logout) ────────────────────────────────────────────── */
.nav-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.nav-user-name {
  color: #94a3b8;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: #64748b;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.nav-logout:hover { color: #f87171; border-color: rgba(248,113,113,0.45); background: rgba(248,113,113,0.08); }

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
}

.login-brand {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

.login-brand em {
  font-style: normal;
  color: var(--primary);
}

.login-title {
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.75rem;
}

.login-card .field input[type="email"],
.login-card .field input[type="password"] {
  width: 100%;
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card .field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.login-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

/* ── Modal form inputs ───────────────────────────────────────────────────────── */
.modal-field input[type="text"],
.modal-field input[type="email"],
.modal-field input[type="tel"],
.modal-field input[type="password"],
.modal-field select,
.modal-field textarea {
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.modal-field input:focus,
.modal-field select:focus,
.modal-field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.modal-field textarea { resize: vertical; min-height: 64px; }

/* ── Role list (roles page) ──────────────────────────────────────────────────── */
.role-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.role-item:last-child { border-bottom: none; }
.role-item:hover { background: #f8fafc; }
.role-item-active { background: #eff6ff !important; border-left: 3px solid var(--primary); }

/* ── Permission matrix ───────────────────────────────────────────────────────── */
.perm-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.perm-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.perm-checks {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.1s;
}

.perm-check:last-child { border-bottom: none; }
.perm-check:hover { background: #f8fafc; }
.perm-check input[type=checkbox] { flex-shrink: 0; cursor: pointer; width: 15px; height: 15px; }

/* ── Delete button variant ───────────────────────────────────────────────────── */
.btn-danger {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}
.btn-danger:hover { background: #fecaca; border-color: #f87171; }

/* ── Table row actions ───────────────────────────────────────────────────────── */
.tbl-actions { display: flex; align-items: center; gap: 0.375rem; white-space: nowrap; }
.tbl-action {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  background: var(--card);
  font-family: inherit;
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tbl-action:hover { color: var(--primary); border-color: var(--primary); background: #eff6ff; }
.tbl-action-danger { color: #dc2626; }
.tbl-action-danger:hover { color: #991b1b; border-color: #fca5a5; background: #fef2f2; }

/* ── Modal form fields ───────────────────────────────────────────────────────── */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-field { display: flex; flex-direction: column; gap: 0.375rem; }
.form-label { font-size: 0.8125rem; font-weight: 600; color: var(--text); }
.form-req { color: #dc2626; margin-left: 2px; }
.form-input {
  width: 100%;
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.form-check-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; cursor: pointer; color: var(--text); }
.form-check-input { width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }

/* ── Wide modal (permissions matrix) ────────────────────────────────────────── */
.modal-wide { width: min(720px, calc(100vw - 2rem)); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main { padding: 1rem 1.25rem 2rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .hero { padding: 1.25rem; }
  nav { padding: 0 1rem; }
  .run-metrics { grid-template-columns: repeat(2, 1fr); }
  .run-metric { border-right: none; border-bottom: 1px solid var(--border); }
  #mainGrid { grid-template-columns: 1fr !important; }
  .nav-user-name { display: none; }
  .form-row-2 { grid-template-columns: 1fr; }
}
