/* ─── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --primary:       #3B82F6;
  --primary-dark:  #2563EB;
  --hot:           #EF4444;
  --warm:          #F59E0B;
  --cold:          #6B7280;
  --success:       #10B981;
  --sidebar-bg:    #0F172A;
  --sidebar-text:  #94A3B8;
  --sidebar-active:#F1F5F9;

  /* Light mode (default) */
  --bg:            #F1F5F9;
  --surface:       #FFFFFF;
  --surface2:      #F8FAFC;
  --border:        #E2E8F0;
  --text:          #0F172A;
  --muted:         #64748B;
  --radius:        10px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0F172A;
    --surface: #1E293B;
    --surface2:#162032;
    --border:  #334155;
    --text:    #F1F5F9;
    --muted:   #94A3B8;
  }
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 16px 12px;
  font-size: 15px; font-weight: 700;
  color: #fff; letter-spacing: -.3px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 8px;
}
.sidebar-logo span { color: var(--primary); }

.sidebar-nav { flex: 1; padding: 4px 8px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 7px; margin-bottom: 2px;
  color: var(--sidebar-text); font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(59,130,246,.18); color: var(--sidebar-active); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.main {
  flex: 1;
  margin-left: 220px;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 16px; font-weight: 600; }

.content { padding: 24px; flex: 1; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 13px; font-weight: 600; text-transform: uppercase;
              letter-spacing: .5px; color: var(--muted); }
.card-body { padding: 20px; }

/* ─── Stat tiles ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border);
             border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600;
     text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
     border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--surface2); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 100px; font-size: 11px; font-weight: 600;
  text-transform: capitalize;
}
.badge-hot  { background: rgba(239,68,68,.12);  color: var(--hot); }
.badge-warm { background: rgba(245,158,11,.12); color: var(--warm); }
.badge-cold { background: rgba(107,114,128,.1); color: var(--cold); }
.badge-unknown { background: rgba(107,114,128,.1); color: var(--cold); }
.badge-new_lead      { background: rgba(59,130,246,.1); color: var(--primary); }
.badge-existing_client { background: rgba(16,185,129,.1); color: var(--success); }
.badge-support       { background: rgba(245,158,11,.1); color: var(--warm); }
.badge-urgent        { background: rgba(239,68,68,.12); color: var(--hot); }
.badge-spam          { background: rgba(107,114,128,.1); color: var(--cold); }
.badge-client        { background: rgba(16,185,129,.12); color: var(--success); }
.badge-lead          { background: rgba(59,130,246,.1);  color: var(--primary); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: opacity .15s, background .15s;
}
.btn:hover { opacity: .88; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--hot); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted);
        text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=number], input[type=time],
select, textarea {
  width: 100%; padding: 8px 12px; border-radius: 7px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
textarea { resize: vertical; min-height: 120px; font-family: monospace; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── Filters bar ────────────────────────────────────────────────────────── */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.filters select, .filters input { width: auto; min-width: 140px; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; justify-content: center; padding: 16px; }
.pagination button { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border);
                     background: var(--surface); color: var(--text); cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: default; }

/* ─── Pipeline / Kanban ──────────────────────────────────────────────────── */
.pipeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.pipeline-col { background: var(--surface2); border: 1px solid var(--border);
                border-radius: var(--radius); min-height: 300px; }
