/* agent-call: the call desk on Work (agent-call.js, docs/AGENT_VIEWS.md).
   Lagoon tokens only; light and dark come from the tokens.

   Phone and tablet portrait (<= 800px): the call card keeps its single column.
   The bar is the top of the call card: who, timer, then Mute / Hold / Hang up
   (the phone dock hides those three where it owns them).
   From 801px, while a call is live or in wrap-up (#workArea.ag-oncall):
     801-1179px  bar and banner across, then the call column (customer card,
                 notes, assist, transfer, wrap-up) and a side column (actions, history)
     >= 1180px   bar and banner across, then three panes: customer | call | actions + history
   .ag-col, #callCard and #callBox become display: contents there, so each
   piece is placed on the grid by itself. Nothing is moved or removed. */

/* ---------- the call bar (all widths) ---------- */
.ag-calltop { display: grid; gap: 10px; min-width: 0; }
.ag-callmain { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; min-width: 0; }
.ag-callmain .ag-who { flex: 1 1 220px; min-width: 0; flex-wrap: wrap; }
.ag-callmain .ag-whotext { flex: 1 1 0; min-width: 0; }
.ag-callmain #callActions { margin: 0; display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 100%; }
.ag-callmain #callActions.hidden { display: none; }
.ag-callmain #callActions button { min-height: 48px; }
.ag-barxfer { display: none; align-items: center; justify-content: center; }
#muteBtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }

.ag-ctimer { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.ag-ctimer:has(#callTimer:empty):has(#callPhase:empty) { display: none; }
#callTimer { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text); }
#callTimer.ag-frozen { color: var(--muted); }
.ag-cphase { font-size: 13px; font-weight: 800; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.ag-cphase:not(:empty)::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--call); flex: 0 0 auto; }
.ag-wrapup .ag-cphase::before { background: var(--warn); }

/* the "Inbound · queue" text of agent.js, as a pill */
.ag-callmain .ag-callsub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.ag-callmain .ag-callsub > span::before { content: none !important; }
.ag-callmain #callMeta:not(:empty) {
  display: inline-block; padding: 2px 10px; border-radius: var(--pill); background: var(--call-soft); color: var(--call-text);
  font-size: 12.5px; font-weight: 800;
}
.ag-callmain #callMeta::first-letter { text-transform: uppercase; }
.ag-callmain #crmLink { flex: 0 0 auto; }

