:root {
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition: all 0.2s ease-in-out;
}

/* Thème Sombre */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0b1120;
    --border: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

/* Thème Clair */
[data-theme="light"] {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --border: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #059669;
    --warning: #d97706;
    --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: var(--font);
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
}

.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    flex-shrink: 0;
    transition: var(--transition);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 30px;
    padding-left: 8px;
    color: #ffffff;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #f8fafc;
}

.nav-item.active {
    background-color: var(--primary);
    color: #ffffff;
}

.nav-item .label {
    flex-grow: 1;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Content */
.content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.container {
    padding: 24px;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
}

/* Grilles & Cartes */
.grid {
    display: grid;
    gap: 20px;
}
.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-body {
    padding: 20px;
}

/* En-tête cliquable pour repliage */
.header-clickable {
    cursor: pointer;
    user-select: none;
}
.header-clickable:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.btn-collapse {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}
.btn-collapse:hover {
    background-color: var(--primary-hover);
    transform: scale(1.08);
}
.btn-collapse.active {
    background-color: var(--border);
    color: var(--text-main);
}

/* Formulaires */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

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

input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    background-color: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.span-2 {
    grid-column: span 2;
}

.align-end {
    display: flex;
    align-items: flex-end;
}

.inline-add-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text-main); }
.btn-danger-outline { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { background-color: var(--border); }

.action-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Tâches */
.task-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background-color: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: var(--transition);
}

.task-late {
    border-left: 4px solid var(--danger);
}

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

.task-content {
    flex-grow: 1;
}

.task-title {
    font-weight: 500;
}

.task-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.8rem;
}

/* Badges */
.badge {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-count { background: rgba(255, 255, 255, 0.2); color: #fff; }
.badge-warning { background: var(--warning); color: #000; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-success { background: var(--success); color: #fff; }
.badge-secondary { background: var(--border); color: var(--text-muted); }

.priority-high { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.priority-medium { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.priority-low { background: rgba(16, 185, 129, 0.2); color: #10b981; }

.cat-pill {
    padding: 2px 6px;
    background: var(--bg-card);
    border-left: 3px solid #2563eb;
    font-size: 0.75rem;
    border-radius: 2px;
}

.color-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

/* Checkbox */
.checkbox-container {
    position: relative;
    cursor: pointer;
    user-select: none;
    width: 20px;
    height: 20px;
}
.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0; width: 0;
}
.checkmark {
    position: absolute;
    top: 0; left: 0;
    height: 20px; width: 20px;
    background-color: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 6px;
}
.checkbox-container input:checked ~ .checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
}
.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px; top: 2px;
    width: 5px; height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

/* Scratchpad */
.scratchpad-area {
    width: 100%;
    min-height: 220px;
    resize: vertical;
    border: 1px solid var(--border);
    background-color: var(--bg-body);
    font-family: inherit;
    padding: 12px;
    line-height: 1.5;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table th, .table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.table th {
    color: var(--text-muted);
    font-weight: 600;
}
.table-select {
    padding: 4px 8px;
    font-size: 0.85rem;
    width: auto;
}
.row-muted {
    opacity: 0.6;
}

/* Notes */
.note-body {
    line-height: 1.6;
    margin-bottom: 15px;
    white-space: pre-line;
}
.note-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* Modale universelle d'édition */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    backdrop-filter: blur(3px);
}

.modal-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6);
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* PIN Auth View */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-body);
}

.auth-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: var(--card-shadow);
}

.pin-container .logo-circle {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

#pin-display {
    text-align: center;
    letter-spacing: 16px;
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 16px;
    background: var(--bg-body);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.key {
    background-color: var(--bg-body);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-size: 1.5rem;
    font-weight: 600;
    padding: 16px 0;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.key:active {
    background-color: var(--primary);
    color: #fff;
}

.key-action {
    font-size: 1.2rem;
}

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.alert.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid var(--danger); }
.alert.success { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid var(--success); }

/* Responsive */
@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .sidebar {
        display: none;
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 100;
        width: 260px;
    }
    .sidebar.open { display: flex; }
    .mobile-toggle { display: block; }
    .span-2 { grid-column: span 1; }
}