/* ========== manager.toast.css (JS-compatible) ========== */

:root{
    --toast-w: 364px;
    --toast-gap: 10px;

    /* macOS Notification Center-like */
    --toast-bg: rgba(245, 245, 247, .72);
    --toast-border: transparent; /* no borders */
    --toast-shadow: none; /* no shadow */

    --toast-text: #0f172a;
    --toast-muted: rgba(15, 23, 42, .68);

    --toast-radius: 18px;
    --toast-blur: 22px;

    --t-success: #16a34a;
    --t-error:   #dc2626;
    --t-warning: #f59e0b;
    --t-info:    #2563eb;
    --t-default: #64748b;
}

@media (prefers-color-scheme: dark){
    :root{
        --toast-bg: rgba(28, 28, 30, .72);
        --toast-border: transparent;
        --toast-shadow: none;
        --toast-text: rgba(255,255,255,.92);
        --toast-muted: rgba(255,255,255,.70);
    }
}

/* ==============================
 * DEFAULT TOASTS
 * ============================== */

#toast-container{
    position: fixed;
    right: 14px;
    top: calc(12px + env(safe-area-inset-top, 0px));
    bottom: auto;
    z-index: 9999;

    width: var(--toast-w);
    max-width: calc(100vw - 40px);

    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--toast-gap);
    max-height: calc(100vh - 40px);
    overflow: hidden;

    pointer-events: none;
}

/* Small helper toast for grouping */
.toast.toast--group{
    grid-template-columns: 1fr auto;
    align-items: center;
}

.toast.toast--group::before,
.toast.toast--group .toast__icon,
.toast.toast--group .toast__close{
    display: none;
}

.toast--group .toast__content{ grid-column: 1 / -1; }

.toast--group .toast__actions{
    grid-template-columns: 1fr 1fr;
    margin-top: 10px;
}

/* Card */
.toast{
    --toast-accent: var(--t-default);

    pointer-events: auto;
    position: relative;
    display: grid;
    grid-template-columns: 40px 1fr 32px;
    align-items: start;
    gap: 12px;

    padding: 12px;
    border-radius: var(--toast-radius);

    background: var(--toast-bg);
    border: 0;
    box-shadow: var(--toast-shadow);

    backdrop-filter: blur(var(--toast-blur)) saturate(1.2);
    -webkit-backdrop-filter: blur(var(--toast-blur)) saturate(1.2);

    color: var(--toast-text);
    overflow: hidden;

    transform: translateY(-8px);
    opacity: 0;
    transition:
        transform .22s cubic-bezier(.2,.8,.2,1),
        opacity .22s ease,
        box-shadow .22s ease;
}

/* без accent-рамок, только лёгкий tint у иконки */
.toast::before{ display:none; }

.toast:hover{
    box-shadow: none;
}

/* ВАЖНО: JS добавляет именно эти классы */
.toast.toast--show{
    transform: translateY(0);
    opacity: 1;
}
.toast.toast--hiding{
    transform: translateY(-8px);
    opacity: 0;
}

/* Icon (JS создаёт .toast__icon + img) */
.toast__icon{
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex: 0 0 auto;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: color-mix(in srgb, var(--toast-accent) 14%, transparent);
    color: var(--toast-accent);
}

.toast__icon img{ width: 24px; height: 24px; display: block; }

/* Content (JS создаёт .toast__content) */
.toast__content{
    min-width: 0;
}

.toast__title{
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 2px 0;
    color: var(--toast-text);
}

.toast__message{
    font-size: 13px;
    line-height: 1.35;
    color: var(--toast-muted);
    margin: 0;
    word-break: break-word;
}

/* pinned/debug: показываем многострочный текст (например JSON) */
.toast[data-pinned="1"] .toast__message{
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
}