.pipeline-col-header {
  padding: 12px 16px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.pipeline-col-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.lead-card { background: var(--surface); border: 1px solid var(--border);
             border-radius: 8px; padding: 14px; box-shadow: var(--shadow); }
.lead-card-name { font-weight: 600; margin-bottom: 2px; }
.lead-card-sub { font-size: 12px; color: var(--muted); }
.lead-card-meta { margin-top: 10px; display: flex; justify-content: space-between; align-items: center; }

/* ─── Transcript viewer ──────────────────────────────────────────────────── */
.transcript { background: var(--surface2); border: 1px solid var(--border);
              border-radius: 8px; padding: 16px; font-size: 13px; line-height: 1.7;
              max-height: 400px; overflow-y: auto; font-family: monospace; white-space: pre-wrap; }
.transcript .caller-line  { color: var(--text); }
.transcript .ken-line     { color: var(--primary); }

/* ─── Drawer / expandable row ────────────────────────────────────────────── */
.detail-row td { background: var(--surface2); padding: 20px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

/* ─── Charts ─────────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 220px; }

/* ─── Grids ──────────────────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 20px; }
@media (max-width: 900px) { .two-col, .three-col { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .pipeline { grid-template-columns: 1fr; } }

/* ─── Search ─────────────────────────────────────────────────────────────── */
.search-wrap { position: relative; margin-bottom: 20px; }
.search-wrap input { padding-left: 36px; }
.search-wrap::before {
  content: '🔍'; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 13px; pointer-events: none;
}

/* ─── Empty state ────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty p { font-size: 14px; }

/* ─── Loading ────────────────────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--surface2) 50%, var(--border) 75%);
            background-size: 200% 100%; animation: shimmer 1.4s infinite;
            border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.loading-row td { padding: 14px 16px; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999;
                   display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border);
         border-radius: 8px; padding: 12px 16px; box-shadow: 0 4px 12px rgba(0,0,0,.15);
         font-size: 13px; min-width: 220px; animation: slideIn .2s ease; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--hot); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Audio player ───────────────────────────────────────────────────────── */
audio { width: 100%; border-radius: 6px; margin-top: 8px; height: 36px; }
audio::-webkit-media-controls-panel { background: var(--surface2); }

/* ─── Misc ───────────────────────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.text-hot   { color: var(--hot); }
.text-warm  { color: var(--warm); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.mt-4  { margin-top: 16px; }
.mb-4  { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.nowrap { white-space: nowrap; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
.bottom-nav { display: none; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: 64px; }
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 8px 0 env(safe-area-inset-bottom, 8px);
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 3px; color: var(--muted); font-size: 10px; font-weight: 500;
    padding: 4px; transition: color .15s;
  }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a svg { width: 20px; height: 20px; }
}

/* ─── Layout shims (match generated HTML structure) ─────────────────────── */
main.content {
  margin-left: 220px;
  padding: 24px;
  min-height: 100vh;
}
@media (max-width: 768px) { main.content { margin-left: 0; } }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-count { font-size: 13px; color: var(--muted); }

/* Card without card-body wrapper */
.card { padding: 20px; margin-bottom: 20px; }
.card > h2 {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); margin-bottom: 16px;
}

/* Stat card (alias for stat-tile) */
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat-card .stat-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin-top: 6px; }

/* Filter bar (alias for .filters) */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.filter-bar select, .filter-bar input { width: auto; min-width: 130px; }

/* Pipeline cards */
.pipeline-cards { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 80px; }
.pipeline-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; box-shadow: var(--shadow);
}
.pipeline-card .card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; padding: 0; border: none; }
.pipeline-card .card-name { font-weight: 600; font-size: 13px; }
.pipeline-card .card-company, .pipeline-card .card-phone, .pipeline-card .card-time { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.pipeline-card .card-date { font-size: 11px; color: var(--muted); margin-top: 8px; margin-bottom: 8px; }
.pipeline-count { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: auto; }

/* Expandable table rows */
tr.expandable { cursor: pointer; }
tr.expanded > td { background: var(--surface2); }
tr.detail-row.hidden, .hidden { display: none !important; }
tr.detail-row td { padding: 0 16px 16px; }
.detail-content { padding: 16px 0 4px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; margin-bottom: 16px; }
.detail-grid > div { display: flex; flex-direction: column; gap: 2px; }
.detail-grid strong { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.full-width { grid-column: 1 / -1; }
.detail-loading { padding: 16px; color: var(--muted); font-size: 13px; }

/* Transcript in detail rows */
.transcript { background: var(--surface2); border: 1px solid var(--border);
              border-radius: 8px; padding: 14px; margin: 12px 0; }
.transcript pre { font-size: 12px; font-family: monospace; white-space: pre-wrap; line-height: 1.6; max-height: 300px; overflow-y: auto; }

/* Audio player in detail */
.audio-player { margin: 12px 0; }
.audio-player strong { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

/* Badge extras */
.badge-intent { background: rgba(59,130,246,.1); color: var(--primary); }
.badge-callback { background: rgba(16,185,129,.1); color: var(--success); }
.badge-other { background: rgba(107,114,128,.1); color: var(--cold); }
.badge-status-client   { background: rgba(16,185,129,.12); color: var(--success); }
.badge-status-prospect { background: rgba(59,130,246,.1); color: var(--primary); }
.badge-status-lead     { background: rgba(59,130,246,.1); color: var(--primary); }
.badge-status-lost     { background: rgba(107,114,128,.1); color: var(--cold); }
.badge-status-spam     { background: rgba(239,68,68,.12); color: var(--hot); }
.badge-status-unknown  { background: rgba(107,114,128,.1); color: var(--cold); }

/* Editable fields in caller detail */
.edit-field {
  padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px;
  width: 100%; margin-top: 4px;
}
.edit-field:focus { outline: none; border-color: var(--primary); }

/* Settings form */
.settings-form .form-group { margin-bottom: 20px; }
.form-actions { margin-top: 24px; }
