:root {
  --bg: #f3f4fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e4e6f2;
  --text: #14151f;
  --muted: #6b6f8a;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #ecebfe;
  --accent: #f59e0b;
  --danger: #e11d48;
  --danger-hover: #be123c;
  --danger-soft: #fde8ec;
  --success: #16a34a;
  --success-soft: #e3f9ea;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #e0e9ff;
  --shadow: 0 1px 2px rgba(20, 21, 31, 0.04), 0 10px 28px rgba(20, 21, 31, 0.07);
  --radius: 16px;
  --radius-sm: 9px;
}

/* Always light — intentionally not following prefers-color-scheme, so the
   dashboard looks the same regardless of the viewer's OS/browser setting. */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 0%, var(--primary-soft), transparent 45%),
    var(--bg);
  color: var(--text);
  padding: 32px 24px 60px;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 1080px; margin: 0 auto; }

/* ── Brand / header ──────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.date-input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.date-input:focus { outline: none; border-color: var(--primary); }
.date-range-sep { color: var(--muted); font-size: 13px; }

/* "Consider Business Hours" toggle (see dashboard.js's loadBusinessHoursToggle) */
.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.toggle-field input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--border);
  transition: background .15s ease;
}
.toggle-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20, 21, 31, 0.25);
  transition: transform .15s ease;
}
.toggle-field input:checked + .toggle-switch {
  background: var(--primary);
}
.toggle-field input:checked + .toggle-switch::before {
  transform: translateX(14px);
}
.toggle-field input:focus-visible + .toggle-switch {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.toggle-field input:disabled + .toggle-switch {
  opacity: .6;
}
.toggle-label { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}
h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.brand-sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: background .12s ease, transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger-hover); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

/* ── Custom modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 31, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modal-fade .12s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 380px;
  max-width: calc(100vw - 40px);
  padding: 22px 22px 18px;
  animation: modal-pop .12s ease;
}
@keyframes modal-pop { from { transform: translateY(6px) scale(.98); } to { transform: none; } }
.modal-title { margin: 0 0 8px; font-size: 16px; letter-spacing: -.01em; }
.modal-msg { margin: 0 0 20px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions .btn { padding: 8px 16px; font-size: 13.5px; }

/* Full Reason + Call Summary viewer (see showDetailsModal in dashboard.js) —
   wider than the default confirm/alert box and scrollable, since both
   fields are stored/shown in full now and can run long. */
.modal-box-wide {
  width: 640px;
  max-width: calc(100vw - 40px);
}
.modal-summary-text {
  margin: 0 0 20px;
  padding: 12px 14px;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.modal-summary-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 14px 0 4px;
}
.modal-summary-label:first-child { margin-top: 0; }
.modal-summary-block {
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Add-customer card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.add-card, .upload-card { padding: 18px 20px; margin-bottom: 22px; }
.add-card h2, .upload-card h2 {
  font-size: 11.5px;
  margin: 0 0 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}
.add-card form, .upload-card form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.add-card input, .add-card select, .upload-card input[type="file"] {
  flex: 1;
  min-width: 150px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.add-card input:focus, .add-card select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text);
  min-width: auto;
}

/* ── Admin settings page ─────────────────────────────────────────────── */
.admin-card { padding: 20px 22px; margin-bottom: 22px; }
.admin-card h2 {
  font-size: 11.5px;
  margin: 0 0 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}
.admin-card h2:not(:first-child) { margin-top: 22px; }
.admin-fields { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; }
.admin-field-wide input { width: 280px; }
.admin-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; }

.form-hint {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 0;
  line-height: 1.5;
}
.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  padding: 8px 12px;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  white-space: pre-line;
}
.form-success {
  color: var(--success, #1a7f37);
  font-size: 13px;
  margin: 10px 0 0;
  padding: 8px 12px;
  background: var(--success-soft, #e6f4ea);
  border-radius: var(--radius-sm);
}
.test-mode-banner {
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 16px;
  padding: 8px 12px;
  background: var(--warning-soft);
  border: 2px dashed var(--warning);
  border-radius: var(--radius-sm);
}
.stale-banner {
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 16px;
  padding: 8px 12px;
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
}

/* ── Table ───────────────────────────────────────────────────────────── */
/* The table now has more columns than fit comfortably on a laptop screen —
   scope the horizontal scroll to this wrapper, not the page body, so the
   header/forms above never get an unwanted horizontal scrollbar too. */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
}
table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: .05em;
}
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
.actions { white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.actions input {
  width: 96px;
  padding: 5px 7px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.muted { color: var(--muted); font-style: italic; }
#empty-msg, #files-empty-msg {
  color: var(--muted);
  text-align: center;
  padding: 32px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-top: 12px;
}

/* ── Files list / file detail (grouping customers by uploaded file) ─────── */
.file-name-cell { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.file-name-icon { font-size: 15px; }
#files-table tbody tr { cursor: pointer; }
#files-table .col-checkbox { width: 36px; }
#files-table td:first-child, #files-table th:first-child { padding-right: 4px; }

/* Selecting multiple files for a bulk delete (see dashboard.js's
   selectedFileIds) — a highlighted bar above the files table, shown only
   once at least one file is checked. */
.bulk-actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
}
/* Without this, the bar's own `display: flex` above always beats the
   browser's built-in `[hidden] { display: none }` rule (an author-origin
   style wins over the user-agent stylesheet regardless of specificity) —
   so `bar.hidden = true` in dashboard.js silently did nothing and the bar
   stayed visible, empty, even with zero files selected. */
.bulk-actions-bar[hidden] { display: none; }
.bulk-actions-bar span { font-size: 13px; font-weight: 600; color: var(--text); margin-right: auto; }
.file-detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.file-detail-header .btn { flex-shrink: 0; }
.file-detail-header h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Status badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
}
.badge-eligible { background: var(--info-soft); color: var(--info); }
.badge-calling { background: var(--info-soft); color: var(--info); }
.badge-completed { background: var(--success-soft); color: var(--success); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }
.badge-hours { background: var(--warning-soft); color: var(--warning); }
.badge-retry { background: var(--warning-soft); color: var(--warning); }
.badge-other { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-voicemail { background: #ede9fe; color: #6d28d9; }

/* Reason and Call Summary share one table column: a one-line glance (see
   previewText in dashboard.js) plus a single "View" button that opens
   showDetailsModal with both in full (see .modal-box-wide below) — neither
   field is shown in full inline anymore. */
.reason-summary-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
}
.reason-preview {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

/* ── Inline edit form (full-width row) ────────────────────────────────── */
.edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 6px 2px;
}
.edit-field { display: flex; flex-direction: column; gap: 4px; }
.edit-field span {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 700;
}
.edit-field input, .edit-field select {
  width: 150px;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.edit-field input:focus, .edit-field select:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.edit-field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
}
.edit-field-checkbox span { text-transform: none; font-weight: 500; font-size: 12.5px; }
.edit-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ── Login page ──────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 15%, var(--primary-soft), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(139, 92, 246, .12), transparent 45%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  width: 300px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}
.login-card h1 { font-size: 16.5px; margin: 0 0 4px; letter-spacing: -.01em; }
.login-card .subtitle { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.login-card button { width: 100%; padding: 11px; font-size: 14px; }
.login-card.setup { width: 380px; }
.login-qr {
  margin: 0 auto 14px;
  line-height: 0;
  background: #fff;
  display: inline-block;
  padding: 8px;
  border-radius: 8px;
}
.login-qr img { width: 260px; height: 260px; display: block; }
.login-secret {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  letter-spacing: .06em;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0 0 14px;
}
.login-card .error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  padding: 8px;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}
