/* Todo: dark, calm, angular. Tokens and rules from docs/UI_STYLE_GUIDE.md. */

:root {
    color-scheme: dark;

    --bg: #0a0c11;
    --surface-1: #10131a;
    --surface-2: #161a23;
    --surface-3: #1e232e;

    --border: #232937;
    --border-strong: #333b4e;

    --text: #e6e9f0;
    --muted: #8b94a8;

    --accent: #8394ff;
    --accent-strong: #5468f0;
    --accent-contrast: #ffffff;

    --attention: #f2b84b;
    --danger: #f06c6c;
    --success: #4cc38a;

    --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
    --accent-line: color-mix(in srgb, var(--accent) 38%, transparent);
    --attention-soft: color-mix(in srgb, var(--attention) 12%, transparent);
    --attention-line: color-mix(in srgb, var(--attention) 40%, transparent);
    --glass: color-mix(in srgb, var(--bg) 78%, transparent);
    --scrim: rgba(3, 5, 9, .62);

    --r-sm: 3px;
    --r: 5px;
    --r-lg: 8px;

    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;

    --fs-xs: 11px;
    --fs-sm: 12.5px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 19px;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);

    --font: Inter, system-ui, -apple-system, BlinkMacSystemFont,
            "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

:root[data-theme="graphite"] {
    --bg: #0c0d0f;
    --surface-1: #131416;
    --surface-2: #1a1c1f;
    --surface-3: #232529;
    --border: #2a2d32;
    --border-strong: #3b3f46;
    --text: #e8e9eb;
    --muted: #8f949c;
    --accent: #3fc8da;
    --accent-strong: #17a4b8;
    --accent-contrast: #021418;
}

:root[data-theme="ember"] {
    --bg: #0e0b0c;
    --surface-1: #151112;
    --surface-2: #1d1819;
    --surface-3: #261f21;
    --border: #31282a;
    --border-strong: #45383c;
    --text: #ede8e7;
    --muted: #9c9091;
    --accent: #ff8f62;
    --accent-strong: #e8663a;
    --accent-contrast: #1c0903;
}

/* --- Base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    overflow: hidden;
    background:
        radial-gradient(
            60rem 28rem at 70% -8rem,
            color-mix(in srgb, var(--accent) 9%, transparent),
            transparent 70%
        ),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

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

::selection { background: var(--accent-line); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

.eyebrow {
    margin: 0;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
}

.muted { color: var(--muted); }

.notice {
    margin: var(--s-4);
    padding: var(--s-3) var(--s-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-sm);
    color: var(--muted);
    font-size: var(--fs-sm);
}

.icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: 34px;
    padding: 0 var(--s-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s,
        transform .08s;
}

.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }

.btn.primary {
    border: 0;
    background: linear-gradient(
        to bottom,
        color-mix(in srgb, var(--accent-strong) 88%, white),
        var(--accent-strong)
    );
    color: var(--accent-contrast);
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18),
        0 4px 14px color-mix(in srgb, var(--accent-strong) 35%, transparent);
}

.btn.primary:hover {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22),
        0 6px 20px color-mix(in srgb, var(--accent-strong) 50%, transparent);
}

.btn.danger { color: var(--danger); }

.btn.dashed {
    background: transparent;
    border-style: dashed;
    border-color: var(--border-strong);
    color: var(--muted);
}

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

.btn.small { min-height: 28px; padding: 0 var(--s-3); font-size: var(--fs-xs); }

.btn.icon-btn { width: 40px; height: 40px; padding: 0; }

.btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}

.btn.ghost:hover { color: var(--text); background: var(--surface-2); }

/* --- Inputs -------------------------------------------------------------- */

.input, .select, .textarea {
    width: 100%;
    min-height: 38px;
    padding: 0 var(--s-3);
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    color: var(--text);
}

.textarea { min-height: 96px; padding: var(--s-3); resize: vertical; line-height: 1.45; }

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

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.field { display: grid; gap: var(--s-1); margin: 0 0 var(--s-4); }

.field > label, .field > .label {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
}

.field > label.check-row {
    font-size: var(--fs-md);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
}

.field .hint, .hint { font-size: var(--fs-xs); color: var(--muted); }

.spacer { flex: 1; }

.check-row {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-height: 38px;
    cursor: pointer;
}

.checkbox {
    appearance: none;
    -webkit-appearance: none;
    flex: none;
    width: 22px;
    height: 22px;
    margin: 0;
    background: var(--surface-1);
    border: 2px solid var(--border-strong);
    border-radius: var(--r-sm);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: border-color .15s, background .15s;
}

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

