/* =========================================================
   1. CORE DESIGN TOKENS (Adaptados para Acessibilidade AAA)
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;600;700;800&display=swap');

:root {
    /* --- TOKENS DE CORES (PADRÃO DARK) --- */
    --bg: #0b0f14;
    --surface: #0c1116;
    --surface-alt: #111827;

    --fg: #ffffff;          /* Texto Principal */
    --fg-subtle: #cbd5e1;   /* Texto Secundário */

    --border-color: #334155;

    /* Inputs */
    --input-bg: rgba(255, 255, 255, 0.04);
    --input-bd: #334155;

    /* Ação / Primary */
    --accent: #3b82f6;
    --accent-hover: #2563eb;

    /* Cores de Mensagens (Dark) */
    --info-bg: rgba(59, 130, 246, 0.15);
    --info-fg: #93c5fd;
    --success-bg: rgba(16, 185, 129, 0.15);
    --success-fg: #6ee7b7;
    --error-bg: rgba(239, 68, 68, 0.15);
    --error-fg: #fca5a5;

    /* Feedback */
    --success: #10b981;
    --error: #ef4444;

    /* Layout */
    --radius: 12px;
    --input-h: 48px;
    --focus-ring: rgba(59, 130, 246, 0.5);
}

/* --- LIGHT THEME --- */
[data-theme="light"] {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-alt: #f8fafc;

    --fg: #0f172a;
    --fg-subtle: #475569;

    --border-color: #cbd5e1;

    --input-bg: #ffffff;
    --input-bd: #cbd5e1;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    /* Cores de Mensagens (Light) */
    --info-bg: #eff6ff;
    --info-fg: #1e3a8a;
    --success-bg: #ecfdf5;
    --success-fg: #064e3b;
    --error-bg: #fef2f2;
    --error-fg: #991b1b;
}

/* =========================================================
   2. RESET E ESTRUTURA GERAL
   ========================================================= */
* { box-sizing: border-box; }

body {
    font-family: "Nunito Sans", sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    margin: 0;
    padding: 40px 20px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 15px;
    line-height: 1.6;
}

.checkout-shell {
    width: 100%;
    max-width: 1100px;
    position: relative;
}

[hidden] { display: none !important; }

/* =========================================================
   3. HEADER & STEPS
   ========================================================= */
.checkout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.checkout-header h1 {
    font-size: 24px;
    font-weight: 800;
    color: var(--fg);
    margin: 0 0 4px 0;
}

.checkout-header p {
    color: var(--fg-subtle) !important;
    font-size: 14px;
    margin: 0;
    font-weight: 600;
}

.steps-indicator {
    display: flex;
    gap: 8px;
    background: var(--surface);
    padding: 6px;
    border-radius: 99px;
    border: 1px solid var(--border-color);
}

.step-pill {
    padding: 8px 16px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
    color: var(--fg-subtle);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    text-transform: uppercase;
    white-space: nowrap;
}

.step-pill.active {
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.step-pill.done {
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}
.step-pill.done::before { content: '✓'; font-weight: 900; }

/* =========================================================
   4. LAYOUT & CARDS
   ========================================================= */
.layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 32px;
    align-items: start;
}

.card, main > section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.card h2 {
    font-size: 18px;
    font-weight: 800;
    color: var(--fg);
    margin: 0 0 24px 0;
}

/* =========================================================
   5. FORMULÁRIO
   ========================================================= */
.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.field label {
    font-size: 13px;
    font-weight: 700;
    color: var(--fg);
}

.field input, .field select {
    height: var(--input-h);
    padding: 0 16px;
    font-size: 15px;
    color: var(--fg);
    background: var(--input-bg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius);
    width: 100%;
    outline: none;
    transition: all 0.2s ease;
    font-weight: 600;
}

.field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 14px center;
    background-repeat: no-repeat;
    background-size: 1.2em;
    padding-right: 40px;
}

.field input:focus, .field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.field input::placeholder { color: var(--fg-subtle); opacity: 0.7; font-weight: 400; }

