/* =====================================================================
   app.css  -  all styles. Mobile first, centred and max 760px on laptop.
   Colours are set once at the top (light and dark), everything else
   uses them, so the look stays consistent.
   ===================================================================== */

/* ---------- Colours and sizes ---------- */

:root {
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --text: #17181c;
    --muted: #6b6f7b;
    --faint: #a3a7b2;
    --border: #e4e5ea;
    --accent: #2563eb;
    --accent-soft: #e8efff;
    --danger: #dc2626;
    --overdue: #dc2626;
    --today: #d97706;
    --ok: #059669;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14), 0 2px 6px rgba(16, 24, 40, 0.06);
    --mix-base: #ffffff;   /* chip text colours are mixed toward this in dark mode */
    --tint: 11%;           /* how strong tinted chip backgrounds are */
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e0f13;
        --surface: #17191f;
        --surface-2: #20232b;
        --text: #ecedf0;
        --muted: #9a9eaa;
        --faint: #6a6e7a;
        --border: #2a2d36;
        --accent: #6d8dff;
        --accent-soft: #1f2a4d;
        --danger: #f87171;
        --overdue: #f87171;
        --today: #fbbf24;
        --ok: #34d399;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
        --tint: 20%;
        color-scheme: dark;
    }
}

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

* { box-sizing: border-box; }

/* Anything marked hidden stays hidden, whatever other rules say. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

h1, h2, h3 { letter-spacing: -0.01em; }

code {
    font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 5px;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons */
button {
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    transition: filter 0.15s, background 0.15s;
}
button:hover { filter: brightness(1.06); }
button.secondary {
    color: var(--text);
    background: var(--surface-2);
}
button.secondary:hover { filter: none; background: var(--border); }
button.link {
    background: none;
    color: var(--accent);
    padding: 4px 8px;
    border-radius: 6px;
}
button.link:hover { filter: none; background: var(--accent-soft); }
.link.danger { color: var(--danger); }

/* Text boxes */
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], textarea, select {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 16px;            /* 16px stops iPhone zooming in */
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--faint); }

.hint { color: var(--muted); font-size: 0.85rem; }

.error {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, transparent);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.9rem;
}

/* ---------- Setup and login ---------- */

.auth {
    max-width: 380px;
    margin: 12vh auto 0;
    padding: 28px 22px;
    background: var(--surface);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
}
@media (max-width: 440px) {
    .auth { margin: 8vh 12px 0; }
}
.auth h1 { margin: 0 0 16px; font-size: 1.5rem; }
.auth form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.auth label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.auth label.check { display: block; font-weight: 400; }
.auth label.check input { margin: 0 6px 0 0; vertical-align: -2px; }
.auth button { padding: 12px 16px; margin-top: 4px; }

/* ---------- Main screen ---------- */

.app {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 16px 110px;
}

/* Header: title, search, settings */
.top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 0 6px;
}
.top h1 { margin: 0; font-size: 1.4rem; font-weight: 700; flex: none; }
.top input[type="search"] {
    flex: 1;
    min-width: 0;
    max-width: 260px;
    margin-left: auto;
    padding: 8px 12px 8px 34px;
    border-radius: 999px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa0ad' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center;
    font-size: 15px;
}
@media (max-width: 480px) { .top input[type="search"] { font-size: 16px; } }

.icon-btn {
    flex: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border-radius: 10px;
}
.icon-btn:hover { filter: none; color: var(--text); background: var(--surface-2); }