.toast__message-row{
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.toast__count{
    flex: 0 0 auto;
    margin-top: 1px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.3;
    font-weight: 700;
    background: rgba(0,0,0,.06);
    color: var(--toast-text);
    opacity: .75;
    user-select: none;
    display: none; /* включаем только при xN */
}

@media (prefers-color-scheme: dark){
    .toast__count{
        background: rgba(255,255,255,.12);
        color: rgba(255,255,255,.92);
    }
}

.toast__link{
    display: inline-block;
    margin-top: 6px;
    font-size: 13px;
    color: var(--t-info);
    text-decoration: none;
}
.toast__link:hover{ text-decoration: underline; }
.toast__link:focus-visible{
    outline: 2px solid color-mix(in srgb, var(--t-info) 45%, transparent);
    outline-offset: 2px;
    border-radius: 8px;
}

/* Close button (JS: .toast__close) */
.toast__close{
    margin-left: auto;
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    border-radius: 999px;
    cursor: pointer;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: #9ca3af;
    transition: background .15s ease, color .15s ease;
}
.toast__close:hover{
    background: rgba(17, 24, 39, .06);
    color: #111827;
}

@media (prefers-color-scheme: dark){
    .toast__close:hover{
        background: rgba(255,255,255,.10);
        color: rgba(255,255,255,.92);
    }
}
.toast__close:focus-visible,
.toast__btn:focus-visible{
    outline: 2px solid color-mix(in srgb, var(--t-info) 45%, transparent);
    outline-offset: 2px;
}

/* Progress (JS: .toast__progress / row / bg / bar / text) */
.toast__progress{ margin-top: 10px; }

.toast__progress-row{
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast__progress-bg{
    flex: 1 1 auto;
    height: 6px;
    background: rgba(17, 24, 39, .10);
    border-radius: 999px;
    overflow: hidden;
}

.toast__progress-bar{
    height: 100%;
    width: 0%;
    border-radius: 999px;
    transition: width .12s linear;
    background: linear-gradient(
        90deg,
        var(--toast-accent),
        color-mix(in srgb, var(--toast-accent) 60%, #ffffff)
    );
}

.toast__progress-text{
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--toast-text);
    min-width: 34px;
    text-align: right;
}

/* Actions (если используешь в options.actions) */
.toast__actions{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.toast__btn{
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 999px;
    cursor: pointer;
    border: 1px solid transparent;
    line-height: 1.2;
    font-weight: 700;
}

.toast__btn--secondary{
    background: rgba(17, 24, 39, .06);
    border-color: rgba(17, 24, 39, .10);
    color: var(--toast-text);
}
.toast__btn--secondary:hover{
    background: rgba(17, 24, 39, .09);
}

.toast__btn--primary{
    background: var(--t-info);
    color: #fff;
}
.toast__btn--primary:hover{ filter: brightness(.95); }

/* Types — JS использует toast--success/error/missed/status/update/message/default */
.toast--success{ --toast-accent: var(--t-success); }
.toast--error  { --toast-accent: var(--t-error); }
.toast--missed { --toast-accent: var(--t-warning); }
.toast--status { --toast-accent: var(--t-info); }
.toast--update { --toast-accent: var(--t-info); }
.toast--message{ --toast-accent: var(--t-default); }
.toast--default{ --toast-accent: var(--t-default); }

/* fallback если браузер не поддерживает color-mix */
@supports not (background: color-mix(in srgb, #000 10%, transparent)){
    .toast__icon{ background: rgba(100,116,139,.14); }
}

@media (max-width: 420px){
    #toast-container{ right: 12px; top: calc(12px + env(safe-area-inset-top, 0px)); bottom: auto; max-width: calc(100vw - 24px); }
    .toast{ grid-template-columns: 38px 1fr 32px; }
}

@media (prefers-reduced-motion: reduce){
    .toast,
    .toast__progress-bar{
        transition: none !important;
    }
}

/* ==============================
 * CALL TOAST (мини-экран звонка как на телефоне)
 * ============================== */

#call-toast-container{
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 10000;

    width: min(420px, calc(100vw - 24px));
    display: flex;
    flex-direction: column;
    gap: var(--toast-gap);

    pointer-events: none;
}

.toast.toast--call{
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;

    padding: 16px;

    background: rgba(17, 24, 39, .78);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 18px 50px rgba(0,0,0,.28);
    color: #fff;

    /* переопределяем базовый .toast (он по умолчанию сдвигает вправо) */
    transform: translateY(10px);
}

/* чтобы уходил вниз (логичнее для bottom toast) */
.toast.toast--call.toast--hiding{
    transform: translateY(10px);
}

.toast--call .toast__close{
    color: rgba(255,255,255,.7);
}
.toast--call .toast__close:hover{
    background: rgba(255,255,255,.10);
    color: #fff;
}

.toast__call_head{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.toast__call_label{
    font-size: 11px;
    letter-spacing: .2px;
    color: rgba(255,255,255,.70);
}

.toast__call_body{
    display: flex;
    align-items: center;
    gap: 14px;
}

.toast__call_avatar{
    width: 46px;
    height: 46px;
    border-radius: 999px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.16);
}

.toast__call_avatar svg{
    width: 22px;
    height: 22px;
    display: block;
    fill: #fff;
    opacity: .95;
}

.toast__call_info{ min-width: 0; flex: 1 1 auto; }

.toast__call_number{
    font-size: 18px;
    font-weight: 700;
    line-height: 1.15;
    margin: 0;
    word-break: break-word;
}

.toast__call_status_row{
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.toast__call_status{
    font-size: 12px;
    color: rgba(255,255,255,.78);
    margin: 0;
}

.toast__call_meta{
    font-size: 11px;
    color: rgba(255,255,255,.60);
    margin-top: 2px;
}

.toast__call_spinner{
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,.25);
    border-top-color: rgba(255,255,255,.95);
    animation: callToastSpin .75s linear infinite;
}

@keyframes callToastSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.toast--call:not([data-state="calling"]) .toast__call_spinner{ display: none; }

.toast__call_actions{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 2px;
}

.toast__call_btn{
    border: 0;
    border-radius: 14px;
    padding: 10px 12px;
    cursor: pointer;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    font-size: 13px;
    font-weight: 700;
}

.toast__call_btn--hang{
    background: rgba(255,59,48,.92);
    color: #fff;
}
.toast__call_btn--hang:hover{ filter: brightness(.96); }

.toast__call_btn--open{
    background: rgba(10,132,255,.92);
    color: #fff;
}
.toast__call_btn--open:hover{ filter: brightness(.96); }

.toast.toast--call[data-state="success"]{ border-color: rgba(52,199,89,.40); }
.toast.toast--call[data-state="error"]{ border-color: rgba(255,59,48,.45); }

@media (max-width: 420px){
    #call-toast-container{ width: calc(100vw - 24px); }
}
