/* ==========================================================================
   Lista de Compras — estilos
   Paleta em tokens; tema claro/escuro por [data-theme] no <html>.
   ========================================================================== */

:root {
    --brand: #16a34a;
    --brand-strong: #15803d;
    --brand-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;

    --bg: #f4f6f5;
    --bg-accent: radial-gradient(1100px 520px at 50% -10%, #d9f6e4 0%, transparent 70%);
    --surface: #ffffff;
    --surface-2: #f8faf9;
    --text: #14201a;
    --text-muted: #61736a;
    --border: #e3e8e5;
    --ring: rgba(22, 163, 74, .28);
    --shadow: 0 1px 2px rgba(16, 32, 24, .04), 0 12px 32px rgba(16, 32, 24, .08);

    --radius: 16px;
    --radius-sm: 10px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
    --brand: #34d399;
    --brand-strong: #10b981;
    --brand-soft: #10321f;
    --danger: #f87171;
    --danger-soft: #3a1a1a;

    --bg: #0e1512;
    --bg-accent: radial-gradient(1100px 520px at 50% -10%, #12332a 0%, transparent 70%);
    --surface: #16201c;
    --surface-2: #1b2723;
    --text: #e8f0ec;
    --text-muted: #94a79c;
    --border: #253530;
    --ring: rgba(52, 211, 153, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--bg);
    background-image: var(--bg-accent);
    background-repeat: no-repeat;
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 780px;
    margin: 0 auto;
    padding: 28px 16px 64px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    z-index: 20;
}
.skip-link:focus { left: 16px; }

/* --------------------------------------------------------------- Cabeçalho */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    border-radius: 14px;
    background: linear-gradient(140deg, var(--brand), var(--brand-strong));
    color: #fff;
    box-shadow: 0 6px 18px rgba(22, 163, 74, .28);
}
.brand-mark svg { width: 24px; height: 24px; }

.brand h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.tagline {
    margin: 2px 0 0;
    font-size: .82rem;
    color: var(--text-muted);
}

/* ------------------------------------------------------------------- Cartão */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.lists-bar {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 18px;
}

.field-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.row { display: flex; gap: 8px; align-items: stretch; }
.row .input { flex: 1 1 auto; min-width: 0; }
.mt-8 { margin-top: 8px; }

/* --------------------------------------------------------- Campos e botões */

.input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-muted); opacity: .85; }
.input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--ring);
}

.select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2361736a' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
}

[data-theme="dark"] .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a79c' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    padding: 0 18px;
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform .12s, background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }

