:root {
  --bg: #eef2f6;
  --bg-soft: #f7f9fc;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-raised: #fbfcfe;
  --ink: #17202a;
  --muted: #647184;
  --muted-strong: #485568;
  --line: #dce3ec;
  --line-strong: #c8d2df;
  --accent: #9f4d45;
  --accent-dark: #76352f;
  --accent-soft: #fff0ed;
  --blue: #315e9d;
  --blue-soft: #e8f0fb;
  --success: #247457;
  --success-soft: #e7f4ed;
  --danger: #ad3e3e;
  --danger-soft: #fde8e8;
  --warning: #9a5d12;
  --warning-soft: #fff3d6;
  --shadow: 0 16px 42px rgba(28, 35, 45, 0.08);
  --shadow-soft: 0 8px 24px rgba(28, 35, 45, 0.06);
  --radius: 8px;
}

.category-help {
  margin: 18px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.product-category-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 100px 120px auto auto;
  align-items: end;
  gap: 10px;
}

.product-category-form button {
  min-height: 42px;
  white-space: nowrap;
}

.product-category-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.product-category-card {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.product-category-card.is-category-hidden {
  opacity: 0.66;
}

.category-order {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  min-width: 36px;
  height: 28px;
  border-radius: 999px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 12px;
  font-weight: 800;
}

.category-card-main {
  min-width: 0;
}

.category-card-main strong,
.category-card-main span {
  display: block;
}

.category-card-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-card-main span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.category-card-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.category-card-actions button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 12px;
}

.category-card-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: 0 0 0 3px rgba(173, 62, 62, 0.1);
}

.product-list-panel {
  min-height: 360px;
}

.product-list-head {
  align-items: flex-start;
}

.panel-title-group,
.product-list-tools,
.product-primary-actions,
.editor-footer,
.editor-footer-actions {
  display: flex;
  align-items: center;
}

.panel-title-group {
  gap: 10px;
}

.record-count {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 12px;
  font-weight: 800;
}

.product-list-tools {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.product-primary-actions,
.editor-footer-actions {
  gap: 8px;
}

.compact-action {
  min-height: 38px;
  padding: 0 15px;
}

.product-list-message:empty {
  display: none;
}

.modal-panel.product-editor-panel {
  width: min(980px, 100%);
  padding-bottom: 0;
}

.modal-panel.category-editor-panel {
  width: min(880px, 100%);
}

.editor-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
}

.product-editor-form {
  gap: 0;
  margin-top: 0;
}

