:root {
    --primary: #4F46E5;
    --primary-light: #EEF2FF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --bg: #F9FAFB;
    --card: #FFFFFF;
    --green: #10B981;
    --red: #EF4444;
    --amber: #F59E0B;
    --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 60px;
}

/* Header */
#sticky-top {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card);
}

header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Search bar */
#search-bar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 7px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}

.search-icon-svg {
    color: var(--text-muted);
    flex-shrink: 0;
    width: 15px;
    height: 15px;
}

#search-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 0.88rem;
    color: var(--text);
    min-width: 0;
}

#search-input::placeholder { color: #B0B7C3; }

#search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
    transition: color 0.1s;
}

#search-clear:hover { color: var(--text); }
#search-clear.hidden { display: none; }

mark {
    background: #FEF08A;
    color: var(--text);
    border-radius: 2px;
    padding: 0 1px;
}

.search-results { grid-column: 1 / -1; }

.header-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
}

#header-summary {
    font-size: 0.8rem;
    color: var(--text-muted);
}

#btn-add {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
    transition: transform 0.1s, box-shadow 0.1s;
}

#btn-add:hover { transform: scale(1.08); box-shadow: 0 4px 14px rgba(79, 70, 229, 0.5); }
#btn-add:active { transform: scale(0.95); }

/* Modal */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}

#modal-overlay.hidden { display: none; }

#modal {
    background: var(--card);
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
    animation: modal-in 0.2s ease;
}

@keyframes modal-in {
    from { transform: translateY(12px) scale(0.98); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

#modal h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

#task-title {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 10px 13px;
    font-size: 1rem;
    outline: none;
    margin-bottom: 13px;
    transition: border-color 0.15s;
}

#task-title:focus { border-color: var(--primary); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 13px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 13px;
}

.form-row .form-group { margin-bottom: 0; }

label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

input[type="date"],
input[type="time"],
select {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 0.9rem;
    outline: none;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s;
}

input[type="date"]:focus,
input[type="time"]:focus,
select:focus { border-color: var(--primary); }

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-actions button {
    padding: 9px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.15s;
}

#btn-cancel { background: var(--bg); color: var(--text-muted); }
#btn-cancel:hover { background: var(--border); }

.modal-actions button[type="submit"] { background: var(--primary); color: #fff; }
.modal-actions button[type="submit"]:hover { background: #4338CA; }

/* Undo toast */
#undo-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1F2937;
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.88rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    z-index: 300;
    white-space: nowrap;
    animation: modal-in 0.2s ease;
}

#undo-toast.hidden { display: none; }

#undo-btn {
    background: none;
    border: 1.5px solid rgba(255,255,255,0.4);
    color: #fff;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}

#undo-btn:hover { background: rgba(255,255,255,0.15); }

/* Bevestigingsdialog */
#confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
}

#confirm-overlay.hidden { display: none; }

#confirm-dialog {
    background: var(--card);
    border-radius: 14px;
    padding: 28px 24px 24px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
    animation: modal-in 0.2s ease;
}

.confirm-icon {
    width: 48px;
    height: 48px;
    background: var(--green);
    color: #fff;
    border-radius: 50%;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}

#confirm-dialog h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
}

#confirm-dialog p {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 20px;
    word-break: break-word;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-actions button {
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.15s;
}

#confirm-no  { background: var(--bg); color: var(--text-muted); }
#confirm-no:hover { background: var(--border); }
#confirm-yes { background: var(--green); color: #fff; }
#confirm-yes:hover { background: #0EA472; }

/* Task list */
main { padding: 16px 20px; }

