:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #f8fafc;
  --text: #111827;
  --muted: #586474;
  --line: #d8dee7;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --brand-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --ok: #15803d;
  --ok-soft: #ecfdf3;
  --focus: rgba(37, 99, 235, 0.16);
  --shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  --shadow-strong: 0 18px 45px rgba(15, 23, 42, 0.14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f16;
  --surface: #111827;
  --surface-2: #1f2937;
  --surface-3: #151e2b;
  --text: #f8fafc;
  --muted: #a8b3c3;
  --line: #2d3748;
  --brand: #60a5fa;
  --brand-2: #93c5fd;
  --brand-soft: rgba(96, 165, 250, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.14);
  --focus: rgba(96, 165, 250, 0.22);
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  --shadow-strong: 0 18px 45px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 520;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: scale(0.98);
}

input,
select {
  font-size: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

:root[data-theme="dark"] .topbar {
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom-color: var(--line);
}

.title-block {
  min-width: 0;
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: 1.1rem;
  font-weight: 850;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-block p {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
}

.top-actions {
  display: flex;
  gap: 8px;
  justify-content: end;
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px 14px 132px;
}

.hidden {
  display: none !important;
}

.panel,
.summary-grid > div,
.dashboard-card,
.list-card,
.item-card,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .summary-grid > div,
:root[data-theme="dark"] .dashboard-card,
:root[data-theme="dark"] .list-card,
:root[data-theme="dark"] .item-card,
:root[data-theme="dark"] .empty-state {
  border-color: var(--line);
}

.compact-form,
.item-form {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.compact-form {
  grid-template-columns: 1fr 1fr auto;
}

.install-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px;
}

.install-panel strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
}

.install-panel span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.install-panel button {
  min-height: 42px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
  padding: 0 14px;
}

.dashboard-panel {
  margin-top: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dashboard-card {
  display: grid;
  align-content: start;
  min-height: 86px;
  padding: 11px;
}

.dashboard-card span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.dashboard-card strong {
  margin-top: 5px;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 950;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-card small {
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-form {
  grid-template-columns: 1fr 138px 92px auto;
}

.import-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

.import-toggle {
  min-height: 46px;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand-2);
  font-weight: 900;
}

.import-form {
  display: grid;
  gap: 8px;
}

.import-form label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.45;
  padding: 12px;
  outline: none;
}

textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

.import-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.import-actions span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.import-actions button {
  min-height: 44px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
  padding: 0 14px;
}

:root[data-theme="dark"] .import-form label {
  color: var(--muted);
}

:root[data-theme="dark"] textarea {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text);
}

:root[data-theme="dark"] textarea::placeholder {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

:root[data-theme="dark"] .field label,
:root[data-theme="dark"] .summary-grid span,
:root[data-theme="dark"] .control-label {
  color: var(--muted);
}

.field.wide {
  min-width: 0;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  padding: 0 12px;
  outline: none;
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

input::placeholder {
  color: var(--muted);
  opacity: 1;
  font-weight: 520;
}

:root[data-theme="dark"] input::placeholder {
  color: var(--muted);
}

.category-suggestion {
  min-height: 16px;
  color: var(--brand-2);
  font-size: 0.72rem;
  font-weight: 800;
}

form button,
.mode-switch button,
.primary-action {
  min-height: 46px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  padding: 0 16px;
}

.stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.list-card {
  display: grid;
  grid-template-columns: 1fr minmax(100px, auto) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  text-align: left;
}

.list-open {
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.list-card h2,
.item-main h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.2;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.pill {
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 8px;
  white-space: nowrap;
}

.quantity-pill {
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-2);
  font-weight: 900;
  padding: 4px 8px;
  white-space: nowrap;
}

:root[data-theme="dark"] .pill {
  color: var(--muted);
}

.list-progress {
  height: 7px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.list-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
}

.list-side {
  display: grid;
  gap: 3px;
  justify-items: end;
}

.list-total {
  align-self: center;
  color: var(--ok);
  font-weight: 900;
  font-size: 1.02rem;
}

.list-side small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.list-delete {
  width: 40px;
  height: 40px;
  align-self: center;
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 900;
}

:root[data-theme="dark"] .list-delete,
:root[data-theme="dark"] .delete-button {
  background: var(--danger-soft);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.mode-switch button {
  display: grid;
  gap: 2px;
  place-items: center;
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
}

.mode-switch span {
  font-weight: 900;
}

.mode-switch small {
  font-size: 0.68rem;
  font-weight: 800;
}

.mode-switch button.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.07);
}

:root[data-theme="dark"] .mode-switch button.active {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.24);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.summary-grid > div {
  padding: 10px 11px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-top: 12px;
}

.tool-row input {
  min-width: 0;
}

.tool-row button {
  min-height: 46px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--brand-2);
  font-weight: 850;
  padding: 0 12px;
}

:root[data-theme="dark"] .tool-row button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--brand-2);
}

