:root {
    --bg-main: #f8fafc;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #ef4444;
    --success: #10b981;
    --border: #e2e8f0;
    --item-hover: #f1f5f9;
    --footer-bg: #fbfbfc;
    --ring: rgba(79, 70, 229, 0.2);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* Dark Mode Palette */
[data-theme="dark"] {
    --bg-main: #0f172a;
    --surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #475569;
    --border: #334155;
    --item-hover: #0f172a;
    --footer-bg: #1e293b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; padding: 1rem;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    background-color: var(--surface); width: 100%; max-width: 520px;
    border-radius: 16px; box-shadow: var(--shadow-lg);
    border: 1px solid var(--border); overflow: hidden;
    display: flex; flex-direction: column;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* --- Header & Theme Toggle --- */
.app-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 2.5rem 2rem 1.5rem;
}
.header-left { display: flex; align-items: flex-start; gap: 1rem; }
.app-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.025em; }
.app-header p { color: var(--text-secondary); font-size: 0.875rem; margin-top: 0.25rem; font-weight: 500;}

.icon-btn {
    background: none; border: none; color: var(--text-tertiary);
    cursor: pointer; padding: 0.25rem; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--item-hover); color: var(--text-primary); }

.progress-ring-circle { transition: stroke-dashoffset 0.5s ease-in-out; transform: rotate(-90deg); transform-origin: 50% 50%; }

/* --- Input Area --- */
.input-section { padding: 0 2rem 1.5rem; }
.input-wrapper {
    display: flex; align-items: center; background: var(--bg-main);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 0.5rem 1rem; transition: all 0.2s ease;
}
.input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); background: var(--surface); }
.input-icon { color: var(--text-tertiary); margin-right: 0.5rem; }
#task-input { flex-grow: 1; border: none; background: transparent; padding: 0.5rem 0; font-size: 1rem; outline: none; color: var(--text-primary); }

/* --- Filters --- */
.filters { display: flex; gap: 1.5rem; padding: 0 2rem; border-bottom: 1px solid var(--border); }
.filter-btn { background: none; border: none; color: var(--text-secondary); font-weight: 500; font-size: 0.875rem; cursor: pointer; padding-bottom: 0.75rem; border-bottom: 2px solid transparent; transition: color 0.2s; }
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- List & Empty State --- */
.list-section { min-height: 250px; max-height: 400px; overflow-y: auto; padding: 1rem 1.5rem; }
.list-section::-webkit-scrollbar { width: 6px; }
.list-section::-webkit-scrollbar-thumb { background-color: var(--text-tertiary); border-radius: 10px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-tertiary); text-align: center; padding: 2rem 0; }
.empty-state.hidden { display: none; }
.empty-state h3 { color: var(--text-primary); font-size: 1rem; margin-top: 1rem; }
.empty-state p { font-size: 0.875rem; margin-top: 0.25rem; }

/* --- Task Items --- */
#task-list { list-style: none; }
.task-item {
    display: flex; align-items: center; padding: 0.875rem 1rem; margin-bottom: 0.5rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s; cursor: grab;
}
.task-item:active { cursor: grabbing; }
.task-item:hover { border-color: var(--text-tertiary); box-shadow: var(--shadow-sm); }
.task-item.dragging { opacity: 0.5; transform: scale(0.98); background: var(--item-hover); }
.task-item.drag-over { border-top: 2px solid var(--primary); }

.drag-handle { color: var(--text-tertiary); cursor: grab; margin-right: 0.5rem; display: flex; }
.task-content { display: flex; align-items: center; gap: 0.75rem; flex-grow: 1; cursor: pointer; overflow: hidden;}
.task-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Checkbox */
.custom-checkbox { width: 1.25rem; height: 1.25rem; border: 2px solid var(--text-tertiary); border-radius: 4px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0; }
.task-item.completed .custom-checkbox { background: var(--primary); border-color: var(--primary); }
.task-item.completed .task-text { text-decoration: line-through; color: var(--text-secondary); }

/* Actions */
.task-actions { opacity: 0; transition: opacity 0.2s; display: flex; gap: 0.25rem; flex-shrink: 0; }
.task-item:hover .task-actions { opacity: 1; }
.action-btn { background: none; border: none; padding: 0.4rem; cursor: pointer; color: var(--text-tertiary); border-radius: 6px; transition: all 0.2s; display: flex; align-items: center; }
.action-btn:hover { background: var(--bg-main); color: var(--text-primary); }
.action-btn.delete-btn:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* --- Premium Edit Mode --- */
.edit-wrapper { display: flex; flex-grow: 1; gap: 0.5rem; align-items: center; }
.edit-input { flex-grow: 1; background: var(--bg-main); border: 1px solid var(--primary); border-radius: 6px; padding: 0.4rem 0.75rem; color: var(--text-primary); outline: none; font-size: 0.95rem; box-shadow: 0 0 0 2px var(--ring); }
.save-btn { background: var(--primary); color: white; border: none; border-radius: 6px; padding: 0.4rem 0.8rem; font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: background 0.2s; }
.save-btn:hover { background: var(--primary-hover); }

/* --- Footer --- */
.app-footer { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; border-top: 1px solid var(--border); background: var(--footer-bg); }
.badge { background: var(--bg-main); border: 1px solid var(--border); color: var(--text-secondary); padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.text-btn { background: none; border: none; color: var(--text-secondary); font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: color 0.2s; }
.text-btn:hover { color: var(--text-primary); }