@media (min-width: 560px) {
    .task-group {
        background: var(--card);
        border: 1px solid var(--border);
        border-left: 3px solid var(--primary);
        border-radius: var(--radius);
        padding: 14px 14px 10px;
    }

    .task-group.group-overdue { border-left-color: var(--red); }
    .task-group.group-today   { border-left-color: var(--amber); background: #FFFDF5; }
    .task-group[data-group="none"],
    .task-group[data-group="done"] { border-left-color: var(--border); }
}

@media (min-width: 860px) {
    main {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
        align-items: start;
    }

    .task-group[data-group="none"],
    .task-group[data-group="done"] {
        grid-column: 1 / -1;
    }

    .empty-state { grid-column: 1 / -1; }
    .error-banner { grid-column: 1 / -1; }
}

@media (min-width: 560px) and (max-width: 859px) {
    main {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        align-items: start;
    }

    .task-group[data-group="none"],
    .task-group[data-group="done"] {
        grid-column: 1 / -1;
    }

    .empty-state { grid-column: 1 / -1; }
    .error-banner { grid-column: 1 / -1; }
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 48px;
    font-size: 0.9rem;
}

/* Groups */
.task-group { margin-bottom: 26px; }

.group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 2px;
}

.group-header h2 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.group-count {
    font-size: 0.68rem;
    background: var(--border);
    color: var(--text-muted);
    padding: 1px 7px;
    border-radius: 99px;
}

.group-sub {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
}

.group-time {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: auto;
}

.group-today .group-header h2 { color: var(--amber); }
.group-overdue .group-header h2 { color: var(--red); }

/* Task items */
.task-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 13px;
    transition: box-shadow 0.15s, transform 0.1s;
}

.task-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.07); }

.task-item.completed { opacity: 0.6; }
.task-item.completed .task-title { text-decoration: line-through; color: var(--text-muted); }

.drag-handle {
    color: #D1D5DB;
    font-size: 0.95rem;
    cursor: grab;
    flex-shrink: 0;
    padding: 2px 1px;
    user-select: none;
}

.drag-handle:active { cursor: grabbing; }

.task-check {
    width: 26px;
    height: 26px;
    border: 2.5px solid #9CA3AF;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    background: #fff;
}

.task-check:hover { border-color: var(--green); background: #F0FDF4; }
.task-check.done { background: var(--green); border-color: var(--green); }
.task-check.done::after { content: '✓'; color: #fff; font-size: 13px; font-weight: 700; }

.task-body {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.task-title {
    font-size: 0.93rem;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-meta {
    display: flex;
    gap: 9px;
    margin-top: 3px;
    flex-wrap: wrap;
}

.meta-chip {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 2px;
}

.meta-chip.date { color: var(--primary); }


/* Drag states */
.sortable-ghost { opacity: 0.35; background: var(--primary-light); }
.sortable-chosen { box-shadow: 0 6px 24px rgba(0,0,0,0.14); transform: scale(1.015); z-index: 10; }

/* Completed group toggle */
.done-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
}

.done-toggle:hover { color: var(--text); }

.done-toggle .arrow { transition: transform 0.2s; }
.done-toggle.collapsed .arrow { transform: rotate(-90deg); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 56px 20px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-state p { font-size: 0.88rem; }

/* Connection error */
.error-banner {
    background: #FEE2E2;
    border: 1px solid #FECACA;
    color: var(--red);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    margin-bottom: 16px;
}

@media (max-width: 480px) {
    header { padding: 12px 16px; }
    main { padding: 12px 16px; }
    #modal { padding: 20px 18px; }
}

/* Inloggen */
.hidden { display: none !important; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 6px 4px;
}

#btn-logout:hover { color: var(--text); text-decoration: underline; }

#login-screen {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#login-form {
    background: var(--card);
    border-radius: 14px;
    padding: 28px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.12);
}

#login-form h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.login-sub {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin: 4px 0 18px;
}

#login-form input {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 1rem;
    outline: none;
    background: var(--card);
    color: var(--text);
}

#login-form input:focus { border-color: var(--primary); }

#login-error {
    background: #FEF2F2;
    color: #B91C1C;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.85rem;
    margin-bottom: 13px;
}

#login-submit {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

#login-submit:hover { background: #4338CA; }
#login-submit:disabled { opacity: 0.6; cursor: default; }
