/* ============================================================
   Twilio Dev Phone — style.css
   Light default (matches reference) + dark theme via
   [data-theme]. Burnt-orange accent (#c2410c). CallHippo-style
   navigation drawer + multi-view layout. No inline styles.
   ============================================================ */

/* The [hidden] attribute must always win, even over class rules like
   `.field { display: flex }` (fixes admin-only fields leaking to users). */
[hidden] { display: none !important; }

/* ---------- Theme tokens ---------- */
:root,
[data-theme="light"] {
  --bg:            #ececef;
  --surface:       #ffffff;
  --surface-2:     #f6f6f8;
  --surface-3:     #eceef2;
  --border:        #e2e5ea;
  --text:          #1f2430;
  --text-dim:      #5b6472;
  --text-faint:    #9aa2b1;

  --primary:       #c2410c;
  --primary-dark:  #9a3412;
  --primary-soft:  #fdf0e9;

  --green:         #16a34a;
  --green-dark:    #15803d;
  --red:           #dc2626;
  --red-dark:      #b91c1c;
  --amber:         #d97706;
  --blue:          #2563eb;

  --key-face:      #ffffff;
  --key-face-2:    #f7f8fa;
  --key-press:     #f0e6df;
  --ripple:        rgba(194, 65, 12, .18);

  --shadow-sm: 0 1px 3px rgba(20,25,40,.08);
  --shadow:    0 6px 20px rgba(20,25,40,.12);
  --shadow-lg: 0 18px 48px rgba(20,25,40,.22);
}

[data-theme="dark"] {
  --bg:            #0f1115;
  --surface:       #171a21;
  --surface-2:     #1e222b;
  --surface-3:     #262b36;
  --border:        #2c313c;
  --text:          #e7eaf0;
  --text-dim:      #9aa3b2;
  --text-faint:    #6b7280;

  --primary:       #f97316;
  --primary-dark:  #c2410c;
  --primary-soft:  #2a1a12;

  --green:         #22c55e;
  --green-dark:    #16a34a;
  --red:           #ef4444;
  --red-dark:      #dc2626;
  --amber:         #f59e0b;
  --blue:          #3b82f6;

  --key-face:      #262b36;
  --key-face-2:    #1e222b;
  --key-press:     #394152;
  --ripple:        rgba(249, 115, 22, .28);

  --shadow-sm: 0 2px 6px rgba(0,0,0,.35);
  --shadow:    0 8px 24px rgba(0,0,0,.45);
  --shadow-lg: 0 18px 48px rgba(0,0,0,.55);
}

/* ---------- Shared constants ---------- */
:root {
  --radius-sm:  8px;
  --radius:     14px;
  --radius-lg:  20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", system-ui, -apple-system, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
  transition: background .25s var(--ease), color .25s var(--ease);
}

