/* --- 1. Design Tokens & Reset --- */
:root {
    /* Paleta Premium "Cyber-Clean" */
    --color-bg: #0f1115;           /* Fundo principal profundo */
    --color-surface: #181b21;      /* Superfície dos cards */
    --color-surface-hover: #22262e;
    --color-surface-highlight: #2a2f38;
    
    --color-text-primary: #f0f2f5;
    --color-text-secondary: #9ca3af; /* Cinza azulado suave */
    --color-text-tertiary: #6b7280;

    --color-brand: #38bdf8;        /* Cyan vibrante */
    --color-brand-subtle: rgba(56, 189, 248, 0.1);
    --color-brand-glow: rgba(56, 189, 248, 0.25);
    
    --color-success: #34d399;
    --color-success-subtle: rgba(52, 211, 153, 0.1);
    --color-danger: #fb7185;

    /* Escala de Espaçamento (Base 4px) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Tipografia (Sistema) */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Segoe UI Mono", "Roboto Mono", monospace;
    
    /* Escala de Tamanhos */
    --text-xs: 0.75rem;   /* 12px */
    --text-sm: 0.875rem;  /* 14px */
    --text-base: 1rem;    /* 16px */
    --text-lg: 1.125rem;  /* 18px */
    --text-xl: 1.5rem;    /* 24px */
    --text-2xl: 2rem;     /* 32px */

    /* Estrutura */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --max-width: 540px;

    /* Efeitos */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 20px var(--color-brand-glow);
    
    /* Animações */
    --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
    --ease-in-out: cubic-bezier(0.645, 0.045, 0.355, 1);
    --transition-fast: 150ms var(--ease-out);
    --transition-smooth: 300ms var(--ease-out);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--color-bg);
    /* Sutil textura de ruído/background para evitar flatness */
    background-image: 
        radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.06) 0%, transparent 60%);
    color: var(--color-text-primary);
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar Personalizada */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--color-surface-highlight);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

/* --- 2. Layout --- */
.app-container {
    width: 100%;
    max-width: var(--max-width);
    padding: var(--space-lg);
    padding-top: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.app-header {
    text-align: center;
    margin-bottom: var(--space-sm);
}

.app-header h1 {
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.02em; /* Tight tracking moderno */
    background: linear-gradient(135deg, #fff 0%, var(--color-text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--space-xs);
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: 400;
}

/* --- 3. Componentes Principais --- */

/* Área de Input */
.task-input-area {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.task-input-area:focus-within {
    border-color: var(--color-brand);
    box-shadow: var(--shadow-md), var(--shadow-glow);
    background: var(--color-surface-hover);
}

#newTaskInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    font-size: var(--text-base);
    padding: var(--space-sm) var(--space-md);
    outline: none;
    font-weight: 500;
}

#newTaskInput::placeholder {
    color: var(--color-text-tertiary);
    font-weight: 400;
}

.btn-add {
    background: var(--color-brand);
    border: none;
    color: #0f172a; /* Contraste escuro no btn claro */
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.btn-add:hover {
    transform: scale(1.05);
    background: #7dd3fc;
}
.btn-add:active {
    transform: scale(0.95);
}

/* Controles (Busca e Filtros) */
.controls-area {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.search-wrapper {
    position: relative;
}

.search-wrapper svg {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
    width: 16px;
    height: 16px;
    pointer-events: none;
}

#searchInput {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 10px var(--space-md) 10px 40px;
    color: var(--color-text-primary);
    outline: none;
    font-size: var(--text-sm);
    transition: var(--transition-fast);
}

#searchInput:focus {
    background: var(--color-surface);
    border-color: rgba(255, 255, 255, 0.1);
}

.filters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    gap: var(--space-xs);
}

