:root {
  --bg: #f9f3f5;
  --bg-soft: #fdf9fa;
  --surface: #ffffff;
  --surface-soft: #fff6f8;
  --text: #22181e;
  --muted: #564c54;
  --line: #ead7dc;
  --line-strong: #ddbfc7;
  --accent: #ec9ea5;
  --accent-strong: #de808e;
  --accent-soft: #fff0f2;
  --accent-rgb: 236, 158, 165;
  --danger: #b03f2a;
  --warning: #b4791e;
  --shadow-sm: 0 10px 26px rgba(52, 26, 35, 0.08);
  --shadow-md: 0 24px 56px rgba(52, 26, 35, 0.14);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --sidebar-width: 250px;
  --mobile-header-h: 116px;
  --mobile-nav-h: 74px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  overflow-y: scroll;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Plus Jakarta Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.45;
  background:
    radial-gradient(circle at 0% 0%, #ffffff 0%, rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 100% 0%, rgba(var(--accent-rgb), 0.24) 0%, rgba(var(--accent-rgb), 0) 44%),
    linear-gradient(180deg, #fdf7f8 0%, #f7eff2 100%);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .1s ease;
}

button:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.28);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  max-width: 1760px;
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: 14px;
  height: calc(100vh - 28px);
  overflow-y: auto;
  padding: var(--space-6) var(--space-4);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(255, 246, 248, 0.95) 100%);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.brand {
  padding: var(--space-2);
  margin-bottom: var(--space-4);
}

.brand-sub {
  margin: 0 0 var(--space-2);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.brand strong {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.menu {
  display: grid;
  gap: var(--space-2);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  min-height: 42px;
  padding: 9px 12px;
  text-align: left;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .1s ease;
}

.menu button i {
  font-size: 18px;
  line-height: 1;
}

.menu button span {
  font-weight: 700;
  letter-spacing: .01em;
}

.menu button:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
}

.menu button.active {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.18) 0%, rgba(var(--accent-rgb), 0.08) 100%);
  color: #7c2f3d;
  box-shadow: var(--shadow-sm);
}

.scope-block {
  margin-top: var(--space-6);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.66);
}

.scope-block small {
  color: var(--muted);
  font-size: 13px;
}

.scope-switch {
  margin-top: var(--space-2);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.scope-switch button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: 36px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

.scope-switch button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.main {
  min-width: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  height: calc(100vh - 28px);
  overflow-y: auto;
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 248, 250, 0.9) 100%);
  box-shadow: var(--shadow-sm);
  transition: opacity .16s ease;
}

.main.is-loading {
  opacity: .9;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 8;
  min-height: 96px;
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

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

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 32px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.household-label {
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.app-icon-btn i {
  font-size: 16px;
  line-height: 1;
}

.app-icon-btn span {
  white-space: nowrap;
}

.topbar-actions button,
.db-indicator {
  min-height: 40px;
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 999px;
}

.db-indicator {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.db-indicator.is-ok {
  border-color: rgba(var(--accent-rgb), 0.48);
  background: var(--accent-soft);
  color: #7a3441;
}

.db-indicator.is-error {
  border-color: #e5b8ae;
  background: #fff1ed;
  color: #8d3523;
}

.topbar-icon-btn:not(.db-indicator) {
  min-width: 40px;
  border-width: 1px;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

.topbar-icon-btn:not(.db-indicator):hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--text);
}

#db-indicator i {
  font-size: 11px;
}

.mobile-tabbar,
.mobile-sheet {
  display: none;
}

.setup-screen.hidden,
.hidden {
  display: none !important;
}

.setup-card,
.panel,
.stat-card,
.entity-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.setup-card {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

.setup-card h2 {
  margin: 0 0 var(--space-2);
  font-size: 28px;
}

.setup-card > p {
  margin: 0;
  color: var(--muted);
}

.setup-form {
  margin-top: var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-3);
}

.auth-card {
  max-width: 520px;
}

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

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
}

.auth-remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

#auth-remember-text {
  font-size: 13px;
}

#auth-message {
  min-height: 18px;
}

.setup-form input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: #fff;
}

