/* ==========================================================================
   CRM — base styles. Theme via [data-theme="light"|"dark"] on <html>.
   ========================================================================== */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 8px;
  --sidebar-w: 220px;
}

html[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --border: #e2e4e9;
  --accent: #3b5bfd;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1d2027;
  --surface-2: #262a33;
  --text: #e7e9ee;
  --text-muted: #9aa0ab;
  --border: #33373f;
  --accent: #5b7dff;
  --accent-text: #ffffff;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: var(--text);
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.sidebar .section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 14px 20px 4px;
}
.sidebar .user-box {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar .user-box strong { color: var(--text); display: block; font-size: 13px; }

/* ---- Main ---- */
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; }
.topbar h1 { font-size: 20px; margin: 0; }

/* theme toggle fixed top-right */
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 500;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

/* ---- Cards / surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin-top: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.form-row { margin-bottom: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 80px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
legend { padding: 0 6px; font-weight: 600; }

/* ---- Multi-email chip input (type an email, press Enter) ---- */
.chip-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.chip-input-wrap:empty { margin-bottom: 0; }
.email-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
}
.email-chip button {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.email-chip button:hover { color: var(--danger); }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ---- Badges / tags ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border); }
.badge-stage-new { background: #dbeafe; color: #1e40af; border-color: transparent; }
.badge-stage-meeting_booked { background: #fef3c7; color: #92400e; border-color: transparent; }
.badge-stage-show_up { background: #dcfce7; color: #166534; border-color: transparent; }
.badge-stage-no_show { background: #fee2e2; color: #991b1b; border-color: transparent; }
.badge-stage-under_consideration { background: #e5e7eb; color: #374151; border-color: transparent; }
.badge-stage-closed_won { background: #d1fae5; color: #065f46; border-color: transparent; }
.badge-stage-lost { background: #f3f4f6; color: #6b7280; border-color: transparent; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; color: #fff; margin-right: 4px; }

/* ---- Alerts / flash ---- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px; }
.alert-success { background: rgba(22,163,74,.12); color: var(--success); border: 1px solid var(--success); }
.alert-error { background: rgba(220,38,38,.12); color: var(--danger); border: 1px solid var(--danger); }
.alert-warning { background: rgba(217,119,6,.12); color: var(--warning); border: 1px solid var(--warning); }
.alert-info { background: rgba(59,91,253,.10); color: var(--accent); border: 1px solid var(--accent); }

/* ---- Modal ---- */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 900; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; max-width: 640px; width: 92%; max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.modal-wide { max-width: 960px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }

.text-muted { color: var(--text-muted); }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---- Floating support chat widget (bottom-right, every logged-in page) ---- */
.chat-widget-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 600;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.chat-widget-bubble:hover { filter: brightness(1.08); }

.chat-widget-panel {
  position: fixed;
  bottom: 88px;
  right: 20px;
  z-index: 600;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat-widget-panel.open { display: flex; }
.chat-widget-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  background: var(--surface-2);
}
.chat-widget-panel-body { flex: 1; min-height: 0; }
.chat-widget-panel-body iframe { width: 100%; height: 100%; border: 0; display: block; }

@media (max-width: 480px) {
  .chat-widget-panel { right: 16px; bottom: 82px; }
  .chat-widget-bubble { right: 16px; bottom: 16px; }
}
