:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --text: #18181b;
  --muted: #71717a;
  --border: #d4d4d8;
  --orange: #f97316;
  --orange-dark: #c2410c;
  --orange-soft: #ffedd5;
  --green: #15803d;
  --red: #b91c1c;
  --shadow: 0 8px 24px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1c1c1f;
    --surface-2: #242428;
    --text: #fafafa;
    --muted: #a1a1aa;
    --border: #3f3f46;
    --orange-soft: #431407;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(100%, 760px); margin: 0 auto; padding: 0 14px 28px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 2px 14px;
}
.eyebrow { margin: 0 0 3px; color: var(--orange); font-size: .75rem; font-weight: 800; letter-spacing: .12em; }
h1 { margin: 0; font-size: clamp(1.25rem, 5vw, 1.75rem); line-height: 1.1; }
h2 { margin: 0 0 14px; font-size: 1.05rem; }

.panel {
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.list-controls label, .form-grid label, .dialog-content label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 650;
}
.row-list { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; margin-top: 7px; }
input, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 20%, transparent); }

.metrics { display: grid; grid-template-columns: 1.5fr .75fr .75fr; gap: 8px; margin: 0 0 12px; }
.metric {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}
.metric span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .76rem; }
.metric strong { display: block; overflow: hidden; font-size: 1.18rem; text-overflow: ellipsis; white-space: nowrap; }
.metric:first-child strong { color: var(--orange); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.span-2 { grid-column: span 2; }
.money-input { display: flex; align-items: center; min-height: 46px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.money-input:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 20%, transparent); }
.money-input span { padding-left: 12px; color: var(--muted); }
.money-input input { border: 0; background: transparent; box-shadow: none; }

.form-actions, .dialog-actions { display: flex; gap: 8px; margin-top: 14px; }
button, .file-btn {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 9px 13px;
  font-weight: 750;
  text-align: center;
}
.primary { background: var(--orange); color: #fff; }
.primary:hover { background: var(--orange-dark); }
.secondary { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.danger { border: 1px solid color-mix(in srgb, var(--red) 45%, var(--border)); background: transparent; color: var(--red); }
.icon-btn { min-height: 38px; padding: 7px 11px; background: var(--orange-soft); color: var(--orange); }
.hidden, .install-hidden { display: none !important; }
.message { min-height: 20px; margin: 9px 0 0; color: var(--green); font-size: .86rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.section-head input { width: min(48%, 260px); min-height: 40px; }
.items { display: grid; gap: 9px; }
.item-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-2);
}
.item-card.bought { opacity: .65; }
.item-card.bought .item-name { text-decoration: line-through; }
.item-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 10px; }
.check-wrap { padding-top: 2px; }
.check-wrap input { width: 22px; min-height: 22px; accent-color: var(--orange); }
.item-name { display: block; font-weight: 800; overflow-wrap: anywhere; }
.item-meta { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 4px; color: var(--muted); font-size: .78rem; }
.item-total { color: var(--orange); font-weight: 850; white-space: nowrap; }
.item-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.item-actions button { min-height: 34px; padding: 5px 10px; font-size: .8rem; }
.empty-state { display: grid; place-items: center; gap: 4px; padding: 28px 10px; border: 1px dashed var(--border); border-radius: 14px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--text); }

.utility-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.file-btn { display: grid; place-items: center; }
.file-btn input { display: none; }
footer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .76rem; text-align: center; }

dialog { width: min(calc(100% - 28px), 420px); border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.dialog-content { padding: 18px; }
.dialog-content h2 { margin-bottom: 12px; }
.dialog-actions { justify-content: flex-end; }

@media (max-width: 520px) {
  .app-shell { padding-inline: 10px; }
  .panel { padding: 13px; border-radius: 15px; }
  .metrics { grid-template-columns: 1.35fr .65fr .65fr; }
  .metric { padding: 10px; }
  .metric strong { font-size: 1rem; }
  .row-list { grid-template-columns: 1fr 1fr; }
  .row-list select { grid-column: span 2; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 10px 8px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head input { width: 100%; }
}