.setup-form button {
  grid-column: 1 / -1;
}

.app-page {
  display: none;
}

.app-page.active {
  display: grid;
  gap: var(--space-4);
  align-content: start;
  animation: page-enter .18s ease;
}

@keyframes page-enter {
  from {
    opacity: .4;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-page.active {
    animation: none;
  }
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
}

.toolbar-label {
  margin: 0;
  font-size: 13px;
  line-height: 1;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.toolbar-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  justify-content: end;
  gap: 10px;
  min-width: 0;
}

.toolbar-actions > * {
  flex: 0 0 auto;
  width: auto;
}

.toolbar-actions > select,
.toolbar-actions > input {
  width: auto;
  min-width: 150px;
}

.toolbar-actions > button {
  min-width: 112px;
}

.inventory-toolbar {
  margin-bottom: 0;
}

.inventory-controls {
  display: grid;
  grid-template-columns: 140px 190px minmax(220px, 1fr) 190px;
  gap: var(--space-2);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.84);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}

.dashboard-main {
  align-items: start;
}

.stat-card {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .03em;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 22px;
  line-height: 1.1;
}

.stat-card-key {
  border-color: rgba(var(--accent-rgb), 0.38);
  background: #fff7f8;
}

.stat-card-key strong {
  font-size: 24px;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.panel {
  padding: var(--space-5);
}

.panel h3 {
  margin: 0 0 var(--space-3);
  font-size: clamp(18px, 1.2vw, 22px);
  line-height: 1.2;
}

.list {
  display: grid;
  gap: var(--space-2);
}

.list .row {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: #fff;
}

.list .row strong {
  display: block;
  font-size: 14px;
}

.list .row p {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: 13px;
}

.dashboard-modules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2);
}

.dashboard-modules button {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 13px;
}

.card-grid,
.inventory-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}

.inventory-group {
  display: grid;
  gap: var(--space-3);
}

.inventory-group h4 {
  margin: 0;
  padding: 0 var(--space-1);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.entity-card {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 184px;
  padding: var(--space-4);
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #fffafb 100%);
  box-shadow: var(--shadow-sm);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background-color .16s ease;
}

@media (hover: hover) {
  .entity-card:hover {
    transform: translateY(-2px);
    border-color: var(--line-strong);
    box-shadow: var(--shadow-md);
  }
}

.entity-card h4 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.entity-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.entity-kpi {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
  color: #7d3442;
  text-align: right;
  white-space: nowrap;
}

.entity-meta,
.entity-note {
  margin: 0;
  color: #5b5058;
  font-size: 13px;
  line-height: 1.35;
}

.entity-note {
  color: #4f444c;
}

.entity-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.entity-card.archived {
  background: var(--surface-soft);
  border-style: dashed;
  opacity: .82;
}

.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--muted);
  background: #fff;
}

.tag.warn {
  color: var(--danger);
  border-color: #ebb9ae;
  background: #fff2ef;
}

.tag.plan-tag.status-idea {
  border-color: #ebcfd4;
  background: #fff3f5;
  color: #7b4650;
}

.tag.plan-tag.status-todo {
  border-color: #ebd8c3;
  background: #fff8e8;
  color: #7a5931;
}

.tag.plan-tag.status-doing {
  border-color: #e8c9cf;
  background: #fff0f3;
  color: #853645;
}

.tag.plan-tag.status-done {
  border-color: #ddcdd2;
  background: #f8f1f4;
  color: #694d54;
}

.meta-table {
  display: grid;
}

.meta-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  align-items: baseline;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.meta-row span {
  color: var(--muted);
  font-size: 13px;
}

.meta-row strong {
  font-size: 15px;
  line-height: 1.3;
  word-break: break-word;
}

.hint {
  margin: var(--space-3) 0 0;
  font-size: 13px;
  color: var(--muted);
}

.hint-list {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}

.hint-list p {
  margin: var(--space-2) 0 0;
  font-size: 13px;
  color: var(--muted);
}

.settings-form,
.modal-form,
.inline-form {
  display: grid;
  gap: var(--space-3);
}

