:root {
    --bg-color: #0f0f12;
    --bg-elev: #17171c;
    --text-color: #e6e6ea;
    --text-dim: #9aa0a6;
    --accent-color: #ff0050;
    --accent-soft: rgba(255, 0, 80, 0.14);
    --accent-glow: rgba(255, 0, 80, 0.4);
    --glass-bg: rgba(30, 30, 35, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --card-bg: rgba(40, 40, 45, 0.8);
    --radius: 16px;
    --radius-sm: 10px;
    --max-width: 640px;
    --tap: 48px;
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 15% 0%, rgba(255, 0, 80, 0.06) 0%, transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(74, 144, 226, 0.05) 0%, transparent 45%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Foco visivel e acessiveis ---- */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* ---- Header compacto ---- */
.app-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(15, 15, 18, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
}

.app-brand { flex: 1; min-width: 0; }
.app-brand h1 {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: #fff;
}
.brand-accent { color: var(--accent-color); }
.subtitle {
    color: var(--text-dim);
    font-size: 0.78rem;
    margin-top: 0.1rem;
}

.header-actions { display: flex; align-items: center; }

/* ---- Historico (toggle compacto no header) ---- */
.history-toggle-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-height: 44px;
    min-width: 44px;
    padding: 0 0.6rem;
    border-radius: 12px;
    color: #fff;
    font-size: 1.15rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    margin-right: 0.5rem;
}
.history-toggle-btn:active { transform: scale(0.96); }
.history-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent-color);
    color: #fff;
    border-radius: 50%;
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

/* ---- Menu do usuario ---- */
.user-menu { position: relative; }
.user-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.35rem 0.6rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: #fff;
    max-width: 150px;
}
.user-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent-color);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 96px;
}
.user-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 170px;
    background: var(--bg-elev);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.4rem;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
    z-index: 60;
}
.user-menu-dropdown[hidden] { display: none; }
.user-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-color);
    text-decoration: none;
    background: none;
    border: none;
}
.user-menu-item:hover, .user-menu-item:focus-visible { background: rgba(255, 255, 255, 0.07); }
.user-menu-logout { color: #ff8099; }

/* ---- Layout principal ---- */
.app-main {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.25rem 1rem 5.5rem;
    flex: 1;
}

/* ---- Card principal ---- */
.primary-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.1rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    margin-bottom: 1.25rem;
}
.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 1rem;
}

.field-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.field-label label { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; }

.paste-btn {
    min-height: 40px;
    padding: 0 1rem;
    border-radius: 10px;
    background: var(--accent-soft);
    color: #ff6b96;
    border: 1px solid rgba(255, 0, 80, 0.35);
    font-weight: 700;
    font-size: 0.85rem;
}
.paste-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.url-input {
    display: block;
    width: 100%;
    min-height: 56px;
    max-height: 220px;
    padding: 0.85rem 1rem;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 1rem;
    resize: none;
    overflow: hidden;
    word-break: break-all;
    -webkit-appearance: none;
    appearance: none;
}
.url-input:focus {
    outline: none;
    border-color: rgba(255, 0, 80, 0.55);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
    display: block;
    width: 100%;
    min-height: 52px;
    margin-top: 0.9rem;
    border: none;
    border-radius: 14px;
    background: linear-gradient(180deg, #ff2b6f, var(--accent-color));
    color: #fff;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    box-shadow: 0 6px 20px var(--accent-glow);
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn-primary:active { transform: translateY(1px); box-shadow: 0 2px 8px var(--accent-glow); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.status-line {
    min-height: 1.2em;
    margin-top: 0.75rem;
    font-size: 0.88rem;
    color: var(--text-dim);
    text-align: center;
    word-break: break-word;
}
.status-line.status-warn { color: #f5b14a; }
.status-line.status-error { color: #ff8099; }

/* ---- Smart clipboard suggestion (local, privacy-first) ---- */
.smart-clipboard {
    margin-top: 0.8rem;
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-left: 4px solid var(--accent-color);
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    animation: toastIn 0.25s ease-out;
}
.smart-clipboard[hidden] { display: none; }
.smart-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #fff;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.smart-head .platform-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #fff;
}
.smart-url {
    font-size: 0.82rem;
    color: var(--text-dim);
    word-break: break-all;
    margin-bottom: 0.8rem;
    line-height: 1.4;
}
.smart-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}
.smart-actions .btn-primary {
    margin-top: 0;
    flex: 1;
    min-height: 44px;
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-ghost {
    min-height: 44px;
    padding: 0.5rem 1rem;
    border-radius: 14px;
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-dim);
    font-weight: 700;
    font-size: 0.9rem;
    flex: 1;
}
.btn-ghost:hover, .btn-ghost:focus-visible { background: rgba(255, 255, 255, 0.06); color: #fff; }

.unsupported-offline {
    margin-top: 0.75rem;
    padding: 0.8rem;
    border-radius: var(--radius-sm);
    background: rgba(245, 177, 74, 0.12);
    border: 1px solid rgba(245, 177, 74, 0.4);
    color: #ffd58a;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
}
.unsupported-offline[hidden] { display: none; }

/* ---- Busca secundaria ---- */
.search-secondary { text-align: center; margin-bottom: 1rem; }
.search-toggle {
    background: none;
    border: 1px solid var(--glass-border);
    color: var(--text-dim);
    border-radius: 999px;
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.search-toggle:hover { color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.search-box { margin-top: 0.75rem; text-align: left; }
.search-box[hidden] { display: none; }
.search-row { display: flex; gap: 0.6rem; }
#searchQuery {
    flex: 1;
    min-height: 48px;
    padding: 0 1rem;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 1rem;
}
.btn-secondary {
    min-height: 48px;
    padding: 0 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

/* ---- Resultados (card unico) ---- */
.single-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}
.single-top { padding: 0.7rem 1rem 0; }
.single-platform {
    display: inline-block;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
}
.single-thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #111;
    margin-top: 0.7rem;
}
.single-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 600;
}
.single-info { padding: 0.9rem 1rem 0.25rem; }
.single-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.single-author { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.35rem; }

.quality-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    padding: 1rem;
    border: none;
}
.chip {
    min-height: 46px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    font-weight: 700;
    font-size: 0.92rem;
    transition: all 0.15s ease;
}
.chip.chip-active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}
.chip:active { transform: scale(0.97); }

.btn-download { margin: 0 1rem 1.25rem; width: calc(100% - 2rem); }

/* ---- Resultados (grade de busca) ---- */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.85rem;
    margin-top: 0.25rem;
}
.video-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}
.video-card.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color);
}
.thumb-wrapper {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #111;
}
.thumb-wrapper img { width: 100%; height: 100%; object-fit: cover; display: block; }
.platform-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 6px;
}
.duration {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
}
.select-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px; height: 24px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
}
.video-card.selected .select-overlay { opacity: 1; background: var(--accent-color); border-color: var(--accent-color); }
.checkmark { color: #fff; font-size: 13px; display: none; }
.video-card.selected .checkmark { display: block; }
.info { padding: 0.7rem; }
.video-title {
    font-size: 0.85rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.video-author { color: var(--text-dim); font-size: 0.75rem; margin-top: 0.3rem; }

/* ---- Barra flutuante (multipla) ---- */
.floating-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom));
    background: rgba(18, 18, 22, 0.96);
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.2);
    z-index: 90;
}
.floating-actions.visible { transform: translateY(0); }
.count-badge { flex: 1 1 auto; color: var(--text-dim); font-size: 0.8rem; white-space: nowrap; }
.count-badge span:first-child { color: #fff; font-weight: 700; }
.count-label { display: none; }
.select-all-btn {
    background: rgba(50, 150, 255, 0.14);
    color: #6db8ff;
    border: 1px solid rgba(50, 150, 255, 0.35);
    padding: 0.6rem 0.7rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.74rem;
    white-space: nowrap;
}
.quality-selector select {
    background: var(--bg-elev);
    color: #fff;
    border: 1px solid var(--glass-border);
    padding: 0.6rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
    max-width: 118px;
}
.download-btn {
    background: var(--accent-color);
    color: #fff;
    border: none;
    min-height: 46px;
    padding: 0 1.1rem;
    border-radius: 12px;
    font-weight: 800;
    box-shadow: 0 4px 14px var(--accent-glow);
    flex: 1 1 140px;
    font-size: 0.92rem;
}

/* ---- Progresso ---- */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 1rem;
}
.progress-overlay.active { opacity: 1; pointer-events: all; }
.progress-box {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 1.6rem;
    border-radius: 18px;
    width: 100%;
    max-width: 340px;
    text-align: center;
}
.progress-box h3 { color: #fff; margin-bottom: 1.1rem; font-size: 1rem; }
.progress-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--accent-color), #ff7a52);
    border-radius: 6px;
}
.progress-bar-fill.pulsing { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}
.progress-text { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.9rem; }

