:root {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-soft: #f9fbff;
  --text: #12253f;
  --text-sub: #5a708a;
  --primary: #0f5f99;
  --primary-strong: #1e83ca;
  --accent: #f59e0b;
  --danger: #dc2626;
  --ok: #16a34a;
  --line: #d9e4f0;
  --radius: 16px;
  --shadow-soft: 0 10px 28px rgba(13, 36, 61, 0.08);
  --shadow: 0 22px 50px rgba(13, 36, 61, 0.12);
}

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

html,
body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: "Nunito", "Manrope", "Figtree", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 0% 0%, #f8fbff 0%, var(--bg) 45%, #dbe6f3 100%);
}

body {
  min-height: 100vh;
}

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

.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 16px 14px 96px;
}

.top-bar {
  padding: 4px 4px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.top-bar-band p {
  margin: 0;
}

.top-bar h1 {
  margin: 6px 0 0;
  font-size: clamp(1.45rem, 3.6vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.eyebrow {
  color: var(--text-sub);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-sub);
  font-size: 0.95rem;
}

.top-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 14px;
  margin-top: 4px;
  color: #1a4d77;
  background: linear-gradient(135deg, #ecf6ff, #cde9ff);
  border: 1px solid #b7d6ef;
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
}

.product-picker {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.product-picker label { font-weight: 700; }
.product-picker select { width: 100%; min-height: 48px; }
.filter-details { margin-bottom: 10px; }
.filter-details summary { cursor: pointer; color: var(--text-sub); }
.filter-details .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 14px 0 0; gap: 10px; }
.filter-details input, .filter-details select { width: 100%; min-width: 0; }
.quick-toggle summary {
  font-weight: 800;
  color: var(--text);
  list-style: none;
  cursor: pointer;
  padding: 2px 0 10px;
  user-select: none;
}

.quick-toggle summary::-webkit-details-marker {
  display: none;
}

.quick-toggle summary::after {
  content: "▾";
  float: right;
  color: var(--text-sub);
  font-weight: 700;
  transform: rotate(0deg);
  transition: transform 0.2s ease;
}

.quick-toggle[open] summary::after {
  transform: rotate(180deg);
}

.quick-toggle .card-head {
  justify-content: flex-start;
  align-items: center;
}

.search-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.search-actions label {
  font-size: 0.82rem;
}

.details summary,
details.card > summary {
  font-weight: 700;
  font-size: 0.95rem;
}

.inventory-search .tiny {
  margin: 0;
  line-height: 1.35;
}

.card > details {
  margin: 0;
}
.picker-empty { text-align: center; color: var(--text-sub); padding: 24px 12px; }
#products-grid .product-card { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#products-grid .product-head,
#products-grid .product-subline,
#products-grid .product-stats,
#products-grid .action-grid { grid-column: 1 / -1; }
#products-grid .product-stat p { margin: 0; }
#products-grid .product-stat .value { margin-top: 5px; }
#products-grid .action-grid { grid-template-columns: repeat(3, 1fr); }
#products-grid .product-card:hover { transform: none; box-shadow: none; }

.stock-list-card { margin-bottom: 12px; padding: 0; overflow: hidden; }
.stock-list th, .stock-list td { padding: 9px 12px; vertical-align: middle; }
.stock-list th:nth-child(2), .stock-list-quantity { text-align: right; white-space: nowrap; }
.stock-list-quantity { font-weight: 750; font-variant-numeric: tabular-nums; }
.stock-list th:last-child, .stock-list td:last-child { width: 65px; color: var(--text-sub); }
.stock-list-product { border: 0; background: none; color: var(--text); padding: 4px 0; text-align: left; cursor: pointer; font-size: 0.84rem; }
.stock-list-product:hover { color: var(--primary); text-decoration: underline; }
.stock-list-product:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.stock-delete { min-width: 44px; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: #9b3131; cursor: pointer; font-size: 0.8rem; }
.stock-delete:hover { background: #fff0f0; }
.stock-delete:focus-visible { outline: 2px solid #9b3131; outline-offset: 2px; }
.delete-product-dialog { width: min(440px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 16px; color: var(--text); box-shadow: var(--shadow); }
.delete-product-dialog::backdrop { background: rgba(9, 29, 48, 0.45); }
.delete-product-dialog h2 { margin: 0 0 16px; font-size: 1.2rem; }
.delete-product-dialog p { line-height: 1.5; }
.delete-product-name { font-weight: 750; }
.delete-confirm { background: #a52e2e; color: #fff; border-color: #a52e2e; }

.inventory-search { display: grid; gap: 8px; margin-bottom: 10px; }
.inventory-search label { font-size: 1.08rem; font-weight: 750; }
.inventory-search input { width: 100%; min-height: 46px; background: #f8fafc; }
.inventory-search p { margin: 0; color: var(--text-sub); font-size: 0.8rem; }
.stock-list .stock-row-selected td { background: #eaf3f8; }
.stock-row-selected .stock-list-product { color: #0f5f99; font-weight: 750; }
.stock-list .stock-empty { padding: 24px 12px; text-align: center; color: var(--text-sub); }

.stock-move { border: 1px solid var(--line); border-radius: 6px; background: white; min-width: 32px; min-height: 44px; cursor: pointer; }
.stock-move:disabled { opacity: 0.3; cursor: default; }
.stock-list td:last-child { white-space: nowrap; }
.carton-equivalent { display: block; font-size: 0.72rem; font-weight: 400; color: var(--text-sub); white-space: normal; }
.carton-fields { border: 1px solid var(--line); border-radius: 10px; margin: 12px 0; padding: 12px; }
.carton-fields legend { font-weight: 700; font-size: 0.9rem; }
.carton-fields p { font-size: 0.85rem; color: var(--primary); }

.alerts {
  min-height: 1.35rem;
}

.alert-card {
  border: 1px solid #f7c2c2;
  background: linear-gradient(120deg, #fff3f2, #ffe9e9);
  color: #7c1d1d;
  border-radius: 12px;
  padding: 12px;
  margin: 6px 0 12px;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.card {
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff 0%, var(--surface) 100%);
  border: 1px solid var(--line);
  padding: 12px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(2px);
}

.stat-card {
  border-left: 4px solid var(--primary);
  background: linear-gradient(165deg, #ffffff 0%, #f6fbff 100%);
}

.stat-title {
  margin: 0;
  font-size: 0.83rem;
  color: var(--text-sub);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  margin: 6px 0 0;
  font-size: 1.32rem;
  font-weight: 800;
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tab-item {
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s ease;
}

.tab-item:hover {
  transform: translateY(-1px);
}

.tab-item.active {
  background: linear-gradient(180deg, var(--primary-strong), var(--primary));
  border-color: var(--primary-strong);
  color: #fff;
  box-shadow: 0 12px 20px rgba(13, 66, 104, 0.24);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

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

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.card-head h3 {
  margin: 0;
}

.btn {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
  text-align: center;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  border: 0;
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
  color: #fff;
}

.btn.btn-primary:hover {
  filter: brightness(1.04);
}

.filters,
.stock-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.filters label,
.modal label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.84rem;
}

.filters {
  margin-bottom: 12px;
}

.filters label select,
.filters label input {
  min-height: 40px;
}

.stock-locations {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.stock-item {
  background: #f6fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.stock-item span {
  font-size: 0.75rem;
  color: var(--text-sub);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 95, 153, 0.22);
  border-color: var(--primary);
}

.products-grid {
  display: grid;
  gap: 10px;
}

.product-card {
  border-radius: var(--radius);
  background: linear-gradient(160deg, #ffffff 0%, #f8fbff 100%);
  border: 1px solid var(--line);
  padding: 12px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.product-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.product-name {
  margin: 0;
  font-size: 1.06rem;
}

.product-subline {
  margin: 4px 0 10px;
  color: var(--text-sub);
  font-size: 0.87rem;
}

.product-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.product-stat {
  background: #f7fbff;
  border: 1px solid #dceafb;
  border-radius: 10px;
  padding: 8px;
}

.product-stat .label {
  color: var(--text-sub);
  font-size: 0.74rem;
}

.product-stat .value {
  margin-top: 2px;
  font-weight: 700;
}

.critical {
  border-left: 4px solid var(--danger);
}

.critical .value {
  color: var(--danger);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tiny {
  font-size: 0.73rem;
  color: #223043;
  margin: 6px 0 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #e5eef7;
  padding: 10px 8px;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  font-size: 0.82rem;
  color: var(--text-sub);
  background: #f8fbff;
}

tr:hover td {
  background: #f8fcff;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.bars .bar-item {
  display: grid;
  grid-template-columns: 78px 1fr 66px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.bars .bar-item strong {
  font-size: 0.86rem;
}

.bar-rail {
  height: 10px;
  background: #e7f1fb;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #1d7bb8, #5ab2d8);
}

.top-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 8px 0;
  border-bottom: 1px dashed #e5edf8;
}

.badge {
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  background: #eaf3fb;
  border: 1px solid #cde0f2;
}

.badge.badge-danger {
  background: #fee6e6;
  border-color: #f4bcbc;
  color: #8d2222;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 12px;
  z-index: 40;
}

.modal.active {
  display: grid;
}

.modal-card {
  width: min(92vw, 540px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.row-toggle {
  display: flex;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
}

.row-toggle input {
  width: auto;
}

.auto-orders {
  margin-bottom: 12px;
}

#auto-orders-list .order-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fbfdff;
}

#auto-orders-list .order-item p {
  margin: 0 0 6px;
}

#auto-orders-list .order-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.muted {
  color: var(--text-sub);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 29, 48, 0.42);
  z-index: 35;
}

.modal-backdrop.active {
  display: block;
}

textarea {
  min-height: 86px;
}

/* Compact inventory workspace. */
.unit-choice-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.unit-choice-buttons .btn { min-height: 48px; font-size: 1rem; }
.unit-choice-buttons [aria-pressed="true"] { background: #0f5f99; color: #fff; border-color: #0f5f99; box-shadow: inset 0 0 0 2px #fff; }
.stock-unit-edit { border: 1px solid #b9d1e2; border-radius: 8px; background: #edf5fa; color: #164d73; min-width: 56px; min-height: 44px; padding: 4px 8px; cursor: pointer; font: inherit; font-weight: 700; white-space: nowrap; }
.stock-unit-edit:focus-visible, .unit-choice-buttons .btn:focus-visible { outline: 3px solid #0f5f99; outline-offset: 2px; }
.unit-change-note { border-left: 3px solid #0f5f99; background: #edf5fa; padding: 12px; font-size: 0.85rem; line-height: 1.6; }
.movement-unit-info { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.movement-unit-info strong { color: #164d73; }
#products-grid .action-grid [data-action="edit"] { grid-column: 1 / -1; }
@media (max-width: 480px) { .unit-choice-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#summary-cards { display: none !important; }
.product-unit-picker { padding: 14px; background: #edf5fa; border: 1px solid #9cbdd5; border-radius: 12px; }
.product-unit-picker > span { font-weight: 700; }
.product-unit-picker small { display: block; line-height: 1.5; }
#product-carton-fields[hidden] { display: none !important; }
#product-form input:disabled { opacity: 0.55; }
body { background: #f4f6f8; }
.app-shell { max-width: 1000px; padding-bottom: 36px; }
.top-bar { align-items: center; padding-bottom: 16px; }
.top-bar h1 { font-size: clamp(1.35rem, 3vw, 1.8rem); }
.top-pill, .eyebrow { display: none; }
.card { background: #fff; box-shadow: none; backdrop-filter: none; border-radius: 12px; }
.stat-title { font-size: 0.7rem; letter-spacing: 0; text-transform: none; }
.stat-value { font-size: 1.2rem; }
.tab-item.active { background: #0f5f99; box-shadow: none; }
.btn-primary { background: #0f5f99; }
.btn, .tab-item { min-height: 44px; }
.btn:hover, .tab-item:hover { transform: none; }
.stock-list th { background: #edf2f6; font-size: 0.74rem; }
.stock-list tbody tr:nth-child(even) { background: #fafbfd; }
.stock-list-product { min-height: 36px; width: 100%; }
.stock-list td { padding-top: 3px; padding-bottom: 3px; }
.stock-list td.stock-list-quantity { font-size: 1rem; color: var(--text); }
.product-card.critical { border-left: 1px solid var(--line); }
.product-card.critical .value { color: var(--text); }
.modal-card { max-height: 90dvh; overflow-y: auto; }
@media (max-width: 480px) {
  .stock-list th, .stock-list td { padding-left: 8px; padding-right: 8px; }
  .stock-list-product { font-size: 0.78rem; min-height: 44px; }
  .stock-list th:nth-child(2) { white-space: normal; }
  input, select, textarea { font-size: 16px; }
}

@media (min-width: 700px) {
  .filters,
  .actions-grid,
  .product-stats,
  .report-grid,
  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  #settings .actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .tab-bar {
    max-width: 420px;
  }
}

@media (min-width: 980px) {
  .filters {
    grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr;
  }

  .actions-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  #settings .actions-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tab-bar {
    max-width: 500px;
  }

  .product-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}