/* ---------- App shell ---------- */
.app {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header__brand { display: flex; align-items: center; gap: 10px; }
.header__title { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.header__actions { display: flex; align-items: center; gap: 10px; }

/* Status indicator */
.status {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.status__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-faint);
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
}
.status.is-ready .status__dot { background: var(--green); box-shadow: 0 0 0 4px rgba(22,163,74,.16); }
.status.is-error .status__dot { background: var(--red);   box-shadow: 0 0 0 4px rgba(220,38,38,.16); }
.status.is-ready .status__label { color: var(--green); font-weight: 600; }
.status.is-error .status__label { color: var(--red); font-weight: 600; }

/* Icon buttons */
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: transform .12s var(--ease), background .2s var(--ease), color .2s var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn--call { border-color: transparent; background: var(--green); color: #fff; width: 38px; height: 38px; }
.icon-btn--call:hover { background: var(--green-dark); color: #fff; }
.icon-btn--danger { border-color: transparent; background: transparent; color: var(--text-faint); width: 38px; height: 38px; }
.icon-btn--danger:hover { background: rgba(220,38,38,.12); color: var(--red); }

/* ---------- Navigation drawer ---------- */
.drawer {
  position: fixed;
  top: 0; left: 0;
  height: 100%;
  width: min(320px, 88vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 120;
  transform: translateX(-105%);
  transition: transform .3s var(--ease);
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }

.drawer__profile {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  padding: 26px 18px 18px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.drawer__avatar {
  display: grid; place-items: center;
  width: 74px; height: 74px; border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-dim);
  margin-bottom: 4px;
}
.drawer__name { font-size: 17px; font-weight: 700; }
.drawer__email { font-size: 13px; color: var(--text-dim); }
.drawer__badge {
  margin-top: 4px;
  font-size: 12px; font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 12px; border-radius: 999px;
}

.drawer__menu { list-style: none; padding: 8px; flex: 1; overflow-y: auto; }
.drawer__item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 14px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 15px; font-weight: 500;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.drawer__item:hover { background: var(--surface-3); color: var(--text); }
.drawer__item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--primary);
}
.drawer__icon { display: grid; place-items: center; width: 24px; }

.drawer__footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.drawer__themelabel { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.drawer__theme {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-3); color: var(--text); cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.drawer__theme:hover { background: var(--surface); color: var(--primary); }
/* Show moon in light mode (tap -> go dark); show sun in dark mode. */
.drawer__theme .icon { display: none; }
[data-theme="light"] .drawer__theme .icon-moon { display: block; }
[data-theme="dark"]  .drawer__theme .icon-sun  { display: block; }

/* ---------- Views ---------- */
.main { display: flex; flex-direction: column; }
.view {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.view[hidden] { display: none; }

.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head__title { font-size: 15px; font-weight: 700; }

/* ---------- Number display ---------- */
.display {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.display__row { display: flex; align-items: center; gap: 10px; }
.display__input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: var(--text);
  font-size: 28px; font-weight: 600; letter-spacing: 1px;
  text-align: right; padding: 6px 4px;
}
.display__input::placeholder { color: var(--text-faint); font-weight: 500; }
.display__hint {
  min-height: 16px; margin-top: 6px;
  font-size: 12px; color: var(--text-dim); text-align: right;
}

/* Country selector */
.country { position: relative; }
.country__btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  cursor: pointer; font-size: 14px;
  transition: background .2s var(--ease);
}
.country__btn:hover { background: var(--surface-3); }
.country__flag { font-size: 18px; line-height: 1; }
.country__code { font-weight: 600; }
.country__caret { color: var(--text-dim); font-size: 11px; }

.country__list {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  width: 250px; max-height: 280px; overflow-y: auto;
  list-style: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 6px;
}
.country__list[hidden] { display: none; }
.country__item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.country__item:hover, .country__item.is-active { background: var(--primary-soft); }
.country__item .flag { font-size: 18px; }
.country__item .name { flex: 1; color: var(--text-dim); }
.country__item .code { font-weight: 600; }

/* ---------- Clock bar ---------- */
.clockbar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 12px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: 13px; font-weight: 600;
}
.clockbar__flag { font-size: 16px; }

/* ---------- Dial pad ----------
   Flat, system-style keys (Material/iOS): no gradients or hover-lift,
   subtle surface fill, compact height, ripple for touch feedback. */
.dialpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  position: relative; overflow: hidden;
  aspect-ratio: 1.7 / 1;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; user-select: none;
  transition: background .15s var(--ease);
}
.key:hover { background: var(--surface-3); }
.key:active, .key.is-pressed { background: var(--key-press); }
.key__digit { font-size: 24px; font-weight: 500; line-height: 1.1; letter-spacing: .5px; }
.key__letters { font-size: 9px; font-weight: 600; letter-spacing: 1.5px; color: var(--text-faint); min-height: 11px; }

/* Ripple */
.ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: var(--ripple); pointer-events: none; animation: ripple .5s var(--ease);
}
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }

/* ---------- Control buttons ---------- */
.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ctrl-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-dim);
  cursor: pointer; font-size: 11px;
  transition: transform .12s var(--ease), background .2s var(--ease), color .2s var(--ease);
}
.ctrl-btn:hover { background: var(--surface-3); color: var(--text); }
.ctrl-btn:active { transform: scale(.95); }

/* ---------- Call / Hang up ---------- */
.call-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.call-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; border: none; border-radius: var(--radius);
  color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .12s var(--ease), filter .2s var(--ease), box-shadow .2s var(--ease);
  box-shadow: var(--shadow-sm);
}
.call-btn:active { transform: scale(.97); }
.call-btn:disabled { opacity: .45; cursor: not-allowed; }
.call-btn--call { background: var(--green); }
.call-btn--call:hover:not(:disabled) { background: var(--green-dark); }
.call-btn--hangup { background: var(--red); }
.call-btn--hangup:hover:not(:disabled) { background: var(--red-dark); }
.call-btn--call.is-calling { animation: callPulse 1.1s infinite; }
@keyframes callPulse {
  0%   { box-shadow: 0 0 0 0 rgba(22,163,74,.45); }
  70%  { box-shadow: 0 0 0 14px rgba(22,163,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}

/* ---------- Recent calls / logs ---------- */
.recents__list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.recent {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; cursor: pointer;
  transition: background .2s var(--ease), transform .12s var(--ease);
}
.recent:hover { background: var(--surface-3); transform: translateX(2px); }
.recent__icon {
  display: grid; place-items: center; width: 36px; height: 36px; margin-top: 1px;
  border-radius: 10px; background: var(--surface-3); color: var(--text-dim); flex-shrink: 0;
}
.recent.is-success .recent__icon { color: var(--green); }
.recent.is-failed  .recent__icon { color: var(--red); }
.recent__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.recent__right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.recent__expand {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  cursor: pointer; transition: transform .2s var(--ease), background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.recent__expand:hover { color: var(--primary); border-color: var(--primary); }
.recent__expand.is-open { transform: rotate(180deg); color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.recent__details { display: none; }
.recent__details.is-open { display: flex; flex-direction: column; gap: 10px; margin-top: 2px; }
.recent__num { font-weight: 600; font-size: 15px; word-break: break-all; }
.recent__meta { font-size: 12px; color: var(--text-dim); margin-top: -5px; }
.recent__status {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-dim); white-space: nowrap;
}
.recent.is-success .recent__status { background: rgba(22,163,74,.14); color: var(--green); }
.recent.is-failed  .recent__status { background: rgba(220,38,38,.14); color: var(--red); }
.recents__empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 16px 0; }

/* Date group headers + load-more (Call Logs & Audit) */
.log-date {
  list-style: none; font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim); padding: 6px 2px 2px; margin-top: 4px;
}
.log-more { list-style: none; display: flex; justify-content: center; padding: 8px 0 2px; }
.load-more-btn {
  font-size: 13px; font-weight: 700; color: var(--primary);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 18px; cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease);
}
.load-more-btn:hover { background: var(--primary-soft); border-color: var(--primary); }

