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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #6c63ff;
  --accent-dark: #5550d4;
  --accent-rgb: 108,99,255;
  --accent2: #4ade80;
  --text: #e2e8f0;
  --muted: #64748b;
  --danger: #f87171;
  --warning: #fbbf24;
}

:root.light #main-content {
  background: #f0f2f5;
  color: #1e293b;
}
:root.light #main-content .card {
  background: #ffffff;
  border-color: #d1d5db;
}
:root.light #main-content .card-label { color: #6b7280; }
:root.light #main-content .card-value { color: #1e293b; }
:root.light #main-content .card-value.green { color: #16a34a; }
:root.light #main-content .card-value.red { color: #dc2626; }
:root.light #main-content .card-value.blue { color: #6c63ff; }
:root.light #main-content .table-wrap {
  background: #ffffff;
  border-color: #d1d5db;
}
:root.light #main-content thead th {
  background: #f3f4f6;
  color: #374151;
  border-bottom-color: #d1d5db;
}
:root.light #main-content tbody tr { border-bottom-color: #e5e7eb; }
:root.light #main-content tbody tr:hover { background: rgba(0,0,0,0.02); }
:root.light #main-content tbody td { color: #1e293b; }
:root.light #main-content h2 { color: #1e293b; }
:root.light #main-content input,
:root.light #main-content select,
:root.light #main-content textarea {
  background: #ffffff;
  border-color: #d1d5db;
  color: #1e293b;
}
:root.light #main-content .page-header select {
  background: #ffffff;
  border-color: #d1d5db;
  color: #1e293b;
}
:root.light #main-content button.secondary {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}
:root.light #main-content .badge-approved { background: rgba(22,163,74,0.12); color: #16a34a; }
:root.light #main-content .badge-rejected { background: rgba(220,38,38,0.12); color: #dc2626; }
:root.light #main-content .badge-pending { background: rgba(217,119,6,0.12); color: #d97706; }
:root.light #main-content .badge-sent { background: rgba(108,99,255,0.12); color: #6c63ff; }
:root.light #main-content strong { color: #1e293b; }
:root.light #main-content .modal { background: #ffffff; border-color: #d1d5db; }
:root.light #main-content .modal h3 { color: #1e293b; }

/* AI Chat Widget */
.chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 4px 20px rgba(var(--accent-rgb),0.5);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 999;
  transition: transform 0.2s, box-shadow 0.2s;
  padding: 0;
}
.chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(var(--accent-rgb),0.7);
  opacity: 1;
}
.chat-window {
  position: fixed;
  bottom: 92px;
  right: 28px;
  width: 360px;
  height: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 998;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}
