/* Anti-flicker: hide upload screen immediately when a saved session exists */
html.has-saved-session #upload-screen {
    display: none !important;
}

/* ── UPLOAD SCREEN ── */
/* flex:1 fills the remaining viewport height after the sticky header
   (body is a flex column in base.css). This eliminates phantom scrollbars
   on budget Android devices like the Infinix Smart 8 without clipping content. */
#upload-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: 20px 16px;
    box-sizing: border-box;
    gap: 0;
}

/* ── UPLOAD CARD (uploading state) ──
   Pixel-matched to the approved prototype: dark elevated card, file icon,
   filename + status on the left, big percentage top-right, full-width
   gradient progress bar, and a bytes/speed row underneath. */
#upload-progress-container.upload-card {
    width: min(440px, 100%);
    margin-top: 12px;
    animation: fade-in 0.2s ease both;
}

.upload-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #1c1b1b;
    border-radius: 20px;
    padding: 24px;
}

.upload-card-top {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.upload-card-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-card-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.upload-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-top: 1px;
}

.upload-card-filename {
    font-size: clamp(1rem, 4vw, 1.15rem);
    font-weight: 600;
    color: var(--text-mid);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.upload-card-status {
    font-size: clamp(0.70rem, 3vw, 0.80rem);
    font-weight: 400;
    color: var(--text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

.upload-card-percent {
    flex-shrink: 0;
    font-size: clamp(1.7rem, 7vw, 2rem);
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.upload-card-track {
    width: 100%;
    height: 10px;
    background: #2a2a2a;
    border-radius: 20px;
    overflow: hidden;
}

.upload-card-fill {
    width: 0%;
    height: 100%;
    border-radius: 20px;
    background: var(--gradient);
    transition: width 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.upload-card-bottom {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 2px;
}

.upload-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-size: clamp(0.72rem, 3vw, 0.78rem);
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}

.upload-card-action-row {
    display: flex;
    justify-content: flex-end;
    width: 100%;
}

/* Pixel-perfect Cancel button — sleek pill style with subtle glass hover */
.upload-cancel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 24px;
    font-family: "Poppins";
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: #e2e2e6;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background 0.18s cubic-bezier(0.2, 0, 0, 1),
        border-color 0.18s cubic-bezier(0.2, 0, 0, 1),
        color 0.18s cubic-bezier(0.2, 0, 0, 1),
        transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.upload-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}

.upload-cancel-btn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.12);
}

.upload-cancel-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.4);
    outline-offset: 2px;
}

.upload-zone {
    width: min(420px, 100%);
    border: 1.5px dashed rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 38px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    background: #121214;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.upload-zone:hover {
    border-color: rgba(255, 255, 255, 0.22);
}

.upload-zone.drag-active {
    border-color: var(--blue);
    background: rgba(83, 100, 253, 0.06);
}

/* Sparkle Pill Header */
.ai-sparkle-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 30px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(168, 85, 247, 0.18));
    border: 1px solid rgba(168, 85, 247, 0.35);
    color: #c084fc;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.15);
}

.ai-sparkle-badge svg {
    color: #e879f9;
    animation: sparkle-spin 3s ease-in-out infinite;
}

@keyframes sparkle-spin {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    50% {
        transform: scale(1.15) rotate(15deg);
    }
}

.upload-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-mid);
}

.upload-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.upload-text h3 {
    font-size: clamp(0.95rem, 4vw, 1.05rem);
    font-weight: 600;
    color: var(--text-dark);
    font-family: "Poppins", sans-serif;
}

.upload-text p {
    font-size: clamp(0.78rem, 3vw, 0.84rem);
    color: var(--text-soft);
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: "Poppins", sans-serif;
    font-weight: 500;
    font-size: clamp(0.85rem, 3.5vw, 0.92rem);
    transition: opacity 0.15s ease, transform 0.1s ease;
}

.upload-btn svg {
    flex-shrink: 0;
    stroke-width: 2.75;
}