.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--primary);
  cursor: pointer; font-size: 13px; padding: 4px 8px; border-radius: 6px; font-weight: 600;
}
.link-btn:hover { background: var(--primary-soft); }
.link-btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.link-btn--danger { color: var(--red); }
.link-btn--danger:hover { background: rgba(255, 59, 48, .12); }

/* ---------- Contacts ---------- */
.contacts__search { margin-bottom: 2px; }
.contacts__add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.contacts__addbtn { padding: 0 18px; }
.contacts__list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.contact {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.contact__avatar {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.contact__body { flex: 1; min-width: 0; }
.contact__name { font-weight: 600; }
.contact__num { font-size: 13px; color: var(--text-dim); word-break: break-all; }
.contact__actions { display: flex; gap: 6px; }

/* ---------- Help ---------- */
.help { display: flex; flex-direction: column; gap: 10px; }
.help__title { font-size: 18px; font-weight: 700; }
.help__sub { font-size: 14px; font-weight: 700; color: var(--primary); margin-top: 8px; }
.help__text { color: var(--text-dim); font-size: 14px; }
.help__list { padding-left: 20px; color: var(--text-dim); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.help__list strong { color: var(--text); }
.help kbd {
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; font-size: 12px; color: var(--text);
}
.help__mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--primary); word-break: break-all; }

/* ---------- Settings panel ---------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  z-index: 90; opacity: 0; transition: opacity .25s var(--ease);
}
.scrim.is-open { opacity: 1; }
.scrim[hidden] { display: none; }
#navScrim { z-index: 110; }

.settings {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(400px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 100;
  transform: translateX(105%); transition: transform .3s var(--ease);
  display: flex; flex-direction: column;
}
.settings.is-open { transform: translateX(0); }
.settings__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px; border-bottom: 1px solid var(--border);
}
.settings__title { font-size: 18px; font-weight: 700; }
.settings__body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.settings__group {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--text-faint); margin-top: 4px; padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.settings__group:first-child { margin-top: 0; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.field__wrap { position: relative; display: flex; }
.field__input {
  width: 100%; padding: 11px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.field__input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field__input.is-invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
select.field__input { appearance: none; cursor: pointer; }
.field__reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 6px; color: var(--text-dim);
}
.field__reveal:hover { background: var(--surface-3); color: var(--text); }
/* Error line takes no space until it actually has a message. */
.field__error { font-size: 12px; color: var(--red); }
.field__error:empty { display: none; }

.settings__actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  flex: 1; padding: 12px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: transform .12s var(--ease), filter .2s var(--ease), background .2s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--ghost { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface); }
.settings__note { font-size: 12px; color: var(--text-faint); line-height: 1.5; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 500; display: flex; flex-direction: column; gap: 10px;
  width: min(360px, 92vw); pointer-events: none;
}
.toast {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px 15px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow);
  color: var(--text); font-size: 14px; font-weight: 500; pointer-events: auto;
  animation: toastIn .3s var(--ease);
}
.toast.is-out { animation: toastOut .3s var(--ease) forwards; }
.toast__icon { flex-shrink: 0; display: inline-flex; align-items: center; color: var(--text-dim); }
.toast__icon svg { display: block; }
.toast__msg { flex: 1; line-height: 1.35; }
.toast__close {
  flex-shrink: 0; display: inline-flex; line-height: 0;
  background: none; border: none; color: var(--text-faint); cursor: pointer;
  padding: 3px; border-radius: 7px;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.toast__close:hover { color: var(--text); background: var(--surface-2); }

/* Bottom countdown timer bar */
.toast__bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  transform-origin: left center; background: var(--blue);
  animation: toastBar linear forwards;
}
@keyframes toastBar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* Per-type accent: icon + timer bar (success = green, error = red) */
.toast--success .toast__icon { color: var(--green); }
.toast--success .toast__bar  { background: var(--green); }
.toast--error   .toast__icon { color: var(--red); }
.toast--error   .toast__bar  { background: var(--red); }
.toast--warning .toast__icon { color: var(--amber); }
.toast--warning .toast__bar  { background: var(--amber); }
.toast--info    .toast__icon { color: var(--blue); }
.toast--info    .toast__bar  { background: var(--blue); }

@keyframes toastIn  { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(16px); } }

