/* ==========================================================================
   LeadAPI admin — design system (v2)
   Premium light SaaS. No build step: CSS custom properties + component layer.
   ========================================================================== */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f4f9;
  --border: #eaecf0;
  --border-strong: #d5d9e0;
  --text: #0c111d;
  --text-2: #475467;
  --muted: #98a2b3;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-700: #3730a3;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, 0.16);

  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #fecdc9;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --warning-border: #fedf89;

  --sidebar-a: #111a2e;
  --sidebar-b: #0a101f;
  --sidebar-text: #c4cbd8;
  --sidebar-muted: #78859b;
  --sidebar-hover: rgba(255, 255, 255, 0.06);

  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 6px 16px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.16);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

/* Subtle custom scrollbars (webkit). */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b5bcc7; background-clip: content-box; }

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

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  background: linear-gradient(180deg, var(--sidebar-a), var(--sidebar-b));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  z-index: 20;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 8px 18px;
  color: #fff; font-weight: 650; font-size: 15.5px; letter-spacing: -0.02em;
}
.brand .brand-mark,
.auth-brand .brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(140deg, #818cf8, #4f46e5);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 4px 12px rgba(79, 70, 229, 0.45);
}

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-label {
  text-transform: uppercase; letter-spacing: 0.07em; font-size: 10.5px;
  color: var(--sidebar-muted); padding: 16px 10px 6px; font-weight: 600;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px;
  color: var(--sidebar-text); font-weight: 500; font-size: 13.5px;
  transition: background 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: linear-gradient(140deg, #4f46e5, #4338ca); color: #fff; box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4); }
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: 0.92; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(140deg, #6366f1, #4338ca); color: #fff;
  display: grid; place-items: center; font-weight: 650; font-size: 13px; flex: none;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
}
.sidebar-user .who { min-width: 0; }
.sidebar-user .who .email {
  color: #fff; font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px;
}
.sidebar-user .who .role { color: var(--sidebar-muted); font-size: 11px; }
.logout-btn {
  width: 100%; margin-top: 10px;
  background: rgba(255, 255, 255, 0.02); color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px; padding: 9px; font-size: 13px; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: background 0.14s ease, border-color 0.14s ease;
}
.logout-btn:hover { background: var(--sidebar-hover); color: #fff; border-color: rgba(255, 255, 255, 0.22); }

.content { margin-left: 252px; flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  height: 66px;
  background: rgba(247, 248, 250, 0.8);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 32px;
}
.topbar h1 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -0.025em; }
.topbar .top-right { color: var(--text-2); font-size: 13px; margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-toggle {
  display: none; flex: none;
  width: 40px; height: 40px; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); color: var(--text); cursor: pointer;
}
.nav-toggle svg { width: 20px; height: 20px; }
.nav-toggle:hover { background: var(--surface-2); }
.sidebar-backdrop { position: fixed; inset: 0; z-index: 18; background: rgba(12, 17, 29, 0.5); border: none; }
.sidebar-backdrop[hidden] { display: none; }

.main { padding: 28px 32px 56px; max-width: 1320px; }

a:focus-visible, button:focus-visible, .btn:focus-visible, .nav-link:focus-visible,
.logout-btn:focus-visible, .form-control:focus-visible, .form-select:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

/* ---------- Page head ---------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .lede { color: var(--text-2); max-width: 760px; font-size: 14px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stat tiles ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-xs);
  transition: box-shadow 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}
.stat-tile:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); border-color: var(--border-strong); }
.stat-tile .label { color: var(--text-2); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-tile .value { font-size: 28px; font-weight: 680; letter-spacing: -0.03em; margin-top: 8px; line-height: 1.1; }
.stat-tile .value.danger { color: var(--danger); }
.stat-tile .value.success { color: var(--success); }

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

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); margin-bottom: 22px; overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 620; font-size: 14.5px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header .sub { font-weight: 400; color: var(--text-2); font-size: 12.5px; }
.card-body { padding: 20px; }
.card-body.tight { padding: 6px 6px 2px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: inherit; font-size: 13.5px; font-weight: 550;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease, transform 0.06s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(180deg, #5b52e8, #4f46e5); color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.14); }
.btn-primary:hover { background: linear-gradient(180deg, #4f46e5, #4338ca); text-decoration: none; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; border-color: #c3c9d2; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); box-shadow: var(--shadow-xs); }
.btn-danger:hover { background: var(--danger-soft); text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn-block { width: 100%; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; line-height: 1.5;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.no-dot::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge-muted { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: #d9defb; }

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

.form-label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.form-hint { color: var(--text-2); font-size: 12.5px; margin: 6px 0 0; }
.form-control, .form-select, textarea.form-control {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 10px 12px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.form-control:hover, .form-select:hover, textarea.form-control:hover { border-color: #c3c9d2; }
.form-control:focus, .form-select:focus, textarea.form-control:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring);
}
.form-control::placeholder { color: var(--muted); }
textarea.form-control { resize: vertical; min-height: 96px; }
.form-group { margin-bottom: 16px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
.masked-secret { font-family: var(--mono); letter-spacing: 1px; color: var(--text-2); font-size: 12.5px; margin: 0 0 8px; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; }

/* ---------- Alerts ---------- */

.alert { border-radius: var(--radius-sm); padding: 12px 15px; margin-bottom: 18px; font-size: 13.5px; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }

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

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.table thead th {
  text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-2); background: var(--surface-2);
  padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
table.table tbody tr:last-child td { border-bottom: none; }
table.table tbody tr { transition: background 0.12s ease; }
table.table tbody tr:hover { background: var(--surface-2); }
table.table tbody tr.lead-row { cursor: pointer; }
table.table tr.row-flagged { background: var(--warning-soft); }
table.table tr.row-flagged:hover { background: #fef4de; }
.cell-truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-strong { font-weight: 550; }
.cell-mono { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.empty-state { text-align: center; padding: 56px 24px; color: var(--text-2); }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; font-weight: 620; }

/* ---------- DataTables overrides (plain build, restyled) ---------- */

.dataTables_wrapper { padding: 16px 16px 4px; }
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length { margin-bottom: 14px; }
.dataTables_wrapper .dataTables_filter { float: right; }
.dataTables_wrapper .dataTables_length { float: left; color: var(--text-2); font-size: 13px; }
.dataTables_wrapper .dataTables_filter label { color: var(--text-2); font-size: 13px; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  font-family: inherit; font-size: 13px; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 11px; margin-left: 8px; background: var(--surface);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
.dataTables_wrapper .dataTables_info { color: var(--text-2); font-size: 12.5px; padding: 12px 16px; clear: both; }
.dataTables_wrapper .dataTables_paginate { padding: 10px 16px; float: right; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  padding: 6px 12px !important; margin-left: 4px; border-radius: 8px !important;
  border: 1px solid var(--border) !important; background: var(--surface) !important; color: var(--text-2) !important;
  font-size: 13px; cursor: pointer;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--primary) !important; border-color: var(--primary) !important; color: #fff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--surface-2) !important; border-color: var(--border-strong) !important; color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover { opacity: 0.45; cursor: default; background: var(--surface) !important; color: var(--muted) !important; }
table.dataTable thead th.sorting, table.dataTable thead th.sorting_asc, table.dataTable thead th.sorting_desc { cursor: pointer; }
table.dataTable { border-collapse: collapse !important; }
table.dataTable.no-footer { border-bottom: 1px solid var(--border); }

/* ---------- Auth (login) ---------- */

.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(760px 380px at 12% -8%, rgba(99, 102, 241, 0.18), transparent 60%),
    radial-gradient(820px 460px at 105% 4%, rgba(59, 130, 246, 0.12), transparent 55%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 408px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 34px; }
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 6px; font-weight: 650; font-size: 18px; letter-spacing: -0.02em; }
.auth-brand .brand-mark { width: 36px; height: 36px; font-size: 17px; }
.auth-sub { text-align: center; color: var(--text-2); margin: 0 0 26px; font-size: 13.5px; }
.auth-card .form-group { margin-bottom: 16px; }
.auth-card .btn-block { margin-top: 4px; padding: 11px; }

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

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.center-page .card { max-width: 520px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.center-page .card-body { padding: 40px 32px; }
.muted { color: var(--text-2); }
.mt-0 { margin-top: 0; }
.nowrap { white-space: nowrap; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(12, 17, 29, 0.5);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 56px 16px; overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }
.modal-dialog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 620; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; border-radius: 6px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 15px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
.field-row { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.json-view {
  background: #0d1424; color: #e5e9f0; border: 1px solid #1c2740; border-radius: 10px;
  padding: 16px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; max-height: 55vh; overflow: auto; margin: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: none; }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .content { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .main { padding: 18px 16px 40px; }
  .sidebar-backdrop { display: none; }
  body.nav-open .sidebar-backdrop:not([hidden]) { display: block; }
}

@media (min-width: 901px) {
  .nav-toggle, .sidebar-backdrop { display: none !important; }
}

@media (max-width: 640px) {
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_paginate { float: none; text-align: left; }
  .dataTables_wrapper .dataTables_filter { margin-top: 8px; }
  .dataTables_wrapper .dataTables_filter input { margin-left: 0; width: 100%; }
  .dataTables_wrapper .dataTables_paginate { margin-top: 6px; }
  .modal-overlay { padding: 16px; }
  .field-row { grid-template-columns: 1fr; }
  .field-row .remove-field { justify-self: start; }
  .btn-sm { padding: 8px 12px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .stat-tile .value { font-size: 24px; }
}
