/* =====================================================================
   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; }
.dl-ofcom-warn { border-color: var(--amber); background: var(--amber-soft); color: var(--text); }  /* Ofcom: auto-dial paused */

/* ---------- 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(255, 107, 51, 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(255, 107, 51, 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); }

/* research from an uploaded file: who to ask for, and the opener (folds away) */
.dl-research { margin-top: 0.55rem; padding-top: 0.5rem; border-top: 1px solid var(--border); display: grid; gap: 0.3rem; }
.dl-ask { margin: 0; font-size: 0.88rem; overflow-wrap: anywhere; }
.dl-ask-label { color: var(--muted); font-weight: 600; }
.dl-opener summary { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; cursor: pointer; font-size: 0.85rem;
                     list-style: none; }
.dl-opener summary::-webkit-details-marker { display: none; }
.dl-opener summary::before { content: "\25B8"; color: var(--muted); font-size: 0.75rem; transition: transform 0.15s; }
.dl-opener[open] summary::before { transform: rotate(90deg); }
.dl-opener-label { flex: none; color: var(--muted); font-weight: 600; }
.dl-opener-peek { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); }
.dl-opener[open] .dl-opener-peek { display: none; }
.dl-opener p { margin: 0.35rem 0 0.4rem; padding: 0.55rem 0.75rem; max-height: 9.5rem; overflow-y: auto;
               border-left: 3px solid var(--accent-bright); border-radius: var(--radius-sm); background: var(--panel);
               font-size: 0.9rem; line-height: 1.45; }

/* 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; }

/* Loudspeaker button: highlighted while on */
.dl-speaker.on { background: var(--accent, #3b82f6); color: #fff; border-color: transparent; }

/* Phones: the call panel stays small while a call is on so the script keeps the screen.
   "Results" opens the rest; it opens by itself when the call ends. */
.dl-size { display: none; }
@media (max-width: 860px) {
  .dl-panel { max-height: 48vh; overflow-y: auto; padding-top: 0.55rem; }
  .dl-panel .dl-who-sub { font-size: 0.78rem; }
  .dl-panel-top .dl-controls { gap: 0.35rem; }
  .dl-panel-top .dl-controls .btn { padding: 0.42rem 0.45rem; font-size: 0.8rem; min-width: 0; }
  .dl-controls .dl-switch span { font-size: 0.78rem; }
  .dl-size { display: inline-flex; }
  .dl-panel.small .dl-results, .dl-panel.small .dl-next, .dl-panel.small .dl-research { display: none; }
  .dl-results { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.35rem; }
  .dl-results .pill-btn { padding: 0.5rem 0.25rem; font-size: 0.76rem; }
  .dl-script { top: 0.4rem; left: 0.4rem; right: 0.4rem; font-size: 0.95rem; }
}

.dl-short { display: none; }
@media (max-width: 860px) {
  .dl-long { display: none; }
  .dl-short { display: inline; }
  /* one tidy row of equal buttons; the two switches sit on the row above */
  .dl-panel-top .dl-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: stretch; }
  .dl-panel-top .dl-controls .dl-switch, .dl-panel-top .dl-controls .cn-box, .dl-panel-top .dl-controls .cn-status { grid-column: span 2; }
  .dl-panel-top .dl-controls .btn { width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* small panel: Auto-dial moves out of the way (it's there again under Results) */
  .dl-panel.small [data-start], .dl-panel.small [data-pause] { display: none; }
}

/* Minimise the script to a slim bar (to see who's next in the list); tap to open again */
.dl-script { display: flex; flex-direction: column; }
.dl-script-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.dl-script-min { align-self: flex-end; margin: 0.35rem 0.45rem 0; padding: 0.3rem 0.6rem; font-size: 0.78rem;
                 border-radius: 999px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); cursor: pointer; }
.dl-script-min .when-min { display: none; }
.dl-script.min { bottom: auto; overflow: visible; }
.dl-script.min .dl-script-body { display: none; }
.dl-script.min .dl-script-min { align-self: stretch; margin: 0; border-radius: var(--radius); padding: 0.55rem 0.8rem; font-size: 0.9rem; text-align: left; }
.dl-script.min .dl-script-min .when-open { display: none; }
.dl-script.min .dl-script-min .when-min { display: inline; }

/* ---------- Call stages: Hello / Ask / Offer / Book in the call panel (app/callstages.py) ---------- */
.dl-stages { display: flex; align-items: center; gap: 0.35rem; margin-top: 0.5rem; flex-wrap: nowrap; }
.dl-stages-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap; }
.dl-stage { flex: 1 1 0; min-width: 0; max-width: 7rem; padding: 0.35rem 0.4rem; border-radius: 99px; font: inherit; font-size: 0.8rem;
  font-weight: 600; cursor: pointer; color: var(--text-soft); background: transparent; border: 1px solid var(--border); }
.dl-stage.on { color: #fff; background: var(--accent, #3b6cf6); border-color: transparent; }
.dl-stage:focus-visible { outline: 2px solid var(--accent-bright, #6c93ff); outline-offset: 1px; }
@media (max-width: 860px) {
  .dl-stages { margin-top: 0.35rem; gap: 0.25rem; }
  .dl-stages-label { font-size: 0.66rem; letter-spacing: 0.04em; }
  .dl-stage { padding: 0.3rem 0.2rem; font-size: 0.74rem; }
}
/* ---------- end of Call stages ---------- */

/* ---------- Typed call notes: the "Notes" box over the list, above the call panel ---------- */
.dl-notes-btn.has { border-color: var(--accent-bright); color: var(--accent-bright); }
.dl-notes { position: fixed; z-index: 90; left: calc(var(--sidebar-w) + 1rem); right: 1rem; width: auto; max-width: 40rem;
            margin-left: auto; bottom: calc(var(--call-panel-h, 0px) + 0.6rem); height: min(22rem, calc(100vh - var(--call-panel-h, 0px) - 2rem));
            display: flex; flex-direction: column; gap: 0.45rem; padding: 0.7rem 0.8rem; border-radius: var(--radius);
            background: var(--panel-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.dl-notes-head { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.dl-notes-head b { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-notes textarea { flex: 1 1 auto; min-height: 6rem; width: 100%; box-sizing: border-box; resize: none; padding: 0.6rem 0.7rem;
                     font: inherit; font-size: 16px; line-height: 1.45; color: var(--text); background: var(--panel);
                     border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.dl-notes-hint { margin: 0; }
@media (max-width: 860px) {
  /* Phones: fill the space between the top of what you can see and the call panel.
     When the keyboard is up, --vv-* (the visible area) keep the box above it. */
  .dl-notes { left: 0.4rem; right: 0.4rem; max-width: none; top: calc(var(--vv-top, 0px) + 0.4rem); bottom: auto;
              height: calc(min(var(--vv-h, 100vh), 100vh - var(--call-panel-h, 0px)) - 0.8rem); }
  .dl-notes-head .btn { min-height: 2.4rem; padding: 0.4rem 0.9rem; }
  /* the Notes button: its own full-width row under the call buttons, easy to hit mid-call */
  .dl-panel-top .dl-controls .dl-notes-btn { order: 1; grid-column: 1 / -1; min-height: 2.5rem; font-weight: 700; }
}
/* ---------- end of Typed call notes ---------- */