.toggle-password {
    position: absolute;
    right: 0;
    top: 32px;
    bottom: 0;
    width: 48px;
    background: none;
    border: none;
    color: var(--fg-subtle);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.toggle-password:hover { color: var(--fg); }

/* =========================================================
   6. BOTÕES
   ========================================================= */
.actions-row {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 16px;
}

.btn {
    height: var(--input-h);
    padding: 0 32px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}
.btn-primary:disabled {
    filter: grayscale(1);
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-ghost {
    background: transparent;
    color: var(--fg-subtle);
    border: 1px solid var(--input-bd);
}
.btn-ghost:hover {
    border-color: var(--fg);
    color: var(--fg);
    background: var(--input-bg);
}

/* =========================================================
   7. SELETORES DE PAGAMENTO (PILLS)
   ========================================================= */
#saleTypePills {
    display: flex;
    margin-bottom: 24px;
    background: var(--input-bg);
    padding: 4px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    gap: 0;
}

#saleTypePills .pill {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--fg-subtle);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

#saleTypePills .pill.active {
    background: var(--surface);
    color: var(--fg);
    border-color: var(--border-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
[data-theme="light"] #saleTypePills .pill.active {
    background: #fff;
    color: var(--accent);
}

#paymentPills { display: flex; gap: 12px; margin-bottom: 24px; }

#paymentPills .pill {
    flex: 1;
    border: 1px solid var(--border-color);
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--fg);
    cursor: pointer;
    transition: all 0.2s;
}

#paymentPills .pill:hover {
    border-color: var(--accent);
    background: var(--input-bg);
}

#paymentPills .pill.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

/* =========================================================
   8. RESUMO & LATERAL
   ========================================================= */
aside.card {
    background: var(--surface-alt);
    position: sticky;
    top: 20px;
    border: 1px solid var(--border-color);
}

aside.card h2, .trust-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fg);
    font-weight: 800;
    margin-bottom: 16px;
    display: block;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 14px;
    color: var(--fg-subtle);
}

.summary-label { font-weight: 600; }
.summary-value { font-weight: 700; color: var(--fg); }

.summary-row.summary-row-price {
    margin-top: 16px;
    padding-top: 20px;
    border-top: 1px dashed var(--border-color);
}

.summary-row-price .summary-value {
    font-size: 20px;
    color: var(--fg);
    font-weight: 800;
}

.summary-discount {
    font-size: 12px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 700;
    margin-top: 6px;
    display: inline-block;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

/* =========================================================
   9. TRUST BADGES & ICONES
   ========================================================= */
.trust-section {
    margin-top: 32px;
    border-top: 1px solid var(--border-color);
    padding-top: 24px;
}

.brand-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 10px;
    width: 100%;
    margin-bottom: 24px;
}

.brand-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px;
    transition: all 0.2s ease;
}

.brand-svg {
    height: 22px;
    width: auto;
    max-width: 100%;
    display: block;
    filter: grayscale(100%) opacity(0.6);
    transition: filter 0.2s;
}

[data-theme="dark"] .brand-svg {
    filter: grayscale(100%) invert(1) opacity(0.8);
}

.brand-pill:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.brand-pill:hover .brand-svg {
    filter: none;
    opacity: 1;
}
[data-theme="dark"] .brand-pill:hover .brand-svg {
    filter: invert(1);
}

.trust-security {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    margin-top: 4px;
}

.trust-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 8px;
}

.trust-ico {
    width: 20px;
    height: 20px;
    color: var(--success);
}

.trust-item span {
    font-size: 11px;
    font-weight: 700;
    color: var(--fg);
    line-height: 1.1;
}

/* =========================================================
   10. MODAL & MENSAGENS
   ========================================================= */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-dialog {
    background: var(--surface);
    color: var(--fg);
    padding: 32px;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

.message {
    margin-top: 20px;
    padding: 16px;
    border-radius: var(--radius);
    font-size: 14px;
    border-left: 4px solid;
    font-weight: 700;
}
.message.error { background: var(--error-bg); color: var(--error-fg); border-color: var(--error-fg); }
.message.info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-fg); }
.message.success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-fg); }

