/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #1d4ed8;
  --blue-dark:   #1e3a8a;
  --blue-mid:    #2563eb;
  --blue-light:  #eff6ff;
  --green:       #16a34a;
  --green-light: #f0fdf4;
  --red:         #dc2626;
  --red-light:   #fef2f2;
  --purple:      #7c3aed;
  --purple-light:#f5f3ff;
  --text:        #111827;
  --text-mid:    #374151;
  --text-muted:  #6b7280;
  --border:      #e5e7eb;
  --border-mid:  #d1d5db;
  --bg:          #f3f4f6;
  --white:       #ffffff;
  --sidebar-w:   220px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

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

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--blue);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-logo {
  width: 34px; height: 34px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}
.sidebar-sub {
  font-size: 11px;
  color: rgba(255,255,255,.55);
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.8);
  transition: background .15s, color .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-item.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-weight: 600;
}
.nav-logout { color: rgba(255,160,160,.85); }
.nav-logout:hover { background: rgba(220,38,38,.18); color: #fca5a5; }

.sidebar-footer {
  padding: 12px 10px 16px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-sig {
  text-align: center;
  font-size: 10px;
  color: rgba(255,255,255,.3);
  margin-top: 8px;
  letter-spacing: .03em;
}

/* ── Main ─────────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; }
.page-title  { font-size: 17px; font-weight: 700; color: var(--text); }
.page-sub    { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text); }
.card-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Filters ─────────────────────────────────────────────────────────────────── */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.filter-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── Stats bar ───────────────────────────────────────────────────────────────── */
.stats-bar { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-chip {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 14px; font-weight: 700; color: var(--text); }
.stat-value.accent { color: var(--blue-mid); }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table thead th.text-right  { text-align: right; }
.table thead th.text-center { text-align: center; }
.table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text-mid);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8faff; }
.table .text-right  { text-align: right; }
.table .text-center { text-align: center; }
.table .mono  { font-family: var(--font-mono); font-size: 11.5px; }
.table .bold  { font-weight: 600; color: var(--text); }
.table .small { font-size: 11px; }
.table .wrap  { word-break: break-all; max-width: 200px; }

.table-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  gap: 10px;
  color: var(--text-muted);
}
.table-empty p { font-size: 13px; font-weight: 500; }
.loading-cell { text-align: center; padding: 32px; color: var(--text-muted); }

/* ── Real-time new row highlight ─────────────────────────────────────────────── */
@keyframes rowFlash {
  0%   { background: #dbeafe; }
  100% { background: transparent; }
}
.row-new td { animation: rowFlash 3s ease-out forwards; }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.page-info  { font-size: 12px; color: var(--text-muted); }
.page-btns  { display: flex; gap: 4px; align-items: center; }
.page-ellipsis { padding: 0 4px; color: var(--text-muted); font-size: 13px; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-visa   { background: #dbeafe; color: #1e40af; }
.badge-mc     { background: #ffedd5; color: #c2410c; }
.badge-other  { background: #f3f4f6; color: #4b5563; }
.badge-gemini { background: var(--purple-light); color: var(--purple); }
.badge-regex  { background: var(--green-light); color: var(--green); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1;
}
.btn-primary {
  background: var(--blue-mid);
  color: #fff;
  border-color: var(--blue-mid);
}
.btn-primary:hover { background: var(--blue); border-color: var(--blue); }
.btn-ghost {
  background: var(--white);
  color: var(--text-mid);
  border-color: var(--border-mid);
}
.btn-ghost:hover { background: #f9fafb; }
.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border-color: transparent;
  font-size: 12px;
}
.btn-danger-ghost:hover { background: var(--red-light); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-page { padding: 5px 10px; min-width: 34px; justify-content: center; font-size: 13px; }
.btn-page.active {
  background: var(--blue-mid);
  color: #fff;
  border-color: var(--blue-mid);
}
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field-hint { font-size: 11px; color: var(--text-muted); }
.required   { color: var(--red); }
.input {
  padding: 7px 10px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input-mono { font-family: var(--font-mono); font-size: 12px; resize: vertical; }
textarea.input { line-height: 1.55; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 400;
}
.toggle-input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--blue-mid); }
.toggle-text  { font-size: 13px; color: var(--text-mid); }

/* ── Settings form ───────────────────────────────────────────────────────────── */
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.form-section  { display: flex; flex-direction: column; gap: 12px; }
.field-group   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-sm      { max-width: 160px; }
.form-actions  { display: flex; gap: 8px; padding-top: 4px; }

.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin: 4px 0;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Clients list ────────────────────────────────────────────────────────────── */
.client-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.client-row:last-child { border-bottom: none; }
.client-info { display: flex; gap: 12px; align-items: flex-start; }
.client-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.client-avatar {
  width: 32px; height: 32px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.client-email { font-size: 13px; font-weight: 600; color: var(--text); }
.client-meta  { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.text-muted   { color: var(--text-muted); font-size: 11px; }

.empty-msg { font-size: 12px; color: var(--text-muted); text-align: center; padding: 24px 0; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.alert-error   { background: var(--red-light);   color: var(--red);   border-color: #fecaca; }
.alert-success { background: var(--green-light);  color: var(--green); border-color: #bbf7d0; }

/* ── Mobile header ──────────────────────────────────────────────────────────── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--blue);
  padding: 0 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}
.mobile-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
}
.hamburger span {
  display: block;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Sidebar overlay backdrop ────────────────────────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  opacity: 0;
  transition: opacity .25s;
}
.sidebar-backdrop.visible { opacity: 1; }

/* ── Responsive breakpoints ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .field-group { grid-template-columns: 1fr; }
  .field-sm    { max-width: 100%; }
}

@media (max-width: 768px) {
  /* Show mobile header, hide fixed sidebar by default */
  .mobile-header { display: flex; }
  .sidebar-backdrop { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    top: 0;
    z-index: 160;
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    padding: 16px 14px 48px;
    gap: 14px;
  }

  .app { flex-direction: column; }

  /* Filters */
  .filter-grid {
    grid-template-columns: 1fr 1fr;
  }
  .filter-actions { flex-wrap: wrap; }
  .filter-actions .btn { flex: 1; justify-content: center; }

  /* Stats */
  .stats-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .stat-chip  { justify-content: center; text-align: center; flex-direction: column; gap: 2px; }

  /* Table: hide less important columns */
  .table thead th:nth-child(3),
  .table thead th:nth-child(4),
  .table tbody td:nth-child(3),
  .table tbody td:nth-child(4) { display: none; }

  /* Pagination */
  .pagination { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-btns  { flex-wrap: wrap; }

  /* Settings form */
  .field-group   { grid-template-columns: 1fr; }
  .field-sm      { max-width: 100%; }
  .form-actions  { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; justify-content: center; }

  /* Client rows */
  .client-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .client-actions { align-self: flex-start; }

  /* Page header */
  .page-title { font-size: 15px; }
}

@media (max-width: 440px) {
  .filter-grid { grid-template-columns: 1fr; }
  .stats-bar   { grid-template-columns: 1fr; }
  .login-card  { padding: 28px 18px; }
}

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  width: 46px; height: 46px;
  background: var(--blue-mid);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  margin: 0 auto 14px;
}
.login-title { font-size: 16px; font-weight: 700; text-align: center; }
.login-sub   { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 3px; margin-bottom: 22px; }
.login-form  { display: flex; flex-direction: column; gap: 14px; }
.login-footer { font-size: 11px; color: var(--text-muted); }