.chat-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
}
.chat-header span { font-size: 11px; opacity: 0.8; display: block; font-weight: 400; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-msg.typing { color: var(--muted); font-style: italic; }
.chat-input-row {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.chat-input-row input {
  flex: 1;
  border-radius: 20px;
  padding: 8px 14px;
}
.chat-input-row button {
  border-radius: 50%;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  flex-shrink: 0;
}

/* Branding settings */
.color-preview {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-preview {
  max-height: 60px;
  max-width: 200px;
  object-fit: contain;
  border-radius: 8px;
}
.palette-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-block;
  border: 1px solid rgba(255,255,255,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-box h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
}

/* Layout */
#app {
  display: flex;
  height: 100vh;
}
/* sidebar styles moved to collapse/expand section */
.logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
nav {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  flex: 1;
}
nav a {
  padding: 10px 24px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
nav a:hover, nav a.active {
  color: var(--text);
  background: rgba(108,99,255,0.1);
  border-left-color: var(--accent);
}
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

#main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.card-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.card-value {
  font-size: 28px;
  font-weight: 700;
}
.card-value.green { color: var(--accent2); }
.card-value.red   { color: var(--danger); }
.card-value.blue  { color: var(--accent); }

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #222537;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody td { padding: 10px 14px; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-approved   { background: rgba(74,222,128,0.15); color: #4ade80; }
.badge-rejected   { background: rgba(248,113,113,0.15); color: #f87171; }
.badge-pending    { background: rgba(251,191,36,0.15); color: #fbbf24; }
.badge-sent       { background: rgba(108,99,255,0.15); color: #6c63ff; }
.badge-hold       { background: rgba(148,163,184,0.15); color: #94a3b8; }
.badge-chargeback { background: rgba(239,68,68,0.2); color: #ef4444; }

/* Forms */
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
button.danger { background: var(--danger); }
button.sm { padding: 4px 10px; font-size: 12px; }

.error { color: var(--danger); font-size: 13px; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 500px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.form-row label { font-size: 12px; color: var(--muted); }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Chart */
.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.chart-bar-label { width: 120px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar-track { flex: 1; background: var(--border); border-radius: 4px; height: 10px; }
.chart-bar-fill  { height: 100%; border-radius: 4px; background: var(--accent); }
.chart-bar-count { width: 50px; text-align: right; font-weight: 600; }

/* Copy button */
.copy-btn { font-size: 11px; padding: 2px 8px; }

/* Lead detail */
.lead-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.detail-field label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 4px; }
.detail-field span  { font-size: 14px; }

/* Tooltip */
.tooltip-wrap { position: relative; display: inline-block; cursor: default; }
.tooltip-box {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
  z-index: 999;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  pointer-events: none;
}
.tooltip-wrap:hover .tooltip-box { display: block; }


/* ── Sidebar collapse/expand ──────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
  position: relative;
  transition: width 0.25s ease, padding 0.25s ease, border 0.25s ease;
  overflow: hidden;
}

.sidebar-collapse {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-collapse:hover { background: var(--border); color: var(--text); }

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  border-right: none !important;
  overflow: hidden !important;
}

.sidebar-expand {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.sidebar-expand.visible { display: flex; }
.sidebar-expand:hover { background: var(--border); color: var(--text); }

/* ── Sidebar overlay (mobile) ─────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
}

/* ── Mobile responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar-expand { display: flex; }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 1001;
    transition: left 0.25s ease;
    padding-top: 16px;
    overflow-y: auto;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }

  #main-content {
    padding: 60px 12px 16px;
    width: 100%;
  }

  #app { flex-direction: column; }

  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; overflow: visible; }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header h2 { font-size: 18px; }

  /* Cards */
  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .card { padding: 12px; }
  .card-value { font-size: 20px; }
  .card-label { font-size: 10px; }

  /* Filters */
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .filters select, .filters input, .filters button {
    width: 100%;
  }

  /* Filter grids in deposits, leads, etc. */
  div[style*="grid-template-columns:repeat(auto-fill"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }

  /* Tables */
  .table-wrap {
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { font-size: 11px; min-width: 700px; }
  thead th { padding: 8px 8px; font-size: 10px; }
  tbody td { padding: 8px 8px; }

  /* Pagination */
  .pagination { font-size: 12px; gap: 6px; }

  /* Modal */
  .modal {
    width: 95vw;
    max-height: 85vh;
    padding: 16px;
    border-radius: 10px;
  }
  .modal h3 { font-size: 16px; margin-bottom: 14px; }
  .lead-detail-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Login */
  .login-box {
    width: 90vw;
    max-width: 360px;
    padding: 24px;
  }

  /* Chat widget */
  .chat-btn {
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  .chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    position: fixed;
  }

  /* Bundle form sections */
  div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Misc inline grids */
  div[style*="display:flex"][style*="gap:16px"] {
    flex-wrap: wrap;
  }

  /* Sidebar nav items - bigger tap targets on mobile */
  nav a { padding: 14px 24px; font-size: 15px; }

  /* Sidebar footer */
  .sidebar-footer { padding: 14px 24px; }

  /* Chart bars */
  .chart-bar-label { width: 80px; font-size: 11px; }

  /* Copy button in modals */
  .copy-btn { font-size: 12px; padding: 6px 12px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .card-value { font-size: 22px; }

  div[style*="grid-template-columns:repeat(auto-fill"] {
    grid-template-columns: 1fr !important;
  }

  .page-header > div {
    width: 100%;
    flex-wrap: wrap;
  }

  table { min-width: 600px; font-size: 10px; }
  thead th { padding: 6px 6px; font-size: 9px; }
  tbody td { padding: 6px 6px; }
}




/* ── Score tooltip ───────────────────────────────────────────────────────── */
.score-hover {
  position: relative;
  display: inline-block;
}
.score-hover .score-tip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card, #1e1e2e);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  pointer-events: none;
  min-width: 180px;
  text-align: left;
  margin-bottom: 6px;
}
.score-hover .score-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border, #333);
}
.score-hover:hover .score-tip {
  display: block;
}
