/* ==========================================================================
   Design tokens
   One palette, one type scale, one spacing scale. Nothing off-scale.
   Every text colour is verified against WCAG AA on its own ground.
   ========================================================================== */

:root {
    --ink:        #16191D;
    --paper:      #FCFCFB;
    --rail:       #F4F4F2;
    --surface:    #FFFFFF;
    --line:       #E4E4E0;
    --line-soft:  #EFEFEC;
    --muted:      #5F6570;
    --accent:     #0F6E5C;
    --accent-ink: #0B5546;
    --accent-wash:#EAF2F0;

    --prio-high:  #B3261E;
    --prio-med:   #8A5200;
    --prio-low:   #1F6B4A;
    --high-wash:  #FBECEB;

    --t-xs:    0.75rem;
    --t-sm:    0.8125rem;
    --t-base:  0.9375rem;
    --t-md:    1.125rem;
    --t-lg:    1.75rem;
    --t-xl:    2.25rem;

    --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --s1: 4px;   --s2: 8px;   --s3: 12px;  --s4: 16px;
    --s5: 24px;  --s6: 32px;  --s7: 48px;  --s8: 64px;

    --r:    6px;
    --r-lg: 10px;
    --r-sm: 2px;

    --shadow: 0 1px 2px rgba(22, 25, 29, 0.04), 0 1px 3px rgba(22, 25, 29, 0.03);
    --ease: cubic-bezier(0.2, 0, 0.13, 1);
}

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

body {
    font-family: var(--sans);
    font-size: var(--t-base);
    line-height: 1.6;
    background-color: var(--paper);
    color: var(--ink);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.icon {
    width: 16px;
    height: 16px;
    display: block;
    flex: none;
}

/* ==========================================================================
   Shell
   ========================================================================== */

.app {
    display: grid;
    grid-template-columns: 264px 1fr;
    height: 100vh;
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: var(--s5) var(--s6) var(--s8);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
    background-color: var(--rail);
    border-right: 1px solid var(--line);
    padding: var(--s5) var(--s3);
    display: flex;
    flex-direction: column;
    gap: var(--s5);
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: 0 var(--s2);
}

/* The lambda is the whole identity: this is a functional-programming
   showcase, so the mark says so rather than a generic checkmark. */
.brand-mark {
    width: 34px;
    height: 34px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r);
    background: var(--accent);
    color: #fff;
    font-family: var(--mono);
    font-size: var(--t-md);
    font-weight: 500;
    line-height: 1;
}

.brand-text { min-width: 0; }

.brand-name {
    font-size: var(--t-base);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: var(--t-xs);
    color: var(--muted);
    line-height: 1.3;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-label {
    padding: var(--s3) var(--s2) var(--s1);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    border-radius: var(--r);
    font-size: var(--t-sm);
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-item:hover { background-color: rgba(22, 25, 29, 0.05); }

.nav-item.active {
    background-color: var(--accent-wash);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    border-radius: var(--r-sm);
    background-color: var(--accent);
}

.nav-icon { display: flex; color: var(--muted); }
.nav-item.active .nav-icon { color: var(--accent); }

.nav-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Counts in mono so the column of numbers aligns down the rail. */
.nav-count {
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.nav-item.active .nav-count { color: var(--accent); }

.nav-dot {
    width: 8px;
    height: 8px;
    flex: none;
    margin: 0 4px;
    border-radius: 50%;
}

.dot-high   { background: var(--prio-high); }
.dot-medium { background: var(--prio-med); }
.dot-low    { background: var(--prio-low); }

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s5);
    padding: var(--s5) var(--s6);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    flex: none;
}

.topbar-heading { min-width: 0; }

h1.view-title {
    font-size: var(--t-lg);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--ink);
}