.settings-form {
  margin-top: var(--space-2);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-form .full,
.modal-form .full,
.inline-form .full {
  grid-column: 1 / -1;
}

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

.field span,
.field small {
  font-size: 13px;
  color: var(--muted);
}

.modal-form {
  margin-top: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-tip {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.subpanel {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--surface-soft);
}

.subpanel h4 {
  margin: 0 0 var(--space-3);
  font-size: 14px;
}

.list.compact .row strong,
.list.compact .row p {
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: #fff;
  transition: border-color .16s ease, box-shadow .16s ease;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.22);
}

.toolbar button,
.setup-form button,
.settings-form button,
.modal-form button,
.modal-head button,
.modal-extra button,
.inline-form button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  min-height: 42px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, transform .1s ease;
}

.toolbar button:hover,
.setup-form button:hover,
.settings-form button:hover,
.modal-form button:hover,
.modal-head button:hover,
.modal-extra button:hover,
.inline-form button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.toolbar button:active,
.setup-form button:active,
.settings-form button:active,
.modal-form button:active,
.modal-head button:active,
.modal-extra button:active,
.inline-form button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.settings-form button {
  grid-column: 1 / -1;
}

.ghost {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 700;
}

.ghost:hover {
  background: var(--surface-soft);
  border-color: var(--accent);
  color: #803744;
}

.modal-extra .danger {
  background: #fff2ef;
  color: var(--danger);
  border-color: #ebb9ae;
}

#settings-refresh-status-btn {
  width: auto;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

#auth-logout-btn {
  width: auto;
  min-height: 38px;
  padding: 6px 14px;
}

.card-grid.is-sortable .entity-card.sortable,
#items-grid.is-sortable .entity-card.sortable {
  cursor: grab;
  touch-action: pan-y;
}

.card-grid.is-sortable .entity-card.sortable:active,
#items-grid.is-sortable .entity-card.sortable:active {
  cursor: grabbing;
}

.entity-card.sortable.dragging {
  opacity: .65;
  border-style: dashed;
  transform: scale(.985) rotate(.2deg);
  z-index: 4;
  box-shadow: var(--shadow-md);
}

.entity-card.sortable.drag-chosen {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.24);
}

.card-grid.sorting .entity-card.sortable,
#items-grid.sorting .entity-card.sortable,
.inventory-group-grid.sorting .entity-card.sortable {
  transition: transform .12s ease, box-shadow .12s ease;
}

.entity-card.sortable.drag-ghost {
  opacity: .34;
}

body.is-sorting {
  user-select: none;
  -webkit-user-select: none;
}

.inline-form button {
  width: fit-content;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: rgba(34, 20, 25, 0.36);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(920px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fff7f9 100%);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  position: sticky;
  top: calc(var(--space-5) * -1);
  z-index: 2;
  margin: calc(var(--space-5) * -1) calc(var(--space-5) * -1) var(--space-3);
  padding: 14px var(--space-5) 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
}

.modal-head button {
  min-height: 38px;
  min-width: 76px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex: 0 0 auto;
}

.modal-head h3 {
  margin: 0;
  font-size: 24px;
  min-width: 0;
  line-height: 1.2;
}

.modal-extra {
  margin-top: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}

