:root {
    --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #7a8394; --line: #e4e7ec;
    --accent: #2f7d4f; --accent-text: #fff; --warn: #b4560b; --danger: #c0392b;
    --radius: 12px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c; --card: #1d2128; --text: #e6e8eb; --muted: #8b93a1; --line: #2c313a;
        --accent: #4caf78; --accent-text: #0d1a12; --warn: #f0a050; --danger: #e5675a;
    }
}
* { box-sizing: border-box; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
main { max-width: 720px; margin: 0 auto; padding: 12px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    max-width: 720px; margin: 0 auto; padding: 14px 12px 4px;
}
.topbar h1 { font-size: 1.3rem; margin: 0; }
.topbar h1 a { text-decoration: none; margin-right: 6px; }
.who { color: var(--muted); font-size: .9rem; }

.card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px; margin-bottom: 12px;
}
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.count { color: var(--muted); font-weight: normal; }
.muted { color: var(--muted); }
.warn { color: var(--warn); font-weight: 600; }
.error { color: var(--danger); margin: 0 0 8px; }

input, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input[type=search], select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--bg); min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled { opacity: .6; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line);
    background: var(--card); cursor: pointer; text-decoration: none; color: var(--text);
    white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: default; }

/* row 1 */
.add-row { display: flex; gap: 8px; align-items: center; }
.search-wrap { position: relative; flex: 1; min-width: 0; }
#addQty { width: 80px; flex: none; }
.add-row .unit { min-width: 32px; color: var(--muted); }
.add-row .check-inline { flex: none; }
.add-row .check-inline input { width: 20px; height: 20px; margin: 0; }
.add-info { margin-top: 8px; font-size: .9rem; min-height: 1.2em; }
.check-inline { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check-inline input { accent-color: var(--accent); cursor: pointer; }

.suggestions {
    position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
    margin: 0; padding: 4px 0; list-style: none; max-height: 320px; overflow-y: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.suggestions li { padding: 8px 12px; cursor: pointer; display: flex; flex-wrap: wrap; gap: 0 8px; }
.suggestions li:hover, .suggestions li.active { background: var(--bg); }
.s-name { font-weight: 600; }
.s-alt { color: var(--muted); font-size: .85rem; align-self: center; }
.s-meta { width: 100%; color: var(--muted); font-size: .8rem; }

/* rows 2 & 3 */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex; align-items: center; gap: 10px; padding: 6px 0;
    border-top: 1px solid var(--line); transition: opacity .2s;
}
.list li:first-child { border-top: 0; }
.list li.leaving { opacity: .3; }
.list li.empty { color: var(--muted); justify-content: center; padding: 10px; }
.list .chk { width: 24px; height: 24px; flex: none; accent-color: var(--accent); cursor: pointer; }
.list .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .qty { width: 76px; flex: none; min-height: 38px; padding: 6px 8px; text-align: right; }
.list .unit { width: 34px; color: var(--muted); font-size: .9rem; }
.list .date { color: var(--muted); font-size: .8rem; }
.list .promo { background: rgba(192, 57, 43, .15); color: var(--danger); font-size: .8rem; padding: 2px 6px;
    border-radius: 4px; font-weight: 600; white-space: nowrap; }
.list li.shop-header { background: var(--bg); padding: 6px 0; font-weight: 600; color: var(--accent);
    border-top: 2px solid var(--line); margin-top: 4px; }
.list li.shop-header:first-child { border-top: 0; margin-top: 0; }
.bought .name { text-decoration: line-through; color: var(--muted); }
.icon { background: none; border: 0; cursor: pointer; font-size: 1.2rem; padding: 6px; opacity: .7; }
.icon:hover { opacity: 1; }

.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.row-head h2 { margin: 0; }
#shopFilter { width: auto; min-height: 38px; padding: 6px 10px; }

.footer-links { display: flex; gap: 8px; flex-wrap: wrap; }

/* forms */
.form label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
.form label input, .form label select { margin-top: 4px; color: var(--text); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label.check { display: flex; align-items: center; gap: 8px; color: var(--text); padding-top: 22px; }
.form label.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

/* history */
.hist { width: 100%; border-collapse: collapse; font-size: .95rem; }
.hist th { text-align: left; color: var(--muted); font-weight: normal; font-size: .8rem; padding: 4px 6px; }
.hist td { padding: 6px; border-top: 1px solid var(--line); }
.hist tfoot td { font-weight: 600; }
.hist .r { text-align: right; white-space: nowrap; }
.hist-group h2 small { margin-left: 6px; }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login-card h1 { font-size: 1.4rem; margin: 0 0 4px; text-align: center; }

@media (max-width: 480px) {
    .add-row { flex-wrap: wrap; }
    .search-wrap { flex-basis: 100%; }
    #addQty { flex: 1; }
    .list .date { display: none; }
}
