/* =====================================================================
   Dialer page
   --call-panel-h = how much of the bottom of the screen the call panel takes
   (set by dialer.js); the list, the script, the lead panel and messages keep clear of it.
   Layers: script 85 < lead panel 90 < call panel 94 < booking form 95 < messages 200.
   ===================================================================== */
:root { --call-panel-h: 0px; }
/* While the call panel is docked (on any page, a call carries on when you switch page),
   every page gets room at the bottom so its last rows can scroll clear of the panel. */
body.dl-docked .main { padding-bottom: calc(var(--call-panel-h) + 1rem); }

/* ---------- today's numbers ---------- */
.dl-stats { display: grid; grid-template-columns: minmax(250px, 1.5fr) repeat(4, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 1.2rem; }
.dl-ring-card { display: flex; align-items: center; gap: 1rem; }
.dl-ring { position: relative; width: 5.2rem; height: 5.2rem; flex: none; }
.dl-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dl-ring circle { fill: none; stroke-width: 3.6; }
.dl-ring .track { stroke: rgba(255, 255, 255, 0.08); }
.dl-ring .fill { stroke: var(--accent-bright); stroke-linecap: round; transition: stroke-dashoffset 0.6s ease, stroke 0.3s; }
.dl-ring.done .fill { stroke: var(--green); }
.dl-ring-num { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.05; }
.dl-ring-num b { font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.dl-ring-num small { font-size: 0.7rem; color: var(--muted); }
.dl-goal-note { font-size: 0.95rem; font-weight: 700; margin-top: 0.15rem; }
.dl-goal-note.done { color: var(--green); }
.dl-bar { height: 5px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-top: 0.55rem; }
.dl-bar i { display: block; height: 100%; border-radius: inherit; background: var(--teal); }

.dl-goal-form { display: flex; align-items: center; gap: 0.45rem; }
.dl-goal-form input { width: 5.5rem; padding: 0.4rem 0.55rem; }

.dl-note { margin-bottom: 1rem; font-size: 0.88rem; color: var(--text-soft); }
.dl-note span { display: block; margin-top: 0.3rem; }

/* ---------- tabs ---------- */
.dl-tabs { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: rgba(5, 10, 28, 0.6);
           border: 1px solid var(--border-strong); }
.dl-tabs button { padding: 0.38rem 0.8rem; border: 0; border-radius: 8px; background: none; color: var(--text-soft);
                  font: inherit; font-size: 0.84rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.dl-tabs button b { margin-left: 0.25rem; color: var(--muted); font-weight: 700; }
.dl-tabs button:hover { color: var(--text); }
.dl-tabs button[aria-selected="true"] { background: var(--accent-soft); color: #fff; box-shadow: inset 0 0 0 1px rgba(77, 155, 255, 0.5); }
.dl-tabs button[aria-selected="true"] b { color: var(--accent-bright); }
.dl-booked { font-size: 0.82rem; font-weight: 600; color: var(--blue); white-space: nowrap; }
.dl-toolbar .search { flex: 1 1 220px; }

/* ---------- the list ---------- */
.dialer-table { min-width: 820px; }
.dialer-table td { padding: 0.6rem 0.9rem; }
.dialer-table tr { scroll-margin-top: 6rem; scroll-margin-bottom: calc(var(--call-panel-h) + 1rem); }
.dialer-table tr.on-call td { background: rgba(47, 214, 123, 0.07); }
.dialer-table tr.on-call td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.dialer-table tr.dnc .lead-name { color: var(--text-soft); }
.dl-phone { display: flex; align-items: center; gap: 0.6rem; }
.dl-call { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; flex: none; padding: 0; border-radius: 50%;
           border: 1px solid rgba(47, 214, 123, 0.5); background: var(--green-soft); color: var(--green); cursor: pointer;
           transition: background 0.15s, color 0.15s; }
.dl-call:hover:not(:disabled) { background: var(--green); color: #04220f; }
.dl-call:disabled { opacity: 0.35; cursor: not-allowed; }
.dl-call svg { width: 1rem; height: 1rem; }
/* the lead's own local time; greyed rows are outside their calling hours (auto-dial skips them) */
.dl-local { display: block; margin-top: 0.25rem; font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.dl-local.off { color: var(--amber); font-weight: 600; }
.dl-local.unknown { font-style: italic; }
.dialer-table tr.off-hours td:not(:nth-child(4)) { opacity: 0.55; }
.dialer-table tr.off-hours .dl-call { border-color: var(--border-strong); background: none; color: var(--muted); }

/* ---------- the call panel ---------- */
.dl-panel { position: fixed; z-index: 94; left: calc(var(--sidebar-w) + 1rem); right: 1rem; bottom: 1rem;
            max-height: calc(100vh - 2rem); overflow-y: auto;
            padding: 0.9rem 1.1rem; border-radius: var(--radius); background: var(--panel-solid);
            border: 1px solid var(--border-strong); box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5); }
.dl-panel.ringing, .dl-panel.connecting { border-color: rgba(77, 155, 255, 0.6); }
.dl-panel.live { border-color: rgba(47, 214, 123, 0.6); }
.dl-panel.ended { border-color: rgba(243, 181, 63, 0.6); }
.dl-panel-top, .dl-idle { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; flex-wrap: wrap; }
.dl-who { flex: 1 1 280px; min-width: 0; }
.dl-state { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.55rem; font-size: 0.85rem; font-weight: 700; color: var(--text-soft); }
.dl-state .pill { font-size: 0.7rem; }
.dl-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--grey); flex: none; }
.connecting .dl-dot, .ringing .dl-dot { background: var(--blue); animation: dl-pulse 1s ease-in-out infinite; }
.live .dl-dot { background: var(--green); }
.ended .dl-dot { background: var(--amber); }
.idle .dl-dot { background: var(--accent-bright); }
@keyframes dl-pulse { 50% { opacity: 0.3; } }
#dl-timer { font-family: var(--mono); font-size: 1.05rem; font-variant-numeric: tabular-nums; color: var(--text); }
.live #dl-timer { color: var(--green); }
.dl-countdown { min-width: 2.2rem; text-align: right; }
.dl-name { display: block; max-width: 100%; margin-top: 0.15rem; font-size: 1.2rem; font-weight: 800;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-who-sub { font-size: 0.82rem; color: var(--text-soft); font-family: var(--mono); overflow-wrap: anywhere; }
.dl-who-sub .muted { font-family: var(--font); }
.dl-next { margin: 0.35rem 0 0; font-size: 0.84rem; color: var(--muted); }
.dl-next:empty { display: none; }
.dl-numbers { margin: 0.25rem 0 0; }
.dl-controls { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.dl-hangup { background: var(--red); border-color: var(--red); color: #fff; }
.dl-hangup:hover:not(:disabled) { background: #ff7a8f; }
.dl-results { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
.dl-results .pill-btn { padding: 0.55rem 0.95rem; font-size: 0.86rem; }
.ended .dl-results .pill-btn { box-shadow: 0 0 0 1px rgba(243, 181, 63, 0.25); }

/* a small on/off switch */
.dl-switch { display: inline-flex; align-items: center; gap: 0.45rem; margin-right: 0.2rem; font-size: 0.82rem; cursor: pointer; }
.dl-switch input { appearance: none; -webkit-appearance: none; position: relative; width: 2.1rem; height: 1.2rem; margin: 0;
                   padding: 0; border-radius: 99px; background: rgba(255, 255, 255, 0.12); border: 1px solid var(--border-strong);
                   cursor: pointer; transition: background 0.15s; }
.dl-switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 0.8rem; height: 0.8rem; border-radius: 50%;
                          background: #fff; transition: transform 0.15s; }
.dl-switch input:checked { background: var(--accent); border-color: var(--accent-bright); }
.dl-switch input:checked::after { transform: translateX(0.88rem); }

/* the call script, over the list and always above the call panel */
.dl-script { position: fixed; z-index: 85; left: calc(var(--sidebar-w) + 1rem); right: 1rem; top: 1rem;
             bottom: calc(var(--call-panel-h) + 0.6rem); overflow: auto; border-radius: var(--radius);
             background: var(--panel-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.has-banner .dl-script { top: 3rem; }

/* keep the lead panel and messages clear of the call panel */
body.dl-docked .drawer, body.dl-docked .drawer-backdrop { bottom: var(--call-panel-h); }
body.dl-docked .toasts { bottom: calc(var(--call-panel-h) + 0.6rem); }
/* While the booking form is open its Save button sits just above the call panel, where
   messages normally go: move them to the top, and let taps on plain messages fall
   through, so a message can never be tapped instead of the form. */
body.dl-docked.bk-open .toasts { top: 0.6rem; bottom: auto; }
body.dl-docked.bk-open .toast:not(.has-action) { pointer-events: none; }

/* ---------- phones and small screens ---------- */
@media (max-width: 1100px) {
  .dl-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dl-ring-card { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  .dl-stats { gap: 0.6rem; }
  .dl-ring { width: 4.4rem; height: 4.4rem; }
  .dl-toolbar .dl-tabs { width: 100%; }
  .dl-tabs { min-width: 0; max-width: 100%; }
  .dl-tabs button { flex: 1 1 0; min-width: 0; padding: 0.38rem 0.4rem; overflow: hidden; text-overflow: ellipsis; }
  .dl-tabs button b { margin-left: 0.15rem; }
  .dl-toolbar select { flex: 1 1 auto; }
  .dl-panel { left: 0; right: 0; bottom: 0; max-height: 70vh; padding: 0.7rem 0.8rem calc(0.7rem + env(safe-area-inset-bottom));
              border-radius: 14px 14px 0 0; border-left: none; border-right: none; border-bottom: none; }
  .dl-who { flex-basis: 100%; }
  .dl-name { font-size: 1.05rem; }
  .dl-panel-top .dl-controls { width: 100%; }
  .dl-panel-top .dl-controls .btn { flex: 1 1 0; }
  .dl-idle .dl-controls { width: 100%; justify-content: flex-end; }
  .dl-idle .dl-controls .btn { flex: 1 1 auto; }
  .dl-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: 0.4rem; margin-top: 0.55rem; }
  .dl-results .pill-btn { padding: 0.55rem 0.4rem; font-size: 0.8rem; }
  .dl-script { left: 0.5rem; right: 0.5rem; top: 0.5rem; }
  .has-banner .dl-script { top: 2.5rem; }
}

@media (max-width: 600px) {
  .dialer-table { min-width: 700px; }
  .dialer-table th:first-child, .dialer-table td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--panel-solid);
    min-width: 9.5rem; max-width: 11rem; box-shadow: 1px 0 0 var(--border);
  }
  .dialer-table tr.on-call td:first-child { background: #12304a; }
  .dl-stats .stat-value { font-size: 1.4rem; }
  .dl-numbers { display: none; }
}

/* AI call notes on the call panel (the switch's own look is in callnotes.css) */
.dl-controls .cn-box, .dl-controls .cn-status { margin-right: 0.35rem; }