.view-sub {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-top: 2px;
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.dot-sep { color: var(--line); }

.search {
    position: relative;
    display: flex;
    align-items: center;
    width: 280px;
    flex: none;
}

.search-icon {
    position: absolute;
    left: var(--s3);
    display: flex;
    color: var(--muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: var(--s2) var(--s7) var(--s2) var(--s6);
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--rail);
    font-family: var(--sans);
    font-size: var(--t-sm);
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.search-input::placeholder { color: var(--muted); }

.search-input:hover { border-color: var(--muted); }

.search-input:focus {
    background: var(--surface);
    border-color: var(--accent);
}

.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
    position: absolute;
    right: var(--s2);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: var(--t-md);
    line-height: 1;
    cursor: pointer;
}

.search-clear:hover { background: var(--line); color: var(--ink); }

/* ==========================================================================
   Stat tiles
   ========================================================================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--s3);
    margin-bottom: var(--s5);
}

.stat {
    position: relative;
    padding: var(--s4);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* A tone bar rather than a coloured card: the number stays the loudest
   thing in the tile, and four saturated panels would fight the task list. */
.stat::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--line);
}

.stat-accent::before { background: var(--accent); }
.stat-done::before   { background: var(--prio-low); }
.stat-warn::before   { background: var(--prio-high); }

.stat-value {
    font-family: var(--mono);
    font-size: var(--t-xl);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.stat-warn .stat-value { color: var(--prio-high); }

.stat-label {
    margin-top: var(--s1);
    font-size: var(--t-xs);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ==========================================================================
   Two-column body
   ========================================================================== */

.columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: var(--s5);
    align-items: start;
}

.col-main { min-width: 0; }

.col-rail {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    position: sticky;
    top: 0;
}

.card {
    padding: var(--s4);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: var(--s3);
}

.progress-figure {
    display: flex;
    align-items: baseline;
    gap: 2px;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.progress-value {
    font-size: var(--t-xl);
    font-weight: 500;
    line-height: 1;
    letter-spacing: -0.03em;
}

.progress-unit { font-size: var(--t-md); color: var(--muted); }

.progress-track,
.breakdown-track {
    height: 6px;
    border-radius: 999px;
    background: var(--rail);
    overflow: hidden;
}

.progress-track { margin: var(--s3) 0 var(--s2); }

.progress-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width 0.4s var(--ease);
}

.card-note {
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.breakdown-row {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s2) 0;
}

.breakdown-row + .breakdown-row { border-top: 1px solid var(--line-soft); }

.breakdown-label {
    width: 58px;
    flex: none;
    font-size: var(--t-sm);
}

.breakdown-track { flex: 1; }

.breakdown-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s var(--ease);
}

.fill-high   { background: var(--prio-high); }
.fill-medium { background: var(--prio-med); }
.fill-low    { background: var(--prio-low); }

.breakdown-count {
    width: 20px;
    flex: none;
    text-align: right;
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

/* ==========================================================================
   Add task
   NB: `display` on the trigger and the form is driven by inline style from
   Laminar, so these rules must hold without owning that property.
   ========================================================================== */

.add-task-trigger {
    align-items: center;
    gap: var(--s3);
    padding: var(--s3) var(--s4);
    margin-bottom: var(--s4);
    border: 1px dashed var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--muted);
    font-size: var(--t-base);
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s var(--ease), color 0.15s var(--ease),
                background-color 0.15s var(--ease);
}

.add-task-trigger:hover {
    border-color: var(--accent);
    border-style: solid;
    background-color: var(--accent-wash);
    color: var(--accent);
}

.add-task-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: none;
    border-radius: 50%;
    background-color: var(--accent);
    color: #fff;
    font-size: var(--t-base);
    font-weight: 500;
    line-height: 1;
}

.add-task-form {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s4);
    margin-bottom: var(--s4);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.quick-add-input {
    width: 100%;
    border: none;
    font-family: var(--sans);
    font-size: var(--t-md);
    font-weight: 500;
    line-height: 1.4;
    padding: 0 0 var(--s3);
    outline: none;
    background: transparent;
    color: var(--ink);
}

.quick-add-input::placeholder { color: var(--muted); font-weight: 400; }

.advanced-options {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s3);
    padding-top: var(--s3);
    border-top: 1px solid var(--line);
}