.toast {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 40;
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  background: #161b20;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1260px) {
  .main {
    padding: var(--space-5);
  }

  .inventory-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 20;
    height: var(--mobile-header-h);
    padding: 8px 12px 6px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(255, 245, 248, 0.96) 100%);
    overflow: hidden;
    box-shadow: none;
  }

  .brand {
    margin-bottom: 4px;
    padding: 0;
  }

  .brand strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 16px;
  }

  .brand-sub {
    margin-bottom: 2px;
    font-size: 10px;
    white-space: nowrap;
  }

  .scope-block {
    margin-top: 0;
    padding: 5px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 42px;
  }

  .scope-block small {
    font-size: 11px;
    flex: 0 0 auto;
  }

  .scope-switch {
    margin-top: 0;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .scope-switch::-webkit-scrollbar {
    display: none;
  }

  .scope-switch button {
    flex: 0 0 auto;
    min-width: 80px;
    min-height: 34px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .menu {
    display: none;
  }

  body {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  .main {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    height: auto;
    min-height: calc(100dvh - var(--mobile-header-h));
    overflow: visible;
    margin-top: var(--mobile-header-h);
    padding: var(--space-3) var(--space-3) calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 18px);
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .topbar {
    position: relative;
    z-index: 1;
    min-height: 74px;
    margin-bottom: var(--space-3);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(6px);
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 19px;
    line-height: 1.12;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #page-desc {
    display: none;
  }

  .household-label {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    width: auto;
    display: flex;
    flex-wrap: nowrap;
    align-self: center;
    gap: 6px;
  }

  .topbar-actions button,
  .db-indicator {
    min-height: 34px;
    min-width: 34px;
    padding: 0;
    border-radius: 999px;
    font-size: 12px;
  }

  .topbar-actions .app-icon-btn span {
    display: none;
  }

  #refresh-data-btn.app-icon-btn {
    width: 34px;
  }

  #db-indicator.app-icon-btn {
    width: 34px;
    min-width: 34px;
  }

  .app-page.active {
    gap: var(--space-3);
  }

  .toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: 10px;
    min-height: 0;
  }

  .toolbar-label {
    font-size: 12px;
    letter-spacing: .06em;
  }

  .toolbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: minmax(0, 1fr);
    justify-content: stretch;
    gap: var(--space-2);
  }

  .toolbar-actions > * {
    width: 100%;
    min-width: 0;
  }

  .toolbar-actions > select,
  .toolbar-actions > input,
  .toolbar-actions > button {
    width: 100%;
    min-width: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
  }

  .stats-grid .stat-card strong {
    font-size: 23px;
  }

  .dashboard-modules {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .settings-form,
  .modal-form,
  .inline-form,
  .inventory-controls {
    grid-template-columns: 1fr;
  }

  .card-grid,
  .inventory-group-grid {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .entity-card {
    padding: var(--space-3);
  }

  .entity-card h4 {
    font-size: 17px;
  }

  .panel {
    padding: var(--space-4);
  }

  .meta-row {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .modal {
    padding: var(--space-3);
  }

  .modal-card {
    max-height: calc(100vh - 24px);
    padding: var(--space-4);
  }

  .modal-head {
    position: static;
    top: auto;
    z-index: auto;
    margin: 0 0 var(--space-3);
    padding: 0;
    border-bottom: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .mobile-tabbar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 28;
    height: var(--mobile-nav-h);
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 244, 247, 0.96) 100%);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
  }

  .mobile-tabbar button {
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-width: 0;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease;
  }

  .mobile-tabbar button i {
    font-size: 17px;
    line-height: 1;
  }

  .mobile-tabbar button span {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
  }

  .mobile-tabbar button.active {
    background: linear-gradient(180deg, rgba(var(--accent-rgb), 0.24) 0%, rgba(var(--accent-rgb), 0.14) 100%);
    color: #7a3340;
  }

  .mobile-sheet {
    position: fixed;
    inset: 0;
    z-index: 32;
    display: grid;
    align-items: end;
    background: rgba(16, 20, 32, 0.42);
    padding: 16px 12px calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 10px);
  }

  .mobile-sheet.hidden {
    display: none;
  }

  .mobile-sheet-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-md);
    padding: 14px;
    display: grid;
    gap: 8px;
  }

  .mobile-sheet-card h4 {
    margin: 0 0 2px;
    font-size: 15px;
  }

  .mobile-sheet-card button {
    border: 1px solid var(--line);
    border-radius: 10px;
    min-height: 40px;
    background: #fff;
    text-align: left;
    padding: 0 12px;
    font-weight: 700;
    cursor: pointer;
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

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

  .toolbar-actions {
    grid-template-columns: 1fr;
  }

  .mobile-tabbar {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    left: 8px;
    right: 8px;
    padding: 6px;
  }

  .mobile-tabbar button span {
    font-size: 9px;
  }

  .mobile-sheet {
    padding-left: 8px;
    padding-right: 8px;
  }
}