/* the amber banner: "Third call. Last time: ..." (filled by agent-customer.js) */
.ag-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 16px; border-radius: 20px;
  background: var(--warn-soft); color: var(--warn-text); font-size: 15px; line-height: 1.4; min-width: 0;
}
.ag-banner.hidden { display: none; }
.ag-banner-ico { width: 24px; height: 24px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ag-banner-tx { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.ag-chip-ok {
  flex: 0 0 auto; padding: 3px 10px; border-radius: var(--pill); background: var(--ok-soft); color: var(--ok-text);
  font-size: 12.5px; font-weight: 800; white-space: nowrap;
}
.ag-callmain + .ag-banner, .ag-calltop .ag-banner { margin-top: 0; }
.ag-calltop:has(.ag-banner:not(.hidden)) { margin-bottom: 0; }
#shieldBox:not(.hidden) { margin-top: 10px; }

/* new boxes are quiet outside the desk */
.ag-livenotes, .ag-callhist, .ag-custactions { display: none; }
.ag-aside { display: contents; }

/* ---------- live notes ---------- */
.ag-livenotes h2 { font-size: 17px; margin-bottom: 8px; }
.ag-livenotes textarea { resize: vertical; min-height: 110px; }
.ag-livenotes .sub { margin: 8px 0 0; font-size: 13px; }

/* ---------- history card (right pane) ---------- */
.ag-callhist h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ag-callhist .ag-cu-summary { margin: 0 0 12px; font-size: 13.5px; }
.ag-callhist .ag-cu-link { padding-left: 0; }
#callHistoryBody { min-width: 0; }

/* ---------- the desk: from 801px ---------- */
@media (min-width: 801px) {
  .ag-work.ag-oncall {
    --cc: 1;                                   /* the call column */
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto repeat(12, auto) 1fr;
    column-gap: 18px; row-gap: 0; align-items: start; min-height: calc(100vh - 190px);
  }
  .ag-oncall > .ag-col, .ag-oncall #callCard, .ag-oncall #callBox { display: contents; }
  .ag-oncall > .ag-col { gap: 0; }
  .ag-oncall #callBox.hidden { display: none; }

  /* bar and banner across */
  /* the banner stays on top; the call bar (who, timer, controls) sticks to the bottom of the window */
  .ag-oncall #callTop { display: contents; }
  .ag-oncall #callBanner { grid-column: 1 / -1; grid-row: 1; margin-bottom: 14px; }
  /* Without a banner the row must still exist (empty, zero high): the panes start at row 2, and a
     first call with no history would otherwise let the call column slide up into row 1 beside them. */
  .ag-oncall #callBanner.hidden { display: block !important; height: 0; margin: 0; padding: 0; overflow: hidden; visibility: hidden; }
  .ag-oncall .ag-callmain { grid-column: 1 / -1; grid-row: 20; position: sticky; bottom: 12px; z-index: 30; margin-top: 6px; box-shadow: var(--shadow-lift); }
  .ag-oncall .ag-callmain {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 18px; flex-wrap: nowrap; gap: 14px;
  }
  .ag-oncall .ag-callmain .ag-who { flex: 1 1 auto; gap: 14px; flex-wrap: nowrap; }
  .ag-oncall .ag-callmain #callActions { flex: 0 0 auto; flex-wrap: nowrap; margin: 0; }
  .ag-oncall .ag-callmain #callActions button { min-height: 46px; padding: 0 18px; font-size: 15px; }
  .ag-oncall .ag-callmain #callActions button.danger { padding: 0 22px; font-weight: 900; }
  .ag-oncall .ag-avatar { width: 52px; height: 52px; font-size: 18px; }
  .ag-oncall .ag-name { font-size: 21px; }
  .ag-oncall .ag-name.mono { font-size: 20px; }
  .ag-oncall .ag-callsub { font-size: 14px; }
  .ag-oncall .ag-barxfer { display: inline-flex; }
  .ag-oncall #callTimerBox { margin: 0 4px; }
  .ag-oncall #callTimer { font-size: 24px; }

  /* the call column, in this order */
  .ag-oncall #custCard, .ag-oncall #shieldBox, .ag-oncall #consultBox, .ag-oncall #incomingBox, .ag-oncall #liveNotesCard,
  .ag-oncall #botCard, .ag-oncall #assistCard, .ag-oncall #xferRow, .ag-oncall #dtmfRow, .ag-oncall #wrapCard {
    grid-column: var(--cc); margin: 0 0 14px; min-width: 0;
  }
  .ag-oncall #custCard { order: -3; }
  .ag-oncall #consultBox, .ag-oncall #incomingBox { order: -2; }
  .ag-oncall #shieldBox { order: 0; }
  .ag-oncall #liveNotesCard { order: 1; }
  .ag-oncall #botCard { order: 2; }
  .ag-oncall #assistCard { order: 3; }
  .ag-oncall #xferRow { order: 4; }
  .ag-oncall #dtmfRow { order: 5; }
  .ag-oncall #wrapCard { order: 6; }
  .ag-oncall #shieldBox { margin-top: 0; }
  .ag-oncall #shieldBox.hidden { display: none; }
  .ag-oncall #shieldBox:not(.hidden) { padding: 10px 14px; background: var(--panel); border-radius: var(--radius-md); }
  .ag-oncall #dtmfRow { padding: 12px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); }
  .ag-oncall #dtmfRow.hidden { display: none; }
  .ag-oncall #xferRow, .ag-oncall #consultBox, .ag-oncall #incomingBox { margin-top: 0; }

  /* the lead list lives in the customer card here */
  .ag-oncall #leadData { display: none; }
  .ag-oncall #custCard .ag-cu-lhead,
  .ag-oncall #custBody > .ag-cu-timeline,
  .ag-oncall #custBody > .ag-cu-link,
  .ag-oncall #custBody > .ag-cu-banner { display: none; }
  .ag-oncall #custBody .ag-cu-field.ag-dup { display: block; }
  .ag-oncall #custBody .ag-cu-fields.ag-alldup { display: grid; }
  .ag-cu-fields.ag-alldup { display: none; }
  .ag-oncall #custCard h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .ag-oncall .ag-cu-live-badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; }

  /* the transfer picker opens from the bar */
  .ag-oncall:not(.ag-xfer-open) #xferRow { display: none; }

  /* quiet while the call is on: the placeholder, the dialler, callbacks, coaching */
  .ag-oncall:not(.ag-wrapup) #wrapCard { display: none; }
  .ag-oncall.ag-wrapup #wrapCard { order: -1; border: 2px solid var(--accent); }
  .ag-oncall.ag-wrapup #custCard { order: -3; }
  .ag-oncall .ag-dial, .ag-oncall .ag-callbacks, .ag-oncall .ag-coaching { display: none; }
  .ag-oncall:not(.ag-wrapup) #liveNotesCard { display: block; }
  .ag-oncall .ag-wrap h2 { font-size: 19px; }

  /* the side column */
  .ag-oncall #callAside { display: flex; flex-direction: column; gap: 14px; grid-column: 2; grid-row: 2 / -1; min-width: 0; }
  .ag-oncall #callAside > .hidden { display: none; }
  .ag-oncall #callHistory:not(.hidden) { display: block; }

  /* customer actions: Open in CRM and Send WhatsApp */
  .ag-oncall #custActions { display: grid; gap: 8px; margin-top: 12px; }
  .ag-oncall #custActions:not(:has(> :not(.hidden))) { display: none; }
  .ag-oncall #custActions > * { min-height: 44px; justify-content: center; text-align: center; }
  .ag-oncall #custActions #crmLink { display: inline-flex; border: 2px solid var(--border-strong); background: var(--panel); color: var(--text); }
  .ag-oncall #custActions #crmLink.hidden { display: none; }
  .ag-oncall #custCard { padding: 18px; }
}

/* ---------- three panes: from 1180px ---------- */
@media (min-width: 1180px) {
  .ag-work.ag-oncall {
    --cc: 2;
    grid-template-columns: 250px minmax(0, 1fr) 270px;
    column-gap: 16px;
  }
  .ag-oncall #custCard { grid-column: 1; grid-row: 2 / -1; margin: 0; align-self: stretch; align-content: start; }
  .ag-oncall #callAside { grid-column: 3; align-self: stretch; }
  .ag-oncall #callAside > .card { flex: 1 1 auto; }
  /* the centre card takes the free height too */
  .ag-oncall:not(.ag-wrapup) #liveNotesCard:not(.hidden) { display: flex; flex-direction: column; min-height: calc(100vh - 400px); }
  .ag-oncall #liveNotesCard textarea { flex: 1 1 auto; min-height: 140px; resize: none; }
  .ag-oncall.ag-wrapup #wrapCard { min-height: calc(100vh - 400px); }
  .ag-oncall #custBody .ag-cu-fields { grid-template-columns: minmax(0, 1fr); }
  .ag-oncall .ag-callmain { padding: 14px 18px; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .ag-callmain, .ag-banner { transition: none; }
}

/* phone: the Actions card follows the call card (it had no order, so it came first) */
@media (max-width: 800px) {
  #actionsCard { order: 1; }
}