/* Quick add: stays at the top while scrolling */
.add {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 8px 0 10px;
    background: var(--bg);
}
.add input {
    width: 100%;
    padding: 13px 14px 13px 42px;
    border-radius: 14px;
    border-color: transparent;
    box-shadow: var(--shadow), 0 0 0 1px var(--border);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E") no-repeat 14px center;
}
.add input:focus { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.add .chips { margin-top: 8px; padding-left: 4px; }
.add .chips:empty { margin-top: 0; }

/* ---------- Chips (small labels on rows and in the add preview) ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.chip {
    --c: var(--muted);
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.6;
    padding: 0 7px;
    border-radius: 6px;
    color: var(--c);
    background: var(--surface-2);   /* older iPhones use this line */
    background: color-mix(in srgb, var(--c) var(--tint), transparent);
}
@media (prefers-color-scheme: dark) {
    .chip { color: color-mix(in srgb, var(--c) 75%, var(--mix-base)); }
}
.chip.firm { --c: var(--firm, var(--muted)); }
.chip.person { --c: var(--muted); font-weight: 500; }
.chip.due { --c: var(--muted); font-weight: 500; }
.chip.due.today { --c: var(--today); font-weight: 600; }
.chip.due.overdue { --c: var(--overdue); font-weight: 700; }
.chip.prio.p1 { --c: var(--today); }
.chip.prio.p2 { color: #fff; background: var(--overdue); }
.chip.status { --c: var(--st, var(--accent)); }
.chip.note { --c: var(--muted); font-style: italic; font-weight: 400; }
.chip.done-at { --c: var(--ok); font-weight: 500; }
@media (max-width: 480px) {
    .chip { max-width: 62vw; }   /* long firm/client names are cut short on phones */
}

/* ---------- Tabs: one pill-shaped control ---------- */

.tabs {
    display: flex;
    gap: 2px;
    margin-top: 4px;
    padding: 3px;
    background: var(--surface-2);
    border-radius: 12px;
}
.tabs button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border-radius: 9px;
    padding: 8px 4px;
}
.tabs button:hover { filter: none; color: var(--text); }
.tabs button.on { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.badge {
    display: inline-block;
    min-width: 17px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--overdue);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
}

/* ---------- Firm and client filter chips (one row, scroll sideways) ---------- */

.chip-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 12px 0 2px;
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
    scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
#client-chips { padding-top: 6px; }

.fchip {
    --firm: var(--accent);
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 0;
    box-shadow: 0 0 0 1px var(--border);
    border-radius: 999px;
    padding: 6px 12px;
}
.fchip::before {             /* a small dot in the firm's colour */
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--firm);
}
#client-chips .fchip::before { display: none; }
.fchip .n { font-weight: 500; color: var(--faint); font-size: 0.78rem; }
.fchip:hover { filter: none; box-shadow: 0 0 0 1px var(--faint); }
.fchip.on { color: #fff; background: var(--firm); box-shadow: none; }
.fchip.on::before { background: rgba(255, 255, 255, 0.85); }
.fchip.on .n { color: rgba(255, 255, 255, 0.8); }

/* ---------- Compact bar: person, group, sort ---------- */

.bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 12px 0 2px;
    font-size: 0.78rem;
    color: var(--muted);
}
.bar label { display: inline-flex; align-items: center; gap: 6px; }
.bar select {
    appearance: none;
    -webkit-appearance: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%239aa0ad' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center;
    border: 0;
    box-shadow: 0 0 0 1px var(--border);
    border-radius: 8px;
    padding: 5px 26px 5px 10px;
    max-width: 46vw;
}
@media (max-width: 480px) { .bar select { font-size: 16px; padding: 4px 24px 4px 8px; } }

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

.group { margin-top: 14px; }
.group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 4px 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    background: none;
    border-radius: 6px;
    text-align: left;
}
.group-head:hover { filter: none; color: var(--text); }
.group-head .chev { font-size: 0.7rem; transition: transform 0.15s; }
.group-head.folded .chev { transform: rotate(-90deg); }
.group-head .group-name.colored { color: var(--firm); }
.group-head .n {
    font-weight: 600;
    color: var(--faint);
    background: var(--surface-2);
    border-radius: 999px;
    padding: 0 7px;
    letter-spacing: 0;
}

