:root {
  --green: #285a45; --ink: #243c32; --bg: #f5f4ed; --card: #fffef8; --border: #d8ded4; --muted: #5e6c61; --warm: #c76b3f; --danger: #a3402a;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
button { border: 1px solid transparent; background: var(--green); color: #fff; padding: .7rem 1.1rem; border-radius: .7rem; cursor: pointer; font-weight: 650; min-height: 48px; touch-action: manipulation; }
button:hover { filter: brightness(.95); }
button:disabled { opacity: .45; cursor: default; }
button.secondary { background: transparent; border-color: #a2b8a8; color: var(--green); }
button.quiet { background: transparent; color: var(--green); padding: .5rem .7rem; font-weight: 500; }
button.danger { background: var(--danger); }
button.quiet.danger { background: transparent; color: var(--danger); }
:focus-visible { outline: 3px solid var(--warm); outline-offset: 3px; }
a { color: var(--green); }
input { width: 100%; border: 1px solid #9faf9e; border-radius: .5rem; padding: .7rem; background: #fff; color: var(--ink); min-height: 48px; }
input[type=radio] { width: auto; min-height: 0; }

.app { max-width: 1000px; margin: auto; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.1rem; text-decoration: none; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { display: grid; place-content: center; flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--green); color: #fff; font-family: Georgia, serif; font-size: 1.5rem; }
.chip { font-size: .78rem; padding: .2rem .6rem; border-radius: 99px; background: #e5ecdf; color: #30533a; white-space: nowrap; }
.chip.offline { background: #fbe9dc; color: #813d26; }
.chip.syncing { background: #eef0e6; color: var(--muted); }
main { flex: 1; padding: 1.25rem 1.5rem 2rem; }

h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.1; letter-spacing: -.03em; margin: .4rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 600px; margin: 0 0 1.4rem; }
.hint { color: var(--muted); font-size: .82rem; margin: .2rem 0 .8rem; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 1.3rem; margin: 1rem 0; max-width: 720px; }
.panel > button { margin: .3rem .5rem .3rem 0; }
.notice { padding: .75rem 1rem; border: 1px solid #a5b7a6; border-radius: .6rem; background: #edf2e9; margin: .7rem 0; }
.notice.error { background: #fff0e8; border-color: #c97952; color: #813d26; }
.reference { display: block; overflow-wrap: anywhere; font-size: .85rem; padding: .6rem; background: #edf1e9; border-radius: .4rem; margin: .5rem 0 1rem; }

.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.item { background: var(--card); border: 1px solid var(--border); border-radius: .9rem; padding: 1.1rem 1.2rem; }
.item.simple { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.item.simple .item-title { flex: 1; }
.item-title { display: flex; justify-content: space-between; align-items: start; gap: .8rem; flex-wrap: wrap; }
.item-title h2 { margin: 0; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: .72rem; background: #e5ecdf; color: #30533a; padding: .15rem .55rem; border-radius: 99px; margin-left: .3rem; }
.pill.on-list { background: #fbe9dc; color: #813d26; }
.pill.saving { background: #eef0e6; color: var(--muted); }
.quantity { font-family: Georgia, serif; font-size: 2.6rem; line-height: 1.25; }
.quantity span { font-family: ui-sans-serif, system-ui, sans-serif; font-size: .9rem; color: var(--muted); margin-left: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.item .actions button { flex: 1; min-width: 4.5rem; }
.item.simple .actions { margin: 0; }

.history, .devices { list-style: none; padding: 0; margin: 0; }
.history li, .devices li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .3rem 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.history li:last-child, .devices li:last-child { border: 0; }
.devices .actions { margin: 0; }
fieldset.mode { border: 0; padding: 0; margin: 0 0 1rem; }
fieldset.mode legend { font-weight: 650; margin-bottom: .3rem; }
fieldset.mode label { display: block; padding: .35rem 0; }

.field { display: flex; flex-direction: column; gap: .35rem; margin: .7rem 0; }
.field > span { font-size: .85rem; font-weight: 650; }
.form-row { display: flex; gap: .8rem; flex-wrap: wrap; }
.form-row > .field { flex: 1; min-width: min(100%, 7rem); }
dialog { width: min(94vw, 32rem); max-height: 90dvh; overflow: auto; border: 1px solid var(--border); border-radius: 1rem; padding: 1.3rem; background: var(--card); color: inherit; }
dialog::backdrop { background: #142a2280; }
dialog .actions { justify-content: flex-end; margin-top: 1rem; }

nav[aria-label=Main] { position: sticky; bottom: 0; display: flex; gap: .4rem; padding: .5rem .8rem calc(.5rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg); }
nav[aria-label=Main] button { flex: 1; min-width: 0; padding: .6rem .3rem; background: transparent; color: var(--muted); }
nav[aria-label=Main] button.active { background: #e3eadf; color: var(--green); }
.toast { position: sticky; bottom: 4.5rem; margin: 0 auto .5rem; width: min(94%, 30rem); display: flex; align-items: center; gap: .3rem; background: var(--ink); color: #fff; border-radius: .8rem; padding: .3rem .4rem .3rem 1rem; box-shadow: 0 6px 24px #0003; }
.toast span { flex: 1; }
.toast button { color: #fff; min-height: 40px; }

.install-card { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--green); border-radius: .9rem; padding: .8rem 1rem; margin: 0 0 1rem; }
.install-card img { border-radius: 10px; flex: none; }
.install-card > div:nth-child(2) { flex: 1; min-width: 12rem; }
.install-card .hint { margin: 0; }
.install-card .actions { margin: 0; }
.steps { padding-left: 1.3rem; }
.steps li { margin: .5rem 0; }
.inline-icon { display: inline-flex; vertical-align: -3px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; }
.qr { width: min(100%, 260px); margin: .5rem auto; background: #fff; border-radius: .6rem; padding: .4rem; }
.qr svg { display: block; width: 100%; height: auto; }
.center { text-align: center; }
.recovery-code { display: block; text-align: center; font-size: clamp(1rem, 4.6vw, 1.35rem); font-weight: 700; letter-spacing: .04em; padding: .9rem .5rem; margin: .6rem 0; background: #edf1e9; border: 2px dashed #a2b8a8; border-radius: .6rem; overflow-wrap: anywhere; }
.check { display: flex; gap: .6rem; align-items: center; margin: 1rem 0 0; font-weight: 600; }
.check input { width: 22px; min-height: 22px; }
.welcome main > button.quiet { margin-top: .3rem; }
.welcome main { max-width: 560px; margin: 0 auto; padding-top: 3rem; }

@media (max-width: 600px) {
  .topbar { padding: .8rem 1rem; }
  main { padding: 1rem; }
  .item-grid { grid-template-columns: 1fr; }
}
