:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #647082;
  --line: #dce4eb;
  --panel: #ffffff;
  --page: #f4f7f8;
  --blue: #0e72a6;
  --cyan: #21a7bd;
  --green: #5c9a42;
  --coral: #e85d4f;
  --yellow: #f5b83d;
  --shadow: 0 18px 42px rgba(22, 45, 65, 0.13);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(33, 167, 189, 0.08), transparent 260px),
    var(--page);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

body.auth-required .sidebar,
body.auth-required .catalog-main,
body.auth-required .cart-drawer,
body.auth-required .modal-backdrop {
  display: none;
}

body.auth-required .app-shell {
  display: block;
  min-height: 100vh;
  background: var(--page);
}

body.auth-required .account-drawer,
body.auth-required .account-drawer[aria-hidden="false"] {
  inset: 50% auto auto 50%;
  display: grid;
  width: min(460px, calc(100vw - 32px));
  height: auto;
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  transform: translate(-50%, -50%);
}

body.auth-required #closeAccount {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  overflow: auto;
  padding: 18px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand-panel {
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff, #eef8fa);
}

.brand-logo {
  display: block;
  width: 150px;
  max-width: 100%;
  height: 76px;
  object-fit: contain;
  object-position: left center;
  margin-bottom: 16px;
}

.eyebrow {
  display: block;
  color: var(--blue);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 8px;
  font-size: 1.9rem;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.3;
  letter-spacing: 0;
}

.brand-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.search-box,
.select-box,
.filter-block {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.search-box span,
.select-box span,
.filter-block > span,
.client-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(33, 167, 189, 0.18);
}

.family-list {
  display: grid;
  gap: 8px;
}

.family-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 52px;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
}

.family-button img,
.family-initial {
  width: 42px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  background: #f5f8fa;
}

.family-initial {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--blue);
  font-weight: 900;
}

.family-button span {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.family-button strong {
  color: var(--muted);
  font-size: 0.84rem;
}

.family-button.is-active,
.family-button:hover {
  border-color: var(--cyan);
  background: #eefbfc;
}

.catalog-main {
  height: 100vh;
  min-width: 0;
  overflow: auto;
  padding: 0 22px 22px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -22px 18px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(220, 228, 235, 0.85);
  background: var(--page);
  box-shadow: 0 10px 24px rgba(22, 45, 65, 0.08);
}

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

.view-toggle {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.view-button,
.secondary-button,
.cart-button,
.primary-button,
.text-button,
.mini-button,
.icon-button,
.add-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.view-button {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
}

.view-button.is-active {
  color: #ffffff;
  background: var(--blue);
}

.secondary-button {
  color: var(--blue);
  background: #ffffff;
  border-color: var(--line);
  text-decoration: none;
  display: inline-grid;
  place-items: center;
}

.cart-button,
.primary-button,
.add-button {
  color: #ffffff;
  background: var(--coral);
}

.cart-button span {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  margin-left: 6px;
  border-radius: 999px;
  color: var(--coral);
  background: #ffffff;
}

.account-button.is-signed-in {
  border-color: rgba(33, 167, 189, 0.35);
  color: var(--blue);
  background: #eefbfc;
}

.family-overview {
  margin-bottom: 18px;
}

.family-overview[hidden] {
  display: none;
}

.family-overview-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(156px, 188px);
  gap: 12px;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 8px;
}

.family-tile {
  display: grid;
  grid-template-rows: 62px auto auto;
  gap: 6px;
  min-height: 136px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
  box-shadow: 0 8px 22px rgba(21, 44, 57, 0.07);
}

.family-tile img {
  width: 100%;
  height: 60px;
  object-fit: contain;
}

.family-tile span {
  font-weight: 900;
}

.family-tile.is-active,
.family-tile:hover {
  border-color: var(--yellow);
  background: #fffaf0;
}

.line-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  min-width: 0;
  padding-bottom: 44px;
}

.line-card {
  display: grid;
  grid-template-rows: 92px auto auto;
  gap: 8px;
  min-height: 172px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
  box-shadow: 0 12px 28px rgba(22, 45, 65, 0.08);
}

.line-card img {
  width: 100%;
  height: 88px;
  object-fit: contain;
  background: #ffffff;
}

.line-card span {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 900;
}

.line-card strong {
  color: var(--muted);
  font-size: 0.9rem;
}

.line-card:hover,
.line-card:focus-visible {
  border-color: var(--cyan);
  box-shadow: 0 18px 40px rgba(22, 45, 65, 0.13);
  outline: none;
}

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

.result-header div {
  display: grid;
  gap: 3px;
}

.result-header span {
  color: var(--muted);
}

.text-button {
  min-height: 34px;
  padding: 0;
  color: var(--blue);
  background: transparent;
}

.text-button.danger {
  color: #b23029;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: 14px;
  min-width: 0;
  padding-bottom: 18px;
}

.load-more-wrap {
  display: grid;
  place-items: center;
  padding: 4px 0 44px;
}

.load-more-wrap[hidden] {
  display: none;
}

.load-more-wrap .secondary-button {
  min-width: min(280px, 100%);
}

.product-card {
  display: grid;
  grid-template-rows: 180px 1fr auto;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(22, 45, 65, 0.08);
}

.product-image {
  display: grid;
  place-items: center;
  min-width: 0;
  background: #ffffff;
}