.btn-primary { background: var(--brand); color: #ffffff; }
.btn-primary:hover { background: var(--brand-strong); }
[data-theme="dark"] .btn-primary { color: #04140c; }

.btn-soft {
    background: var(--brand-soft);
    color: var(--brand-strong);
}
.btn-soft:hover { filter: brightness(.97); }
[data-theme="dark"] .btn-soft { color: var(--brand); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-danger { background: var(--danger); color: #fff; }
[data-theme="dark"] .btn-danger { color: #2a0d0d; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    padding: 0;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color .15s, border-color .15s, background-color .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Alternância dos ícones do tema */
#themeToggle .icon-moon { display: none; }
[data-theme="dark"] #themeToggle .icon-sun { display: none; }
[data-theme="dark"] #themeToggle .icon-moon { display: block; }

.add-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.add-bar .input { flex: 1 1 auto; min-width: 0; }

/* ----------------------------------------------------------- Autocomplete */

.autocomplete { position: relative; flex: 1 1 auto; min-width: 0; }

.suggestions[hidden] { display: none; }

.suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 10;
}

.suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 11px 14px;
    font: inherit;
    font-size: .95rem;
    text-align: left;
    color: var(--text);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.suggestions .suggestion:last-child { border-bottom: none; }
.suggestion:hover,
.suggestion.active { background: var(--brand-soft); }

.suggestion-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.suggestion-cat {
    flex: 0 0 auto;
    font-size: .72rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 2px 9px;
    white-space: nowrap;
}

/* -------------------------------------------------------------- Progresso */

.progress-block { margin-bottom: 14px; }

.progress-head {
    display: flex;
    justify-content: space-between;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.progress {
    height: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--brand), var(--brand-strong));
    border-radius: 99px;
    transition: width .3s ease;
}

/* ------------------------------------------------------------------ Itens */

.items { list-style: none; margin: 0; padding: 0; }

.item {
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    animation: fade-in .22s ease-out;
}

.item-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.item-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.item-summary {
    font-size: .78rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

.expand-btn {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s, background-color .15s, transform .2s;
}
.expand-btn svg { width: 17px; height: 17px; transition: transform .2s; }
.expand-btn:hover { color: var(--text); background: var(--surface-2); }
.expand-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.item.open .expand-btn svg { transform: rotate(180deg); }

.item-details[hidden] { display: none; }

.item-details {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    margin: 10px 0 4px 34px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1 1 90px;
    min-width: 0;
}
.detail-field:nth-child(1) { flex: 0 1 64px; }   /* qtd. */
.pack-field { flex: 1.4 1 150px; }               /* embalagem */
.detail-field:nth-child(3) { flex: 2 1 140px; }  /* marca */
.detail-field:nth-child(4) { flex: 1 1 110px; }  /* preço un. */

.pack-row { display: flex; gap: 6px; min-width: 0; }
.pack-size { flex: 1 1 50px; min-width: 0; }
.pack-unit { flex: 0 0 74px; }

.detail-caption {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}

.detail-input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    font: inherit;
    font-size: .88rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.detail-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring);
}

.detail-total {
    flex: 1 1 100%;
    text-align: right;
    font-size: .82rem;
    font-weight: 600;
    color: var(--brand-strong);
}
[data-theme="dark"] .detail-total { color: var(--brand); }
.detail-total:empty { display: none; }

.totals[hidden] { display: none; }

.totals {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding: 10px 14px;
    font-size: .88rem;
    font-weight: 600;
    background: var(--brand-soft);
    border-radius: var(--radius-sm);
    color: var(--brand-strong);
}
[data-theme="dark"] .totals { color: var(--brand); }
.items .item:last-child { border-bottom: none; }

.item-check {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    accent-color: var(--brand);
    cursor: pointer;
}

.item-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: color .15s;
}

.item.done .item-text {
    color: var(--text-muted);
    text-decoration: line-through;
}

@media (max-width: 560px) {
    .item-details { margin-left: 0; }
    .detail-field:nth-child(1) { flex: 0 1 30%; }
    .pack-field { flex: 1 1 60%; }
    .detail-field:nth-child(3) { flex: 1 1 55%; }
    .detail-field:nth-child(4) { flex: 1 1 38%; }
}

.remove-btn {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s, background-color .15s, opacity .15s;
}
.remove-btn svg { width: 17px; height: 17px; }
.remove-btn:hover { color: var(--danger); background: var(--danger-soft); }
.remove-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* Com mouse o botão aparece no hover; no toque fica sempre visível. */
@media (hover: hover) and (pointer: fine) {
    .remove-btn { opacity: 0; }
    .item:hover .remove-btn,
    .item:focus-within .remove-btn { opacity: 1; }
}

.empty {
    margin: 26px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: .95rem;
}
.empty-emoji { display: block; font-size: 2rem; margin-bottom: 6px; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.seo-block { margin-top: 18px; }
.seo-block h2 { font-size: 1.05rem; }

.app-footer {
    margin-top: 18px;
    text-align: center;
    font-size: .78rem;
    color: var(--text-muted);
}
.app-footer p { margin: 0; }

.footer-links { margin-bottom: 6px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.footer-links a { color: var(--brand-strong); font-weight: 500; text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }
[data-theme="dark"] .footer-links a { color: var(--brand); }

/* ---------------------------------------------------------- Toast e modal */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 20px);
    max-width: min(90vw, 420px);
    padding: 11px 18px;
    font-size: .9rem;
    font-weight: 500;
    color: var(--surface);
    background: var(--text);
    border-radius: 99px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.dialog {
    width: min(92vw, 400px);
    padding: 22px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(8, 18, 14, .5); }
.dialog h2 { margin: 0 0 8px; font-size: 1.1rem; }
.dialog p { margin: 0 0 18px; color: var(--text-muted); font-size: .95rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

@keyframes fade-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------- Páginas de conteúdo */

.prose h2 {
    font-size: 1.15rem;
    margin: 26px 0 8px;
    letter-spacing: -.01em;
}
.prose h2:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--text); font-size: .96rem; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose strong { font-weight: 600; }
.prose .muted { color: var(--text-muted); font-size: .85rem; }
.prose a { color: var(--brand-strong); }
[data-theme="dark"] .prose a { color: var(--brand); }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    font-size: .9rem;
    font-weight: 500;
    color: var(--brand-strong);
    text-decoration: none;
}
.back-link:hover { text-decoration: underline; }
[data-theme="dark"] .back-link { color: var(--brand); }

/* ------------------------------------------------------------- Responsivo */

@media (max-width: 560px) {
    .wrap { padding: 20px 12px 48px; }
    .card { padding: 16px; }
    .brand { gap: 10px; }
    .brand h1 { font-size: 1.25rem; }
    .tagline { font-size: .76rem; }

    /* Empilha os campos que ficariam estreitos demais lado a lado. */
    .add-bar,
    #newListForm { flex-wrap: wrap; }
    .add-bar .btn,
    #newListForm .btn { width: 100%; }
    #newListForm .input { flex: 1 1 100%; }

    .actions .btn { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .app-header, .lists-bar, .add-bar, .actions, .app-footer, .remove-btn, .toast { display: none !important; }
    body { background: #fff; }
    .card { border: none; box-shadow: none; padding: 0; }
}