.checkbox:checked { background: var(--accent-strong); border-color: var(--accent-strong); }

.checkbox:checked::after {
    content: "✓";
    color: var(--accent-contrast);
    font-weight: 800;
    font-size: 14px;
    line-height: 1;
}

.error-box {
    margin: 0 0 var(--s-4);
    padding: var(--s-3);
    border: 1px solid var(--danger);
    border-radius: var(--r-sm);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
    font-size: var(--fs-sm);
}

/* --- Brand --------------------------------------------------------------- */

.mark {
    flex: none;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--r);
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
    color: var(--accent-contrast);
    font-weight: 800;
    box-shadow: 0 0 0 1px var(--accent-line),
        0 6px 18px color-mix(in srgb, var(--accent-strong) 35%, transparent);
}

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

.login {
    height: var(--app-h, 100dvh);
    display: grid;
    place-items: center;
    padding: var(--s-4);
}

.login form {
    width: min(380px, 100%);
    padding: var(--s-5);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-1);
}

.login .brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-5); }

.login h1 { margin: 0; font-size: var(--fs-lg); font-weight: 650; letter-spacing: .01em; }

/* --- Shell --------------------------------------------------------------- */

.shell {
    height: var(--app-h, 100dvh);
    display: grid;
    grid-template-columns: 264px minmax(420px, 1fr);
}

.nav, .main { min-width: 0; min-height: 0; }

.nav {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
}

.nav-head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-4);
    border-bottom: 1px solid var(--border);
}

.nav-head .name { font-weight: 650; letter-spacing: .01em; line-height: 1.2; }
.nav-head .sub { font-size: var(--fs-xs); color: var(--muted); }

.nav-list { overflow-y: auto; padding: var(--s-3) var(--s-2); }

.nav-list .heading {
    margin: var(--s-3) var(--s-2) var(--s-2);
    font-size: var(--fs-xs);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-row {
    display: block;
    width: 100%;
    padding: var(--s-2) var(--s-3);
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-md);
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.nav-row:hover { background: var(--surface-2); }

.nav-row.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }

.nav-row.add { color: var(--muted); font-weight: 400; font-size: var(--fs-sm); }
.nav-row.add:hover { color: var(--text); }

.nav-foot {
    padding: var(--s-3) var(--s-4);
    border-top: 1px solid var(--border);
    display: grid;
    gap: var(--s-3);
}

.status { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--success); box-shadow: 0 0 10px var(--success); }
.dot.error { background: var(--danger); }

.foot-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

.themes { display: flex; gap: var(--s-2); }

.theme-pick {
    width: 16px;
    height: 16px;
    padding: 0;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-sm);
    cursor: pointer;
}

.theme-pick.active { border-color: var(--text); }

.theme-pick[data-pick="default"] { background: linear-gradient(135deg, #0a0c11 50%, #8394ff 50%); }
.theme-pick[data-pick="graphite"] { background: linear-gradient(135deg, #0c0d0f 50%, #3fc8da 50%); }
.theme-pick[data-pick="ember"] { background: linear-gradient(135deg, #0e0b0c 50%, #ff8f62 50%); }

.main {
    display: grid;
    grid-template-rows: 64px minmax(0, 1fr) auto;
    position: relative;
}

.main-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 0 var(--s-6);
    background: var(--glass);
    backdrop-filter: blur(14px) saturate(1.3);
    border-bottom: 1px solid var(--border);
}

.main-head::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 55%;
    height: 1px;
    background: linear-gradient(to right, var(--accent-line), transparent);
}

.main-head .titles { flex: 1; min-width: 0; }

.main-head h1 {
    margin: 0;
    font-size: var(--fs-lg);
    font-weight: 650;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-btn { display: none; }

.main-body { overflow-y: auto; padding: var(--s-5) var(--s-6); }

.column { max-width: 780px; }

.toolbar { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    overflow: hidden;
}

.segmented button {
    min-height: 32px;
    padding: 0 var(--s-4);
    background: transparent;
    border: 0;
    border-left: 1px solid var(--border-strong);
    color: var(--muted);
    font-size: var(--fs-sm);
    cursor: pointer;
}

.segmented button:first-child { border-left: 0; }

.segmented button.active {
    background: var(--accent-soft);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}

/* --- Add bar ------------------------------------------------------------- */

.add-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: var(--s-3) var(--s-6);
    background: var(--glass);
    backdrop-filter: blur(14px) saturate(1.3);
    border-top: 1px solid var(--border);
}

.add-bar .input { min-height: 44px; }
.add-bar .btn { min-height: 44px; }

/* --- Items --------------------------------------------------------------- */

.items { list-style: none; margin: 0; padding: 0; }

.item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--s-3);
    align-items: start;
    padding: var(--s-3) 0;
    border-bottom: 1px solid var(--border);
}

.item.no-check { grid-template-columns: minmax(0, 1fr); }

.item .body {
    min-width: 0;
    padding: 0;
    background: none;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.item .title {
    display: block;
    font-weight: 600;
    overflow-wrap: anywhere;
    transition: color .15s;
}

.item .body:hover .title { color: var(--accent); }

.item.done .title { color: var(--muted); font-weight: 400; text-decoration: line-through; }

.item .meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1) var(--s-3);
    margin-top: var(--s-1);
    font-size: var(--fs-sm);
    color: var(--muted);
}

.chip {
    display: inline-block;
    padding: 0 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    line-height: 18px;
}

.chip.overdue {
    border-color: var(--attention-line);
    background: var(--attention-soft);
    color: var(--attention);
}

.chip.high { border-color: var(--attention-line); color: var(--attention); }

.empty { margin: var(--s-5) 0; font-size: var(--fs-xs); color: var(--muted); }

/* --- Drawer -------------------------------------------------------------- */

.scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: var(--scrim);
    backdrop-filter: blur(3px);
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(400px, 92vw);
    display: grid;
    grid-template-rows: 64px minmax(0, 1fr) auto;
    background: var(--surface-1);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    animation: slide-in .24s ease;
}

