/* Frontend/css/calls.css — the call screen (Calls C2; js/calls_ui.js). */

.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;              /* above the app, below popup alerts */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: max(48px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
    background: radial-gradient(ellipse at 50% 30%, var(--tg-gradiant-primary, #0e1a1f) 0%, var(--tg-bg-primary, #080b0e) 70%);
    color: var(--tg-text-primary, #eef3f1);
    overflow: hidden;
}
body.in-call { overflow: hidden; }

.call-remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    opacity: 0;
    transition: opacity .3s ease;
    pointer-events: none;
}
.call-overlay.call-remote-live .call-remote-video { opacity: 1; }
.call-overlay audio { display: none; }

.call-peer {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 6vh;
    text-align: center;
    transition: margin .3s ease, opacity .3s ease;
}
.call-avatar {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    font-weight: 600;
    background: var(--tg-primary-dark, #148f6b);
    color: #fff;
    box-shadow: 0 0 0 0 var(--tg-primary-transparent, rgba(31,191,143,.42));
}
.call-overlay[data-state="incoming"] .call-avatar,
.call-overlay[data-state="calling"] .call-avatar,
.call-overlay[data-state="ringing"] .call-avatar {
    animation: call-pulse 1.8s ease-out infinite;
}
@keyframes call-pulse {
    0%   { box-shadow: 0 0 0 0 var(--tg-primary-transparent, rgba(31,191,143,.42)); }
    100% { box-shadow: 0 0 0 28px rgba(31,191,143,0); }
}
@media (prefers-reduced-motion: reduce) {
    .call-overlay .call-avatar { animation: none !important; }
}
.call-name {
    margin: 8px 0 0;
    font-size: 26px;
    font-weight: 600;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.call-status {
    margin: 0;
    font-size: 16px;
    color: var(--tg-text-secondary, #c2cec9);
    font-variant-numeric: tabular-nums;
}
.call-secure {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--tg-text-muted, #7c8b85);
}

/* On a live video call the name moves up small, over the picture. */
.call-overlay.call-remote-live .call-peer {
    margin-top: 0;
    padding: 6px 14px;
    border-radius: 14px;
    background: rgba(0, 0, 0, .35);
}
.call-overlay.call-remote-live .call-avatar { display: none; }
.call-overlay.call-remote-live .call-name { font-size: 18px; margin: 0; }

.call-local-video {
    position: absolute;
    right: 16px;
    bottom: 132px;
    width: 104px;
    height: 148px;
    border-radius: 14px;
    object-fit: cover;
    transform: scaleX(-1);          /* a mirror, as people expect of their own face */
    background: #111;
    border: 2px solid rgba(255, 255, 255, .15);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
    z-index: 2;                     /* above the picture, never above the buttons (placed clear of them) */
    touch-action: none;             /* dragged with a thumb (calls_ui.js) */
    cursor: grab;
    transition: left .2s ease, top .2s ease;
}
.call-local-video.is-dragging { transition: none; cursor: grabbing; }
.call-overlay.call-is-video:not(.call-remote-live) .call-local-video {
    /* before the other side's picture arrives, show your own full size,
       behind the buttons (not draggable then) */
    z-index: 0;
    pointer-events: none;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    opacity: .55;
}

.call-controls {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}
.call-controls-incoming { gap: 72px; }

.call-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: none;
    border: 0;
    padding: 0;
    color: var(--tg-text-secondary, #c2cec9);
    font-size: 12px;
    cursor: pointer;
}
.call-btn i {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    background: rgba(255, 255, 255, .12);
    transition: background .15s ease, transform .1s ease;
}
.call-btn:active i { transform: scale(.94); }
.call-btn:focus-visible i { outline: 2px solid var(--tg-primary-light, #35d6a3); outline-offset: 3px; }
.call-btn-toggle.is-off i { background: #fff; color: var(--tg-bg-primary, #080b0e); }
.call-btn-end i { background: var(--tg-danger, #e5484d); }
.call-btn-accept i { background: var(--tg-success, #1fbf8f); }
.call-controls-incoming .call-btn i { width: 68px; height: 68px; font-size: 28px; }
.call-overlay[data-state="incoming"] .call-btn-accept i { animation: call-nudge 1.4s ease-in-out infinite; }
@keyframes call-nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) {
    .call-overlay .call-btn-accept i { animation: none !important; }
}

@media (min-width: 769px) {
    .call-local-video { width: 200px; height: 140px; bottom: 140px; right: 24px; }
}
/* Five buttons (Mute, Speaker, Camera, Flip, End) on one row on a phone. */
@media (max-width: 420px) {
    .call-controls-active { gap: 10px; }
    .call-controls-active .call-btn i { width: 54px; height: 54px; font-size: 22px; }
}

/* Settings → Privacy: the line under "Hide my IP address in calls". */
.settings-hint { display: block; margin-top: 2px; font-size: 12px; line-height: 1.4; color: var(--tg-text-muted, #7c8b85); }

/* ── Calls tab: call history (C5) ─────────────────────────────────────── */
#sidebar-calls .calls-list { padding: 4px 0 96px; }
.call-log-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--tg-text-muted, #7c8b85);
}
.call-log-empty i { font-size: 34px; display: block; margin-bottom: 10px; color: var(--tg-text-secondary, #c2cec9); }
.call-log-empty p { margin: 0; font-size: 14px; line-height: 1.5; }
.call-log-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--tg-border, #1a262b);
}
.call-log-avatar {
    flex: 0 0 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #fff;
    background: var(--tg-primary-dark, #148f6b);
}
.call-log-text { flex: 1; min-width: 0; }
.call-log-name {
    color: var(--tg-text-primary, #eef3f1);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.call-log-what {
    font-size: 13px;
    color: var(--tg-text-muted, #7c8b85);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.call-log-item.is-missed .call-log-name,
.call-log-item.is-missed .call-log-what { color: var(--tg-danger, #e5484d); }
.call-log-when { font-size: 12px; color: var(--tg-text-muted, #7c8b85); white-space: nowrap; }
.call-log-again {
    flex: 0 0 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--tg-primary, #1fbf8f);
    font-size: 20px;
}
.call-log-again:hover { background: var(--tg-hover, #12201d); }
.call-log-again:focus-visible { outline: 2px solid var(--tg-primary-light, #35d6a3); outline-offset: 2px; }

/* Opened from a call notification while the app is locked: who is calling. */
.call-hint-banner {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    left: 16px;
    right: 16px;
    z-index: 3000;
    padding: 14px 16px;
    border-radius: 14px;
    background: #1f9d55;
    color: #fff;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.call-hint-banner i { margin-right: 6px; }

/* Settings → "Check call sound" */
.call-info-overlay {
    position: fixed;
    inset: 0;
    z-index: 3100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.6);
}
.call-info-card {
    width: 100%;
    max-width: 420px;
    padding: 20px;
    border-radius: 16px;
    background: var(--tg-bg-secondary, #151a20);
    color: var(--tg-text-primary, #e8edf2);
    overflow-wrap: anywhere;
}
.call-info-card h3 { margin: 0 0 12px; font-size: 1.1rem; }
.call-info-card p { margin: 0 0 8px; font-size: 0.92rem; }
.call-info-card button { margin-top: 8px; width: 100%; }

/* Minimise: the call becomes a small tile under the header; tap to return. */
.call-minimize {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    left: 14px;
    z-index: 2;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: inherit;
    font-size: 20px;
}
.call-overlay.call-minimized {
    inset: calc(78px + env(safe-area-inset-top, 0px)) 12px auto auto;
    width: 156px;
    padding: 10px 12px;
    border-radius: 16px;
    justify-content: flex-start;
    border: 1px solid var(--tg-primary, #1fbf8f);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    cursor: pointer;
}
.call-add {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: 14px;
    z-index: 2;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: inherit;
    font-size: 20px;
}
.call-add:focus-visible, .call-minimize:focus-visible { outline: 2px solid var(--tg-primary-light, #35d6a3); outline-offset: 3px; }
.call-overlay.call-minimized .call-add { display: none !important; }
.call-overlay.call-minimized.call-is-video { height: 210px; }
.call-overlay.call-minimized .call-controls,
.call-overlay.call-minimized .call-secure,
.call-overlay.call-minimized .call-avatar,
.call-overlay.call-minimized .call-local-video,
.call-overlay.call-minimized .call-minimize { display: none !important; }
.call-overlay.call-minimized .call-peer { margin: 0; gap: 2px; transition: none; }
.call-overlay.call-minimized .call-name { margin: 0; font-size: 15px; max-width: 132px; }
.call-overlay.call-minimized .call-status { font-size: 13px; }

/* Calls tab: calls can't ring this phone while the app is closed. */
.call-push-warning {
    margin: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(240, 173, 78, 0.12);
    border: 1px solid rgba(240, 173, 78, 0.45);
    color: var(--tg-text-primary, #eef3f1);
}
.call-push-warning p { margin: 0 0 8px; font-size: 0.92rem; }
.call-push-warning button { width: 100%; }

/* Phase 3: the line above the message box (tap to change this chat's time). */
.disappear-hint {
    display: block;
    width: 100%;
    margin: 0 0 6px;
    padding: 2px 4px;
    border: 0;
    background: none;
    text-align: center;
    font-size: 12px;
    color: var(--tg-text-muted, #7c8b85);
}
.disappear-hint i { margin-right: 4px; }
.call-info-card .disappear-choice { margin-top: 6px; text-align: left; }
.call-info-card .disappear-choice.is-current { border-color: var(--tg-primary, #1fbf8f); color: var(--tg-primary, #1fbf8f); }

/* ── Group calls (P5): a tile per person ─────────────────────────────── */
.call-grid { display: none; }
.call-overlay.call-group .call-grid {
    position: relative;
    z-index: 1;
    flex: 1;
    width: 100%;
    max-width: 720px;
    min-height: 0;
    margin: 12px 0 16px;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(0, 1fr);
}
@media (min-width: 600px) {
    .call-overlay.call-group .call-grid[data-count="2"],
    .call-overlay.call-group .call-grid[data-count="3"] { grid-template-columns: 1fr 1fr; }
}
.call-overlay.call-group .call-avatar,
.call-overlay.call-group .call-remote-video { display: none; }
.call-overlay.call-group .call-peer { margin-top: 0; gap: 2px; }
.call-overlay.call-group .call-name { font-size: 18px; margin: 0; }
.call-tile {
    position: relative;
    min-height: 0;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(255, 255, 255, .06);
    display: flex;
    align-items: center;
    justify-content: center;
}
.call-tile video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    opacity: 0;
    transition: opacity .3s ease;
}
.call-tile.has-video video { opacity: 1; }
.call-tile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 600;
    background: var(--tg-primary-dark, #148f6b);
    color: #fff;
}
.call-tile.has-video .call-tile-avatar { display: none; }
.call-tile.is-waiting .call-tile-avatar { opacity: .55; }
.call-tile-label {
    position: absolute;
    left: 10px;
    bottom: 8px;
    max-width: calc(100% - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: #fff;
    background: rgba(0, 0, 0, .45);
    padding: 2px 8px;
    border-radius: 10px;
}
.call-tile-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 0;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.call-tile-remove:focus-visible { outline: 2px solid var(--tg-primary-light, #35d6a3); outline-offset: 2px; }

/* the Add picker sits above the call screen */
.call-add-overlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .55);
}
.call-add-overlay .call-info-card { max-height: 80dvh; overflow-y: auto; width: min(360px, 100%); }
.call-add-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 6px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--tg-text-primary, #eef3f1);
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}
.call-add-row:hover, .call-add-row:focus-visible { background: rgba(255, 255, 255, .08); }
.call-add-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    background: var(--tg-primary-dark, #148f6b);
    color: #fff;
}
