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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #4f46e5;
  --sidebar-active-bg: rgba(79,70,229,.15);
  --content-bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text-primary); background: var(--content-bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 230px; min-height: 100vh; background: var(--sidebar-bg);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
  overflow-y: auto; z-index: 100;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo-icon { font-size: 20px; }
.logo-text { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.3px; }
.sidebar-demo-tag {
  margin: 10px 10px 0;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.nav { padding: 12px 8px; flex: 1; }
.nav-section {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  color: rgba(148,163,184,.5); padding: 16px 8px 6px; text-transform: uppercase;
}

.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 6px; color: var(--sidebar-text); font-size: 13.5px; font-weight: 500;
  transition: all .15s; cursor: pointer; margin-bottom: 1px;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #cbd5e1; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active-bg); color: #818cf8; }
.nav-item svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; opacity: .8; }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main { margin-left: 230px; flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
.content { padding: 20px 24px; width: 100%; flex: 1; }

/* ─── Page Header ──────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.page-header .subtitle { color: var(--text-secondary); margin-top: 3px; font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 12px 16px; }

/* ─── Stat Cards ────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-top: 4px; }
.stat-card .stat-sub { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }

/* ─── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; padding: 12px 12px; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 12px 12px; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text-primary); vertical-align: middle; line-height: 1.4; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.td-muted { color: var(--text-secondary); font-size: 12px; }
.table-select-cell { width: 42px; text-align: center; }
.table-select-cell input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.row-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.bulk-action-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ─── Badges ────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-blue   { background: #eff6ff; color: #2563eb; }
.badge-indigo { background: #eef2ff; color: #4338ca; }
.badge-yellow { background: #fefce8; color: #a16207; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-teal   { background: #f0fdfa; color: #0f766e; }
.badge-green  { background: #f0fdf4; color: #16a34a; }
.badge-red    { background: #fef2f2; color: #dc2626; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all .15s; text-decoration: none; line-height: 1; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--card-bg); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f1f5f9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 4px 8px; }
.btn-ghost:hover { background: #f1f5f9; color: var(--text-primary); }

/* ─── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 6px; }
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13.5px; color: var(--text-primary);
  background: var(--card-bg); transition: border-color .15s; outline: none;
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.form-textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ─── Alerts ────────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13.5px; margin-bottom: 16px; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ─── Kill Switch Banner ────────────────────────────────────────────────────── */
.kill-switch-banner {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius);
  padding: 12px 20px; margin-bottom: 20px; display: flex; align-items: center;
  justify-content: space-between; color: #dc2626; font-weight: 500;
}

/* ─── Filter Bar ────────────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; align-items: center; flex-wrap: wrap; }
.filter-bar .form-input, .filter-bar .form-select { width: auto; min-width: 160px; }

/* ─── Lead Detail ───────────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 16px; margin-bottom: 16px; }
.detail-row { display: flex; padding: 6px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-key { width: 140px; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; flex-shrink: 0; padding-top: 1px; }
.detail-val { font-size: 13.5px; color: var(--text-primary); flex: 1; }

.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; padding: 16px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); }

.hooks-list { list-style: none; }
.hooks-list li { padding: 4px 0; padding-left: 16px; position: relative; font-size: 13.5px; }
.hooks-list li::before { content: '→'; position: absolute; left: 0; color: var(--primary); font-weight: 700; }

/* ─── Timeline / Thread ─────────────────────────────────────────────────────── */
.thread-list { display: flex; flex-direction: column; gap: 12px; }
.thread-item { padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border); }
.thread-item.inbound { border-left: 3px solid var(--primary); background: #fafbff; }
.thread-item.outbound { border-left: 3px solid #94a3b8; background: var(--card-bg); }
.thread-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 12px; color: var(--text-secondary); }
.thread-subject { font-weight: 600; font-size: 13px; color: var(--text-primary); margin-bottom: 4px; }
.thread-body { font-size: 13px; color: var(--text-secondary); white-space: pre-wrap; max-height: 120px; overflow: hidden; }
.thread-body.expanded { max-height: none; }
.thread-expand { font-size: 12px; color: var(--primary); cursor: pointer; margin-top: 4px; display: inline-block; }

/* ─── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--card-bg); border-radius: 10px; width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-secondary); line-height: 1; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 20px;
  border-radius: 8px; font-size: 13.5px; font-weight: 500; color: #fff;
  background: var(--text-primary); z-index: 999; box-shadow: var(--shadow-md);
  transition: opacity .3s;
}
.toast.success { background: #16a34a; }
.toast.error { background: var(--danger); }
.toast.hidden { display: none; }

/* ─── Calendar Month View ───────────────────────────────────────────────────── */
.cal-nav {
  display: flex; align-items: center; gap: 12px;
}
.cal-nav-btn {
  font-size: 18px; line-height: 1; padding: 4px 10px; font-weight: 400;
}
.cal-month-title {
  font-size: 15px; font-weight: 600; min-width: 160px; text-align: center;
}
.cal-legend-item {
  display: inline-flex; align-items: center; gap: 5px;
}
.cal-legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px;
}
.cal-legend-dot.upcoming { background: #4f46e5; }
.cal-legend-dot.past     { background: #94a3b8; }
.cal-legend-dot.converted { background: #16a34a; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.cal-day-header {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 0; text-align: center;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cal-cell {
  min-height: 100px; padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  vertical-align: top;
  position: relative;
}
.cal-cell.other-month {
  background: #f8fafc;
}
.cal-cell.other-month .cal-date {
  color: #cbd5e1;
}
.cal-cell.today {
  background: #fafafe;
}
.cal-date {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; color: var(--text-primary);
  width: 26px; height: 26px; border-radius: 50%;
  margin-bottom: 4px;
}
.cal-date.today-dot {
  background: var(--primary); color: #fff; font-weight: 700;
}
.cal-events {
  display: flex; flex-direction: column; gap: 2px;
}
.cal-event-chip {
  font-size: 11.5px; font-weight: 500;
  padding: 2px 6px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: default;
}
.cal-event-chip.upcoming {
  background: #eef2ff; color: #4338ca;
}
.cal-event-chip.past {
  background: #f1f5f9; color: #64748b;
}
.cal-event-chip.converted {
  background: #f0fdf4; color: #16a34a;
}
.cal-overflow {
  font-size: 11px; color: var(--primary); padding: 1px 6px;
  background: none; border: none; cursor: pointer; font-family: inherit;
  text-align: left;
}
.cal-overflow:hover { text-decoration: underline; }

/* ─── Sequence Rounds ───────────────────────────────────────────────────────── */
.seq-round { border-top: 1px solid var(--border); }
.seq-round:first-child { border-top: none; }
.seq-round-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; cursor: pointer; user-select: none;
  transition: background .12s;
}
.seq-round-header:hover { background: #f8fafc; }
.seq-round-chevron { font-size: 11px; color: var(--text-secondary); width: 12px; display: inline-block; }
.seq-round-active .seq-round-header { background: #fafafe; }
.seq-round-archived .seq-round-header { opacity: 0.75; }

/* ─── Log Step Badges ───────────────────────────────────────────────────────── */
.log-step {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.log-step-seq    { background: #ede9fe; color: #5b21b6; }
.log-step-reply  { background: #dcfce7; color: #15803d; }
.log-step-manual { background: #fef9c3; color: #854d0e; }
.log-step-system { background: #f1f5f9; color: #475569; }
.log-step-round  { font-size: 10px; color: var(--text-secondary); font-weight: 500; }

/* ─── Settings Info Boxes ───────────────────────────────────────────────────── */
.settings-info {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}
.settings-info strong { color: var(--text-primary); }
.settings-info ul { margin: 6px 0 0 18px; }
.settings-info li { margin-bottom: 3px; }
.settings-info code {
  background: #e2e8f0; padding: 1px 5px; border-radius: 3px;
  font-size: 12px; color: var(--text-primary);
}

.setup-steps {
  background: #fafffe;
  border: 1px solid #d1fae5;
  border-radius: 6px;
  padding: 14px 18px;
  margin-bottom: 16px;
}
.setup-steps-title {
  font-size: 12px; font-weight: 700; color: #065f46;
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px;
}
.setup-steps-list {
  margin: 0; padding-left: 20px;
  display: flex; flex-direction: column; gap: 6px;
}
.setup-steps-list li {
  font-size: 13px; color: var(--text-secondary); line-height: 1.55;
}
.setup-steps-list li strong { color: var(--text-primary); }
.setup-steps-list li code {
  background: #e2e8f0; padding: 1px 5px; border-radius: 3px;
  font-size: 12px; color: var(--text-primary);
}

/* ─── Dark Mode Toggle Button ───────────────────────────────────────────────── */
.dark-toggle {
  display: flex; align-items: center; gap: 8px;
  margin: 8px; padding: 8px 10px; border-radius: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-text); font-size: 13px; font-weight: 500;
  width: calc(100% - 16px); transition: background .15s;
}
.dark-toggle:hover { background: rgba(255,255,255,.05); color: #cbd5e1; }
.dark-toggle svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; opacity: .8; }

/* ─── Dark Mode ─────────────────────────────────────────────────────────────── */
body.dark {
  --content-bg: #0f172a;
  --card-bg: #1e293b;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
}
body.dark th { background: #1e293b; }
body.dark tr:hover td { background: #263349; }
body.dark .thread-item.inbound { background: #1e2a3d; }
body.dark .thread-item.outbound { background: var(--card-bg); }
body.dark .cal-day-header { background: #1e293b; }
body.dark .cal-cell.other-month { background: #141f30; }
body.dark .cal-cell.today { background: #1e2a40; }
body.dark .seq-round-header:hover { background: #263349; }
body.dark .seq-round-active .seq-round-header { background: #1e2a40; }
body.dark .settings-info { background: #1e293b; }
body.dark .setup-steps { background: #1a2d24; border-color: #166534; }
body.dark .kill-switch-banner { background: #2d1515; border-color: #7f1d1d; color: #fca5a5; }
body.dark .sidebar-demo-tag { background: rgba(245, 158, 11, 0.2); border-color: rgba(245, 158, 11, 0.5); color: #fcd34d; }
body.dark .alert-success { background: #14281e; border-color: #166534; color: #4ade80; }
body.dark .alert-error { background: #2d1515; border-color: #7f1d1d; color: #fca5a5; }
body.dark .alert-warning { background: #2d2008; border-color: #78350f; color: #fcd34d; }
body.dark .btn-secondary { background: #1e293b; color: var(--text-primary); border-color: #334155; }
body.dark .btn-secondary:hover { background: #263349; }
body.dark .btn-ghost:hover { background: #263349; color: var(--text-primary); }
body.dark .badge-gray   { background: #1e293b; color: #94a3b8; }
body.dark .badge-blue   { background: #172554; color: #93c5fd; }
body.dark .badge-indigo { background: #1e1b4b; color: #a5b4fc; }
body.dark .badge-yellow { background: #2d1f00; color: #fcd34d; }
body.dark .badge-orange { background: #2d1500; color: #fb923c; }
body.dark .badge-teal   { background: #042f2e; color: #2dd4bf; }
body.dark .badge-green  { background: #052e16; color: #4ade80; }
body.dark .badge-red    { background: #2d0f0f; color: #f87171; }
body.dark .log-step-seq    { background: #2e1065; color: #c4b5fd; }
body.dark .log-step-reply  { background: #052e16; color: #4ade80; }
body.dark .log-step-manual { background: #2d1f00; color: #fcd34d; }
body.dark .log-step-system { background: #1e293b; color: #94a3b8; }
body.dark .cal-event-chip.upcoming { background: #1e1b4b; color: #a5b4fc; }
body.dark .cal-event-chip.past     { background: #1e293b; color: #64748b; }
body.dark .cal-event-chip.converted { background: #052e16; color: #4ade80; }
body.dark .tag { background: #1e293b; color: #94a3b8; }
body.dark .settings-info code { background: #0f172a; color: #e2e8f0; }
body.dark .setup-steps-list li code { background: #0f172a; color: #e2e8f0; }
body.dark .modal { background: #1e293b; }

/* ─── Misc ──────────────────────────────────────────────────────────────────── */
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.tag { display: inline-block; background: #f1f5f9; color: var(--text-secondary); border-radius: 4px; padding: 2px 7px; font-size: 11.5px; margin: 2px; }
.paused-indicator { display: inline-flex; align-items: center; gap: 5px; color: var(--warning); font-size: 12px; font-weight: 600; }
