:root {
    --bg: #2a1a0f; --bg2: #140b05; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fbf3ec; --muted: #e0c9b5; --accent: #f2b27a; --accent-ink: #2a1505; --field: rgba(255,255,255,.08);
    --soft: rgba(242,178,122,.15); --good: #8ce99a; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8; --bad-bg: rgba(255,168,168,.13);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #fbf4ee; --bg2: #efdfcf; --card: #fff; --line: #e3cdb9; --ink: #2a1a0f; --muted: #6a4d36;
            --accent: #8a4b1f; --accent-ink: #fff; --field: #fffdfb; --soft: #f7e7d8; --good: #2b8a3e; --warn: #a14a00; --warn-bg: #fff1dc; --bad: #c92a2a; --bad-bg: #fff0f0;
            color-scheme: light; }
}
:root[data-theme="light"] { --bg: #fbf4ee; --bg2: #efdfcf; --card: #fff; --line: #e3cdb9; --ink: #2a1a0f; --muted: #6a4d36;
            --accent: #8a4b1f; --accent-ink: #fff; --field: #fffdfb; --soft: #f7e7d8; --good: #2b8a3e; --warn: #a14a00; --warn-bg: #fff1dc; --bad: #c92a2a; --bad-bg: #fff0f0;
            color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #2a1a0f; --bg2: #140b05; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fbf3ec; --muted: #e0c9b5; --accent: #f2b27a; --accent-ink: #2a1505; --field: rgba(255,255,255,.08);
    --soft: rgba(242,178,122,.15); --good: #8ce99a; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8; --bad-bg: rgba(255,168,168,.13);
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-main, .col-side { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header, .warn-box { order: 1; }
.summary { order: 2; }
.list { order: 3; }
.add { order: 4; }
.people { order: 5; }
.settings { order: 6; }
.app > .faq { order: 7; }
.app > footer { order: 8; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.7rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; overflow-wrap: anywhere; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, .label-like { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
input[type=text], input[type=date], input[type=search], textarea { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; line-height: 1.4; }
input[type=date] { -webkit-appearance: auto; appearance: auto; }
input[aria-invalid="true"] { border-color: var(--bad); }
input:focus-visible, button:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible, .file-btn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.empty { margin: .2rem 0; color: var(--muted); overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.warn-box { margin: 0 0 .9rem; padding: .7rem .9rem; border-radius: 12px; background: var(--warn-bg); border-left: 5px solid var(--warn); font-weight: 600; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.small { width: auto; min-height: 44px; padding: 0 .85rem; font-size: .92rem; margin: 0; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: .9rem; }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.inline-link { display: inline; min-height: 0; margin: 0; padding: .4rem .2rem; }
.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin: .9rem 0 0; padding: .5rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg .undo { min-height: 40px; padding: 0 .9rem; border: 1px solid var(--accent); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.row-btns > * { flex: 1 1 9rem; width: auto; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .4rem; }
.tool-grid.gap { margin-top: 1rem; }
a.secondary { min-width: 0; }
.seg { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .4rem; }
.seg label { display: flex; align-items: center; gap: .55rem; margin: 0; min-height: 48px; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink); font-weight: 600; font-size: .95rem; cursor: pointer; line-height: 1.25; min-width: 0; overflow-wrap: anywhere; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--soft); }
.seg input { margin: 0; flex: none; width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }
.seg.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg.three label { position: relative; flex-direction: column; justify-content: center; gap: 0; text-align: center; padding: .3rem .3rem; font-size: .9rem; line-height: 1.2; }
.seg.three .cnt { font-size: 1.15rem; font-weight: 800; }
.seg.three input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg.three label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg.three label:has(input:checked) { color: var(--accent); font-weight: 800; }
.seg.due { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.seg.due label { padding: .35rem .5rem; gap: .4rem; font-size: .9rem; }
.seg.due .wide { grid-column: 1 / -1; }

/* the top tiles */
.summary { padding: .8rem; }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .6rem; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; min-width: 0; padding: .7rem .8rem; border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 12px; background: var(--field); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.tile.on { background: var(--soft); }
.tile.t-late { border-left-color: var(--bad); }
.tile.t-today { border-left-color: var(--warn); }
.tile-k { font-size: .88rem; font-weight: 700; color: var(--muted); }
.tile-n { font-size: 2rem; font-weight: 800; line-height: 1.1; color: var(--accent); }
.tile.t-late .tile-s { color: var(--bad); font-weight: 700; }
.tile.t-today .tile-s { color: var(--warn); font-weight: 700; }
.tile-s { font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; }

/* the list */
.search { margin-top: .2rem; }
.filter { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .6rem; margin: .8rem 0 0; padding: .4rem .7rem; border-radius: 12px; background: var(--soft); font-weight: 600; overflow-wrap: anywhere; }
#list-body { margin-top: .9rem; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.item { border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 12px; padding: .7rem .8rem; background: var(--field); min-width: 0; }
.item.st-open { border-left-color: var(--muted); }
.item.st-late { border-left-color: var(--bad); }
.item.st-today, .item.st-soon { border-left-color: var(--warn); }
.item.st-back { border-left-color: var(--line); }
.item-top { display: flex; gap: .7rem; align-items: flex-start; min-width: 0; }
.item-main { min-width: 0; flex: 1 1 auto; }
.item-what { margin: 0; font-size: 1.08rem; overflow-wrap: anywhere; }
.kind-tag { display: inline-block; margin-left: .5rem; padding: 0 .45rem; border: 1px solid var(--line); border-radius: 999px; font-size: .75rem; font-weight: 700; color: var(--muted); vertical-align: middle; }
.item-line { margin: .15rem 0 0; color: var(--muted); font-size: .93rem; overflow-wrap: anywhere; }
.tag { display: inline-block; margin: .35rem 0 0; padding: .1rem .55rem; border-radius: 999px; font-size: .88rem; font-weight: 700; border: 1px solid currentColor; overflow-wrap: anywhere; max-width: 100%; }
.tag-open, .tag-back { color: var(--muted); }
.tag-ok { color: var(--accent); }
.tag-soon, .tag-today { color: var(--warn); }
.tag-late { color: var(--bad); background: var(--bad-bg); }
.item-note { margin: .5rem 0 0; padding: .4rem .6rem; border-radius: 8px; background: var(--card); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.item-btns > * { flex: 1 1 auto; }
.item-btns .del { color: var(--bad); }
@media (max-width: 599px) { .item-btns > * { flex: 1 1 40%; } }
.thumb { flex: none; width: 56px; height: 56px; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); cursor: zoom-in; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.big-photo .item-top { flex-direction: column; }
.big-photo .thumb { width: 100%; height: auto; max-height: 420px; cursor: zoom-out; }
.big-photo .thumb img { height: auto; max-height: 420px; object-fit: contain; }
.panel { margin-top: .8rem; padding: .8rem; border: 1px solid var(--accent); border-radius: 12px; background: var(--card); }
.panel h4 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.panel label { margin-top: .5rem; }
.panel .row-btns > * { flex: 1 1 5rem; }

/* the form */
.preview { margin: .9rem 0 0; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); overflow-wrap: anywhere; }
.preview:empty { display: none; }
.opt { min-width: 0; }
.file-btn { margin: 0; color: var(--ink); font-size: 1rem; cursor: pointer; }
.photo-prev { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .6rem; }
.photo-prev img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }

/* people */
.ppl { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.person { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem .8rem; border: 1px solid var(--line); border-radius: 12px; padding: .6rem .75rem; background: var(--field); min-width: 0; }
.person.on { border-color: var(--accent); background: var(--soft); }
.person-main { min-width: 0; flex: 1 1 12rem; }
.person-name { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.person-line { margin: .1rem 0 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.person .small { flex: 0 1 auto; max-width: 100%; }

@media print {
    body { background: #fff; color: #000; padding: 0; display: block; }
    .app { width: 100%; display: block; }
    .back, .topbar, header .sub, .add, .people, .settings, .faq, footer, .msg, .tabs, .search, .filter, .item-btns, .panel, .summary { display: none !important; }
    .card, .item { border-color: #999; background: #fff; break-inside: avoid; }
    .item-line, .tag, .item-note { color: #000; }
}

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }

/* narrow phones */
@media (max-width: 420px) {
    .card { padding: 1rem .8rem; }
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    h1 { font-size: 1.5rem; }
    .seg.due { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .tile-n { font-size: 1.7rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .tile { padding: .6rem .6rem; }
}

@media (max-width: 340px) {
    #form > .seg:first-child { grid-template-columns: minmax(0, 1fr); }
}

/* laptops and desktops: the summary and the list on the left, adding and settings on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-main, .col-side { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .warn-box { grid-row: 3; }
    .app > .col-main { grid-column: 1; grid-row: 4; }
    .app > .col-side { grid-column: 2; grid-row: 4; }
    .app > .faq { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .tile-n { font-size: 2.3rem; }
}
