:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-body: #f3f4f6;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

[data-theme="dark"] {
    --primary: #6366f1;
    --bg-body: #111827;
    --bg-sidebar: #1f2937;
    --bg-card: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --border: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    cursor: pointer;
}

.app-wrapper {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    contain: strict;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 3rem;
    color: var(--primary);
}

.logo-section h2 {
    font-weight: 700;
    font-size: 1.5rem;
}

.logo-icon {
    font-size: 2rem;
}

.nav-links {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.95rem;
    text-align: left;
    transition: background-color 0.15s ease, color 0.15s ease;
    will-change: background-color;
}

.nav-btn:hover {
    background: rgba(0,0,0,0.05);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
}

.nav-footer {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 10px;
    border-radius: var(--radius);
    transition: background-color 0.15s ease;
}

.theme-toggle:hover {
    background: rgba(0,0,0,0.05);
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    will-change: scroll-position;
    contain: layout style;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

#page-title {
    font-size: 1.8rem;
    font-weight: 700;
}

#date-display {
    color: var(--text-muted);
    margin-top: 5px;
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.search-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 15px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    width: 300px;
}

.search-box input {
    border: none;
    background: transparent;
    width: 100%;
    color: var(--text-main);
}

.add-task-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.15s ease;
}

.add-task-btn:hover {
    background: var(--primary-hover);
}

.add-task-btn:disabled,
.btn-save:disabled,
.btn-danger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: var(--radius);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.15s ease;
}

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

.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
    contain: layout style;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.stat-icon.blue { background: #3b82f6; }
.stat-icon.orange { background: #f59e0b; }
.stat-icon.green { background: #10b981; }

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.stat-info span {
    font-size: 1.8rem;
    font-weight: 700;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.list-header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.select-all-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
}

#sort-select {
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
}

.task-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.separator-title {
    margin: 2.5rem 0 1rem;
    font-size: 1rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    font-weight: 600;
}

.task-item {
    background: var(--bg-card);
    padding: 1.2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 5px solid transparent;
    contain: layout style;
}

.priority-high { border-left-color: var(--danger); }
.priority-medium { border-left-color: var(--warning); }
.priority-low { border-left-color: var(--success); }

.task-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.custom-checkbox {
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    will-change: background-color;
}

.task-item.completed {
    opacity: 0.75;
    background: rgba(0,0,0,0.02);
    box-shadow: none;
}

.task-item.completed .custom-checkbox {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

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

.task-details {
    display: flex;
    flex-direction: column;
}

.task-title {
    font-weight: 600;
    font-size: 1rem;
}

.task-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.meta-tag {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0,0,0,0.05);
    padding: 2px 8px;
    border-radius: 4px;
}

.task-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selection-control {
    cursor: pointer;
    display: flex;
    align-items: center;
}

.hidden-checkbox {
    display: none;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn span {
    font-size: 22px;
}

.icon-btn:hover, .select-icon-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--primary);
}

.select-icon-btn.selected {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

.icon-btn.delete:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    will-change: opacity;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    contain: layout style;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.2rem;
    position: relative;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-main);
    transition: border-color 0.15s ease;
}

.form-group input.error,
.form-group textarea.error {
    border-color: var(--danger);
}

.error-message {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 4px;
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.priority-selector {
    display: flex;
    gap: 10px;
}

.priority-selector input {
    display: none;
}

.p-badge {
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.p-badge.low { color: var(--success); border-color: var(--success); }
.p-badge.medium { color: var(--warning); border-color: var(--warning); }
.p-badge.high { color: var(--danger); border-color: var(--danger); }

input:checked + .p-badge.low { background: var(--success); color: white; }
input:checked + .p-badge.medium { background: var(--warning); color: white; }
input:checked + .p-badge.high { background: var(--danger); color: white; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 1rem;
}

.btn-cancel {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    transition: background-color 0.15s ease;
}

.btn-save {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    transition: background-color 0.15s ease;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s ease;
}

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

.hidden {
    display: none !important;
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 200;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    will-change: transform, opacity;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state .material-icons-round {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}