/*
 * Shell tokens, page wrapper and global alert stack.
 * Everything here is scoped under .iafwzcai-app so it never leaks onto
 * other wp-admin screens or other plugins' pages.
 */

.iafwzcai-app {
    /* Colors */
    --iafwzcai-primary-grad-start: #8b6cf8;
    --iafwzcai-primary-grad-end: #6a4cf0;
    --iafwzcai-primary-text: #5b3fe0;
    --iafwzcai-primary-text-hover: #4b31c9;
    --iafwzcai-lavender-100: #ebe5ff;
    --iafwzcai-lavender-200: #f1edff;
    --iafwzcai-lavender-300: #f5f2ff;
    --iafwzcai-lavender-border-100: #d9cffb;
    --iafwzcai-lavender-border-200: #e3dcfc;
    --iafwzcai-lavender-border-300: #c9bdfb;
    --iafwzcai-ink: #1b1d2a;
    --iafwzcai-body-text: #4a4f66;
    --iafwzcai-muted-text: #8a8fa6;
    --iafwzcai-muted-text-2: #9aa0b4;
    --iafwzcai-page-bg: #f6f7fa;
    --iafwzcai-card-bg: #fff;
    --iafwzcai-border-100: #eceef5;
    --iafwzcai-border-200: #e4e6ef;
    --iafwzcai-border-300: #f1f2f7;
    --iafwzcai-success: #10b981;
    --iafwzcai-success-dark: #0f9f6e;
    --iafwzcai-success-bg: #e8f8f1;
    --iafwzcai-error: #e0393e;
    --iafwzcai-error-dark: #d23339;
    --iafwzcai-error-bg: #fdecec;

    /* Radius */
    --iafwzcai-radius-sm: 8px;
    --iafwzcai-radius-md: 14px;
    --iafwzcai-radius-lg: 20px;
    --iafwzcai-radius-pill: 999px;

    /* Shadows */
    --iafwzcai-shadow-card: 0 4px 16px rgba(20, 22, 50, .04);
    --iafwzcai-shadow-menu: 0 18px 40px -12px rgba(30, 30, 70, .28);

    /* Font: WordPress admin's own system-font stack. No external/CDN fonts. */
    --iafwzcai-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;

    font-family: var(--iafwzcai-font);
    color: var(--iafwzcai-body-text);
    background: var(--iafwzcai-page-bg);
}

.iafwzcai-app button,
.iafwzcai-app input,
.iafwzcai-app select,
.iafwzcai-app textarea {
    font-family: inherit;
}

.iafwzcai-app *,
.iafwzcai-app *::before,
.iafwzcai-app *::after {
    box-sizing: border-box;
}

/* ============================================================
 * Fixed page shell
 * Locks #wpbody-content to the viewport height so this plugin's page never
 * scrolls the whole wp-admin document — only .iafwzcai-shell-body (the area
 * below the pinned header) scrolls internally. This stylesheet is only
 * ever enqueued on this plugin's own admin page (see iafwzcai_enqueue_scripts()
 * in admin.php), so these ID selectors never reach any other screen.
 * ============================================================ */
#wpbody-content {
    position: sticky;
    top: var(--wp-admin--admin-bar--height, 32px);
    height: calc(100vh - var(--wp-admin--admin-bar--height, 32px));
    overflow: hidden;
    padding-bottom: 0;
}

#wpfooter {
    display: none;
}

/* Matches WP's own admin-menu color (#1d2327, see #adminmenuback in
   wp-admin/css/admin-menu.css) so the margin strip around .iafwzcai-app reads
   as an intentional dark frame instead of a blank void. */
#wpcontent {
    padding-left: 0;
    background: #1d2327;
}

.iafwzcai-app {
    display: flex;
    flex-direction: column;
    /* An 8px gap on every side (top/right/bottom/left) — the height is
       shortened by 2x the gap (top margin + bottom margin) so the frame
       reads as an even strip all the way around instead of a thin top and
       a thick bottom/right. */
    height: calc(100vh - var(--wp-admin--admin-bar--height, 32px) - 16px);
    /* Overrides wp-admin's own `.wrap { margin: 10px 20px 0 2px; }`. */
    margin: 8px;
    border-radius: var(--iafwzcai-radius-md);
    overflow: hidden;
}

.iafwzcai-shell-header {
    flex-shrink: 0;
}

.iafwzcai-shell-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

@media print {
    #wpbody-content,
    #wpcontent,
    .iafwzcai-app,
    .iafwzcai-shell-body {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        background: #fff !important;
        margin: 0 !important;
    }
}

