/* =============================================================================
   Agent Meeko - calls (RM-175)
   The floating call window, its tiles and controls, the ringing card, and the
   call buttons and history lines in Chat.
   ============================================================================= */

/* ---- The call window ------------------------------------------------------------------ */
/* Elements below set their own display; hidden must still hide them. */
.call-window [hidden], .calls-ring [hidden] { display: none !important; }

.call-window {
    position: fixed;
    right: var(--gutter, 24px);
    bottom: var(--gutter, 24px);
    z-index: 450;
    width: 380px;
    max-width: calc(100vw - 2 * var(--gutter, 24px));
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-large, 12px);
    background: var(--accent);
    color: var(--text-on-dark, #ffffff);
    box-shadow: 0 24px 60px -20px rgba(16, 24, 40, 0.65);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px);
    transition:
        transform var(--duration-panel-open, 320ms) var(--easing-standard, cubic-bezier(0.4, 0, 0.2, 1)),
        opacity var(--duration-panel-open, 320ms) var(--easing-standard, cubic-bezier(0.4, 0, 0.2, 1));
}
.call-window--visible { opacity: 1; transform: translateY(0); }
.call-window--expanded {
    inset: 0;
    width: auto;
    max-width: none;
    border-radius: 0;
}

.call-window__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.call-window__badge {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}
.call-window__heading { flex: 1 1 auto; min-width: 0; }
.call-window__title { font-weight: 700; font-size: var(--font-size-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-window__status { margin-top: 2px; font-size: var(--font-size-small); opacity: 0.75; font-variant-numeric: tabular-nums; }
/* Meeko in Meetings: the notice that Meeko is taking notes. */
.call-window__meeko-tag {
    display: inline-flex; align-items: center; gap: 6px; margin-top: 4px;
    padding: 2px 8px; border-radius: 5px; font-size: var(--font-size-small); font-weight: 600;
    background: rgba(255, 255, 255, 0.12); white-space: nowrap;
}
.call-window__meeko-tag::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--status-success, #0f9d58); }
.call-window__meeko-tag--paused::before { background: rgba(255, 255, 255, 0.5); }
.call-window__meeko-tag[hidden] { display: none; }
.call-window__icon-button {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-button, 5px);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.call-window__icon-button:hover, .call-window__icon-button:focus-visible { background: rgba(255, 255, 255, 0.12); }

/* ---- Add people (RM-176): inside the window, so it works full screen too ---------------- */
.call-window__add {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.12);
}
.call-window__add-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-radius: var(--radius-button, 5px);
    background: rgba(255, 255, 255, 0.1);
}
.call-window__add-search input {
    flex: 1 1 auto;
    min-width: 0;
    height: 36px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: var(--font-size-base);
    outline: none;
}
.call-window__add-search input::placeholder { color: rgba(255, 255, 255, 0.6); }
.call-window__add-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.call-window--expanded .call-window__add-list { max-height: 40vh; }
.call-window__add-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-button, 5px);
    cursor: pointer;
}
.call-window__add-row:hover { background: rgba(255, 255, 255, 0.08); }
.call-window__add-row input { accent-color: var(--status-success, #0f9d58); width: 16px; height: 16px; flex: none; }
.call-window__add-face {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: none;
    overflow: hidden;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    font-size: var(--font-size-small);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.call-window__add-face img { width: 100%; height: 100%; object-fit: cover; }
.call-window__add-row input:checked ~ .call-window__add-name { font-weight: 600; }
.call-window__add-name { display: flex; flex-direction: column; min-width: 0; font-size: var(--font-size-base); }
.call-window__add-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--font-size-small); opacity: 0.75; }
.call-window__add-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--presence); }
.call-window__add-empty { margin: 4px 0; font-size: var(--font-size-small); opacity: 0.75; }
.call-window__add-actions { display: flex; justify-content: flex-end; gap: 8px; }
.call-window__add-button {
    min-height: 34px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius-button, 5px);
    background: var(--status-success, #0f9d58);
    color: var(--text-on-dark, #ffffff);
    font: inherit;
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
}
.call-window__add-button--quiet { background: rgba(255, 255, 255, 0.12); }
.call-window__add-button:disabled { opacity: 0.6; cursor: default; }

/* ---- The stage and its tiles ------------------------------------------------------------- */
.call-window__stage {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
    aspect-ratio: 4 / 3;
    background: rgba(0, 0, 0, 0.18);
}
.call-window--expanded .call-window__stage { flex: 1 1 auto; aspect-ratio: auto; min-height: 0; padding: 12px; gap: 12px; }
.call-window__stage[data-count="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.call-window--expanded .call-window__stage[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: 1fr; }
.call-window__stage[data-count="3"], .call-window__stage[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.call-window__stage[data-count="5"], .call-window__stage[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* In the small window, two people: the other person fills it, I am a small tile in the corner. */
.call-window:not(.call-window--expanded) .call-window__stage[data-count="2"] .call-tile--me {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 30%;
    aspect-ratio: 3 / 4;
    z-index: 1;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
/* Somebody sharing their screen: it takes the stage, everyone else is a strip below. */
.call-window__stage--sharing { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; grid-auto-rows: minmax(0, 1fr); }
.call-window__stage--sharing .call-tile--main { grid-column: 1 / -1; grid-row: span 3; }

.call-window__waiting {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: var(--font-size-base);
    opacity: 0.8;
}

.call-tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    border-radius: var(--radius-medium, 8px);
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
    display: grid;
    place-items: center;
    outline: 2px solid transparent;
    transition: outline-color 160ms ease;
}
.call-tile--speaking { outline-color: var(--status-success, #0f9d58); }
.call-tile__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.call-tile--has-video .call-tile__video { display: block; }
.call-tile--screen .call-tile__video { object-fit: contain; background: rgba(0, 0, 0, 0.4); }
.call-tile--mirror .call-tile__video { transform: scaleX(-1); }
.call-tile__face {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.call-tile--has-video .call-tile__face { display: none; }
.call-tile__name {
    position: absolute;
    left: 8px;
    bottom: 8px;
    max-width: calc(100% - 16px);
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.45);
    font-size: var(--font-size-small);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.call-tile__muted {
    position: absolute;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
}

/* ---- The controls ------------------------------------------------------------------------- */
.call-window__controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
}
.call-control {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: inherit;
    cursor: pointer;
    transition: background 160ms ease, transform 160ms ease;
}
.call-control:hover, .call-control:focus-visible { background: rgba(255, 255, 255, 0.24); }
.call-control:active { transform: scale(0.96); }
.call-control:disabled { opacity: 0.6; cursor: default; }
.call-control--off { background: var(--surface-panel, #ffffff); color: var(--accent); }
.call-control--off:hover { background: var(--surface-subtle, #f7f8f9); }
.call-control[aria-pressed="true"]:not(.call-control--off) { background: var(--status-success, #0f9d58); }
.call-control--hang-up { background: var(--status-danger, #d92d20); }
.call-control--hang-up:hover, .call-control--hang-up:focus-visible { background: var(--status-danger, #d92d20); filter: brightness(1.1); }

/* ---- The ringing card ----------------------------------------------------------------------- */
.calls-ring { flex-direction: column; align-items: stretch; cursor: default; width: 340px; }
.calls-ring__top { display: flex; align-items: center; gap: 12px; }
.calls-ring__face { flex: none; }
/* RM-180: the avatar helper leaves the size to us; without it a photo shows at full size. */
.calls-ring__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    overflow: hidden;
    border-radius: 50%;
    font-size: var(--font-size-base);
    font-weight: 700;
}
.calls-ring__avatar .avatar-photo { width: 100%; height: 100%; object-fit: cover; }
.calls-ring__actions { display: flex; gap: 8px; margin-top: 12px; }
.calls-ring__button {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--control-height-small, 34px);
    padding: 0 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-button, 5px);
    background: var(--surface-panel);
    color: var(--text-primary);
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
}
.calls-ring__button--answer { background: var(--status-success, #0f9d58); border-color: var(--status-success, #0f9d58); color: var(--text-on-dark, #ffffff); }
.calls-ring__button--decline { color: var(--status-danger, #d92d20); }
/* RM-180: three buttons on a video ring. Labels stay on one line; Sound only gives way first. */
.calls-ring__button { white-space: nowrap; min-width: 0; }
.calls-ring__button--voice { flex: 0 1 auto; }
@media (max-width: 420px) {
    .calls-ring__button--voice span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
.calls-ring__button:hover, .calls-ring__button:focus-visible { filter: brightness(0.97); }
/* The ringing card sits above an open call window's corner. */
.calls-ring-stack { z-index: 460; }

/* ---- In Chat ------------------------------------------------------------------------------------ */
.staff-chat__call-buttons { display: flex; gap: 4px; flex: none; }
.staff-chat__call-button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    /* RM-180: soft, like the chat toolbar's own buttons. */
    border: 0;
    border-radius: var(--am-radius, 5px);
    background: var(--am-blue-tint, #f1f3f8);
    color: var(--am-blue, #19213b);
    cursor: pointer;
}
.staff-chat__call-button:hover, .staff-chat__call-button:focus-visible { background: var(--am-blue-soft, #e6e9f2); outline: none; }
.staff-chat__call-button:disabled { opacity: 0.6; cursor: default; }
.staff-chat__call-line {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 6px auto;
    padding: 6px 12px;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--surface-subtle);
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    max-width: 100%;
}
.staff-chat__call-line--missed { color: var(--status-danger, #d92d20); border-color: var(--status-danger-tint, #fdeceb); background: var(--status-danger-tint, #fdeceb); }
.staff-chat__call-icon { display: inline-grid; place-items: center; }
.staff-chat__call-join {
    padding: 2px 10px;
    border: 0;
    border-radius: 999px;
    background: var(--status-success, #0f9d58);
    color: var(--text-on-dark, #ffffff);
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
}

/* ---- Phones: the call is the whole screen ----------------------------------------------------------- */
@media (max-width: 560px) {
    .call-window { inset: 0; width: auto; max-width: none; border-radius: 0; }
    .call-window__stage { flex: 1 1 auto; aspect-ratio: auto; min-height: 0; }
    .call-window__stage[data-count="2"] { grid-template-columns: 1fr; grid-template-rows: repeat(2, minmax(0, 1fr)); }
    .call-control { width: 54px; height: 54px; }
    .calls-ring-stack { left: 12px; right: 12px; }
    .calls-ring { width: auto; }
}

/* ---- The host's lobby (RM-178) ------------------------------------------------------------------ */
.call-window__lobby-button { position: relative; }
/* Somebody new knocked: the button rings out three times, so it is seen with the sound off. */
.call-window__lobby-button--knock { animation: call-lobby-knock 900ms ease-out 3; }
@keyframes call-lobby-knock {
    0% { box-shadow: 0 0 0 0 rgba(15, 157, 88, 0.7); }
    100% { box-shadow: 0 0 0 12px rgba(15, 157, 88, 0); }
}
@media (prefers-reduced-motion: reduce) { .call-window__lobby-button--knock { animation: none; background: rgba(15, 157, 88, 0.35); } }
.call-window__lobby-count {
    position: absolute;
    top: 2px;
    right: 1px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--status-success, #0f9d58);
    color: var(--text-on-dark, #ffffff);
    font-size: 10.5px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}
.call-window__lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--font-size-base); }
.call-window__lobby-head--split { margin-top: 6px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
/* The People list scrolls inside the window rather than pushing the stage off it. */
.call-window__lobby { max-height: 46vh; overflow-y: auto; }
.call-window__people-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--radius-button, 5px);
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    cursor: pointer;
}
.call-window__people-icon:hover, .call-window__people-icon:focus-visible { background: rgba(255, 255, 255, 0.22); }
.call-window__people-icon--still { background: transparent; opacity: 0.45; cursor: default; }
.call-window__people-icon--danger:hover, .call-window__people-icon--danger:focus-visible { background: var(--status-danger, #d92d20); }
.call-window__add-status .icon { flex: none; }

/* RM-178: a raised hand on a tile. */
.call-tile__hand {
    position: absolute;
    top: 8px;
    left: 8px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--status-warning);
    color: var(--text-on-dark, #ffffff);
}
.call-tile--hand { outline-color: var(--status-warning); }
.call-window__lobby-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.call-window__lobby-row .call-window__add-name { flex: 1 1 auto; }
.call-window__lobby-row .call-window__add-button { flex: none; }
.call-window__lobby-face {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    font-size: var(--font-size-small);
    font-weight: 700;
}

/* ---- Minimised (RM-178): a bar in the corner, the call carries on ----------------------------------- */
/* The stage stays in the page (hidden) so remote sound keeps playing through its audio elements. */
.call-window--minimised {
    flex-direction: row;
    align-items: center;
    width: 340px;
}
.call-window--minimised .call-window__head { flex: 1 1 auto; min-width: 0; border-bottom: 0; padding: 10px 6px 10px 12px; }
.call-window--minimised .call-window__heading { cursor: pointer; }
.call-window--minimised .call-window__stage,
.call-window--minimised .call-window__add,
.call-window--minimised [data-call-layout] { display: none !important; }
.call-window--minimised .call-window__controls { flex: none; gap: 8px; padding: 10px 12px 10px 0; }
.call-window--minimised .call-control { width: 38px; height: 38px; }

@media (max-width: 560px) {
    .call-window.call-window--minimised {
        inset: auto 12px calc(12px + env(safe-area-inset-bottom, 0px)) 12px;
        width: auto;
        border-radius: var(--radius-large, 12px);
    }
    .call-window--minimised .call-window__controls { padding-bottom: 10px; }
}

/* ---- Waiting for the host, and "your meeting starts soon" (RM-178) ------------------------------------
   Both are incoming-call cards in the ringing stack, so they wear its navy (theme-layer.css) and its
   slide in, with no second set of colours here. */
/* The whole line is the message ("Ann is waiting to join Weekly review"), so it wraps rather than being cut off. */
.meeting-wait .incoming-call__number, .meeting-reminder .incoming-call__number { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
.meeting-wait .incoming-call__detail, .meeting-reminder .incoming-call__detail { flex: 1 1 auto; min-width: 0; }
.meeting-wait__badge {
    flex: none;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
}
.meeting-wait__spinner {
    flex: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: var(--text-on-dark, #ffffff);
    border-radius: 50%;
    animation: meeting-wait-spin 900ms linear infinite;
}
@keyframes meeting-wait-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .meeting-wait__spinner { animation-duration: 2400ms; } }
.meeting-reminder__close {
    flex: none;
    align-self: flex-start;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin: -4px -6px 0 0;
    border: 0;
    border-radius: var(--radius-button, 5px);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.meeting-reminder__close:hover, .meeting-reminder__close:focus-visible { background: rgba(255, 255, 255, 0.12); }