/* ---------- Popup mode (Chrome extension) ---------- */
.popup-mode body { padding: 0; display: block; }
.popup-mode .app { width: 380px; max-width: 380px; border-radius: 0; border: none; box-shadow: none; }
.popup-mode .view { padding: 14px; gap: 14px; }
.popup-mode .header { padding: 12px 14px; }
.popup-mode .header__title { font-size: 15px; }
.popup-mode .display__input { font-size: 24px; }
.popup-mode .key__digit { font-size: 22px; }
.popup-mode .dialpad { gap: 10px; }
.popup-mode .settings, .popup-mode .drawer { width: 100%; }
.popup-mode .contacts__add { grid-template-columns: 1fr 1fr; }
.popup-mode .contacts__addbtn { grid-column: 1 / -1; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  body { padding: 0; }
  .app { border-radius: 0; border: none; min-height: 100vh; }
  .contacts__add { grid-template-columns: 1fr 1fr; }
  .contacts__addbtn { grid-column: 1 / -1; }
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Clock bar region (state/timezone) selector ---------- */
.clockbar__region {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 45%;
}
.clockbar__region[hidden] { display: none; }
.clockbar__region:focus { outline: none; border-color: var(--primary); }

/* ---------- Drawer brand header (replaces profile block) ---------- */
.drawer__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}
.drawer__brandicon {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff; flex-shrink: 0;
}
.drawer__brandname { font-size: 16px; font-weight: 700; }

/* ============================================================
   APPLE REDESIGN  (overrides — loaded last so these win)
   Apple-blue accent, SF system font, frosted-glass left rail.
   ============================================================ */

/* ---- Accent + font tokens ---- */
:root, [data-theme="light"] {
  --primary:      #007AFF;   /* Apple blue */
  --primary-dark: #0062CC;
  --primary-soft: rgba(0,122,255,.12);
  --ripple:       rgba(0,122,255,.18);
  --glass:        rgba(255,255,255,.62);
  --glass-brd:    rgba(255,255,255,.55);
  --glass-shadow: 0 10px 30px rgba(20,30,60,.14);
  --page-a:       #eef2f8;
  --page-b:       #e6ecf6;
}
[data-theme="dark"] {
  --primary:      #0A84FF;   /* Apple blue (dark) */
  --primary-dark: #0060df;
  --primary-soft: rgba(10,132,255,.18);
  --ripple:       rgba(10,132,255,.30);
  --glass:        rgba(28,30,34,.55);
  --glass-brd:    rgba(255,255,255,.10);
  --glass-shadow: 0 10px 30px rgba(0,0,0,.45);
  --page-a:       #0d0f13;
  --page-b:       #14171d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 600px at 12% 10%, rgba(0,122,255,.10), transparent 60%),
    radial-gradient(800px 600px at 90% 90%, rgba(90,200,250,.10), transparent 55%),
    linear-gradient(160deg, var(--page-a), var(--page-b));
  background-attachment: fixed;
  padding-left: 96px;   /* room for the floating rail */
}

/* ---- Floating glass rail ---- */
.rail {
  position: fixed;
  left: 16px; top: 50%; transform: translateY(-50%);
  z-index: 120;
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  padding: 10px 8px;
  width: 60px;
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  border-radius: 22px;
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
}
.rail__brand {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  color: #fff; background: var(--primary);
  margin-bottom: 4px;
}
.rail__menu { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; width: 100%; align-items: center; }

.rail__item, .rail__theme {
  position: relative;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: none; background: transparent;
  color: var(--text-dim);
  border-radius: 14px;
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease), transform .12s var(--ease);
}
.rail__item:hover, .rail__theme:hover { background: var(--primary-soft); color: var(--primary); }
.rail__item:active, .rail__theme:active { transform: scale(.92); }
.rail__item.is-active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(0,122,255,.35); }
.rail__item:focus-visible, .rail__theme:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.rail__footer { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--glass-brd); width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* Signed-in user avatar pinned to the bottom of the rail */
.rail__user {
  position: relative;
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 14px;
  cursor: default;
}
.rail__user .userchip__avatar { width: 32px; height: 32px; font-size: 13px; }
.rail__user .userchip__dot {
  position: absolute; top: 5px; right: 5px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface);
}

/* Hover-to-reveal label (glass tooltip to the right) */
.rail__item::after, .rail__theme::after, .rail__brand::after, .rail__user::after {
  content: attr(data-label);
  position: absolute; left: calc(100% + 14px); top: 50%; transform: translateY(-50%) scale(.96);
  white-space: nowrap;
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--glass-brd);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  box-shadow: var(--glass-shadow);
  padding: 7px 11px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .15s var(--ease), transform .15s var(--ease);
}
.rail__item:hover::after, .rail__theme:hover::after, .rail__brand:hover::after, .rail__user:hover::after,
.rail__item:focus-visible::after, .rail__theme:focus-visible::after {
  opacity: 1; transform: translateY(-50%) scale(1);
}
/* Show correct sun/moon inside the rail toggle */
.rail__theme .icon { display: none; }
[data-theme="light"] .rail__theme .icon-moon { display: block; }
[data-theme="dark"]  .rail__theme .icon-sun  { display: block; }