/* ── Reusable spinner (14px ring) ── */
.iafwzcai-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--iafwzcai-lavender-border-200);
    border-top-color: var(--iafwzcai-primary-grad-end);
    animation: iafwzcai-spin .7s linear infinite;
    vertical-align: middle;
}

@keyframes iafwzcai-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Global alert / toast stack ── */
.iafwzcai-alerts-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 340px;
    max-width: calc(100vw - 40px);
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    z-index: 100000;
    pointer-events: none;
}

.iafwzcai-alert-card {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--iafwzcai-card-bg);
    border-radius: var(--iafwzcai-radius-sm);
    box-shadow: var(--iafwzcai-shadow-card);
    padding: 12px 14px;
    border-left: 4px solid var(--iafwzcai-muted-text);
    font-family: var(--iafwzcai-font);
    font-size: 13px;
    color: var(--iafwzcai-body-text);
    animation: iafwzcai-alert-in .2s ease-out;
}

.iafwzcai-alert-card.iafwzcai-alert-success {
    border-left-color: var(--iafwzcai-success);
}

.iafwzcai-alert-card.iafwzcai-alert-failed {
    border-left-color: var(--iafwzcai-error);
}

.iafwzcai-alert-card.iafwzcai-alert-progress {
    border-left-color: var(--iafwzcai-primary-grad-end);
}

.iafwzcai-alert-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--iafwzcai-border-300);
    color: var(--iafwzcai-muted-text);
}

.iafwzcai-alert-card.iafwzcai-alert-success .iafwzcai-alert-icon {
    background: var(--iafwzcai-success-bg);
    color: var(--iafwzcai-success-dark);
}

.iafwzcai-alert-card.iafwzcai-alert-failed .iafwzcai-alert-icon {
    background: var(--iafwzcai-error-bg);
    color: var(--iafwzcai-error-dark);
}

.iafwzcai-alert-card.iafwzcai-alert-progress .iafwzcai-alert-icon {
    background: var(--iafwzcai-lavender-100);
    color: var(--iafwzcai-primary-grad-end);
}

.iafwzcai-alert-body {
    flex: 1;
    min-width: 0;
}

.iafwzcai-alert-title {
    font-weight: 700;
    color: var(--iafwzcai-ink);
    margin: 0 0 2px;
    font-size: 13px;
}

.iafwzcai-alert-message {
    margin: 0;
    color: var(--iafwzcai-body-text);
    overflow-wrap: break-word;
}

.iafwzcai-alert-close {
    background: none;
    border: none;
    padding: 2px;
    margin: -2px -2px 0 0;
    cursor: pointer;
    color: var(--iafwzcai-muted-text);
    line-height: 1;
    flex-shrink: 0;
}

.iafwzcai-alert-close:hover {
    color: var(--iafwzcai-ink);
}

@keyframes iafwzcai-alert-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .iafwzcai-alerts-stack {
        right: 10px;
        bottom: 10px;
        left: 10px;
        width: auto;
        max-width: none;
    }
}

/* ── Shared confirm dialog (replaces window.confirm()) ── */
.iafwzcai-confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100001; /* above the Test run popup, which asks for this confirmation */
    background: rgba(22, 20, 45, 0.45);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.iafwzcai-confirm-overlay.show {
    display: flex;
}

