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

:root {
  --bg:           #fdf6ec;
  --bg-alt:       #f5e6d3;
  --surface:      #fffdf8;
  --surface-2:    #fdf0e0;
  --border:       #e8d5b7;
  --border-focus: #d97706;
  --accent:       #d97706;
  --accent-hover: #b45309;
  --accent-light: #fef3c7;
  --accent-muted: #f59e0b;
  --green:        #65a30d;
  --green-bg:     #f7fee7;
  --green-border: #d9f99d;
  --red:          #dc2626;
  --red-bg:       #fef2f2;
  --red-border:   #fecaca;
  --yellow:       #d97706;
  --yellow-bg:    #fffbeb;
  --yellow-border:#fde68a;
  --text:         #292218;
  --text-muted:   #7c6a52;
  --text-dim:     #b59b77;
  --radius:       16px;
  --radius-sm:    12px;
  --shadow-sm:    0 1px 3px rgba(120,60,10,.07), 0 1px 2px rgba(120,60,10,.05);
  --shadow:       0 4px 16px rgba(120,60,10,.10), 0 1px 4px rgba(120,60,10,.06);
  --shadow-lg:    0 20px 60px rgba(120,60,10,.14), 0 4px 12px rgba(120,60,10,.08);
  --transition:   0.15s ease;
  --font:         'Nunito', system-ui, -apple-system, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Dark Theme ─────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #1a1612;
  --bg-alt:       #211d17;
  --surface:      #252018;
  --surface-2:    #2c2620;
  --border:       #3d3428;
  --border-focus: #f59e0b;
  --accent:       #f59e0b;
  --accent-hover: #d97706;
  --accent-light: #2d1f00;
  --accent-muted: #d97706;
  --green:        #84cc16;
  --green-bg:     #0d1f00;
  --green-border: #2a4a00;
  --red:          #f87171;
  --red-bg:       #2a0000;
  --red-border:   #5a1010;
  --yellow:       #f59e0b;
  --yellow-bg:    #2a1800;
  --yellow-border:#5a3500;
  --text:         #f0e6d3;
  --text-muted:   #a89070;
  --text-dim:     #6b5840;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.4),  0 1px 2px rgba(0,0,0,0.3);
  --shadow:       0 4px 16px rgba(0,0,0,0.5), 0 1px 4px rgba(0,0,0,0.35);
  --shadow-lg:    0 20px 60px rgba(0,0,0,0.6),0 4px 12px rgba(0,0,0,0.4);
}

/* ─── Theme Toggle Button ────────────────────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  color: var(--text-muted);
  transition: color var(--transition), transform var(--transition);
  font-family: var(--font);
}
.theme-toggle:hover {
  color: var(--accent);
  transform: rotate(20deg) scale(1.15);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
  color: var(--text);
  line-height: 1.5;
}

/* ─── Typography ─────────────────────────────────────────────────────────────── */
h1 { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.025em; color: var(--text); }
h2 { font-size: 1.3rem;  font-weight: 600; color: var(--text); }
h3 { font-size: 1rem;    font-weight: 600; color: var(--text); }
p  { color: var(--text-muted); }

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:    var(--shadow-sm);
  padding: 1.75rem;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .65rem 1.35rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -.01em;
}

