/* ============================================================
 * cgDialog + cgToast — unified card-dialog system
 *
 * Single visual language for every centred / landscape card dialog
 * in the app. Replaces the disconnected window.alert / window.confirm
 * paths AND, eventually, the existing cgConfirm / cgPrompt / flash
 * modal implementations so there is one renderer for everything.
 *
 * Source of truth: popup-catalog-system.html reference. Token names
 * mirror admin-theme.css; values fall back to the reference defaults
 * via var(…, fallback) so the dialog renders correctly on POS pages
 * too (whose body doesn't pick up the .cg-admin-body scope).
 *
 * SVG icons are injected from JS; everything else is in this file.
 * ============================================================ */

/* ---------- Backdrop ---------- */
.cg-dialog-backdrop {
    position: fixed; inset: 0;
    z-index: 100001;                   /* above splash (99999) + flash-modal (100000) */
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: rgba(16, 37, 53, 0.45);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: cg-dialog-bd-in 180ms ease both;
}
.cg-dialog-backdrop.cg-dialog-closing {
    animation: cg-dialog-bd-out 180ms ease both;
}

/* ---------- Card ---------- */
.cg-dialog {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: var(--card, #ffffff);
    color: var(--ink, #1a2530);
    border-radius: var(--t-radius-lg, 14px);
    padding: 28px 32px;
    box-shadow: 0 24px 60px rgba(16, 37, 53, 0.28);
    display: flex; gap: 20px; align-items: flex-start;
    animation:
        cg-dialog-card-in
        var(--t-duration, 180ms)
        var(--t-ease, cubic-bezier(0.2, 0.6, 0.2, 1)) both;
    font-family: var(--cg-font-ui, 'IBM Plex Sans', -apple-system, sans-serif);
}
.cg-dialog.is-centered {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 13px;
    max-width: 430px;
}

/* ---------- Close X (top-right) ---------- */
.cg-dialog-close {
    position: absolute;
    top: 15px; right: 17px;
    width: 27px; height: 27px;
    border: 0; padding: 0;
    background: transparent;
    color: var(--muted, #6b7680);
    cursor: pointer;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 140ms ease, color 140ms ease;
}
.cg-dialog-close:hover {
    background: var(--fill, #f3f5f6);
    color: var(--ink, #1a2530);
}
.cg-dialog-close svg { width: 15px; height: 15px; }

/* ---------- Icon halo ---------- */
.cg-dialog-icon {
    width: 56px; height: 56px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.cg-dialog-icon svg { width: 28px; height: 28px; }

.cg-dialog.is-success .cg-dialog-icon { background: var(--success-tint, #eaf6ee); color: var(--green, #2f9e6e); }
.cg-dialog.is-error   .cg-dialog-icon { background: var(--danger-tint,  #fbecea); color: var(--danger, #b1483b); }
.cg-dialog.is-warning .cg-dialog-icon { background: var(--warning-tint, #fbf2e0); color: var(--warning, #9a6a12); }
.cg-dialog.is-info    .cg-dialog-icon { background: var(--brand-tint,   #E4F0F5); color: var(--brand,   #1d6b8c); }
.cg-dialog.is-confirm .cg-dialog-icon { background: var(--brand-tint,   #E4F0F5); color: var(--brand,   #1d6b8c); }

/* ---------- Body / title / message ---------- */
.cg-dialog-body { flex: 1; min-width: 0; }
.cg-dialog.is-centered .cg-dialog-body { width: 100%; }

.cg-dialog-title {
    margin: 0;
    font-size: 18px;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--ink, #1a2530);
    line-height: 1.3;
}
.cg-dialog-message {
    margin: 5px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink-soft, #3d4853);
}
.cg-dialog-message b { color: var(--ink, #1a2530); }

/* ---------- Optional input fields ---------- */
.cg-dialog-fields { display: flex; flex-direction: column; gap: 12px; margin-top: 13px; }
.cg-dialog-field label {
    display: block;
    margin-bottom: 5px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-soft, #3d4853);
}
.cg-dialog-field input,
.cg-dialog-field textarea {
    width: 100%;
    border: 1px solid var(--line-strong, #cdd4da);
    border-radius: 9px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink, #1a2530);
    background: #fff;
    resize: vertical;
}
.cg-dialog-field input:focus,
.cg-dialog-field textarea:focus {
    outline: 0;
    border-color: var(--brand, #1d6b8c);
    box-shadow: 0 0 0 3px var(--brand-tint, #E4F0F5);
}
.cg-dialog-field-error {
    margin-top: 4px;
    font-size: 11px;
    color: var(--danger, #b1483b);
    min-height: 14px;
}

/* ---------- Actions row ---------- */
.cg-dialog-actions {
    display: flex; gap: 9px;
    margin-top: 18px;
}
.cg-dialog.is-centered .cg-dialog-actions {
    width: 100%;
    justify-content: center;
}
.cg-dialog-btn {
    border: 0;
    border-radius: 11px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 150ms ease, transform 80ms ease, box-shadow 150ms ease;
    color: #fff;
}
.cg-dialog-btn.is-full { flex: 1; }
.cg-dialog-btn:active { transform: translateY(1px); }

.cg-dialog-btn.is-primary { background: var(--brand, #1d6b8c); }
.cg-dialog-btn.is-primary:hover { background: var(--brand-deep, #155570); }

.cg-dialog-btn.is-success { background: var(--green, #2f9e6e); }
.cg-dialog-btn.is-success:hover { background: var(--green-deep, #268a5f); }

.cg-dialog-btn.is-danger { background: var(--danger, #b1483b); }
.cg-dialog-btn.is-danger:hover { background: var(--danger-deep, #8f392f); }

.cg-dialog-btn.is-ghost {
    background: var(--fill, #f3f5f6);
    color: var(--ink-soft, #3d4853);
}
.cg-dialog-btn.is-ghost:hover { background: #e8ebed; }

/* ---------- Keyframes ---------- */
@keyframes cg-dialog-bd-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes cg-dialog-bd-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}
@keyframes cg-dialog-card-in {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .cg-dialog-backdrop,
    .cg-dialog { animation: none; }
}

/* ============================================================
 * cgToast — non-blocking top-right snackbar
 * ============================================================ */
.cg-toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 100002;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
    max-width: 360px;
}
.cg-toast {
    pointer-events: auto;
    background: var(--ink, #1a2530);
    color: #ffffff;
    border-radius: 12px;
    padding: 13px 16px;
    display: flex; align-items: center; gap: 11px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    animation: cg-toast-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
    font-family: var(--cg-font-ui, 'IBM Plex Sans', -apple-system, sans-serif);
}
.cg-toast.cg-toast-out { animation: cg-toast-out 180ms ease both; }
.cg-toast-icon {
    width: 22px; height: 22px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.cg-toast-icon svg { width: 13px; height: 13px; }
.cg-toast.is-success .cg-toast-icon { background: var(--green, #2f9e6e); }
.cg-toast.is-error   .cg-toast-icon { background: var(--danger, #b1483b); }
.cg-toast.is-info    .cg-toast-icon { background: var(--brand, #1d6b8c); }
.cg-toast-message { flex: 1; min-width: 0; }
.cg-toast-undo {
    border: 0;
    background: transparent;
    color: #ffffff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    opacity: 0.92;
}
.cg-toast-undo:hover { opacity: 1; background: rgba(255, 255, 255, 0.1); }

@keyframes cg-toast-in {
    from { transform: translateY(-8px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
@keyframes cg-toast-out {
    from { transform: translateY(0);    opacity: 1; }
    to   { transform: translateY(-8px); opacity: 0; }
}
