/* ------------------------------------------------------------------
   Tasks — minimalist stylesheet
   Sans-serif, restrained palette, generous white space.
------------------------------------------------------------------ */

:root {
    --bg:        #ffffff;
    --surface:   #ffffff;
    --ink:       #1a1a1a;
    --ink-soft:  #6b6b6b;
    --ink-faint: #a0a0a0;
    --line:      #ececec;
    --line-2:    #e0e0e0;
    --accent:    #1a1a1a;      /* near-black accent keeps it monochrome */
    --danger:    #b00020;
    --flag:      #c8a200;      /* muted gold for priority */
    --overdue:   #b00020;
    --radius:    8px;
    --gap:       1rem;
    --maxw:      720px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Login / setup ---------- */

.login-body {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.login-card {
    width: 100%;
    max-width: 340px;
}
.login-title {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0 0 1.5rem;
    text-align: center;
}
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--ink-soft); }
.login-form input {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    font: inherit;
    color: var(--ink);
}
.login-form input:focus { outline: none; border-color: var(--ink); }
.login-form button {
    margin-top: 0.5rem;
    padding: 0.7rem;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
.login-error {
    background: #fdecef;
    color: var(--danger);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin: 0 0 1rem;
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.9);
    backdrop-filter: saturate(180%) blur(8px);
    z-index: 10;
}
.nav { display: flex; gap: 1.5rem; }
.nav-link {
    text-decoration: none;
    color: var(--ink-faint);
    font-size: 0.95rem;
    font-weight: 500;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s;
}
.nav-link:hover { color: var(--ink-soft); }
.nav-link.is-active { color: var(--ink); border-bottom-color: var(--ink); }
.nav-right { display: flex; align-items: center; gap: 1.25rem; }
.nav-logout { text-decoration: none; color: var(--ink-faint); font-size: 0.85rem; }
.nav-logout:hover { color: var(--ink-soft); }

/* ---------- Page ---------- */

.container {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 2.5rem 1.5rem 6rem;
}
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}
.page-title {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin: 0;
}
.btn-add {
    border: 1px solid var(--line-2);
    background: var(--surface);
    color: var(--ink);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.btn-add:hover { border-color: var(--ink); }

.page-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
/* Quieter secondary action (e.g. "Delete completed") */
.btn-ghost-sm {
    border: 1px solid transparent;
    background: none;
    color: var(--ink-faint);
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.btn-ghost-sm:hover {
    color: var(--danger);
    border-color: var(--line-2);
}

/* ---------- Controls (search + tag filter) ---------- */

.controls {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}
.search-input {
    flex: 1 1 auto;
    font: inherit;
    color: var(--ink);
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--surface);
}
.search-input::placeholder { color: var(--ink-faint); }
.search-input:focus { outline: none; border-color: var(--ink); }

.tag-filter {
    flex: 0 0 auto;
    font: inherit;
    color: var(--ink);
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    max-width: 40%;
}
.tag-filter:focus { outline: none; border-color: var(--ink); }

.loading, .empty {
    color: var(--ink-faint);
    text-align: center;
    padding: 3rem 0;
    font-size: 0.95rem;
}

/* ---------- Task list ---------- */

.task-list { display: flex; flex-direction: column; gap: 0.25rem; }

/* Date cluster headers (All tasks view) */
.date-group {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin: 1.75rem 0 0.25rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--line);
}
.date-group:first-child { margin-top: 0; }

.task {
    border-bottom: 1px solid var(--line);
    padding: 0.85rem 0;
}
/* The card body is clickable to edit; the checkbox and action buttons
   have their own pointers and stop short of triggering edit. */
.task-main { cursor: pointer; }
.subtask { cursor: pointer; }
.task-main {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    border: 1.5px solid var(--line-2);
    border-radius: 50%;
    cursor: pointer;
    flex: 0 0 auto;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
}
.checkbox:hover { border-color: var(--ink-soft); }
.checkbox:checked { background: var(--ink); border-color: var(--ink); }
.checkbox:checked::after {
    content: "";
    position: absolute;
    left: 5px; top: 2px;
    width: 4px; height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.task-body { flex: 1 1 auto; min-width: 0; }
.task-titleline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.task-title {
    font-size: 1rem;
    color: var(--ink);
    word-break: break-word;
}
.task.is-done .task-title { color: var(--ink-faint); text-decoration: line-through; }

.flag { color: var(--flag); font-size: 0.9rem; line-height: 1; }
.recur-badge {
    font-size: 0.7rem;
    color: var(--ink-faint);
    border: 1px solid var(--line-2);
    border-radius: 4px;
    padding: 1px 5px;
    text-transform: lowercase;
}

.task-desc {
    color: var(--ink-soft);
    font-size: 0.875rem;
    margin: 0.25rem 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.task-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.4rem;
    flex-wrap: wrap;
}
.deadline { font-size: 0.8rem; color: var(--ink-soft); }
.deadline.is-overdue { color: var(--overdue); font-weight: 500; }

.labels { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.label-chip {
    font-size: 0.72rem;
    color: var(--ink-soft);
    background: #f5f5f5;
    border-radius: 4px;
    padding: 1px 7px;
}

.task-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s;
    flex: 0 0 auto;
}
.task-main:hover .task-actions,
.subtask:hover .task-actions { opacity: 1; }
.icon-btn {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--ink-faint);
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
}
.icon-btn:hover { color: var(--ink); background: #f2f2f2; }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Subtasks ---------- */

/* Collapse toggle shown above the subtask group */
.subtasks-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.35rem 0 0 2.5rem;
    padding: 0.15rem 0;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--ink-faint);
    font: inherit;
    font-size: 0.8rem;
}
.subtasks-toggle:hover { color: var(--ink-soft); }
.chevron {
    display: inline-block;
    font-size: 0.7rem;
    line-height: 1;
    transition: transform 0.15s ease;
}
.chevron.is-collapsed { transform: rotate(-90deg); }
.subtasks-count { letter-spacing: 0.01em; }