/* ---- Glass header + panels ---- */
.header {
  background: transparent;
  border-bottom: 1px solid var(--border);
}
.settings {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}

/* Slightly translucent app card so the glass theme reads through */
.app {
  background: var(--surface);
  border-radius: 22px;
}

/* ---- Responsive: keep the rail, tighten spacing ---- */
@media (max-width: 560px) {
  body { padding-left: 80px; }
  .rail { left: 10px; width: 54px; }
  .rail__item, .rail__theme { width: 40px; height: 40px; }
}

/* ============================================================
   SETTINGS PANEL — solid right sidebar (desktop) + centered modal (mobile)
   ============================================================ */

/* Desktop: clear, solid right-hand sidebar (glass tint, readable). */
.settings {
  background: var(--surface);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px rgba(20,30,60,.18);
  z-index: 130;                 /* above the left rail (120) */
}
#settingsScrim { z-index: 125; }

/* Mobile: open as a centered modal card instead of a side sheet. */
@media (max-width: 560px) {
  .settings {
    top: 50%; left: 50%; right: auto;
    height: auto; max-height: 86vh;
    width: min(440px, 92vw);
    border: 1px solid var(--glass-brd);
    border-radius: 20px;
    box-shadow: var(--glass-shadow);
    transform: translate(-50%, -50%) scale(.96);
    opacity: 0; visibility: hidden;
    transition: transform .25s var(--ease), opacity .25s var(--ease), visibility .25s var(--ease);
  }
  .settings.is-open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1; visibility: visible;
  }
  .settings__body { flex: 1; overflow-y: auto; }
}

/* ============================================================
   TOASTS — top-right, slide in from right, slide out to right
   (glass style, stacked). Overrides the earlier centered toasts.
   ============================================================ */
.toasts {
  top: 20px; right: 20px;
  bottom: auto; left: auto;
  transform: none;
  align-items: flex-end;
  width: min(360px, calc(100vw - 40px));
}
.toast {
  width: 100%;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--glass-shadow);
  animation: toastInRight .32s var(--ease);
}
.toast.is-out { animation: toastOutRight .3s var(--ease) forwards; }