.option-field { flex: 1; min-width: 140px; }

.option-field label {
    display: block;
    font-size: var(--t-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: var(--s1);
}

select, input[type="date"], input[type="time"] {
    width: 100%;
    padding: var(--s2) var(--s3);
    border: 1px solid var(--line);
    border-radius: var(--r);
    font-family: var(--mono);
    font-size: var(--t-sm);
    background: var(--rail);
    color: var(--ink);
    transition: border-color 0.15s var(--ease);
}

select { font-family: var(--sans); }

select:hover, input[type="date"]:hover, input[type="time"]:hover {
    border-color: var(--muted);
}

.add-task-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--s2);
    margin-top: var(--s4);
    padding-top: var(--s4);
    border-top: 1px solid var(--line);
}

.btn-cancel, .btn-submit {
    border: 1px solid transparent;
    padding: var(--s2) var(--s4);
    border-radius: var(--r);
    font-family: var(--sans);
    font-size: var(--t-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn-cancel { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-cancel:hover { background: var(--rail); color: var(--ink); }

.btn-submit { background: var(--accent); color: #fff; }
.btn-submit:hover { background: var(--accent-ink); }

.btn-submit:disabled {
    background: var(--rail);
    border-color: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

/* ==========================================================================
   Task list
   ========================================================================== */

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

.group-header {
    display: flex;
    align-items: center;
    gap: var(--s3);
    margin: var(--s4) 0 var(--s2);
}

.task-list > .group-header:first-child { margin-top: 0; }

.group-name {
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    flex: none;
}

.group-overdue .group-name { color: var(--prio-high); }

.group-rule { flex: 1; height: 1px; background: var(--line); }

.group-count {
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    flex: none;
}

/* Rows are cards now. At two tasks a bare list read as an unfinished page;
   a bounded surface gives the content weight without adding decoration. */
.task-row {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--s3);
    padding: var(--s3) var(--s3) var(--s3) var(--s4);
    margin-bottom: var(--s2);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.task-row:hover {
    border-color: #D6D6D1;
    box-shadow: var(--shadow);
}

/* The priority spine: the only saturated colour on a row. */
.task-row::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--line);
    transition: background-color 0.2s var(--ease);
}

.task-row--high::before   { background-color: var(--prio-high); }
.task-row--medium::before { background-color: var(--prio-med); }
.task-row--low::before    { background-color: var(--prio-low); }

.task-row.completed { background: var(--rail); }
.task-row.completed::before { background-color: var(--line); }

.task-checkbox-wrapper { padding-top: 2px; flex: none; }

.task-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    flex: none;
    border: 1.5px solid var(--muted);
    border-radius: var(--r-sm);
    background-color: var(--surface);
    cursor: pointer;
    transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.task-checkbox:hover { border-color: var(--accent); }

.task-checkbox:checked {
    background-color: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.2l2.3 2.3 4.7-4.7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 12px 12px;
}

.task-body { flex-grow: 1; min-width: 0; }

.task-title {
    font-size: var(--t-base);
    font-weight: 400;
    line-height: 1.5;
    color: var(--ink);
    margin-bottom: var(--s1);
    overflow-wrap: anywhere;
}

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

.task-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s1) var(--s3);
    font-family: var(--mono);
    font-size: var(--t-xs);
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
    color: var(--muted);
}

.priority-label { font-size: var(--t-xs); font-weight: 500; }

.priority-high   { color: var(--prio-high); }
.priority-medium { color: var(--prio-med); }
.priority-low    { color: var(--prio-low); }

.task-row.completed .priority-label { color: var(--muted); }

.overdue-chip {
    padding: 1px var(--s2);
    border-radius: 999px;
    background: var(--high-wash);
    color: var(--prio-high);
    font-family: var(--sans);
    font-size: var(--t-xs);
    font-weight: 600;
}

.task-actions { flex: none; opacity: 0; transition: opacity 0.15s var(--ease); }

.task-row:hover .task-actions,
.task-row:focus-within .task-actions { opacity: 1; }

.delete-action {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--sans);
    font-size: var(--t-sm);
    font-weight: 500;
    padding: var(--s1) var(--s2);
    border-radius: var(--r);
    transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.delete-action:hover { color: var(--prio-high); background: var(--high-wash); }

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--s8) var(--s5);
    border: 1px dashed var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
}