.upload-btn:hover {
    opacity: 0.9;
}

.upload-btn:active,
.upload-btn.pressed {
    background-color: var(--blue-dark);
    transform: scale(0.97);
}

#file-input {
    display: none;
}

.file-chip {
    display: none;
    flex-direction: row;
    width: min(420px, 100%);
    justify-content: space-between;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: 50px;
    padding: 10px 16px;
    margin-top: 16px;
    font-size: clamp(0.78rem, 3.5vw, 0.92rem);
    background: #121214;
}

.file-chip p {
    font-weight: 400;
    color: var(--text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.remove-file-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: 8px;
    padding: 2px;
    transition: transform 0.1s ease;
}

.remove-file-btn:hover {
    transform: scale(1.1);
}

.generate-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: min(420px, 100%);
    margin-top: 28px;
    padding: 15px;
    background: var(--gradient);
    border: none;
    color: white;
    border-radius: 50px;
    font-family: "Poppins", sans-serif;
    font-weight: 500;
    font-size: clamp(0.9rem, 4vw, 1.05rem);
    cursor: pointer;
    transition: transform 0.2s ease;
    text-align: center;
}

.generate-btn:active {
    transform: scale(0.96);
}

.generate-btn:disabled,
.generate-btn.btn-disabled-quota {
    filter: grayscale(0.85);
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
}

/* ── DAILY QUOTA BADGE ── */
.quota-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    margin-bottom: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9999px;
    font-size: clamp(0.72rem, 3.2vw, 0.82rem);
    font-weight: 500;
    color: var(--text-soft, #a1a1aa);
    letter-spacing: 0.2px;
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.quota-badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    flex-shrink: 0;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

.quota-badge--warning .quota-badge-dot {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.quota-badge--exhausted {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.quota-badge--exhausted .quota-badge-dot {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.quota-badge--custom {
    background: rgba(168, 85, 247, 0.1);
    border-color: rgba(168, 85, 247, 0.3);
    color: #d8b4fe;
}

.quota-badge--custom .quota-badge-dot {
    background: #a855f7;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.5);
}

/* ── ERROR MESSAGE ── */
.error-msg {
    display: none;
    width: min(420px, 100%);
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: 16px;
    background: #121214;
    border: 0.5px solid var(--border);
    font-size: clamp(0.72rem, 3vw, 0.82rem);
    font-weight: 400;
    color: var(--text-dark);
    align-items: center;
    gap: 12px;
    line-height: 1.45;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    animation: toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.97);
    }

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

.error-msg-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

/* These modifier classes are kept as they are standard patterns for JS injection */
.error-msg--warning .error-msg-icon {
    background: rgba(255, 255, 255, 0.04);
}

.error-msg--error .error-msg-icon {
    background: rgba(255, 255, 255, 0.04);
}

.error-msg-icon img,
.error-msg-icon svg {
    width: 21px;
    height: 21px;
    display: block;
}

.error-msg-text {
    flex: 1;
    min-width: 0;
    font-weight: 400;
}

.error-msg-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 4px;
    border-radius: 50%;
    transition: background-color 0.15s, color 0.15s;
}

.error-msg-close:hover {
    background-color: rgba(255, 255, 255, 0.15);
    color: var(--text-dark);
}

/* ── CONSENT POPUP ── */
#consent-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    z-index: 999;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.2s ease forwards;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.consent-popup {
    background: #121214;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    width: min(520px, 95%);
    max-height: 85dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    animation: slide-up 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.consent-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* sleek thin scrollbar (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
    padding-right: 6px;
}

/* sleek thin scrollbar (WebKit/Chromium) */
.consent-body::-webkit-scrollbar {
    width: 5px;
}

.consent-body::-webkit-scrollbar-track {
    background: transparent;
}

.consent-body::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.1));
    border-radius: 999px;
    transition: background 0.15s ease;
}

.consent-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--blue), var(--blue-dark));
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }

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

