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

/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
  --bg:       #0f1117;
  --bg2:      #1a1d27;
  --bg3:      #22263a;
  --accent:   #6c63ff;
  --accent2:  #00d4aa;
  --danger:   #ff4d6a;
  --warn:     #ffd166;
  --text:     #e0e0f0;
  --muted:    #8888aa;
  --border:   #2e3150;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,0.4);
}

/* ── Light mode overrides ────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:       #f4f6fb;
  --bg2:      #ffffff;
  --bg3:      #eef0f7;
  --accent:   #5a52e0;
  --accent2:  #00a88a;
  --danger:   #e03355;
  --warn:     #d4930a;
  --text:     #1a1d2e;
  --muted:    #6b6f8a;
  --border:   #d0d4e8;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,0.1);
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #1a1d27 0%, #22263a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
}
.header-inner { max-width: 1200px; margin: 0 auto; }
.logo { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.logo span { color: var(--text); }
.tagline { color: var(--muted); margin-top: .25rem; font-size: .9rem; }

/* ── Main ────────────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  color: var(--text);
}

/* ── Drop Zone ───────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  transition: all .2s;
  cursor: pointer;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(108,99,255,.07);
}
.drop-icon { font-size: 2.5rem; }
.drop-zone p { color: var(--muted); margin-top: .5rem; }
.drop-zone .sub { font-size: .8rem; }

/* ── File List ───────────────────────────────────────────────────────── */
.file-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.file-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-size: .8rem;
  color: var(--accent2);
  display: flex; align-items: center; gap: .5rem;
}
.file-chip .rm { cursor: pointer; color: var(--danger); font-weight: 700; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  padding: .55rem 1.3rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
.btn:hover:not(:disabled) { opacity: .87; transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-success  { background: var(--accent2); color: #111; }
.btn-ghost    { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }

.upload-actions { margin-top: 1rem; display: flex; gap: .75rem; }

/* ── Progress ────────────────────────────────────────────────────────── */
.progress-wrap { margin-top: 1rem; }
.progress-bar {
  height: 8px; border-radius: 99px;
  background: var(--bg3);
  overflow: hidden;
}
.progress-bar div {
  height: 100%; background: var(--accent);
  border-radius: 99px; transition: width .3s;
}
#progressLabel { font-size: .8rem; color: var(--muted); margin-top: .4rem; display: block; }

/* ── Filters ─────────────────────────────────────────────────────────── */
.filters {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: .35rem; min-width: 160px; }
.filter-group label { font-size: .8rem; color: var(--muted); }
.filter-group input,
.filter-group select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .5rem .75rem;
  font-size: .9rem;
  outline: none;
}
.filter-group input:focus,
.filter-group select:focus { border-color: var(--accent); }

/* ── KPI Grid ────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}
.kpi-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.kpi-icon { font-size: 1.8rem; margin-bottom: .5rem; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.kpi-label { font-size: .8rem; color: var(--muted); margin-top: .3rem; }

/* ── Charts ──────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.5rem;
}
.chart-card canvas { max-height: 280px; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 1rem;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
thead th {
  background: var(--bg3); color: var(--muted);
  padding: .75rem 1rem; text-align: left;
  font-weight: 600; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
tbody tr:hover { background: var(--bg3); }
tbody td { padding: .65rem 1rem; color: var(--text); }
.badge {
  display: inline-block; padding: .2rem .6rem;
  border-radius: 99px; font-size: .75rem; font-weight: 600;
}
.badge-in  { background: rgba(0,212,170,.15); color: var(--accent2); }
.badge-out { background: rgba(108,99,255,.15); color: var(--accent); }
.badge-mis { background: rgba(255,77,106,.15); color: var(--danger); }
.badge-unk { background: rgba(136,136,170,.15); color: var(--muted); }

/* ── Errors ──────────────────────────────────────────────────────────── */
#errorList { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
#errorList li {
  background: rgba(255,77,106,.1); border: 1px solid var(--danger);
  border-radius: 8px; padding: .6rem 1rem; font-size: .85rem; color: var(--danger);
}

/* ── Footer ──────────────────────────────────────────────────────────── */
footer {
  text-align: center; padding: 1.5rem;
  color: var(--muted); font-size: .8rem;
  border-top: 1px solid var(--border);
}

/* ── Utility ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Cancelled badge ─────────────────────────────────────────────────── */
.badge-can {
  background: rgba(255, 77, 106, 0.15);
  color: #ff4d6a;
}

/* ── KPI card accent colours per call type ───────────────────────────── */
.kpi-incoming  .kpi-value { color: #00d4aa; }
.kpi-outgoing  .kpi-value { color: #6c63ff; }
.kpi-missed    .kpi-value { color: #ffd166; }
.kpi-cancelled .kpi-value { color: #ff4d6a; }

/* ── Contact name filter input ───────────────────────────────────────── */
#nameFilter {
  min-width: 180px;
}

/* ── OFW-specific additions ─────────────────────────────────────────────── */

/* Contact legend */
.contact-legend h2 { margin-bottom: .75rem; }
.contact-grid {
  display: flex; flex-wrap: wrap; gap: 1rem;
}
.contact-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  min-width: 220px;
}
.contact-name  { font-weight: 700; font-size: 1rem; color: var(--text); }
.contact-phone { font-size: 1.1rem; color: var(--accent2); margin-top: .3rem; font-family: monospace; }

/* Mono phone numbers in tables */
td.mono { font-family: monospace; color: var(--accent2); font-size: .85rem; }

/* Status / type KPI colours */
.kpi-completed .kpi-value { color: #00d4aa; }
.kpi-missed    .kpi-value { color: #ffd166; }
.kpi-cancelled .kpi-value { color: #ff4d6a; }
.kpi-video     .kpi-value { color: #6c63ff; }
.kpi-audio     .kpi-value { color: #00d4aa; }

/* New badges */
.badge-completed { background: rgba(0,212,170,.15);  color: #00d4aa; }
.badge-can       { background: rgba(255,77,106,.15);  color: #ff4d6a; }
.badge-mis       { background: rgba(255,209,102,.15); color: #ffd166; }
.badge-unk       { background: rgba(136,136,170,.15); color: #8888aa; }
.badge-video     { background: rgba(108,99,255,.15);  color: #6c63ff; }
.badge-audio     { background: rgba(0,212,170,.15);   color: #00d4aa; }

/* ── Site Navigation Bar ─────────────────────────────────────────────────── */
.site-nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0;
  max-width: 100%;
  padding: 0 2rem;
}
.site-nav a {
  display: inline-block;
  padding: .75rem 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
  border-bottom: 3px solid transparent;
  transition: color .2s, border-color .2s;
}
.site-nav a:hover {
  color: var(--text);
  border-bottom-color: var(--border);
}
.site-nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Phone badge ─────────────────────────────────────────────────────────── */
.badge-phone {
  background: rgba(255, 209, 102, 0.15);
  color: #ffd166;
}

/* ── Incoming / Outgoing KPI colours ─────────────────────────────────────── */
.kpi-incoming .kpi-value { color: #00d4aa; }
.kpi-outgoing .kpi-value { color: #6c63ff; }

/* ── PDF Converter Page ──────────────────────────────────────────────────── */
.step-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: .75rem;
}
.step-badge {
  width: 2rem; height: 2rem;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.step-desc {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}
.raw-text-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
  color: var(--muted);
  font-size: .85rem;
}
.btn-sm {
  padding: .3rem .8rem;
  font-size: .8rem;
}
.raw-text {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  font-size: .78rem;
  font-family: monospace;
  color: var(--muted);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.mapping-grid {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.mapping-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 1rem;
  align-items: start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
@media (max-width: 640px) {
  .mapping-row { grid-template-columns: 1fr; }
}
.mapping-label strong {
  display: block;
  color: var(--text);
  margin-bottom: .3rem;
}
.mapping-hint {
  font-size: .78rem;
  color: var(--muted);
  margin-top: .25rem;
}
.mapping-dropdown {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .5rem .75rem;
  font-size: .9rem;
  outline: none;
  cursor: pointer;
}
.mapping-dropdown:focus { border-color: var(--accent); }
.mapping-sample {
  font-size: .78rem;
  color: var(--accent2);
  font-family: monospace;
  margin-top: .4rem;
  min-height: 1.2em;
}
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}
/* ── Carrier Import Page ─────────────────────────────────────────────────── */
.carrier-card { margin-bottom: 0; }

.carrier-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.carrier-logo {
  width: 3rem; height: 3rem;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem; color: #fff;
  flex-shrink: 0;
}
.tmobile-logo  { background: #e20074; }
.att-logo      { background: #00a8e0; font-size: .75rem; }
.verizon-logo  { background: #cd040b; }
.apple-logo    { background: #555; font-size: 1.4rem; }
.ofw-logo      { background: #6c63ff; font-size: .7rem; }

.carrier-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .5rem;
}
.carrier-tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: .35rem .9rem;
  font-size: .85rem;
  cursor: pointer;
  transition: all .2s;
}
.carrier-tab.active,
.carrier-tab:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.steps-list {
  list-style: none;
  counter-reset: steps;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding: 0;
}
.steps-list li {
  counter-increment: steps;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  font-size: .9rem;
  color: var(--text);
  line-height: 1.5;
}
.steps-list li::before {
  content: counter(steps);
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 1.5rem; height: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
  flex-shrink: 0;
  margin-top: .1rem;
}
.carrier-format {
  margin-top: 1.25rem;
  padding: .75rem 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--muted);
}
.carrier-format code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .2rem .5rem;
  font-family: monospace;
  font-size: .82rem;
  color: var(--accent2);
  margin: 0 .25rem;
}
.carrier-tip {
  background: rgba(108,99,255,.1);
  border: 1px solid rgba(108,99,255,.3);
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .85rem;
  color: var(--text);
  margin-top: 1rem;
  line-height: 1.6;
}
.carrier-detected {
  margin-top: .75rem;
  padding: .6rem 1rem;
  background: rgba(0,212,170,.1);
  border: 1px solid rgba(0,212,170,.3);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--accent2);
}
.carrier-badge {
  font-weight: 600;
}
.link-accent {
  color: var(--accent2);
  text-decoration: none;
  font-weight: 600;
}
.link-accent:hover { text-decoration: underline; }
/* ── Supported Carriers Grid ─────────────────────────────────────────────── */
.support-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.support-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  transition: border-color .2s;
}
.support-card.supported {
  border-left: 3px solid var(--accent2);
}
.support-card:hover {
  border-color: var(--accent);
}
.support-card .carrier-logo {
  align-self: flex-start;
}
.support-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: .35rem;
}
.support-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: .35rem;
}
.support-format {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.8;
}
.support-format code {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .4rem;
  font-size: .75rem;
  color: var(--accent2);
  margin: 0 .1rem;
  display: inline-block;
}
.support-export {
  font-size: .8rem;
  color: var(--muted);
}
.support-btn {
  align-self: flex-start;
  margin-top: auto;
  font-size: .8rem;
  padding: .3rem .8rem;
}

/* ── Native + Supported badges ───────────────────────────────────────────── */
.badge-native {
  background: rgba(0, 212, 170, 0.15);
  color: #00d4aa;
  font-weight: 700;
}
.badge-supported {
  background: rgba(108, 99, 255, 0.15);
  color: #6c63ff;
  font-weight: 700;
}

/* ── Sprint logo ─────────────────────────────────────────────────────────── */
.sprint-logo {
  background: #ffce00;
  color: #000;
}
/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — CallScanner
   Breakpoints: 768px (tablet), 480px (phone)
═══════════════════════════════════════════════════════════════════════════ */

/* ── Base mobile meta fixes ──────────────────────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

img, canvas, table {
  max-width: 100%;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }
  .header-inner {
    text-align: center;
  }
  .logo {
    font-size: 1.4rem;
  }
  .tagline {
    font-size: .8rem;
  }
}

/* ── Navigation ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .site-nav {
    padding: 0 .5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
    display: flex;
    gap: 0;
  }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a {
    padding: .65rem .85rem;
    font-size: .78rem;
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .site-nav a {
    padding: .6rem .65rem;
    font-size: .72rem;
  }
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    padding: 0 .75rem;
    margin: 1rem auto;
    gap: 1rem;
  }
}

@media (max-width: 480px) {
  main {
    padding: 0 .5rem;
    margin: .75rem auto;
    gap: .75rem;
  }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .card {
    padding: 1.25rem;
    border-radius: 10px;
  }
  .card h2 {
    font-size: 1rem;
    margin-bottom: .75rem;
  }
  .card h3 {
    font-size: .95rem;
  }
}

@media (max-width: 480px) {
  .card {
    padding: 1rem;
    border-radius: 8px;
  }
}

/* ── Drop zone ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .drop-zone {
    padding: 1.75rem 1rem;
  }
  .drop-icon {
    font-size: 2rem;
  }
  .drop-zone p {
    font-size: .85rem;
  }
}

@media (max-width: 480px) {
  .drop-zone {
    padding: 1.25rem .75rem;
  }
  .drop-icon {
    font-size: 1.75rem;
  }
}

/* ── Upload actions ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .upload-actions {
    flex-wrap: wrap;
    gap: .5rem;
  }
  .upload-actions .btn {
    flex: 1;
    min-width: 120px;
    text-align: center;
  }
}

/* ── File chips ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .file-chip {
    font-size: .75rem;
    padding: .3rem .7rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .btn {
    padding: .55rem 1rem;
    font-size: .85rem;
  }
  .btn-sm {
    padding: .35rem .7rem;
    font-size: .78rem;
  }
}

/* ── Filters ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .filters {
    flex-direction: column;
    gap: .75rem;
  }
  .filter-group {
    min-width: unset;
    width: 100%;
  }
  .filter-group input,
  .filter-group select,
  .mapping-dropdown {
    width: 100%;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  #applyFilter,
  #resetFilter {
    width: 100%;
  }
}

/* ── KPI Grid ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
  }
  .kpi-card {
    padding: 1rem .75rem;
  }
  .kpi-value {
    font-size: 1.3rem;
  }
  .kpi-icon {
    font-size: 1.5rem;
  }
  .kpi-label {
    font-size: .72rem;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  .kpi-card {
    padding: .85rem .6rem;
  }
  .kpi-value {
    font-size: 1.15rem;
  }
  .kpi-icon {
    font-size: 1.3rem;
    margin-bottom: .3rem;
  }
  .kpi-label {
    font-size: .68rem;
  }
}

/* ── Charts Grid ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .chart-card canvas {
    max-height: 220px;
  }
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }

  table {
    font-size: .78rem;
    min-width: 500px;
  }

  thead th {
    padding: .6rem .75rem;
    font-size: .72rem;
    white-space: nowrap;
  }

  tbody td {
    padding: .55rem .75rem;
    white-space: nowrap;
  }

  /* Scroll hint */
  .table-wrap::after {
    content: "← scroll →";
    display: block;
    text-align: center;
    font-size: .7rem;
    color: var(--muted);
    padding: .4rem 0 .2rem;
  }
}

@media (max-width: 480px) {
  table {
    font-size: .75rem;
  }
  thead th,
  tbody td {
    padding: .5rem .6rem;
  }
}

/* ── Table header row ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .table-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
  }
  .table-header h2 {
    margin-bottom: 0;
  }
  .table-header .btn {
    width: 100%;
    text-align: center;
  }
}

/* ── Contact legend ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .contact-grid {
    grid-template-columns: 1fr;
  }
  .contact-card {
    padding: .85rem 1rem;
  }
}

/* ── Support carriers grid ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .support-grid {
    grid-template-columns: 1fr;
  }
  .support-card {
    flex-direction: row;
    align-items: flex-start;
    gap: .75rem;
  }
  .support-card .carrier-logo {
    flex-shrink: 0;
  }
  .support-btn {
    display: none; /* hidden on mobile — inline nav sufficient */
  }
}

@media (max-width: 480px) {
  .support-card {
    flex-direction: column;
  }
  .support-badges {
    flex-wrap: wrap;
  }
}

/* ── Carrier cards ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .carrier-header {
    gap: .75rem;
  }
  .carrier-logo {
    width: 2.5rem;
    height: 2.5rem;
    font-size: .85rem;
  }
  .carrier-header h2 {
    font-size: 1rem;
  }
  .carrier-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
  }
  .carrier-tabs::-webkit-scrollbar { display: none; }
  .carrier-tab {
    flex-shrink: 0;
    font-size: .8rem;
    padding: .3rem .75rem;
  }
  .steps-list li {
    font-size: .85rem;
    gap: .6rem;
  }
  .steps-list li::before {
    width: 1.35rem;
    height: 1.35rem;
    font-size: .7rem;
  }
  .carrier-format {
    font-size: .78rem;
  }
  .carrier-format code {
    font-size: .72rem;
    display: inline-block;
    margin: .1rem .1rem;
  }
}

/* ── Mapping grid (PDF Converter) ────────────────────────────────────────── */
@media (max-width: 768px) {
  .mapping-row {
    grid-template-columns: 1fr;
    gap: .5rem;
  }
  .mapping-label strong {
    font-size: .9rem;
  }
  .mapping-hint {
    font-size: .75rem;
  }
  .mapping-sample {
    font-size: .75rem;
  }
}

/* ── Preview actions ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .preview-actions {
    flex-direction: column;
    gap: .5rem;
  }
  .preview-actions .btn {
    width: 100%;
    text-align: center;
  }
}

/* ── Step header (PDF Converter) ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .step-header {
    gap: .65rem;
  }
  .step-badge {
    width: 1.75rem;
    height: 1.75rem;
    font-size: .85rem;
  }
  .step-header h2 {
    font-size: .95rem;
  }
  .step-desc {
    font-size: .82rem;
  }
}

/* ── Raw text preview ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .raw-text {
    font-size: .72rem;
    max-height: 200px;
  }
  .raw-text-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: .4rem;
  }
}

/* ── Error card ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #errorList li {
    font-size: .8rem;
    padding: .5rem .75rem;
  }
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  footer {
    padding: 1rem;
    font-size: .72rem;
  }
}

/* ── Badges on mobile ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .badge {
    font-size: .68rem;
    padding: .15rem .45rem;
  }
}

/* ── Mono phone numbers ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  td.mono {
    font-size: .75rem;
  }
}

/* ── Progress bar label ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #progressLabel {
    font-size: .75rem;
  }
}

/* ── Carrier detected banner ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .carrier-detected {
    font-size: .8rem;
    padding: .5rem .75rem;
  }
}

/* ── Prevent horizontal overflow ────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }
  .card,
  .kpi-card,
  .support-card,
  .carrier-card,
  .contact-card {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}

/* ── Touch-friendly tap targets ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .btn,
  .carrier-tab,
  .site-nav a,
  select,
  input[type="date"],
  input[type="text"],
  input[type="number"] {
    min-height: 44px; /* Apple HIG minimum tap target */
    line-height: 1.4;
  }
  .rm {
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ── Landscape phone adjustments ─────────────────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
/* ── Theme toggle button ─────────────────────────────────────────────────── */
.theme-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: background .2s, border-color .2s, transform .15s, box-shadow .2s;
  outline: none;
}
.theme-toggle:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(108,99,255,0.4);
}
.theme-toggle:active {
  transform: scale(.95);
}

/* Light mode body/header/table adjustments */
[data-theme="light"] body {
  color: var(--text);
  background: var(--bg);
}
[data-theme="light"] header {
  background: linear-gradient(135deg, #e8eaf6 0%, #f0f2ff 100%);
  border-bottom: 1px solid var(--border);
}
[data-theme="light"] .logo {
  color: var(--accent);
}
[data-theme="light"] .site-nav {
  background: var(--bg2);
}
[data-theme="light"] thead th {
  background: var(--bg3);
  color: var(--muted);
}
[data-theme="light"] tbody tr:hover {
  background: var(--bg3);
}
[data-theme="light"] .raw-text {
  color: var(--muted);
}
[data-theme="light"] .kpi-card {
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
[data-theme="light"] .chart-card canvas {
  filter: none;
}
[data-theme="light"] .carrier-logo {
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
[data-theme="light"] code {
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--border);
}
[data-theme="light"] .carrier-tip {
  background: rgba(90,82,224,.08);
  border-color: rgba(90,82,224,.25);
}
[data-theme="light"] .carrier-detected {
  background: rgba(0,168,138,.1);
  border-color: rgba(0,168,138,.3);
}
[data-theme="light"] .file-chip {
  background: var(--bg3);
  border-color: var(--border);
  color: var(--accent);
}
[data-theme="light"] .progress-bar {
  background: var(--bg3);
}
[data-theme="light"] .drop-zone {
  border-color: var(--border);
}
[data-theme="light"] .drop-zone.dragover {
  background: rgba(90,82,224,.05);
  border-color: var(--accent);
}
[data-theme="light"] .mapping-row {
  background: var(--bg3);
}
[data-theme="light"] .mapping-dropdown,
[data-theme="light"] .filter-group input,
[data-theme="light"] .filter-group select {
  background: var(--bg2);
  color: var(--text);
  border-color: var(--border);
}
[data-theme="light"] #errorList li {
  background: rgba(224,51,85,.08);
  border-color: var(--danger);
  color: var(--danger);
}
[data-theme="light"] .support-card {
  background: var(--bg3);
}
[data-theme="light"] footer {
  border-top-color: var(--border);
  color: var(--muted);
}

/* ── Mobile toggle position ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  .theme-toggle {
    bottom: 1rem;
    right: 1rem;
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.15rem;
  }
}
/* ── Call Pattern Insights ───────────────────────────────────────────────── */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.insight-panel {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.insight-header {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.insight-header.no-call   { background: rgba(255,77,106,.08);  border-left: 3px solid #ff4d6a; }
.insight-header.multi     { background: rgba(108,99,255,.08);  border-left: 3px solid #6c63ff; }
.insight-header.short-call{ background: rgba(255,209,102,.08); border-left: 3px solid #ffd166; }
.insight-header.long-call { background: rgba(0,212,170,.08);   border-left: 3px solid #00d4aa; }

.insight-icon  { font-size: 1.6rem; flex-shrink: 0; }
.insight-title { font-weight: 700; font-size: .9rem; color: var(--text); }
.insight-count { font-size: .78rem; color: var(--muted); margin-top: .15rem; }

.insight-body  { padding: 1rem 1.25rem; max-height: 280px; overflow-y: auto; }
.insight-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: .5rem 0; }
.insight-more  { color: var(--muted); font-size: .75rem; margin-top: .5rem; text-align: center; }

/* No-call date tags */
.insight-tag-wrap { display: flex; flex-wrap: wrap; gap: .35rem; }
.insight-tag {
  padding: .2rem .6rem;
  border-radius: 6px;
  font-size: .75rem;
  font-family: monospace;
  font-weight: 600;
}
.tag-grey { background: rgba(255,77,106,.15); color: #ff4d6a; border: 1px solid rgba(255,77,106,.2); }

/* Multi-call / duration rows */
.insight-rows { display: flex; flex-direction: column; gap: .4rem; }
.insight-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .5rem;
  background: var(--bg2);
  border-radius: 6px;
  font-size: .78rem;
  flex-wrap: wrap;
}
.insight-date {
  font-family: monospace;
  color: var(--muted);
  font-size: .75rem;
  min-width: 85px;
  flex-shrink: 0;
}
.insight-pill {
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  flex-shrink: 0;
}
.pill-purple { background: rgba(108,99,255,.2);  color: #6c63ff; }
.pill-amber  { background: rgba(255,209,102,.2); color: #ffd166; }
.pill-teal   { background: rgba(0,212,170,.2);   color: #00d4aa; }
.pill-red    { background: rgba(255,77,106,.2);  color: #ff4d6a; }

.insight-times {
  color: var(--muted);
  font-size: .72rem;
  font-family: monospace;
  flex: 1;
}
.insight-contact {
  color: var(--text);
  font-size: .75rem;
  flex: 1;
}
.insight-num {
  color: var(--muted);
  font-size: .7rem;
  font-family: monospace;
  margin-left: .35rem;
}

/* Mobile */
@media (max-width: 480px) {
  .insight-grid { grid-template-columns: 1fr; }
  .insight-body { max-height: 220px; }
}
/* ── Insight direction chips ─────────────────────────────────────────────── */
.insight-row-multi {
  flex-direction: column;
  align-items: flex-start;
  gap: .4rem;
  padding: .6rem .75rem;
}
.insight-dir-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.insight-times-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
}
.insight-time-chip {
  font-size: .68rem;
  font-family: monospace;
  padding: .15rem .45rem;
  border-radius: 4px;
  font-weight: 600;
}
.time-in  { background: rgba(0,212,170,.15);  color: #00d4aa; }
.time-out { background: rgba(108,99,255,.15); color: #6c63ff; }

.pill-grey       { background: rgba(136,136,170,.2); color: #8888aa; }
.pill-purple-sm  { background: rgba(108,99,255,.15); color: #6c63ff; }
/* ── Synopsis Page ───────────────────────────────────────────────────────── */
.synopsis-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.synopsis-actions {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.synopsis-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  padding: 1rem;
  background: var(--bg3);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

/* Legal alienation optional headers — must track site theme (avoid dark fallback on light mode) */
.alienation-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.alienation-meta-row .alienation-meta-input {
  flex: 1;
  min-width: 140px;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.alienation-meta-row #alienCaseNo {
  min-width: 160px;
}
.alienation-meta-row .alienation-meta-input::placeholder {
  color: var(--muted);
  opacity: 0.88;
}
.alienation-meta-row .alienation-meta-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.alienation-custody-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.65rem;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--text);
  max-width: 42rem;
  line-height: 1.45;
}
.alienation-custody-check input[type="checkbox"] {
  margin-top: 0.2rem;
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.alienation-custody-check span {
  user-select: none;
}

.syn-stat {
  text-align: center;
  min-width: 70px;
  flex: 1;
}
.syn-stat-val {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
}
.syn-stat-lbl {
  font-size: .65rem;
  color: var(--muted);
  margin-top: .2rem;
}
.syn-section {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.syn-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.syn-section-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: .85rem;
  padding: .5rem .85rem;
  background: rgba(108,99,255,.08);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
}
.syn-section-body {
  font-size: .92rem;
  line-height: 1.85;
  color: var(--text);
}
.syn-section-body p {
  margin: 0 0 1rem;
}
.syn-section-body p:last-child {
  margin-bottom: 0;
}

/* Print styles */
@media print {
  header, nav, .upload-card, .upload-actions,
  .synopsis-actions, footer, .theme-toggle,
  #progressWrap, #errorCard { display: none !important; }
  .synopsis-stats { background: #f5f5f5 !important; }
  .syn-section-title { background: #e8e8ff !important; color: #333 !important; }
  body { color: #000 !important; background: #fff !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

@media (max-width: 480px) {
  .synopsis-header { flex-direction: column; }
  .synopsis-actions { width: 100%; }
  .synopsis-actions .btn { flex: 1; text-align: center; }
  .syn-stat { min-width: 60px; }
  .syn-stat-val { font-size: 1rem; }
}