.btn-primary {
  background: linear-gradient(135deg, #f59e0b, var(--accent));
  color: #fff;
  box-shadow: 0 2px 8px rgba(217,119,6,.35);
}
.btn-primary:hover  { background: linear-gradient(135deg, var(--accent), var(--accent-hover)); box-shadow: 0 4px 14px rgba(217,119,6,.45); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-alt); color: var(--text); border-color: #d4b896; }

.icon-btn { padding: .4rem; line-height: 0; }
.icon-btn:hover { color: var(--accent); }

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-danger-outline {
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
}
.btn-danger-outline:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm   { padding: .45rem .9rem; font-size: .82rem; }
.btn-full { width: 100%; }

/* ─── Form elements ──────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1.1rem; }
.form-group label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type="text"],
input[type="password"],
input[type="tel"],
select {
  width: 100%;
  padding: .65rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(217,119,6,.15);
}
input::placeholder { color: var(--text-dim); }

/* ─── Alert / flash ──────────────────────────────────────────────────────────── */
.alert {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  margin-bottom: 1.1rem;
  border: 1px solid transparent;
}
.alert-error   { background: var(--red-bg);    border-color: var(--red-border);    color: #991b1b; }
.alert-success { background: var(--green-bg);  border-color: var(--green-border);  color: #3a7c0a; }
.alert-info    { background: var(--accent-light); border-color: #fde68a;           color: #92400e; }

/* ─── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 6px rgba(120,60,10,.08);
}
.navbar-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  letter-spacing: -.01em;
}
.navbar-brand span { color: var(--accent); }
.navbar-nav { display: flex; align-items: center; gap: .25rem; }
.navbar-status-dot { margin-left: .25rem; }
.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 700;
  padding: .4rem .75rem;
  border-radius: 8px;
  transition: all var(--transition);
}
.nav-link:hover  { color: var(--text); background: var(--bg-alt); }
.nav-link.active { color: var(--accent-hover); background: var(--accent-light); }

/* ─── Status dot ─────────────────────────────────────────────────────────────── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.ready   { background: var(--green); box-shadow: 0 0 0 2px var(--green-bg); }
.status-dot.busy    { background: var(--red);   box-shadow: 0 0 0 2px var(--red-bg);   }
.status-dot.offline { background: #c9b99a; }
.status-dot.ringing { background: var(--yellow); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .6; transform: scale(1.35); }
}

/* ─── Dialer ─────────────────────────────────────────────────────────────────── */
.dialer-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 1.5rem;
  background: linear-gradient(160deg, #fdf6ec 0%, #f5e6d3 60%, #eddcc3 100%);
}

.dialer-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.dialer-display {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .9rem 1.1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  box-shadow: inset 0 2px 6px rgba(120,60,10,.06);
}
.dialer-display input {
  background: transparent;
  border: none;
  box-shadow: none;
  text-align: center;
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: .04em;
  color: var(--text);
  padding: 0;
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
}
.dialer-display input:focus { box-shadow: none; border: none; }

.dialer-clear-btn {
  width: 100%;
  padding: .55rem;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: .06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialer-clear-btn:hover  { background: #fee2e2; border-color: #fca5a5; }
.dialer-clear-btn:active { background: #fecaca; transform: scale(.98); }

/* ─── Keypad ─────────────────────────────────────────────────────────────────── */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}

.key {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: .06rem;
  box-shadow: var(--shadow-sm);
}
.key:hover  { background: var(--accent-light); border-color: var(--accent-muted); }
.key:active { background: #fde68a; border-color: var(--accent); transform: scale(.95); box-shadow: none; }

.key-digit {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  font-family: var(--font);
}
.key-letters {
  font-size: .5rem;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ─── Call controls ──────────────────────────────────────────────────────────── */
.dialer-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding-top: .15rem;
}

.call-timer { flex-shrink: 0; }

.call-btn {
  flex: 1;
  max-width: 160px;
  padding: .75rem .5rem;
  border: none;
  border-radius: 999px;
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.call-btn-call {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 4px 16px rgba(217,119,6,.40);
}
.call-btn-call:hover:not(:disabled) {
  background: linear-gradient(135deg, #d97706, #b45309);
  box-shadow: 0 6px 20px rgba(180,83,9,.50);
  transform: translateY(-1px);
}
.call-btn-call:active:not(:disabled) { transform: translateY(0); }
.call-btn-call:disabled { background: #e8d5b7; box-shadow: none; cursor: not-allowed; color: #b59b77; }

.call-btn-hangup {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 16px rgba(220,38,38,.35);
  animation: ring-pulse 1.8s infinite;
}
.call-btn-hangup:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 6px 20px rgba(185,28,28,.50);
}

@keyframes ring-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(220,38,38,.35); }
  50%       { box-shadow: 0 4px 24px rgba(220,38,38,.60); }
}

/* ─── Incoming call banner ───────────────────────────────────────────────────── */
#incomingBanner {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  text-align: center;
  animation: incoming-glow 1.6s ease-in-out infinite;
}
.incoming-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: .2rem;
}
.incoming-from {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .65rem;
}
.incoming-actions {
  display: flex;
  gap: .5rem;
  justify-content: center;
}
.call-btn-answer {
  background: linear-gradient(135deg, #84cc16, #65a30d);
  color: #fff;
  box-shadow: 0 4px 16px rgba(101,163,13,.35);
}
.call-btn-answer:hover {
  background: linear-gradient(135deg, #65a30d, #4d7c0f);
  box-shadow: 0 6px 20px rgba(77,124,15,.45);
  transform: translateY(-1px);
}
.call-btn-reject {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 16px rgba(220,38,38,.35);
}
.call-btn-reject:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 6px 20px rgba(185,28,28,.45);
  transform: translateY(-1px);
}
@keyframes incoming-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(101,163,13,.0); }
  50%       { box-shadow: 0 0 0 6px rgba(101,163,13,.18); }
}

/* ─── Timer ──────────────────────────────────────────────────────────────────── */
.dialer-timer-wrap {
  text-align: center;
}

.call-timer {
  font-size: 1.5rem;
  font-style: italic;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}

/* ─── Admin layout ───────────────────────────────────────────────────────────── */
.admin-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .875rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  box-shadow: var(--shadow-sm);
  border-left-width: 3px;
}
.stat-card.accent { border-left-color: var(--accent); }
.stat-card.green  { border-left-color: var(--green); }
.stat-card.red    { border-left-color: var(--red); }
.stat-card.yellow { border-left-color: var(--yellow); }
.stat-card:not(.accent):not(.green):not(.red):not(.yellow) { border-left-color: var(--border); }

.stat-card .stat-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
}
.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.03em;
}
.stat-card .stat-sub {
  font-size: .78rem;
  color: var(--text-muted);
}

/* ─── Inline stats grid ──────────────────────────────────────────────────────── */
.inline-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.istat {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .875rem 1.5rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
/* remove right border on every 3rd item */
.istat:nth-child(3n) { border-right: none; }
/* remove bottom border on last row items */
.istat:nth-last-child(-n+3):nth-child(3n+1),
.istat:nth-last-child(-n+3):nth-child(3n+1) ~ .istat { border-bottom: none; }
.istat:first-child { padding-left: 1.5rem; }
.istat-value {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.03em;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
}
.istat-value.accent { color: var(--accent); }
.istat-value.green  { color: var(--green); }
.istat-value.red    { color: var(--red); }
.istat-value.yellow { color: var(--yellow); }
.istat-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  white-space: nowrap;
}
.istat-sub {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}
.td-actions {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  align-items: center;
}
.table-card-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
}
.table-card-header h3 { margin: 0; }
.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.data-table tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid #f0e4d0;
  color: var(--text-muted);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--row-hover); }

