*, *::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;
}

/* 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 {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
}
.logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
}
nav {
  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: hidden;
}
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:hover { opacity: 0.85; }
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; }