/* ---- Instalar (discreto) ---- */
.install-btn {
    position: fixed;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    right: 1rem;
    min-height: 44px;
    padding: 0 1rem;
    border-radius: 999px;
    background: var(--bg-elev);
    border: 1px solid var(--glass-border);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    z-index: 95;
}
.install-btn[hidden] { display: none; }
.install-btn:active { transform: scale(0.97); }

.history-empty { text-align: center; color: #888; padding: 2rem; }

/* ---- Painel de historico (desliza da borda) ---- */
.history-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 380px;
    height: 100vh;
    height: 100dvh;
    background: rgba(18, 18, 22, 0.98);
    border-left: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    transition: right 0.28s ease;
    overflow-y: auto;
    box-shadow: -12px 0 36px rgba(0, 0, 0, 0.5);
}
.history-panel.open { right: 0; }
.history-header {
    position: sticky;
    top: 0;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(18, 18, 22, 0.96);
}
.history-header h3 { color: #fff; font-size: 1.05rem; }
.close-history {
    min-height: 40px;
    min-width: 40px;
    background: none;
    border: none;
    color: #bbb;
    font-size: 1.6rem;
    line-height: 1;
}
.close-history:active { color: #fff; }
.history-list { padding: 0.75rem; }
.history-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.85rem;
    margin-bottom: 0.5rem;
}
.history-item-title {
    color: #fff;
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.history-item-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-dim);
}


@media (hover: hover) and (pointer: fine) {
    .chip:hover { border-color: rgba(255, 255, 255, 0.3); }
    .video-card:hover .thumb-wrapper img { transform: scale(1.04); }
    .thumb-wrapper img { transition: transform 0.4s ease; }
}

/* ---- Desktop >= 900px ---- */
@media (min-width: 900px) {
    .app-header { padding: 1rem 1.5rem; }
    .app-brand h1 { font-size: 1.6rem; }
    .app-main { padding: 2.25rem 1.5rem 7rem; }
    .primary-card { padding: 2rem; }
    .quality-group { grid-template-columns: repeat(5, 1fr); }
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1.25rem;
    }
    .floating-actions {
        left: 50%;
        right: auto;
        bottom: 26px;
        transform: translateX(-50%) translateY(120%);
        border: 1px solid var(--glass-border);
        border-radius: 999px;
        width: auto;
        justify-content: center;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    }
    .floating-actions.visible { transform: translateX(-50%) translateY(0); }
    .count-label { display: inline; }
}