[data-theme="dark"] { --row-hover: rgba(255,255,255,.04); }
[data-theme="light"], :root { --row-hover: #fdf6ec; }

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border: 1px solid transparent;
}
.badge-completed  { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.badge-failed     { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.badge-busy       { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-no-answer  { background: #f5e6d3; color: #7c6a52; border-color: #e8d5b7; }
.badge-canceled   { background: #f5e6d3; color: #7c6a52; border-color: #e8d5b7; }
.badge-in-progress{ background: var(--accent-light); color: #92400e; border-color: #fde68a; }
.badge-initiated  { background: #f7fee7; color: #3a7c0a; border-color: #d9f99d; }
.badge-ringing    { background: #fefce8; color: #713f12; border-color: #fef08a; }
.badge-default    { background: #f5e6d3; color: #7c6a52; border-color: #e8d5b7; }

.dir-badge {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.dir-badge.dir-in  { color: var(--green); }
.dir-badge.dir-out { color: var(--text-muted); }

/* ─── Settings section ───────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 768px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: .25rem .5rem;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--hover-bg); }
.modal-body { padding: 1.25rem 1.5rem 1.5rem; }

/* ─── Auth pages ─────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #fdf6ec 0%, #f5e6d3 60%, #eddcc3 100%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
}
.auth-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-logo .logo-icon {
  width: 56px; height: 56px;
  background: var(--accent-light);
  border: 1px solid #fde68a;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: .7rem;
}
.auth-logo h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin-bottom: .2rem;
}
.auth-logo p  { font-size: .875rem; }

/* ─── Section titles ─────────────────────────────────────────────────────────── */
.section-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: .875rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Collapsible sections ───────────────────────────────────────────────────── */
button.collapsible-toggle {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  padding: 0;
  color: inherit;
}
button.collapsible-toggle:hover .collapse-icon { color: var(--accent); }

.collapse-icon {
  color: var(--text-dim);
  transition: transform .2s ease, color .15s ease;
  flex-shrink: 0;
  margin-left: auto;
  margin-right: 0;
}
button.section-title::after { display: none; }
button.section-title {
  gap: .6rem;
}
button.section-title .collapse-icon { margin-left: auto; }

button[aria-expanded="false"] .collapse-icon { transform: rotate(-90deg); }

.collapsible-panel {
  overflow: hidden;
  transition: opacity .2s ease;
}
.collapsible-panel.collapsed {
  display: none;
}

/* ─── Divider ────────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .admin-wrap { padding: 1rem .875rem 3rem; }
  .inline-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .istat {
    min-width: 0;
    padding: .85rem 1rem;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .istat:nth-child(3n) { border-right: 1px solid var(--border); }
  .istat:nth-child(2n) { border-right: none; }
  .istat:nth-last-child(-n+3):nth-child(3n+1),
  .istat:nth-last-child(-n+3):nth-child(3n+1) ~ .istat { border-bottom: 1px solid var(--border); }
  .istat:nth-last-child(-n+2) { border-bottom: none; }
  .istat-label {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .istat-sub { display: inline; }
  .stat-grid  { grid-template-columns: repeat(2, 1fr); }
  .card       { padding: 1.4rem 1.1rem; }
  .table-card-header {
    padding: 1rem;
    gap: .75rem;
  }
  .table-card-header h3 { font-size: 1rem; }
  .callback-scroll,
  .recordings-scroll,
  .calls-scroll {
    overflow-x: hidden;
  }
  .callback-table,
  .callback-table thead,
  .callback-table tbody,
  .callback-table tr,
  .callback-table td,
  .recordings-table,
  .recordings-table thead,
  .recordings-table tbody,
  .recordings-table tr,
  .recordings-table td,
  .calls-table,
  .calls-table thead,
  .calls-table tbody,
  .calls-table tr,
  .calls-table td {
    display: block;
    width: 100%;
  }
  .callback-table thead,
  .recordings-table thead,
  .calls-table thead {
    display: none;
  }
  .callback-table tbody tr,
  .recordings-table tbody tr,
  .calls-table tbody tr {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
  }
  .callback-table tbody tr:last-child,
  .recordings-table tbody tr:last-child,
  .calls-table tbody tr:last-child {
    border-bottom: none;
  }
  .callback-table tbody td,
  .recordings-table tbody td,
  .calls-table tbody td {
    padding: 0;
    border-bottom: none;
    color: var(--text-muted);
  }
  .callback-table tbody td[colspan],
  .recordings-table tbody td[colspan],
  .calls-table tbody td[colspan] {
    grid-column: 1 / -1;
    text-align: center;
  }
  .callback-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(7rem, auto);
    gap: .75rem 1rem;
    align-items: start;
  }
  .callback-table tbody td:nth-child(1) { grid-column: 1; }
  .callback-table tbody td:nth-child(2) { grid-column: 2; }
  .callback-table tbody td:nth-child(3) { grid-column: 1 / -1; }
  .callback-table .td-actions {
    gap: .5rem;
  }
  .callback-table .td-actions .btn {
    flex: 1 1 7rem;
  }
  .recordings-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .45rem 1rem;
    align-items: start;
  }
  .recordings-table tbody td:nth-child(1) {
    grid-column: 1 / -1;
    font-size: .82rem;
  }
  .recordings-table tbody td:nth-child(2) {
    grid-column: 1;
    font-weight: 700;
    color: var(--text);
    overflow-wrap: anywhere;
  }
  .recordings-table tbody td:nth-child(3) {
    grid-column: 2;
    color: var(--text);
    font-family: var(--font-mono);
    white-space: nowrap;
  }
  .recordings-table tbody td:nth-child(4),
  .recordings-table tbody td:nth-child(5) {
    grid-column: 1 / -1;
  }
  .recordings-table tbody td:nth-child(4) {
    min-width: 0;
    margin-top: .35rem;
  }
  .recordings-table audio {
    display: block;
    width: 100% !important;
    max-width: none !important;
    min-width: 0;
  }
  .recordings-table .td-actions .icon-btn {
    flex: 0 0 auto;
  }
  .calls-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .45rem 1rem;
    align-items: center;
  }
  .calls-table tbody td:nth-child(1) {
    grid-column: 1;
    white-space: nowrap;
  }
  .calls-table tbody td:nth-child(2) {
    grid-column: 2;
    justify-self: end;
  }
  .calls-table tbody td:nth-child(3) {
    grid-column: 1;
  }
  .calls-table tbody td:nth-child(6) {
    grid-column: 2;
    justify-self: end;
    color: var(--text);
    font-family: var(--font-mono);
    white-space: nowrap;
  }
  .calls-table tbody td:nth-child(4),
  .calls-table tbody td:nth-child(5) {
    grid-column: 1 / -1;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .calls-table tbody td:nth-child(4)::before,
  .calls-table tbody td:nth-child(5)::before {
    content: attr(data-label) ": ";
    font-family: var(--font);
    font-weight: 700;
    color: var(--text-dim);
  }
  .data-table thead th:nth-child(n+5),
  .data-table tbody td:nth-child(n+5) { display: none; }
  .calls-table tbody td:nth-child(5),
  .calls-table tbody td:nth-child(6) { display: block; }
  .recordings-table tbody td:nth-child(5) { display: block; }
  .data-table tbody tr.call-inbound { display: none; }
  h1 { font-size: 1.35rem; }
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-alt); }
::-webkit-scrollbar-thumb { background: #d4b896; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b59b77; }

/* ─── Utility ────────────────────────────────────────────────────────────────── */
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-2  { margin-bottom: 1rem; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: .75rem; }
.gap-3 { gap: 1rem; }
.text-muted  { color: var(--text-muted); }
.text-dim    { color: var(--text-dim); }
.text-small  { font-size: .875rem; }
.text-center { text-align: center; }
.font-mono   { font-family: var(--font-mono); font-size: .85em; }

/* ─── Dialer 3-column layout ─────────────────────────────────────────────────── */
.dialer-wrap {
  align-items: stretch;
  gap: 1.5rem;
  flex-wrap: nowrap;
  padding: 2rem 1.5rem;
  justify-content: center;
}
.dialer-card,
.sidebar-card {
  flex: 1 1 0;
  min-width: 0;
  max-width: 380px;
  padding: 1.75rem 1.5rem;
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
}

/* Mobile: single column */
@media (max-width: 900px) {
  .dialer-wrap { flex-wrap: wrap; flex-direction: column; align-items: center; padding: 1.5rem 1rem; }
  .dialer-card,
  .sidebar-card { flex: none; width: 100%; max-width: 420px; }
}

/* Contact list */
.contact-list {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  overflow-y: auto;
  margin-bottom: .5rem;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.contact-row:hover { background: var(--bg-alt); }
.contact-dial-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-align: left;
  font-family: var(--font);
  color: var(--text);
}
.contact-dial-btn:hover .contact-name { color: var(--accent); }
.contact-name {
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.2;
  transition: color var(--transition);
}
.contact-phone {
  font-size: .78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.contact-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: .2rem .35rem;
  border-radius: 6px;
  font-size: .8rem;
  line-height: 1;
  transition: all var(--transition);
  flex-shrink: 0;
}
.contact-delete-btn:hover { background: var(--red-bg); color: var(--red); }

/* Recent Calls tabs */
.rc-tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: .875rem;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: .2rem;
}
.rc-tab {
  flex: 1;
  padding: .4rem .5rem;
  border: none;
  border-radius: 10px;
  background: none;
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.rc-tab-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.rc-panel { display: flex; flex-direction: column; gap: .35rem; }
.rc-call-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.rc-call-row:hover { background: var(--bg-alt); }
.rc-direction-icon { font-size: .9rem; flex-shrink: 0; width: 1.5rem; text-align: center; }
.rc-call-info { flex: 1; min-width: 0; }
.rc-call-number {
  font-size: .82rem;
  font-family: var(--font-mono);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rc-call-name {
  font-family: var(--font);
  font-weight: 700;
}
.rc-call-phone {
  font-size: .74rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .05rem;
}
.rc-call-meta {
  font-size: .72rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  margin-top: .1rem;
}
.rc-dial-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .2rem .45rem;
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  font-family: var(--font);
}
.rc-dial-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent-muted);
  color: var(--accent-hover);
}
.rc-save-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .2rem .45rem;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  font-family: var(--font);
  line-height: 1;
}
.rc-save-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent-muted);
  color: var(--accent-hover);
}


/* ─── In-call controls (mute / hold) ────────────────────────────────────────── */
.in-call-controls {
  display: flex;
  gap: .5rem;
  justify-content: center;
}
.ctrl-btn {
  flex: 1;
  max-width: 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: .02em;
}
.ctrl-btn:hover { background: var(--bg-alt); border-color: var(--border-focus); color: var(--text); }
.ctrl-btn-active {
  background: var(--accent-light);
  border-color: var(--accent-muted);
  color: var(--accent-hover);
}
.ctrl-btn-active:hover { background: #fde68a; }

/* ─── Recording toggle ───────────────────────────────────────────────────────── */
.record-toggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding-top: .1rem;
}
.record-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .03em;
}
.record-toggle-label input[type="checkbox"] { display: none; }
.record-toggle-slider {
  width: 34px; height: 18px;
  background: var(--border);
  border-radius: 9px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.record-toggle-slider::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 12px; height: 12px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}
.record-toggle-label input:checked ~ .record-toggle-slider { background: var(--red); }
.record-toggle-label input:checked ~ .record-toggle-slider::after { transform: translateX(16px); }
.record-notice {
  font-size: .72rem;
  color: var(--text-dim);
  text-align: center;
}

/* ─── Recording indicator (pulsing dot next to timer) ────────────────────────── */
.rec-indicator {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--red);
  vertical-align: middle;
  margin-left: .5rem;
  animation: rec-blink 1.2s ease-in-out infinite;
}
@keyframes rec-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* ─── Connection quality bar ─────────────────────────────────────────────────── */
.quality-bar {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  margin-left: .25rem;
  opacity: .5;
  transition: opacity var(--transition);
}
.quality-bar[data-level]:not([data-level="0"]) { opacity: 1; }
.qbar-bar {
  width: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--transition), height var(--transition);
}
.qbar-bar:nth-child(1) { height: 6px; }
.qbar-bar:nth-child(2) { height: 10px; }
.qbar-bar:nth-child(3) { height: 14px; }

/* Level 1: poor — 1 bar red */
.quality-bar[data-level="1"] .qbar-bar:nth-child(1) { background: var(--red); }

/* Level 2: ok — 2 bars yellow */
.quality-bar[data-level="2"] .qbar-bar:nth-child(1),
.quality-bar[data-level="2"] .qbar-bar:nth-child(2) { background: var(--yellow); }

/* Level 3: good — all bars green */
.quality-bar[data-level="3"] .qbar-bar { background: var(--green); }

/* ─── Contact search ─────────────────────────────────────────────────────────── */
.contact-search-wrap {
  margin-bottom: .6rem;
}
.contact-search-wrap input[type="search"] {
  width: 100%;
  padding: .45rem .75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .82rem;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.contact-search-wrap input[type="search"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(217,119,6,.15);
}

/* ─── Contact edit button ────────────────────────────────────────────────────── */
.contact-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: .2rem .35rem;
  border-radius: 6px;
  font-size: .8rem;
  line-height: 1;
  transition: all var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.contact-edit-btn:hover { background: var(--accent-light); color: var(--accent-hover); }

/* Contact letter header */
.contact-letter {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: .2rem .5rem .1rem;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1px;
}

/* Contact company sub-line */
.contact-company {
  font-size: .72rem;
  color: var(--accent-muted);
  font-weight: 600;
  line-height: 1.2;
}

/* ─── Voicemail button ───────────────────────────────────────────────────────── */
.call-btn-voicemail {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  font-size: .8rem;
}
.call-btn-voicemail:hover {
  background: var(--bg-alt);
  border-color: var(--accent-muted);
  color: var(--text);
  transform: translateY(-1px);
}

/* ─── Callback badge ─────────────────────────────────────────────────────────── */
.callback-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
  margin-right: .5rem;
}

/* ─── Purge call logs ────────────────────────────────────────────────────────── */
.purge-panel {
  display: flex;
  justify-content: center;
  padding: 1rem 1.25rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.purge-form {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  justify-content: center;
}
.purge-label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.purge-input {
  width: 5rem;
  padding: .45rem .6rem;
  font-size: .9rem;
  font-family: var(--font-mono);
  text-align: center;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color var(--transition);
}
.purge-input:focus {
  outline: none;
  border-color: var(--red);
}
.purge-btn { padding: .45rem 1.1rem; font-size: .85rem; }
