:root {
  color-scheme: light;
  --bg: #f5f5f0;
  --surface: #fff;
  --text: #202722;
  --muted: #647068;
  --line: #dce3dc;
  --green: #315c45;
  --green-dark: #244733;
  --soft-green: #e8f1e9;
  --danger: #a62e2e;
  --shadow: 0 5px 20px rgb(29 47 35 / 7%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151b17;
  --surface: #202923;
  --text: #eff5f0;
  --muted: #b2c0b6;
  --line: #39473d;
  --green: #8bc19a;
  --green-dark: #a1d1ae;
  --soft-green: #263b2e;
  --danger: #ff9999;
  --shadow: 0 5px 20px rgb(0 0 0 / 20%);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; padding-bottom: env(safe-area-inset-bottom); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }
.topbar { position: relative; min-height: 62px; padding: 10px max(18px, calc((100% - 980px) / 2)); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { display: inline-flex; gap: 10px; align-items: center; color: var(--text); font-weight: 750; font-size: 1.1rem; text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.account-bar { display: flex; align-items: center; gap: 10px; color: var(--muted); }
main { position: relative; width: min(980px, calc(100% - 28px)); margin: 24px auto 60px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 20px; }
.auth-card { max-width: 480px; margin: 8vh auto 0; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.5rem, 5vw, 2rem); margin-bottom: 12px; }
h2 { font-size: 1.15rem; margin-bottom: 14px; }
h3 { font-size: 1rem; margin-bottom: 8px; }
.muted, .hint { color: var(--muted); line-height: 1.5; }
.hint { font-size: .88rem; margin: 8px 0 14px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; }
.tabs { border-bottom: 1px solid var(--line); margin: 18px 0; }
.tab { border: 0; color: var(--muted); background: transparent; padding: 10px 12px; white-space: nowrap; }
.tab.selected { color: var(--green); font-weight: 700; border-bottom: 3px solid var(--green); }
.menu-toggle { width: 44px; min-width: 44px; padding: 8px; }
.menu-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.main-nav { position: fixed; top: calc(68px + env(safe-area-inset-top)); right: max(12px, calc((100vw - 980px) / 2)); z-index: 8; display: grid; width: min(280px, calc(100vw - 24px)); max-height: calc(100dvh - 84px - env(safe-area-inset-top)); overflow-y: auto; gap: 4px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.nav-button { border: 0; border-radius: 8px; padding: 12px 14px; background: transparent; color: var(--text); text-align: left; }
.nav-button:hover { background: var(--soft-green); }
.nav-button.selected { color: var(--green); font-weight: 700; background: var(--soft-green); }
.nav-divider { height: 1px; margin: 4px 6px; background: var(--line); }
.nav-logout { color: var(--danger); }
.nav-logout:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.pull-refresh-indicator { height: 0; overflow: hidden; opacity: 0; text-align: center; color: var(--muted); font-size: .9rem; transition: height .15s ease, opacity .15s ease; }
#lists-page.pulling .pull-refresh-indicator, #lists-page.refreshing .pull-refresh-indicator { height: 38px; opacity: 1; }
#lists-page.pull-ready .pull-refresh-indicator { color: var(--green); font-weight: 700; }
.quick-add-section { margin-bottom: 16px; }
.quick-add-section h1 { margin-bottom: 14px; }
.quick-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; }
.quick-entry-submit { min-height: 44px; }
.quick-entry-message { margin: 10px 0 0; }
#entry-page { max-width: 680px; margin: 0 auto; }
#entry-page > .muted { margin-bottom: 18px; }
.entry-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.product-details { padding: 12px; border-radius: 9px; background: var(--soft-green); color: var(--muted); font-size: .9rem; line-height: 1.5; }
label { display: grid; gap: 6px; font-size: .9rem; font-weight: 620; }
input, select { width: 100%; min-height: 44px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--green) 35%, transparent); outline-offset: 1px; }
form { display: grid; gap: 14px; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; gap: 7px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; font-weight: 650; color: var(--text); background: var(--surface); }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-quiet { border-color: var(--line); }
.button-danger { color: var(--danger); }
.button-small { min-height: 34px; padding: 5px 9px; font-size: .85rem; }
.full { width: 100%; }
.message { min-height: 1.4em; color: var(--danger); margin: 0; }
.toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.list-picker { min-width: min(220px, 100%); flex: 1; }
.sort-picker { width: 170px; }
.entry-list { display: grid; gap: 10px; }
.entry-card { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: start; gap: 12px; padding: 15px; }
.entry-card.bought { opacity: .68; }
.entry-check { width: 22px; height: 22px; min-height: 22px; margin-top: 2px; accent-color: var(--green); }
.entry-main { min-width: 0; }
.entry-name { font-size: 1.02rem; font-weight: 700; overflow-wrap: anywhere; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; color: var(--muted); font-size: .88rem; margin-top: 4px; }
.entry-price { white-space: nowrap; text-align: right; font-weight: 700; }
.entry-actions { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.entry-edit { grid-column: 1 / -1; width: 100%; padding-top: 10px; }
.entry-edit-grid { display: grid; gap: 9px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.entry-details { grid-column: 2 / -1; margin-top: 8px; color: var(--muted); font-size: .87rem; line-height: 1.5; }
.list-total { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; position: sticky; bottom: 8px; }
.total-amount { font-size: 1.25rem; font-weight: 780; color: var(--green); white-space: nowrap; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.setting-row h2 { margin-bottom: 5px; }
.setting-row p { margin-bottom: 0; }
.inline-label { display: flex; align-items: center; gap: 8px; }
.inline-label select { min-width: 115px; }
.settings-list { display: grid; gap: 8px; margin: 12px 0 20px; }
.notification-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; }
.notification-item input { width: 22px; min-height: 22px; accent-color: var(--green); }
.help-box { background: var(--soft-green); padding: 16px; border-radius: 12px; margin-top: 20px; }
.help-box p { margin-bottom: 0; line-height: 1.55; }
.admin-section { margin: 14px 0; }
.admin-table { display: grid; gap: 8px; }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.admin-row-main { min-width: 0; }
.admin-row-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; }
.badge { border-radius: 20px; padding: 3px 8px; background: var(--soft-green); font-size: .76rem; color: var(--green); }
.offline-banner { position: sticky; top: 0; z-index: 10; padding: 9px 16px; text-align: center; color: #532e00; background: #ffdf9c; font-weight: 650; }
.dialog { width: min(500px, calc(100% - 28px)); max-height: 88vh; overflow: auto; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dialog-close { position: sticky; float: right; top: 0; border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; line-height: 1; }
.dialog-content { clear: both; }
.dialog-list { display: grid; gap: 9px; }
.toast { position: fixed; z-index: 20; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #202722; color: white; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); transition: .2s; max-width: min(90vw, 500px); text-align: center; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 680px) {
  main { width: calc(100% - 20px); margin-top: 14px; }
  .topbar { padding: max(9px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 9px max(12px, env(safe-area-inset-left)); }
  .brand { gap: 7px; font-size: 1rem; }
  .brand img { width: 30px; height: 30px; }
  .account-bar { gap: 5px; }
  #user-label { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
  .main-nav { top: calc(60px + env(safe-area-inset-top)); right: 10px; max-height: calc(100dvh - 74px - env(safe-area-inset-top)); }
  .card { padding: 15px; border-radius: 13px; }
  .quick-entry { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .quick-entry-submit { width: 100%; }
  .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; gap: 8px; padding: 12px; }
  .toolbar > .button { width: 100%; min-width: 0; padding-inline: 8px; font-size: .88rem; }
  .toolbar .list-picker { grid-column: 1 / -1; min-width: 0; }
  .toolbar .sort-picker { width: auto; min-width: 0; }
  .toolbar #members-button { grid-column: 1 / -1; }
  .entry-card { gap: 9px; }
  .entry-actions .button { flex: 1; }
  .setting-row, .admin-row { align-items: flex-start; flex-direction: column; }
  .admin-row-actions { justify-content: flex-start; }
  .list-total { position: static; }
  .entry-fields { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 380px) {
  #user-label { max-width: 92px; }
}