.empty-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: var(--s3);
    border-radius: 50%;
    background: var(--accent-wash);
    color: var(--accent);
}

.empty-mark .icon { width: 20px; height: 20px; }

.empty-heading { font-size: var(--t-base); font-weight: 600; color: var(--ink); }

.empty-body {
    margin-top: 2px;
    font-size: var(--t-sm);
    color: var(--muted);
    max-width: 34ch;
}

/* ==========================================================================
   Focus & motion
   ========================================================================== */

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

.search-input:focus-visible { outline-offset: 1px; }
.quick-add-input:focus-visible { outline-offset: 4px; }
.nav-item:focus-visible { outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Below this the rail costs more than it gives — the list needs the width. */
@media (max-width: 1120px) {
    .columns { grid-template-columns: minmax(0, 1fr); }

    .col-rail {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .col-rail .card { flex: 1; min-width: 240px; }
}

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; height: auto; overflow-y: auto; }

    body { height: auto; overflow-y: auto; }

    .main { overflow: visible; }

    .content { overflow: visible; padding: var(--s4) var(--s4) var(--s7); }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--line);
        padding: var(--s3);
        gap: var(--s3);
        overflow: visible;
    }

    .brand { padding: var(--s1) var(--s2); }

    /* Wrapping, never a horizontal scroller: every filter stays visible. */
    .nav { flex-direction: row; flex-wrap: wrap; gap: var(--s1); }

    .nav-label { flex-basis: 100%; padding: var(--s2) var(--s2) 0; }

    .nav-item { min-height: 40px; border: 1px solid transparent; }

    .nav-item.active { border-color: var(--accent); }
    .nav-item.active::before { content: none; }

    .nav-text { flex: 0 1 auto; }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: var(--s3);
        padding: var(--s4);
    }

    .search { width: 100%; }
}

@media (max-width: 620px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
    h1.view-title { font-size: 1.5rem; }
    .stat-value, .progress-value { font-size: 1.75rem; }
    .option-field { min-width: 100%; }
    .add-task-actions .btn-cancel,
    .add-task-actions .btn-submit { flex: 1; }
}

@media (hover: none) {
    .task-actions { opacity: 1; }
    .task-row:hover { border-color: var(--line); box-shadow: none; }

    .delete-action {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        min-width: 44px;
    }

    .task-checkbox { width: 22px; height: 22px; background-size: 14px 14px; }

    .nav-item { min-height: 44px; }
}

/* ---- Unreadable-payload notice -------------------------------------- */
/* Shown only when startup found stored tasks it could not decode. Uses the
   high-priority wash rather than a new colour, so it reads as "attention"
   without introducing a token that exists for one element. */

.notice {
    display: none;              /* Laminar flips this to flex when it applies */
    align-items: flex-start;
    gap: var(--s3);
    margin-bottom: var(--s4);
    padding: var(--s3) var(--s4);
    border: 1px solid var(--prio-high);
    border-radius: var(--r-lg);
    background: var(--high-wash);
    color: var(--ink);
}

.notice-body { flex: 1; min-width: 0; }

.notice-title {
    font-size: var(--t-base);
    font-weight: 600;
    margin-bottom: var(--s1);
}

.notice-text {
    font-size: var(--t-sm);
    color: var(--muted);
    line-height: 1.5;
    overflow-wrap: anywhere;    /* the storage key is a long unbroken token */
}

.notice-dismiss {
    flex: none;
    width: 32px;
    height: 32px;               /* keeps the 32px touch target used elsewhere */
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--r);
    background: transparent;
    color: var(--muted);
    font-size: var(--t-md);
    line-height: 1;
    cursor: pointer;
}

.notice-dismiss:hover { background: rgba(0, 0, 0, 0.06); color: var(--ink); }