@keyframes slide-in { from { transform: translateX(104%); } to { transform: none; } }

.drawer-head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 0 var(--s-4);
    border-bottom: 1px solid var(--border);
}

.drawer-head .eyebrow { flex: 1; }

.drawer-body { overflow-y: auto; padding: var(--s-4); }

.drawer-foot {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-top: 1px solid var(--border);
}

/* --- List builder -------------------------------------------------------- */

.templates { display: grid; gap: var(--s-3); margin-bottom: var(--s-5); }

.template-card {
    padding: var(--s-3) var(--s-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r);
    text-align: left;
    cursor: pointer;
}

.template-card:hover { border-color: var(--border-strong); }

.template-card.active { border-color: var(--accent); background: var(--accent-soft); }

.template-card .t-name { display: block; font-weight: 600; }
.template-card .t-desc { display: block; font-size: var(--fs-sm); color: var(--muted); }

.section { margin: var(--s-5) 0 var(--s-3); }

.card {
    margin-bottom: var(--s-3);
    padding: var(--s-3) var(--s-4);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r);
}

.card.is-hidden { opacity: .65; }

.card .row { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

.card .row .input { flex: 1; min-width: 140px; }

.card .sub { margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--muted); }

.card .flags { display: flex; gap: var(--s-4); flex-wrap: wrap; margin-top: var(--s-2); }

.card .flags .check-row { min-height: 30px; font-size: var(--fs-sm); }

.options { margin-top: var(--s-3); display: grid; gap: var(--s-2); }

.options .opt { display: flex; gap: var(--s-2); align-items: center; }

.add-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 160px) auto;
    gap: var(--s-2);
}

.builder-actions { display: flex; gap: var(--s-3); margin: var(--s-5) 0; flex-wrap: wrap; }

/* --- Narrow windows and phones ------------------------------------------- */

@media (max-width: 760px) {
    .shell { grid-template-columns: minmax(0, 1fr); }

    .nav {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(86vw, 340px);
        box-shadow: var(--shadow-2);
        transform: translateX(-104%);
        visibility: hidden;
        transition: transform .24s ease, visibility 0s linear .24s;
    }

    .shell.nav-open .nav {
        transform: none;
        visibility: visible;
        transition: transform .24s ease;
    }

    .menu-btn { display: inline-flex; }

    .main { grid-template-rows: 56px minmax(0, 1fr) auto; }
    .main-head { padding: var(--s-2) var(--s-3); }
    .main-body { padding: var(--s-4) var(--s-3); }
    .add-bar { padding: var(--s-3); padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }

    .nav-row { min-height: 44px; display: flex; align-items: center; }
    .btn { min-height: 44px; }
    .btn.small { min-height: 36px; }
    .segmented button { min-height: 40px; }
    .checkbox { width: 26px; height: 26px; }
    .item { padding: var(--s-3) 0; }

    textarea, select, input { font-size: 16px; }

    .add-field { grid-template-columns: minmax(0, 1fr); }
}

@media (hover: none) {
    .theme-pick { width: 22px; height: 22px; }
}