.product-image img {
  width: 100%;
  height: 170px;
  object-fit: contain;
  padding: 14px;
}

.product-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.product-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.product-kicker span {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  color: #0c5a74;
  background: #e8f7f9;
  font-size: 0.72rem;
  font-weight: 900;
}

.product-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.product-meta div {
  min-width: 0;
}

.product-meta dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.product-meta dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.product-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.product-actions strong {
  font-size: 1.02rem;
}

.add-button {
  min-width: 104px;
}

.products-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.products-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

.products-table th,
.products-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.products-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fbfc;
  font-size: 0.74rem;
  text-transform: uppercase;
}

.products-table td strong,
.products-table td span {
  display: block;
}

.products-table td span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.table-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.table-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.mini-button,
.icon-button {
  width: 38px;
  padding: 0;
  color: var(--blue);
  background: #ffffff;
  border-color: var(--line);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  text-align: center;
}

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

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(430px, 100vw);
  height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 180ms ease;
}

.cart-drawer[aria-hidden="false"] {
  transform: translateX(0);
}

.account-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 12;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(460px, 100vw);
  height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 180ms ease;
}

.account-drawer[aria-hidden="false"] {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-body {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 16px;
  padding-top: 16px;
}

.account-header {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
}

.auth-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
}

.auth-loading[hidden] {
  display: none;
}

.auth-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #d8e6ec;
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: auth-spin 800ms linear infinite;
}

@keyframes auth-spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-fields {
  display: grid;
  gap: 12px;
}

body.auth-checking .auth-fields {
  display: none;
}

.auth-mode-panel {
  display: none;
  gap: 12px;
}

#signInForm {
  display: grid;
}

.auth-fields[data-mode="creating"] #signInForm,
.auth-fields[data-mode="forgot"] #signInForm,
.auth-fields[data-mode="new-password"] #signInForm {
  display: none;
}

.auth-fields[data-mode="creating"] #createAccountForm,
.auth-fields[data-mode="forgot"] #forgotPasswordForm,
.auth-fields[data-mode="new-password"] #newPasswordForm {
  display: grid;
}

.auth-fields label,
.client-field {
  display: grid;
  gap: 8px;
}

.auth-fields label span,
.client-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-message {
  margin: 0;
  color: var(--blue);
  font-weight: 800;
}

.auth-message:empty {
  display: none;
}

.customer-orders,
.customer-order-detail,
.customer-order-items {
  display: grid;
  gap: 10px;
}

.customer-order-line,
.customer-order-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfdfe;
  text-align: left;
}

.customer-order-line span,
.customer-order-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.customer-order-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.client-field {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.cart-items {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.cart-empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
}

.cart-item span,
.cart-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.qty-controls {
  display: grid;
  grid-template-columns: 32px minmax(44px, auto) 32px 32px;
  align-items: center;
  gap: 4px;
}

.qty-controls button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 900;
}

.qty-controls span {
  min-width: 44px;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

.cart-footer {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 900;
}

.total-row span {
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 33, 47, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.add-modal {
  display: grid;
  gap: 16px;
  width: min(520px, 100%);
  max-height: min(720px, 92vh);
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal-header,
.modal-actions,
.modal-product,
.modal-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-header h2 {
  margin-top: 3px;
  font-size: 1.15rem;
  line-height: 1.25;
}

.modal-product {
  align-items: stretch;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
}

.modal-product img {
  width: 130px;
  height: 118px;
  object-fit: contain;
  background: #ffffff;
}

.modal-product dl,
.modal-product div,
.modal-summary div,
.bulk-picker {
  min-width: 0;
}

.modal-product dl {
  display: grid;
  align-content: center;
  gap: 10px;
  flex: 1;
  margin: 0;
}

.modal-product dt,
.bulk-picker > span,
.modal-summary span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.modal-product dd {
  margin: 2px 0 0;
  font-weight: 900;
}

.bulk-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.bulk-stepper {
  display: inline-grid;
  grid-template-columns: 42px 64px 42px;
  align-items: center;
  gap: 6px;
}

.bulk-stepper button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 1.2rem;
  font-weight: 900;
}

.bulk-stepper button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.bulk-stepper strong {
  text-align: center;
  font-size: 1.2rem;
}

.modal-summary {
  padding: 14px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
}

.modal-summary div {
  display: grid;
  gap: 4px;
}

.modal-summary span {
  color: rgba(255, 255, 255, 0.72);
}

.modal-summary strong {
  font-size: 1.12rem;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  padding: 12px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

  .app-shell > * {
    min-width: 0;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .family-list {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }

  .catalog-main {
    height: auto;
    overflow: visible;
  }

  .topbar {
    position: relative;
  }
}

@media (max-width: 640px) {
  .sidebar,
  .catalog-main {
    padding: 14px;
  }

  .catalog-main {
    padding-top: 0;
  }

  .topbar {
    margin: 0 -14px 14px;
    padding: 14px;
  }

  .topbar,
  .result-header,
  .product-actions,
  .modal-actions,
  .modal-product,
  .bulk-picker {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-product img {
    width: 100%;
  }

  .family-list {
    grid-auto-columns: minmax(172px, 210px);
    grid-auto-flow: column;
    grid-template-columns: none;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 120px;
    min-width: 0;
  }

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

  .product-card {
    grid-template-rows: 156px 1fr auto;
  }

  .cart-drawer,
  .account-drawer {
    width: 100vw;
  }
}
