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

[hidden] {
    display: none !important;
}

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface-hover: #222240;
    --border: #2a2a4a;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #6c63ff;
    --accent-hover: #5a52d5;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #2ecc71;
    --warning: #f39c12;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    padding: 1rem;
    -webkit-font-smoothing: antialiased;
}

.app {
    width: 100%;
    max-width: 540px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ── Header ──────────────────────────────────────────── */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

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

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s;
}

.icon-btn:hover {
    border-color: var(--accent);
}

.btn-instalar {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-instalar:hover {
    background: var(--accent-hover);
}

/* ── Dashboard ───────────────────────────────────────── */

.dashboard {
    animation: fadeIn 0.2s ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.stat-num {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-alert {
    border-color: var(--danger);
    background: rgba(231, 76, 60, 0.08);
}

.stat-alert .stat-num {
    color: var(--danger);
}

.stat-today {
    border-color: var(--warning);
    background: rgba(243, 156, 18, 0.08);
}

.stat-today .stat-num {
    color: var(--warning);
}

/* ── Busca ───────────────────────────────────────────── */

.barra-busca {
    display: flex;
    gap: 0.5rem;
    animation: fadeIn 0.15s ease;
}

.barra-busca input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    outline: none;
}

.barra-busca input::placeholder {
    color: var(--text-muted);
}

/* ── Filtros ─────────────────────────────────────────── */

.filtros {
    display: flex;
    gap: 0.5rem;
}

.filtro-grupo {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
}

.filtro-select {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.filtro-select:focus {
    border-color: var(--accent);
}

/* ── Formulário ──────────────────────────────────────── */

.form-tarefa {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-linha {
    display: flex;
    gap: 0.5rem;
}

.form-linha input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-linha input:focus {
    border-color: var(--accent);
}

.form-linha input::placeholder {
    color: var(--text-muted);
}

.form-linha button {
    background: var(--accent);
    color: #fff;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.form-linha button:hover {
    background: var(--accent-hover);
}

.form-detalhes {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    animation: fadeIn 0.15s ease;
}

.form-row {
    display: flex;
    gap: 0.5rem;
}

.form-select,
.form-date {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

.form-select-sm {
    max-width: 120px;
}

.form-textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    resize: vertical;
    outline: none;
    font-family: inherit;
}

.form-textarea:focus,
.form-select:focus,
.form-date:focus {
    border-color: var(--accent);
}

.btn-detalhes {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.2rem 0;
    text-align: left;
    transition: color 0.2s;
}

.btn-detalhes:hover {
    color: var(--accent);
}

/* ── Lista de tarefas ────────────────────────────────── */

.lista-tarefas {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.vazio {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 0;
    font-size: 0.95rem;
}

.tarefa {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    transition: border-color 0.2s, opacity 0.3s, transform 0.15s;
    touch-action: pan-y;
    user-select: none;
}

.tarefa:hover {
    border-color: var(--accent);
}

.tarefa.concluida {
    opacity: 0.5;
}

.tarefa.concluida .titulo {
    text-decoration: line-through;
    color: var(--text-muted);
}

.tarefa.overdue {
    border-left: 3px solid var(--danger);
}

/* Prioridade indicator */
.tarefa.prio-alta {
    border-left: 3px solid var(--danger);
}

.tarefa.prio-media {
    border-left: 3px solid var(--warning);
}

.tarefa.prio-baixa {
    border-left: 3px solid var(--success);
}

.tarefa.concluida.prio-alta,
.tarefa.concluida.prio-media,
.tarefa.concluida.prio-baixa {
    border-left-color: var(--border);
}

/* Check button */
.btn-check {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--success);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    transition: border-color 0.2s, background 0.2s;
}

.btn-check:hover {
    border-color: var(--success);
    background: rgba(46, 204, 113, 0.1);
}

.tarefa.concluida .btn-check {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

/* Conteúdo da tarefa */
.tarefa-conteudo {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.tarefa-linha1 {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.titulo {
    font-size: 0.95rem;
    cursor: default;
    word-break: break-word;
    line-height: 1.3;
}

.tem-desc {
    font-size: 0.75rem;
    flex-shrink: 0;
}

.tarefa-meta {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    align-items: center;
}

/* Badges */
.badge-categoria,
.badge-data,
.badge-prioridade {
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-categoria {
    letter-spacing: 0.02em;
}

.badge-data {
    background: var(--border);
    color: var(--text-muted);
}

.badge-data.atrasada {
    background: rgba(231, 76, 60, 0.2);
    color: var(--danger);
}

.badge-data.hoje {
    background: rgba(243, 156, 18, 0.2);
    color: var(--warning);
}

.badge-prioridade {
    background: var(--border);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-prioridade.prio-alta {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

.badge-prioridade.prio-media {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

.badge-prioridade.prio-baixa {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
}

/* Botão excluir */
.btn-excluir {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem;
    line-height: 1;
    opacity: 0;
    transition: color 0.2s, opacity 0.2s;
    flex-shrink: 0;
    margin-top: 2px;
}

.tarefa:hover .btn-excluir {
    opacity: 1;
}

.btn-excluir:hover {
    color: var(--danger);
}

/* ── Footer ──────────────────────────────────────────── */

.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.5rem 0;
}

.footer-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-lote {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-lote:hover {
    border-color: var(--accent);
    color: var(--text);
}

.btn-lote-perigo:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ── Modal ───────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.form-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.form-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    outline: none;
}

.form-input:focus {
    border-color: var(--accent);
}

.modal-body .form-textarea {
    width: 100%;
}

.modal-body .form-row {
    gap: 0.5rem;
}

.form-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 0.5rem;
}

.btn-cancelar {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-cancelar:hover {
    color: var(--text);
}

.btn-salvar {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-salvar:hover {
    background: var(--accent-hover);
}

/* ── Animações ───────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Mobile ──────────────────────────────────────────── */

@media (max-width: 480px) {
    body {
        padding: 0.75rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        flex-wrap: wrap;
    }

    .form-select-sm {
        max-width: none;
    }

    .btn-excluir {
        opacity: 0.6;
    }

    .footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .footer-actions {
        width: 100%;
        justify-content: center;
    }
}
