:root {
    --bg: #1f300b; --bg2: #0c1504; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f5fbe9; --muted: #cfe0b3; --accent: #a9e34b; --accent-ink: #142004; --field: rgba(255,255,255,.08);
    --soft: rgba(169,227,75,.15); --good: #a9e34b; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f5fbe8; --bg2: #e3f1c8; --card: #fff; --line: #d2e4b0; --ink: #1b2608; --muted: #4c5c30;
            --accent: #4a7a07; --accent-ink: #fff; --field: #fbfef6; --soft: #ebf6d6; --good: #2b8a3e; --warn: #b45309; --warn-bg: #fff1dc; --bad: #c92a2a; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f5fbe8; --bg2: #e3f1c8; --card: #fff; --line: #d2e4b0; --ink: #1b2608; --muted: #4c5c30;
            --accent: #4a7a07; --accent-ink: #fff; --field: #fbfef6; --soft: #ebf6d6; --good: #2b8a3e; --warn: #b45309; --warn-bg: #fff1dc; --bad: #c92a2a; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #1f300b; --bg2: #0c1504; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f5fbe9; --muted: #cfe0b3; --accent: #a9e34b; --accent-ink: #142004; --field: rgba(255,255,255,.08);
    --soft: rgba(169,227,75,.15); --good: #a9e34b; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8;
    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; }
.add { order: 3; }
.list { order: 4; }
.settings { order: 5; }
.app > .faq { order: 6; }
.app > footer { order: 7; }
/* first use: the form straight under the title */
.app.setup .add { order: 2; }
.app.setup .summary { order: 3; }
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, legend, .label-like { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input[type=search], input[type=date], select, 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; }
select { -webkit-appearance: auto; appearance: auto; }
input[type=date] { -webkit-appearance: auto; appearance: auto; }
textarea { resize: vertical; line-height: 1.4; min-height: 84px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { 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; }
.hint:empty { display: none; }
[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; }
.secondary.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; }
button:disabled { opacity: .45; cursor: default; }
.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; }
.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: .2rem 0 .8rem; 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; }
.settings .msg.show { margin: .8rem 0 0; }
.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 .wide { grid-column: 1 / -1; }
.settings .tool-grid + label { margin-top: 1.1rem; }
.settings select + .tool-grid { margin-top: 1rem; }

/* use first */
.summary { border: 2px solid var(--accent); }
.next { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.next-left { margin: .2rem 0 0; font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.next-left.soon { color: var(--warn); }
.sum-empty { margin: 0; color: var(--muted); }
.counts { list-style: none; margin: .7rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.counts li { padding: .25rem .7rem; border-radius: 999px; background: var(--field); border: 1px solid var(--line); font-size: .9rem; }
.counts li.warn { border-color: var(--warn); }
.counts b { font-weight: 800; }
.summary .link { margin-top: .1rem; }

/* the list */
.find { margin-bottom: .6rem; }
.find label { margin-top: 0; }
.empty { margin: 0; color: var(--muted); }
.group { margin-top: .8rem; }
.group:first-of-type { margin-top: 0; }
.g-h { margin: .2rem 0 .55rem; font-size: 1rem; color: var(--accent); }
.g-h.warn { color: var(--warn); }
.g-h.bad { color: var(--bad); }
.g-hint { margin: -.3rem 0 .55rem; }
details.archive summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.box-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.box-list:empty { display: none; }
.box { border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 14px; padding: .65rem .8rem .7rem; background: var(--field); min-width: 0; transition: box-shadow .3s; }
.box.soon { border-left-color: var(--warn); }
.box.expired { border-left-color: var(--bad); }
.box.archive { border-left-color: var(--line); }
.box.flash { box-shadow: 0 0 0 3px var(--accent); }
.box-top { display: flex; justify-content: space-between; align-items: baseline; gap: .2rem .6rem; flex-wrap: wrap; }
.box-name { margin: 0; font-size: 1.08rem; overflow-wrap: anywhere; min-width: 0; }
.badge { font-size: .82rem; font-weight: 700; padding: .1rem .6rem; border-radius: 999px; background: var(--soft); color: var(--ink); border: 1px solid var(--line); white-space: nowrap; }
.box-sub { margin: .1rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.box-note { margin: .35rem 0 0; font-size: .9rem; white-space: pre-line; overflow-wrap: anywhere; }
.dl { list-style: none; margin: .45rem 0 0; padding: 0; }
.dl li { position: relative; padding: .12rem 0 .12rem 1.15rem; font-size: .97rem; overflow-wrap: anywhere; }
.dl li::before { content: ""; position: absolute; left: .1rem; top: .62em; width: .55rem; height: .55rem; border-radius: 50%; background: var(--line); }
.box-btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.box-btns.two { margin-top: .4rem; }
.mini { flex: 1 1 4.5rem; min-height: 44px; padding: 0 .6rem; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; min-width: 0; }
.mini.strong { flex-basis: 8rem; color: var(--ink); background: var(--soft); }
.mini.bad { color: var(--bad); }

/* the form */
.add #form { margin: 0; }
.add #form > label:first-child { margin-top: 0; }
.opt { min-width: 0; }
.inline { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.inline input { width: 5.5rem; flex: none; text-align: center; }
.inline.grow input { flex: 1 1 auto; width: auto; text-align: left; }
.unit { color: var(--muted); font-weight: 600; font-size: .92rem; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: .5rem; }
.preview { margin: 1rem 0 0; padding: .55rem .75rem; border-radius: 12px; background: var(--soft); font-weight: 600; overflow-wrap: anywhere; }
.preview:empty { display: none; }

/* the item's main line */
.st { margin: .35rem 0 0; font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.st.soon { color: var(--warn); }
.st.expired { color: var(--bad); }
.st.done { color: var(--muted); font-weight: 600; }
.next.expired { color: var(--bad); }
.counts li.bad { border-color: var(--bad); }
.alert { margin: .7rem 0 0; padding: .5rem .75rem; border-radius: 12px; background: var(--warn-bg); border-left: 4px solid var(--bad); font-weight: 600; overflow-wrap: anywhere; }

/* place filter */
.places { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .8rem; }
.place { min-height: 40px; padding: 0 .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.place[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* form extras */
fieldset.mode { border: 0; margin: 0; padding: 0; 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: .45rem; margin: 0; min-height: 48px; padding: .35rem .65rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink); font-weight: 600; font-size: .92rem; cursor: pointer; line-height: 1.25; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--soft); }
.seg input { margin: 0; flex: none; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.quick { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; }
.chip { min-height: 40px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); color: var(--accent); font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; }
.pair label { margin-top: .9rem; }
.tool-grid.gap { margin-top: 1rem; }

@media print {
    body { background: #fff; color: #000; padding: 0; display: block; }
    .app { width: 100%; display: block; }
    .back, .topbar, header .sub, .summary, .add, .settings, .faq, footer, .msg, .places, .find, .box-btns, .archive, .g-hint, .theme-toggle, .help-btn { display: none !important; }
    .card, .box { border-color: #999; background: #fff; break-inside: avoid; }
    .st, .st.soon, .st.expired, .g-h, .g-h.warn, .g-h.bad, .box-sub { 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; }
    .box { padding: .6rem .65rem .65rem; }
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .row-btns > * { flex-basis: 100%; }
    h1 { font-size: 1.5rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .pair { grid-template-columns: minmax(0, 1fr); }
    .inline:not(.grow) { flex-wrap: wrap; }
}

/* laptops and desktops: deadlines on the left, the form on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.25fr) 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; }
    .next { font-size: 1.4rem; }
}