/* Each group is one rounded card; rows are separated by hairlines */
.tasks {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow), 0 0 0 1px var(--border);
    overflow: hidden;
}
#groups > .tasks { margin-top: 14px; }   /* Done tab: one card, no groups */
.task {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 12px 12px 14px;
    cursor: pointer;
    transition: background 0.12s;
}
.task + .task { border-top: 1px solid var(--border); }
.task:hover { background: var(--surface-2); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.task.saving { opacity: 0.55; }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 500; overflow-wrap: anywhere; }
.task .desc {
    margin-top: 1px;
    color: var(--muted);
    font-size: 0.84rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.task .meta { margin-top: 6px; }
.task.is-done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }

/* Circle checkbox: large enough for a thumb */
.check {
    flex: none;
    position: relative;
    width: 22px;
    height: 22px;
    margin-top: 0;
    padding: 0;
    border-radius: 50%;
    border: 1.6px solid var(--faint);
    background: transparent;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.check::before {             /* a bigger invisible tap area */
    content: "";
    position: absolute;
    inset: -10px;
}
.check:hover:not(:disabled) { filter: none; border-color: var(--accent); background: var(--accent-soft); }
.check:disabled { cursor: default; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after {
    content: "";
    position: absolute;
    left: 6.5px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
/* The short "tick" before a done task leaves the list */
.task.completing .check { background: var(--ok); border-color: var(--ok); transform: scale(1.08); }
.task.completing .check::after {
    content: "";
    position: absolute;
    left: 6.5px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.task.completing .title { color: var(--muted); text-decoration: line-through; }
.task.completing { opacity: 0.6; transition: opacity 0.25s; }

/* Drag handle (only in "My order") */
.drag-handle {
    flex: none;
    align-self: center;
    padding: 10px 6px;
    margin: -10px -6px -10px 0;
    color: var(--faint);
    font-size: 0.9rem;
    letter-spacing: -3px;
    cursor: grab;
    opacity: 0.7;
    touch-action: none;        /* the finger drags the row instead of scrolling */
    user-select: none;
    -webkit-user-select: none;
}
.drag-handle:hover { opacity: 1; color: var(--muted); }
.task.dragging {
    z-index: 2;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    border-radius: 10px;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

.empty { color: var(--muted); text-align: center; margin-top: 48px; font-size: 0.95rem; }
.load-more { display: block; margin: 18px auto; }

/* ---------- Toast (message at the bottom) ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 32px);
    padding: 10px 10px 10px 16px;
    border-radius: 12px;
    background: rgba(23, 24, 28, 0.94);
    color: #fff;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { transform: translate(-50%, 10px); } to { transform: translate(-50%, 0); } }
.toast #toast-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.toast .link { flex: none; color: #9db8ff; }
.toast .link:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- Edit sheet (bottom sheet on phone, centred box on laptop) ---------- */

.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 18, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 6px 18px calc(18px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    animation: sheet-up 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheet-up { from { transform: translateY(40px); } to { transform: none; } }
@media (min-width: 700px) {
    .sheet-panel {
        left: 50%;
        right: auto;
        bottom: auto;
        top: 6vh;
        width: 600px;
        max-height: 88vh;
        transform: translateX(-50%);
        border-radius: 18px;
        padding: 12px 24px 20px;
        animation: none;
    }
    .sheet-grip { visibility: hidden; }
}
.sheet-head { display: flex; align-items: center; justify-content: center; position: relative; min-height: 30px; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--border); }
.sheet-close { position: absolute; right: -8px; top: 0; }

.sheet-title, .sheet-desc {
    display: block;
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 6px 8px;
    margin-left: -8px;
    width: calc(100% + 16px);
    resize: none;
    box-shadow: none;
}
.sheet-title { font-size: 1.2rem; font-weight: 650; overflow: hidden; }
.sheet-desc { font-size: 0.92rem; color: var(--muted); }
.sheet-title:hover, .sheet-desc:hover { background: var(--surface-2); }
.sheet-title:focus, .sheet-desc:focus { background: var(--surface); border-color: var(--accent); }

.sheet-section { margin-top: 16px; }
.sheet-section h3 {
    margin: 0 0 8px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.sheet-section h3.overdue { color: var(--overdue); }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }

.opt {
    --firm: var(--accent);
    position: relative;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface-2);
    border: 0;
    border-radius: 999px;
    padding: 7px 13px;
}
.opt:hover { filter: none; background: var(--border); }
.opt.colored { color: var(--firm); }
@media (prefers-color-scheme: dark) {
    .opt.colored { color: color-mix(in srgb, var(--firm) 70%, #fff); }
}
.opt.on, .opt.colored.on { color: #fff; background: var(--firm); }
.opt.add-chip { color: var(--accent); background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.opt .dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--overdue);
    border: 2px solid var(--surface);
}
input.date-pick { font-size: 0.85rem; padding: 6px 10px; border-radius: 999px; background: var(--surface-2); border-color: transparent; }

.new-client { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.new-client input { padding: 7px 10px; }
.new-client input:first-child { flex: 1 1 160px; }
.new-client .code { width: 110px; }
.new-client .hash { color: var(--faint); margin-right: -3px; }

.danger-link {
    margin-top: 22px;
    padding: 8px 0;
    background: none;
    color: var(--danger);
    font-weight: 600;
}
.danger-link:hover { filter: none; text-decoration: underline; }
.sheet-times { margin: 6px 0 0; font-size: 0.74rem; color: var(--faint); }

/* ---------- Team tab ---------- */

.team-wrap {
    width: 100%;
    overflow-x: auto;
    margin-top: 14px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow), 0 0 0 1px var(--border);
}
.team { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.team th {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--faint);
    padding: 10px 2px 8px;
    text-align: center;
}
.team td { padding: 10px 2px; border-top: 1px solid var(--border); text-align: center; }
.team th:first-child, .team td.who { text-align: left; padding-left: 14px; }
.team td.who { max-width: 140px; }
.team .who-btn {
    padding: 2px 0;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: left;
    font-weight: 600;
}
.team .who-btn:hover { background: none; text-decoration: underline; }
.team .num { font-variant-numeric: tabular-nums; font-weight: 650; }
.team .num.zero { color: var(--faint); font-weight: 400; opacity: 0.7; }
.team .num.red { color: var(--overdue); }
.team .num.orange { color: var(--today); }
.team .arrow { padding: 2px 8px; transition: transform 0.15s; display: inline-block; color: var(--faint); }
.team .arrow.open { transform: rotate(90deg); color: var(--accent); }
.team-split td { text-align: left; padding: 6px 14px 12px; background: var(--surface-2); border-top: 0; }
@media (max-width: 480px) {
    .team { table-layout: fixed; font-size: 0.85rem; }
    .team th { font-size: 0.56rem; text-transform: none; letter-spacing: 0; padding: 8px 0 6px; white-space: normal; }
    .team th:first-child, .team td.who { width: 27%; padding-left: 10px; }
    .team th:last-child, .team td:last-child { width: 26px; }
    .team .arrow { padding: 2px 4px; }
}

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

.settings {
    position: fixed;
    inset: 0;
    z-index: 25;
    overflow-y: auto;
    background: var(--bg);
}
.settings-inner { max-width: 760px; margin: 0 auto; padding: 0 16px 70px; }
.set-block {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow), 0 0 0 1px var(--border);
    padding: 16px 16px 14px;
    margin-top: 14px;
}
.set-block h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 700; }
.set-block .hint { margin: 0 0 10px; }

.set-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 7px 0;
    border-top: 1px solid var(--border);
}
.set-row.archived .set-name, .set-row.archived .set-code, .set-row.archived .set-fixed-name { opacity: 0.5; text-decoration: line-through; }
.set-row input[type="text"] {
    background: transparent;
    border-color: transparent;
    border-radius: 8px;
    padding: 6px 8px;
}
.set-row input[type="text"]:hover { background: var(--surface-2); }
.set-row input[type="text"]:focus { background: var(--surface); border-color: var(--accent); }
.set-name { flex: 1 1 140px; min-width: 0; font-weight: 500; }
.set-code { width: 100px; color: var(--muted); }
.set-codebox { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.set-row .hash { color: var(--faint); }
.set-color {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    cursor: pointer;
    overflow: hidden;
}
.set-color::-webkit-color-swatch-wrapper { padding: 0; }
.set-color::-webkit-color-swatch { border: 0; border-radius: 50%; }
.set-color::-moz-color-swatch { border: 0; border-radius: 50%; }
.set-dot { width: 12px; height: 12px; margin: 0 7px; border-radius: 50%; background: var(--st); flex: none; }
.set-fixed-name { flex: 1; padding: 6px 8px; font-weight: 500; }
.set-fixed { font-size: 0.75rem; padding-right: 8px; }
.set-check { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.set-toggle { padding: 4px 6px; color: var(--faint); transition: transform 0.15s; display: inline-block; }
.set-toggle.open { transform: rotate(90deg); color: var(--accent); }
.set-toggle-space { width: 30px; }
.set-tools { display: inline-flex; flex-wrap: wrap; gap: 0; margin-left: auto; }
.set-tools .link { padding: 4px 7px; font-size: 0.82rem; }
.set-add { border-top: 1px dashed var(--border); }
.set-add .opt { padding: 6px 14px; }
.set-clients { margin: 0 0 6px 18px; padding-left: 12px; border-left: 2px solid var(--border); }
.set-clients .set-row:first-child { border-top: 0; }

.cheat-example { font: 0.85rem ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-wrap: anywhere; }
.cheat { border-collapse: collapse; font-size: 0.88rem; width: 100%; }
.cheat td { padding: 6px 8px 6px 0; vertical-align: top; border-top: 1px solid var(--border); }
.cheat td:first-child { white-space: nowrap; width: 1%; }

.pw-form { display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.set-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Trash */
.trash { list-style: none; margin: 12px 0 0; padding: 0; }
.trash-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-top: 1px solid var(--border);
}
.trash-row .body { flex: 1; min-width: 0; }
.trash-row .title { color: var(--muted); }
.trash-row .meta { margin-top: 4px; }

/* ---------- Phones ---------- */

@media (max-width: 480px) {
    .app { padding: 0 12px 110px; }
    .chip-row { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
    .tabs button { font-size: 0.8rem; padding: 8px 2px; gap: 3px; }
    .badge { min-width: 15px; padding: 0 4px; line-height: 15px; font-size: 0.62rem; }
    .settings-inner { padding: 0 12px 70px; }
}

/* Created / updated line on each row */
.task .times {
    display: flex;
    flex-wrap: wrap;
    gap: 0 12px;
    margin-top: 5px;
    font-size: 0.7rem;
    color: var(--faint);
    font-variant-numeric: tabular-nums;
}
.task .times span { white-space: nowrap; }

/* ---------- Archive ---------- */

/* Done | Archived switch (Done tab) */
.seg {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    background: var(--surface-2);
    border-radius: 9px;
}
.seg button {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border-radius: 7px;
    padding: 4px 12px;
}
.seg button:hover { filter: none; color: var(--text); }
.seg button.on { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }

.chip.archived { --c: #7c3aed; font-weight: 500; }

/* Archive and Delete side by side at the bottom of a task */
.sheet-actions { display: flex; gap: 18px; align-items: center; margin-top: 22px; }
.sheet-actions .danger-link { margin-top: 0; }
.archive-link {
    padding: 8px 0;
    background: none;
    color: var(--accent);
    font-weight: 600;
}
.archive-link:hover { filter: none; text-decoration: underline; }

/* "Archive all N" button (Done tab), on the right of the bar */
.archive-all {
    order: 10;
    margin-left: auto;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 8px;
    padding: 5px 12px;
}
.archive-all:hover { filter: brightness(0.97); }
.archive-all:disabled { opacity: 0.5; cursor: default; }

/* =====================================================================
   COMPACT LAYOUT (Gmail-style)
   Tighter spacing everywhere. On a laptop each task is one slim line:
   tick | title | – description | labels | created/updated
   On a phone: title, then labels and description, then the times.
   ===================================================================== */

body { font-size: 14px; }

.top { padding: 10px 0 4px; }
.top h1 { font-size: 1.2rem; }
.top input[type="search"] { padding: 6px 12px 6px 32px; background-position: 11px center; }
.icon-btn { width: 34px; height: 34px; }

.add { padding: 6px 0 8px; }
.add input { padding: 10px 12px 10px 38px; border-radius: 10px; background-position: 13px center; }
.add .chips { margin-top: 6px; }

.tabs { padding: 2px; border-radius: 10px; }
.tabs button { padding: 6px 4px; font-size: 0.82rem; border-radius: 8px; }

.chip-row { padding-top: 8px; gap: 5px; }
#client-chips { padding-top: 5px; }
.fchip { padding: 4px 10px; font-size: 0.8rem; gap: 5px; }
.bar { padding: 8px 0 0; }

.group { margin-top: 10px; }
.group-head { padding: 2px 4px 5px; }
.tasks { border-radius: 10px; box-shadow: 0 0 0 1px var(--border); }
#groups > .tasks { margin-top: 10px; }

.task { gap: 10px; padding: 8px 10px 8px 12px; }
.task .title { font-weight: 600; }
.task .desc.empty { display: none; }
.task .meta { margin-top: 3px; }
.task .times { margin-top: 2px; }
.chip { font-size: 0.68rem; line-height: 1.5; padding: 0 6px; }

.check { width: 18px; height: 18px; margin-top: 1px; }
.check.on::after, .task.completing .check::after { left: 5px; top: 2px; width: 4px; height: 8px; }

/* Phones: keep each task to 2-3 short lines */
@media (max-width: 699px) {
    .task .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
}

/* Laptop: one line per task */
@media (min-width: 700px) {
    .task { align-items: center; min-height: 40px; padding: 4px 8px 4px 14px; }
    .task .check { margin-top: 0; }
    .task .body { display: flex; align-items: center; gap: 10px; }
    .task .title { flex: 0 1 auto; max-width: 42%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
    .task .desc, .task .desc.empty { display: block; flex: 1 1 0; min-width: 0; margin: 0; }
    .task .desc:not(.empty)::before { content: "– "; }
    /* Labels keep their full size; only the title and the firm label shorten when space runs out. */
    .task .meta { flex: 0 0 auto; margin: 0; flex-wrap: nowrap; overflow: hidden; max-width: 50%; }
    .task .meta .chip { flex: none; }
    .task .meta .chip.firm { flex: 0 1 auto; min-width: 0; }
    .task .times {
        flex: none;
        display: block;
        width: 128px;
        margin: 0;
        text-align: right;
        font-size: 0.66rem;
        line-height: 1.25;
    }
    .task .times span { display: block; }
    .drag-handle { margin: 0 -4px 0 0; padding: 8px 4px; }
}

/* Bulk buttons in the Done tab: Archive all / Delete all, on the right */
.bulk { order: 10; margin-left: auto; display: inline-flex; gap: 6px; }
.bulk .archive-all { margin-left: 0; order: 0; }
.delete-all {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
    border-radius: 8px;
    padding: 5px 12px;
}
.delete-all:hover { filter: brightness(0.97); }
.delete-all:disabled { opacity: 0.5; cursor: default; }

/* Phones: one-line filter bar and one-line times */
@media (max-width: 699px) {
    .bar { gap: 6px 8px; }
    .bar .bar-label { display: none; }          /* the menus show their choice anyway */
    .bar select { font-size: 16px; padding: 3px 22px 3px 8px; max-width: 38vw; background-position: right 7px center; }
    .task { padding: 7px 8px 7px 10px; }
    .task .times { gap: 0 8px; font-size: 0.62rem; }
}
@media (max-width: 699px) {
    .bar label { flex: 1 1 0; min-width: 0; }      /* the menus share the row equally */
    .bar select { width: 100%; max-width: none; }
}
@media (max-width: 699px) {
    .bar label:first-of-type { flex-grow: 1.45; }   /* Person: "Everyone (12)" needs the most room */
}
@media (max-width: 699px) {
    .bar label:nth-of-type(2) { flex-grow: 0.8; }    /* Group: short words */
    .bar label:nth-of-type(3) { flex-grow: 1.2; }    /* Sort: "My order", "Recently updated" */
    .bar select { padding-right: 20px; background-position: right 6px center; }
}

/* ---------- Bulk select ---------- */

/* Square checkbox on each row */
.sel {
    flex: none;
    position: relative;
    width: 16px;
    height: 16px;
    margin-top: 2px;
    padding: 0;
    border-radius: 4px;
    border: 1.5px solid var(--faint);
    background: transparent;
    opacity: 0.75;
}
.sel::before { content: ""; position: absolute; inset: -9px -6px; }   /* bigger tap area */
.sel:hover { filter: none; opacity: 1; border-color: var(--accent); }
.sel.on { opacity: 1; background: var(--accent); border-color: var(--accent); }
.sel.on::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.task { gap: 8px; }
.task.selected { background: var(--accent-soft); }
.task.selected:hover { background: var(--accent-soft); }
@media (min-width: 700px) {
    .task .sel { margin-top: 0; }
}

/* The action bar at the bottom */
.selbar {
    position: fixed;
    left: 50%;
    bottom: calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 35;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    width: min(740px, calc(100vw - 20px));
    padding: 8px 10px;
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
    animation: toast-in 0.18s ease-out;
}
.selbar-top { display: flex; align-items: center; gap: 6px; }
.sel-x {
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 0.85rem;
}
.sel-x:hover { filter: none; color: var(--text); }
.sel-count { font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.selbar .link { font-size: 0.82rem; white-space: nowrap; }
.sel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    overflow-x: auto;
    scrollbar-width: none;
    max-width: 100%;
}
.sel-actions::-webkit-scrollbar { display: none; }
.sel-btn {
    flex: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border-radius: 8px;
    padding: 6px 12px;
}
.sel-btn:hover { filter: none; background: var(--border); }
.sel-btn.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.sel-menu {
    flex: none;
    appearance: none;
    -webkit-appearance: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border: 0;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}
@media (max-width: 699px) {
    .sel-actions { margin-left: 0; width: 100%; }
    .sel-menu { font-size: 16px; padding: 4px 8px; }   /* 16px stops iPhone zooming in */
}

/* Room for the bar: the toast sits above it, the list scrolls clear of it */
body.has-selection .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
body.has-selection .app { padding-bottom: 170px; }
@media (max-width: 699px) {
    body.has-selection .toast { bottom: calc(110px + env(safe-area-inset-bottom)); }
}
@media (max-width: 699px) {
    /* Phones: every action visible (two rows) instead of scrolling sideways */
    .sel-actions { flex-wrap: wrap; overflow-x: visible; gap: 6px; }
    .sel-actions > * { flex: 1 1 auto; text-align: center; }
    body.has-selection .toast { bottom: calc(140px + env(safe-area-inset-bottom)); }
    body.has-selection .app { padding-bottom: 210px; }
}

/* ---------- Suggestions under the add box (# @ ^) ---------- */
.ac {
    position: absolute;
    top: calc(100% - 4px);
    left: 0;
    z-index: 20;
    width: min(420px, 100%);
    max-height: 300px;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
}
.ac-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
}
.ac-item.on, .ac-item:hover { background: var(--accent-soft); }
.ac-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--faint)); }
.ac-dot.plain { background: var(--faint); }
.ac-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ac-sub { color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.ac-code { flex: none; color: var(--faint); font: 0.75rem ui-monospace, SFMono-Regular, Menlo, monospace; }