.iafwzcai-confirm-box {
    width: 100%;
    max-width: 440px;
    background: var(--iafwzcai-card-bg, #fff);
    border-radius: var(--iafwzcai-radius-lg, 20px);
    box-shadow: 0 30px 80px -20px rgba(20, 20, 60, .45);
    padding: 26px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.iafwzcai-confirm-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--iafwzcai-radius-md, 14px);
    background: var(--iafwzcai-error-bg, #fdecec);
    color: var(--iafwzcai-error, #e0393e);
    display: flex;
    align-items: center;
    justify-content: center;
}

.iafwzcai-confirm-icon-neutral {
    background: var(--iafwzcai-lavender-100, #ebe5ff);
    color: var(--iafwzcai-primary-grad-end, #6a4cf0);
}

.iafwzcai-confirm-title {
    font-size: 19px;
    font-weight: 800;
    color: var(--iafwzcai-ink, #1b1d2a);
    margin: 0;
}

.iafwzcai-confirm-input {
    width: 100%;
    height: 42px;
}

.iafwzcai-confirm-body {
    font-size: 14px;
    color: var(--iafwzcai-body-text, #4a4f66);
    line-height: 1.55;
    margin: 0;
    /* Several existing confirm messages use a blank line to separate a
       warning paragraph; preserve that instead of collapsing it. */
    white-space: pre-line;
}

.iafwzcai-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.iafwzcai-btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 42px;
    padding: 0 18px;
    border: none;
    border-radius: var(--iafwzcai-radius-md, 14px);
    background: var(--iafwzcai-error, #e0393e);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.iafwzcai-btn-danger:hover {
    background: var(--iafwzcai-error-dark, #d23339);
    color: #fff;
}

.iafwzcai-confirm-actions .iafwzcai-btn-secondary {
    height: 42px;
    border-radius: var(--iafwzcai-radius-md, 14px);
}

/* Confirm dialog while its action runs (busyLabel): both buttons disabled, spinner on the
   confirm button, blocked cursor. */
.iafwzcai-confirm-actions button:disabled {
    cursor: not-allowed;
}

.iafwzcai-confirm-actions .iafwzcai-btn-secondary:disabled {
    opacity: .55;
}

.iafwzcai-confirm-actions .iafwzcai-loading,
.iafwzcai-confirm-actions .iafwzcai-loading:disabled {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    opacity: .85;
    cursor: not-allowed;
}

.iafwzcai-confirm-actions .iafwzcai-loading::before {
    content: "";
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    box-sizing: border-box;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    animation: iafwzcai-confirm-spin .7s linear infinite;
}

@keyframes iafwzcai-confirm-spin {
    to { transform: rotate(360deg); }
}


/* License banner: pinned between the header and the scrolling body (not a WP admin notice). */
.iafwzcai-license-banner {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 12px 24px 0;
    padding: 12px 16px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--lb-border);
    border-radius: 12px;
    background: var(--lb-bg);
    color: var(--iafwzcai-body-text);
    font-family: var(--iafwzcai-font);
    font-size: 13px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(20, 22, 40, .04);
}
/* Accent stripe drawn inside the rounded box. A 4px border-left next to a 12px radius and a 1px
   border of another colour bent into a crescent at both left corners. */
.iafwzcai-license-banner::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 4px;
    background: var(--lb-accent);
}
.iafwzcai-license-banner--warning  { --lb-accent: #f59e0b; --lb-bg: #fffaf0; --lb-border: #fbe3b0; --lb-ink: #92590a; }
.iafwzcai-license-banner--critical { --lb-accent: var(--iafwzcai-error); --lb-bg: #fff5f5; --lb-border: #f7cfd0; --lb-ink: #b3262b; }
.iafwzcai-license-banner--expired  { --lb-accent: var(--iafwzcai-error); --lb-bg: #fff5f5; --lb-border: #f7cfd0; --lb-ink: #b3262b; }
.iafwzcai-license-banner-icon {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    color: var(--lb-accent);
    box-shadow: 0 0 0 1px var(--lb-border);
}
.iafwzcai-license-banner-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.iafwzcai-license-banner-title { color: var(--lb-ink); font-size: 13.5px; font-weight: 700; }
.iafwzcai-license-banner-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 10px;
    background: var(--lb-accent);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.iafwzcai-license-banner-btn:hover,
.iafwzcai-license-banner-btn:focus { color: #fff; filter: brightness(.92); }
@media (max-width: 640px) {
    .iafwzcai-license-banner { flex-wrap: wrap; margin: 10px 12px 0; }
    .iafwzcai-license-banner-btn { margin-left: 48px; }
}

/* Dismissible banner: close button, and `hidden` must win over the flex display. */
.iafwzcai-license-banner[hidden] { display: none; }
.iafwzcai-license-banner-msg a { color: var(--lb-ink); font-weight: 600; text-decoration: underline; }
.iafwzcai-license-banner-msg a:hover,
.iafwzcai-license-banner-msg a:focus { color: var(--lb-ink); text-decoration: none; }
/* Notice banners (licence, reconnect needed) belong on the main pages only: none show while the
   Add / Edit wizard (Steps 1-3) is open. The wizard has its own message next to the Zoho connection. */
.iafwzcai-app:has(#iafwzcai-setup-popupOverlay.show) .iafwzcai-license-banner,
.iafwzcai-app:has(#iafwzcai-setup-popupOverlay[data-mode="edit"]) .iafwzcai-license-banner { display: none; }
/* The same banners stay hidden while the Edit screen is open, from the very first paint of a direct load: the server renders
   its overlay with the marker below (the .show class above is only added by the wizard script). Only this plugin's own
   notices are hidden here; WordPress and other plugins' notices are never touched. */
.iafwzcai-banner-dismiss {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--lb-ink);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.iafwzcai-banner-dismiss:hover,
.iafwzcai-banner-dismiss:focus-visible { background: rgba(0, 0, 0, .06); }