@keyframes toastInRight {
  from { opacity: 0; transform: translateX(120%); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOutRight {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(120%); }
}

@media (max-width: 560px) {
  .toasts { top: 12px; right: 12px; width: calc(100vw - 24px); }
}

/* ============================================================
   NEW FEATURES — balance, live call bar, log meta, switch, export
   ============================================================ */

/* Balance chip in the header */
.balance {
  font-size: 12px; font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 6px 10px; border-radius: 999px;
  white-space: nowrap;
}
.balance[hidden] { display: none; }

/* Daily call-limit usage chip (between balance and status) */
.usage {
  font-size: 12px; font-weight: 700;
  color: var(--text-dim, #6b7280);
  background: var(--surface-2, rgba(120,120,128,0.12));
  border: 1px solid var(--border, rgba(120,120,128,0.24));
  padding: 6px 10px; border-radius: 999px;
  white-space: nowrap;
}
.usage--warn { color: #b26a00; background: rgba(255,159,10,0.14); border-color: rgba(255,159,10,0.35); }
.usage--full { color: #c0392b; background: rgba(255,59,48,0.14); border-color: rgba(255,59,48,0.35); }
.usage[hidden] { display: none; }

/* Live call status bar */
.callbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  border: 1px solid var(--border);
  color: var(--primary);
  font-weight: 700; font-size: 14px;
}
.callbar[hidden] { display: none; }
.callbar__pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(52,199,89,.5);
  animation: callDot 1.4s infinite;
}
.callbar__state { flex: 1; }
.callbar__timer { font-variant-numeric: tabular-nums; color: var(--text); }
@keyframes callDot {
  0%   { box-shadow: 0 0 0 0 rgba(52,199,89,.5); }
  70%  { box-shadow: 0 0 0 8px rgba(52,199,89,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,199,89,0); }
}

/* Logs: right-side actions + save-to-contacts */
.section-head__actions { display: flex; gap: 6px; align-items: center; }
.recent__right { display: flex; align-items: center; gap: 8px; }
.recent__save {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.recent__save:hover { background: var(--primary-soft); color: var(--primary); }

/* Settings switch row */
.field--switch {
  flex-direction: row; align-items: center; justify-content: space-between;
}
.switch {
  -webkit-appearance: none; appearance: none;
  width: 44px; height: 26px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border);
  position: relative; cursor: pointer; flex-shrink: 0;
  transition: background .2s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .2s var(--ease);
}
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { transform: translateX(18px); }

/* Call-log duration + cost line (shown on every row) */
.recent__pending {
  font-size: 10.5px;
  font-weight: 400;
  font-style: italic;
  color: var(--text-dim);
  opacity: .7;
}

.field__hint { display: block; font-size: 11px; font-weight: 400; color: var(--text-dim); margin-top: 2px; max-width: 260px; }

/* Recording player + transcript */
.recent__media { margin-top: 2px; display: flex; flex-direction: column; gap: 8px; }
.recent__audio { width: 100%; max-width: 340px; height: 34px; }

/* Compact media toggles (Audio / Transcript / AI summary) */
.media-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.media-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.media-btn svg { flex: 0 0 auto; }
.media-btn:hover { border-color: var(--primary); color: var(--primary); }
.media-btn.is-active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.media-chip { font-size: 11px; font-style: italic; color: var(--text-dim); opacity: .75; padding: 4px 2px; }

.media-panels { display: flex; flex-direction: column; gap: 8px; }
.media-panel { display: none; }
.media-panel.is-open { display: block; position: relative; }

/* Icon-only copy button pinned to the card's top-right */
.panel-copy {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim); cursor: pointer;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.panel-copy:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.panel-action {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px;
  padding: 5px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--primary); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s var(--ease);
}
.panel-action:hover { background: var(--primary-soft); }

/* ===== Transcript = two-sided chat ===== */
.media-panel--transcript .recent__transcript-text {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; margin: 0;
  padding: 12px 40px 12px 12px;
  max-height: 300px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.tx-line { display: flex; flex-direction: column; gap: 3px; max-width: 86%; margin: 0; }
.tx-line--a { align-self: flex-start; align-items: flex-start; }
.tx-line--b { align-self: flex-end; align-items: flex-end; }
.tx-who { font-size: 11px; font-weight: 700; padding: 0 6px; }
.tx-line--a .tx-who { color: var(--primary); }
.tx-line--b .tx-who { color: #0d9488; }
.tx-msg { font-size: 13px; line-height: 1.45; padding: 8px 12px; border-radius: 14px; color: var(--text); }
.tx-line--a .tx-msg { background: var(--primary-soft); border-bottom-left-radius: 4px; }
.tx-line--b .tx-msg { background: rgba(13, 148, 136, .13); border-bottom-right-radius: 4px; }
.tx-line--plain { max-width: 100%; color: var(--text-dim); font-size: 12.5px; }

/* ===== AI summary = violet insight card ===== */
.media-panel--summary {
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.summary-head {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; background: var(--primary);
}
.summary-head svg { width: 14px; height: 14px; fill: #fff; flex: 0 0 auto; }
.media-panel--summary .recent__summary-text {
  background: var(--surface); border: none; border-radius: 0; margin: 0;
  padding: 12px 14px;
  font-size: 13px; line-height: 1.6; color: var(--text); white-space: pre-wrap;
}
.media-panel--summary .panel-copy {
  top: 7px; right: 8px;
  background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .45); color: #fff;
}
.media-panel--summary .panel-copy:hover { background: rgba(255, 255, 255, .32); border-color: #fff; color: #fff; }

/* Redial button (inside the opened card) */
.recent__redial {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--green); color: #fff; font-size: 12px; font-weight: 700;
  transition: filter .15s var(--ease), transform .12s var(--ease);
}
.recent__redial:hover { filter: brightness(1.07); }
.recent__redial:active { transform: scale(.96); }
.recent__summary {
  border: 1px solid var(--primary); border-radius: 10px;
  background: var(--primary-soft); padding: 9px 11px;
}
.recent__summary-h {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; color: var(--primary); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: .03em;
}
.recent__summary-h svg { flex: 0 0 auto; }
.recent__summary-text { font-size: 12.5px; font-weight: 400; color: var(--text); line-height: 1.5; white-space: pre-wrap; }

.recent__transcript { font-size: 12px; }
.recent__transcript > summary {
  cursor: pointer; color: var(--primary); font-weight: 600;
  list-style: none; display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 0; user-select: none;
}
.transcript__icon { flex: 0 0 auto; }
.transcript__copy {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px; padding: 3px; border: none; background: none; line-height: 0;
  color: var(--text-dim); cursor: pointer; border-radius: 5px;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.transcript__copy:hover { color: var(--primary); background: var(--primary-soft); }
.transcript__copy:active { transform: scale(.9); }

/* ---------- Call outcome (disposition) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0, 0, 0, .4);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal__card {
  width: min(420px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 20px;
}
.modal__title { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.modal__sub { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dispo__tags { display: flex; flex-wrap: wrap; gap: 8px; }
.dispo__tag {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.dispo__tag:hover { border-color: var(--primary); }
.dispo__tag.is-selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.dispo__note {
  width: 100%; margin-top: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 13px; font-family: inherit; resize: vertical;
}

/* WhatsApp send modal */
.modal__card--wide { width: min(480px, 100%); max-height: 88vh; overflow-y: auto; }
.wa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.wa-grid .field, .wa-params .field { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.wa-grid .field__label, .wa-params .field__label { font-size: 12px; color: var(--text-dim); }
#waModal .field__input { width: 100%; }
.wa-params { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 2px; }
.wa-note { font-size: 12px; color: var(--text-dim); margin: 4px 0; }

/* WhatsApp delivery-status badge (Logs + Audit) */
.wa-status-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wa-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; border: 1px solid;
}
.wa-status--ok      { color: #137a3a; background: rgba(52,199,89,.14);  border-color: #137a3a; }
.wa-status--sent    { color: var(--primary); background: var(--primary-soft); border-color: var(--primary); }
.wa-status--pending { color: #b26a00; background: rgba(255,159,10,.14); border-color: #b26a00; }
.wa-status--fail    { color: #c0392b; background: rgba(255,59,48,.14);  border-color: #c0392b; }
.wa-tpl { font-size: 11px; color: var(--text-dim); }

.recent__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.recent__wa {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer;
  background: #25d366; color: #fff; font-size: 12px; font-weight: 700;
  transition: filter .15s var(--ease), transform .12s var(--ease);
}
.recent__wa:hover { filter: brightness(1.05); }
.recent__wa:active { transform: scale(.96); }

.recent__dispo { margin-top: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.dispo-badge {
  font-size: 11px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); padding: 3px 9px; border-radius: 999px;
}
.dispo-edit {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: none; border: none; cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.dispo-edit svg { flex: 0 0 auto; }
.dispo-edit:hover { background: var(--primary-soft); }
.recent__note {
  flex-basis: 100%; font-size: 12px; color: var(--text-dim); font-weight: 400; line-height: 1.45;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
}

/* ---------- User management (admin) ---------- */
.user-add { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; margin-bottom: 12px; }
/* ---------- Analytics (admin) ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat-card__value { font-size: 22px; font-weight: 800; color: var(--text); }
.stat-card__label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.analytics__h { font-size: 14px; font-weight: 700; margin: 18px 0 8px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 6px 0; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar__fill { width: 60%; min-height: 4px; background: var(--primary); border-radius: 5px 5px 0 0; }
.bar__label { font-size: 9px; color: var(--text-dim); }
.bar__val { font-size: 10px; font-weight: 700; color: var(--text-dim); }
.table-wrap { overflow-x: auto; }
.atable { width: 100%; border-collapse: collapse; font-size: 13px; }
.atable th, .atable td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.atable th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-dim); }
@media (max-width: 560px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }

.logs-filter { display: grid; grid-template-columns: 1fr 190px; gap: 8px; }
.logs-filter--audit { grid-template-columns: 1fr 116px 104px; }
@media (max-width: 560px) { .logs-filter, .logs-filter--audit { grid-template-columns: 1fr; } }

/* Custom chevron for dropdowns */
select.field__input {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* Admin tag manager (Settings) */
.dispo-admin__list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.dispo-admin__item {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 6px 5px 12px; font-size: 13px; font-weight: 600;
}
.dispo-admin__rm {
  border: none; background: none; color: var(--text-dim); cursor: pointer;
  font-size: 16px; line-height: 1; width: 20px; height: 20px; border-radius: 50%;
}
.dispo-admin__rm:hover { background: rgba(255, 59, 48, .14); color: var(--red); }
.dispo-admin__item--base { background: var(--surface); color: var(--text-dim); }
.dispo-admin__tag { font-size: 11px; font-style: normal; color: var(--text-dim); opacity: .8; padding-right: 6px; }
.dispo-admin__editable { cursor: text; border-bottom: 1px dashed transparent; }
.dispo-admin__item:hover .dispo-admin__editable { border-bottom-color: var(--border); }
.dispo-admin__edit {
  min-width: 140px; padding: 4px 8px; font-size: 13px; font-weight: 600;
  border-radius: 8px;
}
.dispo-admin__add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.users__list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.user-row.is-disabled { opacity: .55; }
.user-row__avatar {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; flex-shrink: 0;
}
.user-row__info { flex: 1; min-width: 0; }
.user-row__name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.user-row__sub { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.tfa-pill { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.tfa-pill--on  { background: rgba(52, 199, 89, .16);  color: #1a7f37; border-color: #1a7f37; }
.tfa-pill--off { background: rgba(255, 59, 48, .14);  color: #c0392b; border-color: #c0392b; }
.user-row__badge { font-size: 10px; font-weight: 700; color: var(--primary); background: var(--primary-soft); padding: 2px 7px; border-radius: 999px; }
.user-row__badge--off { color: var(--red); background: rgba(255, 59, 48, .12); }
.user-row__actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-row__btn {
  font-size: 12px; font-weight: 600; color: var(--primary);
  background: none; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; cursor: pointer;
}
.user-row__btn:hover { background: var(--primary-soft); border-color: var(--primary); }
@media (max-width: 560px) {
  .user-add { grid-template-columns: 1fr 1fr; }
  .user-row { flex-wrap: wrap; }
  .user-row__actions { flex-basis: 100%; justify-content: flex-end; }
}
.recent__transcript[open] > summary { margin-bottom: 4px; }
.recent__transcript-text {
  font-weight: 400; color: var(--text); line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; white-space: pre-wrap;
  max-height: 180px; overflow-y: auto;
}
.recent__stats {
  margin-top: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   SCROLLING — let the view area scroll inside the card
   ============================================================ */
.app {
  max-height: calc(100vh - 48px);   /* fit within viewport (body has 24px padding) */
}
.main {
  flex: 1 1 auto;
  min-height: 0;                     /* required so a flex child can scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.header { flex: 0 0 auto; }          /* header stays put while views scroll */

/* Keep the Call / Hang Up buttons reachable without scrolling */
#view-dialpad .call-controls {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--surface);
  margin: 0 -18px;                   /* span the view's horizontal padding */
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 6px);
  box-shadow: 0 -10px 14px -10px rgba(0, 0, 0, .18);
}

@media (max-width: 480px) {
  .app { max-height: 100vh; }
}

/* ============================================================
   USER PICKER (multi-user)
   ============================================================ */
.userpick { position: relative; }
.userpick__btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer; color: var(--text);
  transition: background .18s var(--ease);
}
.userpick__btn:hover { background: var(--surface-3); }
.userpick__avatar {
  display: grid; place-items: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 15px;
}
.userpick__avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.userpick__info { display: flex; flex-direction: column; align-items: flex-start; flex: 1; min-width: 0; }
.userpick__name { font-weight: 600; font-size: 14px; }
.userpick__mobile { font-size: 12px; color: var(--text-dim); }
.userpick__caret { color: var(--text-dim); font-size: 12px; }

.userpick__list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto;
}
.userpick__list[hidden] { display: none; }
.userpick__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.userpick__item:hover { background: var(--surface-3); }
.userpick__item.is-active { background: var(--primary-soft); }
.userpick__del {
  display: grid; place-items: center; width: 28px; height: 28px;
  border: none; background: transparent; color: var(--text-faint);
  border-radius: 7px; cursor: pointer;
}
.userpick__del:hover { background: rgba(220,38,38,.12); color: var(--red); }
.userpick__add {
  padding: 10px; border-radius: 8px; cursor: pointer;
  color: var(--primary); font-weight: 700; font-size: 14px;
  border-top: 1px solid var(--border); margin-top: 4px;
}
.userpick__add:hover { background: var(--primary-soft); }

/* ============================================================
   AUTH — login overlay + current-user chip
   ============================================================ */
.login {
  position: fixed; inset: 0; z-index: 300;
  display: grid; place-items: center;
  background: rgba(15,20,35,.55);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  padding: 20px;
}
.login[hidden] { display: none; }
.login__card {
  width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--glass-brd);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 26px 22px;
  text-align: center;
}
.login__logo {
  width: 52px; height: 52px; border-radius: 15px;
  display: grid; place-items: center; margin: 0 auto;
  background: var(--primary); color: #fff;
}
.login__title { font-size: 19px; font-weight: 700; }
.login__sub { font-size: 13px; color: var(--text-dim); margin-top: -6px; }
.login .field { text-align: left; }
.login__submit { margin-top: 6px; }
.login__err { min-height: 16px; font-size: 13px; color: var(--red); }

/* Current-user chip on the dialpad */
.userchip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.userchip__avatar {
  display: grid; place-items: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 15px;
}
.userchip__info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.userchip__name { font-weight: 600; font-size: 14px; }
.userchip__mobile { font-size: 12px; color: var(--text-dim); }
.userchip__badge {
  font-size: 11px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); padding: 3px 9px; border-radius: 999px;
}

/* Logout button in the rail — red accent */
#logoutBtn { color: var(--red); }
#logoutBtn:hover { background: rgba(220,38,38,.12); color: var(--red); }

/* Settings is now a normal page/view, not a slide-out panel */
#view-settings .settings__body { padding: 0; gap: 14px; }

/* Ensure hidden rail items (e.g. admin-only Audit) actually hide —
   .rail__item sets display:grid which otherwise overrides [hidden]. */
.rail__item[hidden] { display: none !important; }

/* 2FA enrollment QR */
.login__qr {
  display: grid; place-items: center;
  padding: 12px; margin: 4px auto;
  background: #fff; border-radius: 12px; border: 1px solid var(--border);
  width: max-content;
}
.login__qr img, .login__qr canvas { display: block; }
.login__secret { font-size: 12px; color: var(--text-dim); }
.login__secret code { font-family: ui-monospace, Menlo, monospace; color: var(--text); word-break: break-all; }

/* Only one login card visible at a time (display:flex was overriding [hidden]) */
.login__card[hidden] { display: none !important; }

/* ============================================================
   MOBILE: move the left rail to a bottom tab bar
   ============================================================ */
@media (max-width: 560px) {
  body { padding: 0 0 68px 0; }              /* room for the bottom bar */

  .app {
    max-width: 100%;
    max-height: calc(100vh - 68px);
    border-radius: 0;
    border: none;
  }

  /* Rail -> fixed bottom bar */
  .rail {
    top: auto; bottom: 0; left: 0; right: 0;
    transform: none;
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 2px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
  }
  .rail__brand { display: none; }            /* no room for the logo on mobile */
  .rail__menu {
    flex-direction: row;
    justify-content: space-around;
    gap: 2px;
    flex: 1;
    overflow: visible;
  }
  .rail__footer {
    flex-direction: row;
    border-top: none;
    margin: 0; padding: 0;
    width: auto;
    gap: 2px;
  }
  .rail__item, .rail__theme { width: 46px; height: 46px; }

  /* Tooltips don't make sense on touch — hide the hover labels */
  .rail__item::after, .rail__theme::after, .rail__brand::after, .rail__user::after { display: none !important; }
}
