/* ===== Design system ===== */
:root {
    --bg-base: #f1f5f9;
    --bg-mesh-1: #e0e7ff;
    --bg-mesh-2: #fce7f3;
    --bg-mesh-3: #dbeafe;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --border: #e2e8f0;
    --border-focus: #6366f1;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: #eef2ff;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --secondary: #f1f5f9;
    --secondary-hover: #e2e8f0;
    --secondary-text: #334155;
    --success: #10b981;
    --success-bg: #ecfdf5;
    --error: #ef4444;
    --error-bg: #fef2f2;
    --warning-bg: #fffbeb;
    --warning-text: #b45309;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.12), 0 8px 16px -8px rgba(99, 102, 241, 0.08);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    color: var(--text);
    min-height: 100vh;
    background: var(--bg-base);
    line-height: 1.5;
}

/* ===== Layout shell ===== */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

.app-shell::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 10% 0%, var(--bg-mesh-1) 0%, transparent 55%),
        radial-gradient(ellipse 70% 50% at 90% 10%, var(--bg-mesh-2) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 50% 100%, var(--bg-mesh-3) 0%, transparent 55%);
    pointer-events: none;
    z-index: 0;
}

.app-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.25rem 5rem;
    position: relative;
    z-index: 1;
}

/* ===== Top bar — logo esquerda, usuario direita ===== */
.site-header {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 1rem clamp(1.25rem, 4vw, 2.5rem);
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-icon svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    flex-shrink: 0;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

.user-pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
}

.logout-form {
    margin: 0;
}

.btn-link {
    width: auto;
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-link:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: #fecaca;
}

/* ===== Main card ===== */
.container {
    width: 100%;
    max-width: 560px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2rem 2rem 2.25rem;
    box-shadow: var(--shadow-lg);
    text-align: left;
}

.page-hero {
    text-align: center;
    margin-bottom: 2rem;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.35rem 0.75rem;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    margin-bottom: 1rem;
    letter-spacing: 0.02em;
}

h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.page-hero p,
.container > p {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 0;
    line-height: 1.6;
}

/* ===== Form ===== */
form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.custom-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 0;
}

.field-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: -0.25rem;
}

[hidden] {
    display: none !important;
}

select:disabled {
    background-color: #f8fafc;
    color: var(--text-muted);
    cursor: not-allowed;
}

input,
select,
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--font);
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    appearance: none;
}

input::placeholder {
    color: var(--text-muted);
}

input:hover,
select:hover,
.form-control:hover {
    border-color: #cbd5e1;
}

input:focus,
select:focus,
.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

/* ===== Quality row ===== */
.qualidade-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.625rem;
    align-items: stretch;
}

@media (max-width: 480px) {
    .qualidade-row {
        grid-template-columns: 1fr;
    }
}

.btn-secondary {
    width: auto;
    padding: 0.75rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--secondary);
    color: var(--secondary-text);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
    border-color: #cbd5e1;
}

.btn-secondary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.qualidade-status {
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    text-align: left;
}

.qualidade-status.ok {
    color: #047857;
    background: var(--success-bg);
}

.qualidade-status.erro {
    color: #b91c1c;
    background: var(--error-bg);
}

.qualidade-status:not(.ok):not(.erro) {
    color: var(--text-secondary);
    background: var(--accent-soft);
}

/* ===== Primary button ===== */
button[type="submit"],
#submit-btn {
    width: 100%;
    padding: 0.9375rem 1.5rem;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 700;
    color: white;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-top: 0.25rem;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

button[type="submit"]:hover:not(:disabled),
#submit-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

button[type="submit"]:active:not(:disabled),
#submit-btn:active:not(:disabled) {
    transform: translateY(0);
}

button[type="submit"]:disabled,
#submit-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

/* ===== Progress ===== */
.download-progress {
    margin-top: 0.25rem;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #f8fafc 0%, var(--accent-soft) 100%);
    border: 1px solid #c7d2fe;
    text-align: left;
}

.progress-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.progress-spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid #c7d2fe;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent-gradient);
    border-radius: 999px;
    transition: width 0.4s ease;
}

.progress-detail,
.progress-eta {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.progress-eta {
    color: var(--text-muted);
}

/* ===== Messages ===== */
.message {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    line-height: 1.5;
}

.message.success {
    background: var(--success-bg);
    color: #047857;
    border: 1px solid #a7f3d0;
}

.message.error {
    background: var(--error-bg);
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.cookie-warning {
    margin-bottom: 1.25rem;
}

/* ===== Login page ===== */
.login-page .container {
    max-width: 420px;
}

.login-page .page-hero {
    margin-bottom: 1.75rem;
}

.login-form {
    margin-top: 0;
}

.login-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1.25rem;
    border-radius: var(--radius-lg);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.login-icon svg {
    width: 28px;
    height: 28px;
    stroke: white;
    fill: none;
}

/* ===== Footer ===== */
footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 1.25rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    background: transparent;
}

footer strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .container {
        padding: 1.5rem 1.25rem 1.75rem;
        border-radius: var(--radius-lg);
    }

    h1 {
        font-size: 1.5rem;
    }

    .site-header {
        padding: 0.875rem 1rem;
    }
}