.editor-section {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 22px;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.editor-section-head h3 {
  font-size: 15px;
}

.editor-section-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.product-basics-grid,
.description-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-span-2 {
  grid-column: span 2;
}

.product-media-editor {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.cover-editor,
.product-media-editor .gallery-editor {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.cover-editor .cover-preview {
  width: 100%;
  max-width: 220px;
}

.editor-footer {
  justify-content: space-between;
  gap: 16px;
  margin: 0 -18px;
  padding: 14px 18px;
  background: var(--surface-raised);
  box-shadow: 0 -1px 0 var(--line);
}

.editor-footer .message {
  flex: 1;
}

.form-submit {
  min-height: 42px;
  color: #fff;
  background: #273545;
  border-color: #273545;
  box-shadow: 0 8px 18px rgba(39, 53, 69, 0.14);
}

.form-submit:hover {
  background: #17202a;
  border-color: #17202a;
  box-shadow: 0 10px 22px rgba(23, 32, 42, 0.18);
}

@media (max-width: 980px) {
  .product-category-form {
    grid-template-columns: minmax(0, 1fr) 100px 120px;
  }

  .editor-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

@media (max-width: 640px) {
  .product-category-form,
  .product-category-list,
  .product-basics-grid,
  .description-grid,
  .product-media-editor {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(238, 242, 246, 0) 320px),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

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

button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 13px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

button:hover {
  background: var(--accent-dark);
  box-shadow: 0 8px 18px rgba(118, 53, 47, 0.14);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button:focus-visible {
  outline: 3px solid rgba(49, 94, 157, 0.18);
  outline-offset: 2px;
}

.shell {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 56px;
}

.is-hidden {
  display: none !important;
}

.login-view {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.login-panel,
.panel,
.modal-panel,
.stat-card,
.entry-card,
.module-hero,
.module-nav {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.login-panel {
  width: min(420px, 100%);
  padding: 30px;
}

.login-logo {
  width: 68px;
  height: 68px;
  margin-bottom: 18px;
  border-radius: 50%;
  object-fit: cover;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.4;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: #394150;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(159, 77, 69, 0.13);
}

.message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.message.is-error {
  color: var(--danger);
}

.message.is-success {
  color: var(--success);
}

.login-form,
.entity-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.admin-view {
  display: grid;
  gap: 14px;
}

body.modal-open {
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px;
  border: 1px solid rgba(220, 227, 236, 0.82);
  border-radius: var(--radius);
  background: rgba(247, 249, 252, 0.9);
  backdrop-filter: blur(16px);
}

.brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--line);
}

.admin-account {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.secondary-btn,
.ghost-btn,
.chip,
.nav-btn {
  color: var(--muted-strong);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(23, 32, 42, 0.02);
}

.secondary-btn:hover,
.ghost-btn:hover,
.chip:hover,
.nav-btn:hover {
  color: var(--ink);
  background: var(--bg-soft);
  border-color: var(--line-strong);
  box-shadow: 0 8px 16px rgba(28, 35, 45, 0.06);
}

.ghost-btn.is-active,
.nav-btn.is-active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: rgba(159, 77, 69, 0.28);
  box-shadow: inset 0 0 0 1px rgba(159, 77, 69, 0.08);
}

.module-nav {
  position: sticky;
  top: 90px;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
}

.nav-btn {
  position: relative;
  min-height: 56px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 3px;
  overflow: hidden;
  padding: 8px 12px 8px 14px;
  text-align: left;
}

.nav-btn.is-active::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 7px;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.nav-btn span {
  color: inherit;
  opacity: 0.72;
  font-size: 12px;
}

.nav-btn strong {
  font-size: 15px;
}

.module {
  display: none;
}

.module.is-active {
  display: grid;
  gap: 14px;
}

.module-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 104px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(232, 240, 251, 0.78)),
    var(--surface);
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-balance {
  min-width: 160px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  text-align: right;
}

.hero-balance span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.hero-balance strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.hero-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.primary-action {
  min-height: 48px;
  padding: 0 18px;
  background: #273545;
  border-color: #273545;
  box-shadow: 0 8px 18px rgba(39, 53, 69, 0.14);
}

.primary-action:hover {
  background: #17202a;
  border-color: #17202a;
  box-shadow: 0 10px 22px rgba(23, 32, 42, 0.18);
}

.primary-action.compact-action {
  min-height: 38px;
  padding: 0 15px;
}

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

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--blue);
}

.stat-card:nth-child(2)::before {
  background: var(--accent);
}

.stat-card:nth-child(3)::before {
  background: var(--warning);
}

.stat-card:nth-child(4)::before {
  background: var(--success);
}

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

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

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

.entry-card {
  min-height: 148px;
  display: grid;
  align-content: end;
  padding: 18px;
  color: var(--ink);
  text-align: left;
}

.entry-card:hover {
  background: #fff;
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.entry-card span,
.entry-card strong {
  display: block;
}

.entry-card span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.entry-card strong {
  margin-top: 8px;
  font-size: 20px;
  line-height: 1.25;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(360px, 0.86fr) minmax(480px, 1.14fr);
  gap: 14px;
  align-items: start;
}

.ledger-layout {
  grid-template-columns: 1fr;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.upload-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.file-picker input {
  padding: 8px;
}

.cover-preview {
  width: 160px;
  aspect-ratio: 4 / 5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-soft);
}

.gallery-editor {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.gallery-preview {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 0 6px;
}

.gallery-preview img {
  width: 82px;
  aspect-ratio: 4 / 5;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--surface-soft);
}

.filter-row,
.panel-actions,
.item-actions,
.lead-actions,
.ledger-total {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-row {
  justify-content: flex-end;
}

.panel-actions {
  justify-content: flex-end;
}

.chip {
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.chip.is-active {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: rgba(49, 94, 157, 0.24);
  box-shadow: inset 0 0 0 1px rgba(49, 94, 157, 0.05);
}

.login-form > button[type="submit"],
.entity-form > button[type="submit"] {
  min-height: 42px;
  justify-self: stretch;
  color: #fff;
  background: #273545;
  border-color: #273545;
  box-shadow: 0 8px 18px rgba(39, 53, 69, 0.14);
}

.login-form > button[type="submit"]:hover,
.entity-form > button[type="submit"]:hover {
  background: #17202a;
  border-color: #17202a;
  box-shadow: 0 10px 22px rgba(23, 32, 42, 0.18);
}

.export-btn {
  min-height: 32px;
  color: var(--blue);
  background: var(--blue-soft);
  border: 1px solid rgba(49, 94, 157, 0.24);
  font-size: 12px;
  box-shadow: inset 0 0 0 1px rgba(49, 94, 157, 0.05);
}

.export-btn:hover {
  color: #244977;
  background: #dce9f8;
  border-color: rgba(49, 94, 157, 0.34);
}

.export-btn:disabled {
  color: var(--muted);
  background: var(--bg-soft);
  border-color: var(--line);
  box-shadow: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 42, 0.38);
  backdrop-filter: blur(6px);
}

.modal-panel {
  width: min(540px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  padding: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(23, 32, 42, 0.22);
}

.modal-head {
  position: sticky;
  top: -18px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -18px -18px 0;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  min-width: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.item-list,
.lead-list {
  display: grid;
  gap: 10px;
}

.item-card,
.lead-card {
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 1px 0 rgba(23, 32, 42, 0.02);
}

.item-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.media-card {
  grid-template-columns: 72px minmax(0, 1fr) auto;
}

.ledger-card {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.lead-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.item-thumb {
  width: 72px;
  aspect-ratio: 4 / 5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--bg-soft);
}

.item-main,
.lead-main {
  min-width: 0;
}

.item-title-row,
.lead-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 7px;
}

.item-title-row h3,
.lead-main h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.item-meta,
.lead-meta,
.lead-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.lead-note {
  color: var(--muted-strong);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-row span {
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted-strong);
  background: var(--bg-soft);
  font-size: 12px;
  font-weight: 700;
}

.item-value {
  white-space: nowrap;
  font-size: 18px;
}

.item-value.is-income {
  color: var(--success);
}

.item-value.is-expense {
  color: var(--danger);
}

.badge,
.lead-kind,
.lead-status,
.ledger-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge {
  color: #40505e;
  background: var(--bg-soft);
}

.badge.is-online,
.lead-status.is-confirmed {
  color: var(--success);
  background: var(--success-soft);
}

.badge.is-offline {
  color: #7e3b3b;
  background: var(--danger-soft);
}

.lead-kind {
  color: #704239;
  background: var(--accent-soft);
}

.lead-status {
  color: #40505e;
  background: var(--bg-soft);
}

.lead-status.is-pending {
  color: var(--warning);
  background: var(--warning-soft);
}

.lead-status.is-rejected {
  color: var(--danger);
  background: var(--danger-soft);
}

.ledger-status {
  color: var(--blue);
  background: var(--blue-soft);
}

.item-actions,
.lead-actions {
  align-items: flex-start;
  justify-content: flex-end;
}

.item-actions button,
.lead-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.danger-btn {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(173, 62, 62, 0.18);
}

.danger-btn:hover {
  color: #8e3131;
  background: #f9dada;
  border-color: rgba(173, 62, 62, 0.32);
}

.empty {
  padding: 28px 12px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.ledger-total {
  color: var(--muted);
  font-size: 13px;
}

.ledger-total strong {
  color: var(--ink);
}

.ledger-insights {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.insight-toolbar {
  display: grid;
  grid-template-columns: 160px minmax(180px, 1fr);
  gap: 12px;
}

.insight-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.insight-summary span {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.insight-summary strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 17px;
}

.chart-box {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

#ledgerChart {
  display: block;
  width: 100%;
  height: auto;
}

#ledgerChart line {
  stroke: var(--line-strong);
  stroke-width: 1;
}

#ledgerChart text {
  fill: var(--muted);
  font-size: 11px;
}

#ledgerChart polyline {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.amount-line {
  stroke: var(--blue);
}

.quantity-line {
  stroke: var(--accent);
}

.amount-dot {
  fill: var(--blue);
}

.quantity-dot {
  fill: var(--accent);
}

.legend-amount {
  fill: var(--blue) !important;
  font-weight: 800;
}

.legend-quantity {
  fill: var(--accent) !important;
  font-weight: 800;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.category-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-pill {
  min-height: 38px;
  gap: 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
}

.category-pill:hover {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: rgba(49, 94, 157, 0.28);
}

.category-pill span,
.category-pill strong {
  display: inline-block;
}

@media (max-width: 1040px) {
  .stats,
  .entry-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-column,
  .ledger-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }

  button {
    min-height: 44px;
    padding: 0 14px;
  }

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

  textarea {
    min-height: 96px;
    font-size: 16px;
  }

  .shell {
    width: 100%;
    padding: 0 10px calc(96px + env(safe-area-inset-bottom));
  }

  .admin-view {
    gap: 10px;
  }

  .topbar,
  .panel-head,
  .module-hero,
  .lead-card,
  .ledger-card {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-head,
  .module-hero {
    flex-direction: column;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin: 0 -10px;
    padding: 10px;
    border-width: 0 0 1px;
    border-radius: 0;
  }

  .brand {
    min-width: 0;
  }

  .brand img {
    width: 42px;
    height: 42px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .admin-account {
    margin-top: 3px;
    font-size: 12px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions button {
    min-height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }

  .module-nav {
    position: fixed;
    inset: auto 0 0;
    top: auto;
    z-index: 40;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 7px 10px calc(8px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 8px 8px 0 0;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -10px 28px rgba(28, 35, 45, 0.1);
  }

  .nav-btn {
    min-width: 0;
    min-height: 56px;
    justify-items: center;
    padding: 8px 4px 7px;
    border-color: transparent;
    background: transparent;
    text-align: center;
    box-shadow: none;
  }

  .nav-btn.is-active::before {
    top: 6px;
    bottom: auto;
    left: 50%;
    width: 28px;
    height: 3px;
    transform: translateX(-50%);
  }

  .nav-btn span {
    font-size: 11px;
  }

  .nav-btn strong {
    font-size: 14px;
  }

  .module.is-active {
    gap: 10px;
  }

  .module-hero {
    min-height: auto;
    padding: 14px;
  }

  .module-hero h2 {
    font-size: 22px;
  }

  .hero-balance {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }

  .hero-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-action {
    width: 100%;
  }

  .stats,
  .entry-grid,
  .field-grid,
  .upload-row,
  .gallery-editor,
  .insight-toolbar,
  .insight-summary {
    grid-template-columns: 1fr;
  }

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

  .stat-card,
  .entry-card,
  .panel,
  .ledger-insights {
    padding: 14px;
  }

  .entry-card {
    min-height: 112px;
  }

  .two-column,
  .ledger-layout {
    gap: 10px;
  }

  .panel-head {
    gap: 10px;
  }

  .panel-actions {
    width: 100%;
    justify-content: space-between;
  }

  .product-list-tools,
  .product-primary-actions {
    width: 100%;
  }

  .product-list-tools {
    display: grid;
    justify-content: stretch;
  }

  .product-list-tools .filter-row {
    justify-content: flex-start;
  }

  .product-primary-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .product-primary-actions button {
    width: 100%;
  }

  .product-editor-panel,
  .category-editor-panel {
    width: 100%;
    max-height: calc(100dvh - 20px);
  }

  .editor-section {
    padding: 16px 0;
  }

  .editor-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-footer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .editor-footer-actions button {
    width: 100%;
  }

  .ledger-total {
    gap: 10px;
  }

  .entity-form {
    gap: 12px;
  }

  .media-card {
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: start;
  }

  .item-thumb {
    width: 72px;
    max-height: none;
    aspect-ratio: 4 / 5;
  }

  .media-card .item-actions {
    grid-column: 1 / -1;
  }

  .ledger-card {
    gap: 10px;
  }

  .item-value {
    justify-self: start;
    font-size: 20px;
  }

  .item-actions,
  .lead-actions,
  .filter-row,
  .panel-actions,
  .topbar-actions {
    justify-content: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .item-actions,
  .lead-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  }

  .item-actions button,
  .lead-actions button,
  .chip,
  .export-btn {
    min-height: 40px;
  }

  .lead-card {
    gap: 12px;
  }

  .lead-top {
    gap: 6px;
  }

  .chart-box {
    min-height: 214px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #ledgerChart {
    width: 680px;
    max-width: none;
    height: 246px;
  }

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

  .category-pill {
    justify-content: space-between;
  }

  .modal-backdrop {
    align-items: end;
    place-items: end center;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - 20px);
    padding: 14px;
    border-radius: 8px 8px 0 0;
  }

  .modal-head {
    top: -14px;
    margin: -14px -14px 0;
    padding: 14px;
  }

  .modal-actions {
    flex-shrink: 0;
  }
}