.terms-label {
    color: var(--fg-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
.terms-label a { color: var(--accent); font-weight: 800; }
.terms-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 20px; height: 20px;
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
}

/* =========================================================
   11. MOBILE (Responsivo)
   ========================================================= */
@media (max-width: 860px) {
    body { padding: 0; background: var(--bg); }
    .checkout-shell { padding: 0; }

    .checkout-header {
        display: block !important;
        text-align: center;
        padding: 24px;
        background: var(--surface-alt);
        border-bottom: 1px solid var(--border-color);
    }
    .checkout-header > div:first-child { width: 100%; margin-bottom: 20px; }

    .steps-indicator {
        display: flex;
        justify-content: center;
        gap: 4px;
        width: 100%;
        background: transparent;
        border: none;
        padding: 0;
    }
    .step-pill {
        flex: 1;
        justify-content: center;
        background: var(--surface);
        border: 1px solid var(--border-color);
        font-size: 10px;
        padding: 8px 4px;
    }
    .step-pill.active { background: var(--accent); border-color: var(--accent); }

    .layout { display: flex !important; flex-direction: column !important; gap: 0; }

    main {
        order: 1 !important;
        border: none;
        box-shadow: none;
        padding: 24px;
        background: var(--bg);
        margin: auto;
    }

    aside.card {
        order: 2 !important;
        border: none;
        border-radius: 0;
        position: static !important;
        border-top: 1px solid var(--border-color);
        background: var(--surface-alt);
        padding: 32px 24px;
    }

    .field input, .field select, .btn { height: 50px; font-size: 16px; }
    .actions-row { flex-direction: column-reverse; gap: 16px; }
    .actions-row button { width: 100%; }

    #paymentPills { gap: 8px; flex-wrap: wrap; }
    #paymentPills .pill { padding: 12px 6px; font-size: 13px; flex: 1 1 30%; min-width: 90px; }

    .brand-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}

/* =========================================================
   12. ESTILOS CNH - DEFINITIVO (CORREÇÃO INLINE-FLEX)
   ========================================================= */

/* Container geral (Onde ficam todas as opções) */
.cnh-checkbox-group {
    display: flex;
    flex-wrap: wrap; /* Permite quebrar linha se não couber */
    gap: 8px;        /* Espaço entre os botões */
    margin-top: 8px;
    align-items: center;
}

/* Wrapper individual (Input + Label) */
.cnh-checkbox-wrapper {
    display: inline-flex !important; /* FORÇA ficar na mesma linha */
    align-items: center;
    position: relative;
    margin: 0;
    padding: 0;
    width: auto !important; /* Impede que ocupe 100% */
}

/* ESCONDE o checkbox nativo (mas mantém funcionalidade) */
.field input.cnh-checkbox-hidden {
    position: absolute !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    pointer-events: none !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    z-index: -1;
}

/* O "Botão" visível (Label) */
.cnh-checkbox-pill {
    display: inline-flex !important; /* Garante comportamento flex interno */
    align-items: center;
    justify-content: center;

    padding: 10px 20px; /* Tamanho confortável */
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);

    font-size: 14px;
    font-weight: 700;
    color: var(--fg-subtle);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;

    min-width: 48px; /* Largura mínima para letras finas com 'I' */
    line-height: 1;
    white-space: nowrap;
}

/* Hover */
.cnh-checkbox-pill:hover {
    border-color: var(--accent);
    background: var(--surface-alt);
    color: var(--fg);
}

/* ESTADO SELECIONADO (CHECKED) */
.cnh-checkbox-hidden:checked + .cnh-checkbox-pill,
.cnh-checkbox-hidden:checked ~ .cnh-checkbox-pill {
    background: var(--accent) !important;
    color: #ffffff !important;
    border-color: var(--accent) !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Estado de Erro no Container Pai */
.cnh-error-border .cnh-checkbox-pill {
    border-color: var(--error) !important;
    background: rgba(239, 68, 68, 0.05);
    color: var(--error);
}

/* Texto de Ajuda */
.cnh-info-text {
    font-size: 12px;
    color: var(--fg-subtle);
    margin-top: 8px;
    display: block;
    line-height: 1.4;
    width: 100%; /* Força quebra de linha para o texto ficar abaixo */
}
.cnh-info-text strong {
    color: var(--accent);
    font-weight: 800;
}