.tool-row button.active {
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: #fff;
}

.item-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 11px;
  padding: 12px;
  box-shadow: none;
}

.check-button {
  width: 42px;
  height: 42px;
  margin-top: 1px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: transparent;
  font-weight: 900;
  font-size: 1.1rem;
}

.item-card.purchased {
  opacity: 0.68;
}

.item-card.purchased .check-button {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

.item-card.purchased h2 {
  text-decoration: line-through;
}

.item-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.quick-price-button {
  min-height: 38px;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 10px;
}

:root[data-theme="dark"] .quick-price-button {
  background: var(--brand-soft);
}

.item-controls {
  display: grid;
  grid-template-columns: 84px 116px 1fr 44px;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.price-insight {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.price-insight span,
.muted-insight {
  border-radius: 999px;
  background: var(--surface-2);
  padding: 4px 8px;
}

.quick-list .category-header,
.quick-list .control-label.category,
.quick-list .delete-button,
.quick-list .price-insight {
  display: none;
}

.quick-list .category-section {
  box-shadow: none;
}

.quick-list .item-card {
  grid-template-columns: 52px 1fr;
  padding: 14px;
}

.quick-list .item-controls {
  grid-template-columns: 1fr 1fr;
}

.control-label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.control-label input,
.control-label select {
  min-height: 40px;
  padding: 0 8px;
}

.delete-button {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 900;
}

.pending {
  color: var(--warn);
  font-weight: 900;
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 4px 8px;
}

.line-total {
  color: var(--ok);
  font-weight: 900;
}

.category-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .category-section {
  border-color: var(--line);
}

.category-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 84%, var(--surface-2));
}

.category-header h2 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 950;
  line-height: 1.15;
}

.category-header span,
.category-totals span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.category-totals {
  display: grid;
  justify-items: end;
  text-align: right;
}

.category-totals strong {
  color: var(--ok);
  font-size: 1rem;
  font-weight: 950;
  white-space: nowrap;
}

.category-items {
  display: grid;
  gap: 0;
}

.category-items .item-card {
  border-width: 0;
  border-radius: 0;
}

.category-items .item-card + .item-card {
  border-top: 1px solid var(--line);
}

.empty-state {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 36px 14px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

.statusbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(14, 23, 31, 0.97);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 650;
}

:root[data-theme="dark"] .statusbar,
:root[data-theme="dark"] .shopping-dock {
  background: rgba(4, 10, 9, 0.96);
}

.shopping-dock {
  position: fixed;
  right: 12px;
  bottom: calc(38px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  max-width: 736px;
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: var(--shadow-strong);
  color: #fff;
}

.shopping-dock span {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.shopping-dock strong {
  display: block;
  margin-top: 2px;
  font-size: 1.45rem;
  line-height: 1.1;
}

@media (max-width: 640px) {
  .compact-form,
  .item-form,
  .import-actions {
    grid-template-columns: 1fr;
  }

  .install-panel {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .summary-grid strong {
    font-size: 0.98rem;
    overflow-wrap: anywhere;
  }

  .item-controls {
    grid-template-columns: 1fr 1fr;
  }

  .control-label.category {
    grid-column: 1 / -1;
  }

  .delete-button {
    width: 100%;
  }

  .tool-row {
    grid-template-columns: 1fr;
  }

  .mode-switch button {
    padding: 7px 6px;
  }

  .list-card {
    grid-template-columns: 1fr auto;
  }

  .list-side {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-items: start;
  }

  .list-delete {
    grid-column: 2;
  }

  .item-card {
    grid-template-columns: 44px 1fr;
    padding: 11px;
  }

  .check-button {
    width: 40px;
    height: 40px;
  }

  .category-header {
    padding: 11px;
  }
}

@media (max-width: 390px) {
  main {
    padding-right: 10px;
    padding-left: 10px;
  }

  .topbar {
    padding-right: 10px;
    padding-left: 10px;
  }

  .summary-grid {
    gap: 6px;
  }

  .summary-grid > div {
    padding: 9px 8px;
  }

  .dashboard-grid,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .item-head {
    grid-template-columns: 1fr;
  }

  .category-header {
    grid-template-columns: 1fr;
  }

  .category-totals {
    justify-items: start;
    text-align: left;
  }
}