.subtasks {
    margin: 0.4rem 0 0 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.subtasks.is-collapsed { display: none; }
.subtask {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.4rem 0;
}
.subtask .checkbox { width: 15px; height: 15px; }
.subtask .checkbox:checked::after { left: 4px; top: 1px; width: 3px; height: 7px; }
.subtask-title { font-size: 0.92rem; }
.subtask.is-done .subtask-title { color: var(--ink-faint); text-decoration: line-through; }

.add-subtask {
    margin: 0.4rem 0 0 2.5rem;
    border: none;
    background: none;
    color: var(--ink-faint);
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 0.2rem 0;
}
.add-subtask:hover { color: var(--ink); }

/* ---------- Dialog ---------- */

.dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    width: 90%;
    max-width: 460px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18);
    color: var(--ink);
}
.dialog::backdrop { background: rgba(0,0,0,0.25); }
.dialog-form { padding: 1.75rem; display: flex; flex-direction: column; gap: 1rem; }
.dialog-title { font-size: 1.2rem; font-weight: 600; margin: 0 0 0.25rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.82rem; color: var(--ink-soft); }
.field small { color: var(--ink-faint); font-weight: 400; }
.field input, .field textarea, .field select {
    font: inherit;
    color: var(--ink);
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: #fff;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--ink); }
.field-row { display: flex; gap: 0.75rem; }
.field-row .field { flex: 1; }
.field-row.single .field { flex: 1 1 100%; }
/* Ensure [hidden] wins over .field's display:flex */
.field[hidden] { display: none !important; }
.field-check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--ink); cursor: pointer; }
.field-check input { width: 16px; height: 16px; }

.dialog-error { background: #fdecef; color: var(--danger); padding: 0.5rem 0.65rem; border-radius: var(--radius); font-size: 0.82rem; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }
.btn-ghost {
    border: 1px solid var(--line-2);
    background: #fff;
    color: var(--ink-soft);
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    font: inherit;
    cursor: pointer;
}
.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-primary {
    border: none;
    background: var(--accent);
    color: #fff;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}
.btn-primary:hover { opacity: 0.9; }

/* ---------- Settings ---------- */

.settings {
    display: flex;
    flex-direction: column;
    gap: 3rem;
    max-width: 520px;
}
.settings-section { }
.settings-heading {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
}
.settings-note {
    color: var(--ink-soft);
    font-size: 0.85rem;
    margin: 0 0 1rem;
}
.settings-form { display: flex; flex-direction: column; gap: 1rem; max-width: 360px; }
.settings-actions { margin-top: 0.25rem; }

.form-msg {
    font-size: 0.85rem;
    margin: 0;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius);
}
.form-msg.is-error { background: #fdecef; color: var(--danger); }
.form-msg.is-ok { background: #eef7ee; color: #2e7d32; }

.label-add {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
    max-width: 420px;
}
.label-add .search-input { flex: 1 1 auto; }

.label-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.label-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--line);
}
.label-row .label-chip { flex: 0 0 auto; }
.label-usage { color: var(--ink-faint); font-size: 0.8rem; flex: 1 1 auto; }
.label-row .icon-btn {
    flex: 0 0 auto;
    opacity: 0.6;
}
.label-row:hover .icon-btn { opacity: 1; }
.empty-row, .label-list .loading { color: var(--ink-faint); font-size: 0.9rem; padding: 0.75rem 0; }

@media (max-width: 520px) {
    .container { padding: 1.75rem 1.1rem 5rem; }
    .field-row { flex-direction: column; gap: 1rem; }
    .subtasks, .add-subtask { margin-left: 1.75rem; }
    .nav-right { gap: 0.9rem; }
}
