:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06);
  --shadow-md: 0 4px 6px rgba(16,24,40,0.05), 0 10px 15px rgba(16,24,40,0.06);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

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

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #111827 0%, #1a2233 100%);
  color: #e5e7eb;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}

.sidebar .brand .logo-dot {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }

.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a.active svg { opacity: 1; }

.sidebar .sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 16px;
  margin-top: 16px;
}

.sidebar .user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 13px;
  color: #9ca3af;
}

.sidebar .logout-link {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f87171;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
}
.sidebar .logout-link:hover { background: rgba(248,113,113,0.1); color: #fca5a5; }

main.content {
  margin-left: 250px;
  flex: 1;
  padding: 32px 40px;
}

h1.page-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; }
p.page-subtitle { color: var(--text-muted); margin: 0 0 28px; font-size: 14px; }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--info-bg); color: var(--info-text); }
.stat-icon.green { background: var(--success-bg); color: var(--success-text); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning-text); }
.stat-icon.indigo { background: var(--primary-light); color: var(--primary); }

.stat-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* Section headers */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 32px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 13px 16px; white-space: nowrap; }
th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.wrap { white-space: normal; max-width: 320px; }
td.muted { color: var(--text-muted); }

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #f3f4f6;
  color: #4b5563;
}
.pill.status-ended, .pill.status-analyzed, .pill.status-confirmed { background: var(--success-bg); color: var(--success-text); }
.pill.status-in_progress, .pill.status-pending { background: var(--warning-bg); color: var(--warning-text); }
.pill.status-cancelled { background: var(--danger-bg); color: var(--danger-text); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-link { background: transparent; color: var(--primary); padding: 0; font-weight: 600; }

/* Forms */
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-field input, .form-field textarea, .form-field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-field input:focus, .form-field textarea:focus, .form-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-field textarea { min-height: 90px; resize: vertical; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* Detail page */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.detail-row { font-size: 14px; }
.detail-row .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.detail-row .value { font-weight: 600; }
.transcript-box {
  white-space: pre-wrap;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font-size: 13.5px;
  line-height: 1.65;
  max-height: 420px;
  overflow-y: auto;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #eef2ff 0%, var(--bg) 45%), var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  text-align: center;
}
.login-brand .logo-dot {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-brand .logo-dot svg { width: 24px; height: 24px; }
.login-brand h1 { font-size: 19px; margin: 0; font-weight: 700; }
.login-brand p { font-size: 13.5px; color: var(--text-muted); margin: 0; }
.login-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
}
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 14.5px; margin-top: 6px; }

@media (max-width: 860px) {
  .sidebar { position: static; width: 100%; height: auto; }
  main.content { margin-left: 0; padding: 24px 20px; }
  .app-shell { flex-direction: column; }
  .detail-grid { grid-template-columns: 1fr; }
}

.content-inner { max-width: 1100px; margin: 0 auto; }

.status-select {
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
}
.status-select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Danger button */
.btn-danger-sm {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger-sm:hover { background: #fecaca; }

/* Custom status dropdown */
.status-dropdown { position: relative; display: inline-block; }
.status-trigger {
  border: none;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-trigger svg { width: 12px; height: 12px; opacity: 0.7; }
.status-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 30;
  min-width: 140px;
}
.status-menu[hidden] { display: none; }
.status-option {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-option:hover { background: #f3f4f6; }
.status-option .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-option.status-pending .dot { background: #d97706; }
.status-option.status-in_progress .dot { background: #2563eb; }
.status-option.status-resolved .dot { background: #16a34a; }
.status-option.status-cancelled .dot { background: #dc2626; }

/* Audio player */
audio.recording-player { width: 100%; max-width: 380px; height: 36px; }

.route-card-header { cursor: pointer; user-select: none; }
.route-chevron { transition: transform 0.15s; flex-shrink: 0; }
.search-box {
  width: 100%;
  max-width: 360px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
}
.search-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* ---- Visual refresh (v2) ---- */
.content-inner { max-width: none; }

:root {
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 2px 10px rgba(16,24,40,0.05);
  --shadow-md: 0 10px 28px rgba(16,24,40,0.09), 0 2px 6px rgba(16,24,40,0.04);
}

.card, .table-wrap, .stat-card, .login-card {
  border-radius: 16px;
}

.stat-card {
  padding: 22px 24px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon { width: 48px; height: 48px; border-radius: 13px; }
.stat-icon svg { width: 24px; height: 24px; }
.stat-value { font-size: 30px; letter-spacing: -0.01em; }

.card { padding: 24px; }

th { padding: 14px 20px; letter-spacing: 0.06em; font-size: 11.5px; }
td { padding: 16px 20px; font-size: 14px; }
tbody tr { transition: background 0.12s ease; }

.btn {
  border-radius: 10px;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-primary:hover { box-shadow: 0 6px 16px rgba(79,70,229,0.32); transform: translateY(-1px); }
.btn-secondary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.pill { padding: 4px 11px; font-size: 12px; }
.status-select, .status-trigger { border-radius: 999px; }

.sidebar { padding: 26px 18px; }
.sidebar nav a {
  border-radius: 10px;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.sidebar nav a.active { box-shadow: 0 8px 20px rgba(79,70,229,0.35); }
.sidebar nav a:hover:not(.active) { transform: translateX(2px); }

.section-title { font-size: 16px; letter-spacing: -0.01em; }

h1.page-title { letter-spacing: -0.025em; }

.route-card, .route-card .card { border-radius: 16px; }

@media (max-width: 1400px) {
  main.content { padding: 32px 32px; }
}

.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-picker label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  user-select: none;
}
.day-picker input:checked + span { color: var(--primary); }
.day-picker label:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