.filter-btn {
    background: transparent;
    border: none;
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.filter-btn:hover {
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.filter-btn.active {
    background: var(--color-surface-surface);
    color: var(--color-brand);
    background: var(--color-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Lista de Tarefas */
.task-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.task-item {
    background: var(--color-surface);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    
    /* Animação de entrada */
    animation: slideIn 0.3s var(--ease-out) forwards;
    opacity: 0;
    transform: translateY(10px);
    
    transition: border-color 0.2s, transform 0.2s;
    position: relative;
    overflow: hidden;
}

.task-item:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: var(--color-surface-hover);
}

/* Estado Concluído */
.task-item.completed {
    background: rgba(15, 23, 42, 0.3); /* Levemente mais transparente */
    border-color: transparent;
}

.task-item.completed .task-text {
    text-decoration: line-through;
    color: var(--color-text-tertiary);
}

.task-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: var(--space-xs);
}

.task-text {
    font-size: var(--text-base);
    font-weight: 400;
    color: var(--color-text-primary);
    transition: color 0.2s;
    word-break: break-word;
}

.task-meta {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
    font-family: var(--font-mono);
    opacity: 0.8;
}

.task-actions {
    display: flex;
    gap: var(--space-xs);
    opacity: 0;
    transform: translateX(4px);
    transition: all 0.2s ease;
}

.task-item:hover .task-actions {
    opacity: 1;
    transform: translateX(0);
}

.icon-btn {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary);
}
.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn.delete:hover {
    color: var(--color-danger);
    background: rgba(251, 113, 133, 0.12);
}

.icon-btn.edit:hover {
    color: var(--color-brand);
    background: var(--color-brand-subtle);
}

/* Custom Checkbox */
.checkbox-wrapper {
    position: relative;
    width: 22px;
    height: 22px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px; /* Ajuste visual alinhado com texto */
}

.custom-checkbox {
    appearance: none;
    width: 100%;
    height: 100%;
    border: 2px solid var(--color-text-tertiary);
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    display: grid;
    place-content: center;
}

.custom-checkbox::before {
    content: "";
    width: 12px;
    height: 12px;
    transform: scale(0);
    transition: 0.2s transform ease-in-out;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
    background-color: var(--color-bg);
}

/* Hover state para checkbox */
.checkbox-wrapper:hover .custom-checkbox {
    border-color: var(--color-text-secondary);
}

/* Checked state */
.custom-checkbox:checked {
    border-color: var(--color-success);
    background: var(--color-success);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.3);
}

.custom-checkbox:checked::before {
    transform: scale(1);
    background-color: var(--color-bg); /* Símbolo escuro no bg verde */
}

/* Animação de clique */
.checkbox-wrapper:active .custom-checkbox {
    transform: scale(0.85);
}

/* Estados & Empty */
.hidden {
    display: none !important;
}

.empty-state {
    text-align: center;
    padding: var(--space-2xl) 0;
    color: var(--color-text-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    opacity: 0;
    animation: fadeIn 0.5s ease-out forwards;
}

.empty-state svg {
    opacity: 0.3;
    stroke: var(--color-text-primary);
}

/* Overlay (Modal) */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 12, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    animation: fadeIn 0.2s ease-out forwards;
}

.overlay-content {
    background: var(--color-surface);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    transform: scale(0.95);
    animation: scaleUp 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.overlay h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-md);
    font-weight: 600;
}

#editInput {
    width: 100%;
    background: var(--color-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text-primary);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-lg);
    font-size: var(--text-base);
    transition: border-color 0.2s;
}

#editInput:focus {
    outline: none;
    border-color: var(--color-brand);
}

.overlay-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

.btn-secondary, .btn-primary {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s, transform 0.1s;
}

.btn-secondary {
    background: transparent;
    color: var(--color-text-secondary);
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.05);
    color: var(--color-text-primary);
}

.btn-primary {
    background: var(--color-brand);
    color: #000;
    font-weight: 600;
}
.btn-primary:hover {
    opacity: 0.9;
}
.btn-primary:active {
    transform: scale(0.98);
}

/* --- 4. Animações Keyframes --- */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleUp {
    to { transform: scale(1); }
}

/* Slide Out */
.slide-out {
    animation: slideOut 0.3s var(--ease-in-out) forwards;
    pointer-events: none; /* Impede interação durante saída */
}

@keyframes slideOut {
    to {
        opacity: 0;
        transform: translateX(40px);
        /* Compensar altura aproximada do item para layout não pular bruscamente (padding + gap) */
        margin-bottom: -78px; 
    }
}

/* Responsividade Mobile Extra */
@media (max-width: 480px) {
    :root {
        --radius-md: 10px;
    }
    .app-container {
        padding: var(--space-md);
    }
    .app-header h1 {
        font-size: var(--text-xl);
    }
    .task-actions {
        opacity: 1; /* Sempre visível no mobile, touch é dificultar hover */
        transform: translateX(0);
    }
}