.consent-popup h3 {
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    font-weight: 700;
    color: var(--text-dark);
    text-align: center;
    margin-bottom: 14px;
    font-family: "Poppins";
}

.consent-popup p {
    font-size: clamp(0.7rem, 2.5vw, 0.78rem);
    color: var(--text-soft);
    text-align: left;
    line-height: 1.6;
}

.consent-age-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: clamp(0.7rem, 2.5vw, 0.78rem);
    color: var(--text-soft);
    line-height: 1.5;
    cursor: pointer;
    flex-shrink: 0;
}

.consent-age-check input[type="checkbox"] {
    flex-shrink: 0;
    margin-top: 2px;
    width: 18px;
    height: 18px;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 6px;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    background: #1a1a1e;
    cursor: pointer;
    display: grid;
    place-content: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.consent-age-check input[type="checkbox"]:active {
    transform: scale(0.92);
}

.consent-age-check input[type="checkbox"]::after {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: white;
    clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 16%, 80% 0%, 38% 62%);
    transform: scale(0);
    transition: transform 0.12s ease;
}

.consent-age-check input[type="checkbox"]:checked {
    background: var(--blue);
    border-color: var(--blue);
}

.consent-age-check input[type="checkbox"]:checked::after {
    transform: scale(1);
}

.consent-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 12px;
    padding-top: 0;
    flex-shrink: 0;
}

.btn-continue:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: var(--blue);
}

.btn-refuse {
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: #1e1e22;
    color: var(--text-mid);
    border-radius: 10px;
    font-family: "Poppins", sans-serif;
    font-weight: 500;
    font-size: clamp(0.72rem, 2.5vw, 0.82rem);
    cursor: pointer;
    transition: background 0.15s;
}

.btn-refuse:active {
    background: rgb(194, 194, 194);
}

.btn-continue {
    padding: 8px 12px;
    border: 1px solid var(--blue);
    background: var(--blue);
    color: white;
    border-radius: 10px;
    font-family: "Poppins", sans-serif;
    font-weight: 500;
    font-size: clamp(0.72rem, 2.5vw, 0.82rem);
    cursor: pointer;
    transition: background 0.15s;
}

.btn-continue:active {
    background: var(--blue-dark);
}

/* ── PREFERENCES FOR LOW-END DEVICES ── */
@media (prefers-reduced-motion: reduce) {
    #consent-backdrop {
        backdrop-filter: none;
    }
}

/* ── NOTIFY ME BAR ── */
/* Fixed pill at the bottom of the screen, shown while generation is running.  */
/* Hidden by default — JS adds .notify-bar--visible to show it.                */
#notify-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #1c1c20;
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 8px 8px 8px 20px;
    width: min(420px, calc(100% - 32px));
    box-shadow: 0 6px 32px rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.34, 1.3, 0.64, 1), visibility 0.28s;
    will-change: transform, opacity;
}

#notify-bar.notify-bar--visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

#notify-bar-text {
    font-size: clamp(0.74rem, 3vw, 0.86rem);
    color: var(--text-soft);
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}

#notify-bar-btn {
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 11px 22px;
    font-family: "Poppins", sans-serif;
    font-weight: 500;
    font-size: clamp(0.82rem, 3vw, 0.9rem);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
    touch-action: manipulation;
    white-space: nowrap;
}

#notify-bar-btn:active {
    transform: scale(0.94);
    background: var(--blue-dark);
}

/* State: permission granted */
#notify-bar.notify-bar--granted #notify-bar-text {
    color: var(--text-mid);
}

#notify-bar.notify-bar--granted #notify-bar-btn {
    background: #1e3a2a;
    color: #4ade80;
    pointer-events: none;
    cursor: default;
}

/* State: permission denied */
#notify-bar.notify-bar--denied #notify-bar-btn {
    background: #2a1e1e;
    color: #f87171;
    pointer-events: none;
    cursor: default;
    font-size: clamp(0.72rem, 2.5vw, 0.8rem);
}