:root {
  color-scheme: light;
  --navy: #132238;
  --navy-2: #1b2f4b;
  --ink: #172033;
  --muted: #697386;
  --line: #e2e7ef;
  --paper: #ffffff;
  --canvas: #f4f6f9;
  --orange: #ff6b35;
  --orange-soft: #fff0e9;
  --blue: #3974e9;
  --blue-soft: #edf3ff;
  --teal: #159a8c;
  --teal-soft: #e9f8f5;
  --danger: #c8473d;
  --shadow: 0 8px 30px rgba(24, 39, 66, 0.07);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--canvas);
  color: var(--ink);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(57, 116, 233, 0.35);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 238px;
  flex-direction: column;
  padding: 28px 20px;
  color: white;
  background: var(--navy);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  color: var(--navy);
  background: var(--orange);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.28);
}
.brand strong, .brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: #9eacc0; font-size: 0.75rem; }
.side-nav { display: grid; gap: 6px; margin-top: 52px; }
.side-link {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 12px;
  padding: 0 13px;
  border-radius: 11px;
  color: #b7c2d2;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 650;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.side-link:hover { color: white; transform: translateX(2px); }
.side-link.active { color: white; background: var(--navy-2); }
.side-link.active::after {
  width: 4px;
  height: 22px;
  margin-left: auto;
  border-radius: 4px;
  background: var(--orange);
  content: "";
}
.nav-icon { display: grid; width: 22px; place-items: center; font-size: 1.15rem; }
.sidebar-foot {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  padding: 14px 12px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-top: 5px;
  border-radius: 50%;
  background: #39d0a1;
  box-shadow: 0 0 0 4px rgba(57, 208, 161, 0.12);
}
.sidebar-foot strong { font-size: 0.78rem; }
.sidebar-foot small { margin-top: 4px; color: #8998ad; font-size: 0.69rem; line-height: 1.35; }

main { width: calc(100% - 238px); margin-left: 238px; padding: 34px clamp(24px, 3vw, 48px) 72px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.eyebrow {
  margin: 0 0 6px;
  color: #7c8798;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.65rem, 3vw, 2.2rem); letter-spacing: -0.045em; line-height: 1.1; }
h2 { margin-bottom: 0; font-size: 1.24rem; letter-spacing: -0.025em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-state {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  background: white;
  font-size: 0.8rem;
  font-weight: 650;
}
.sync-state .status-dot { margin-top: 0; }
.mobile-menu { display: none; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  position: relative;
  min-height: 138px;
  padding: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 3px 16px rgba(24,39,66,0.035);
}
.stat-card::before { position: absolute; inset: 0 auto 0 0; width: 4px; content: ""; background: var(--card-accent); }
.stat-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.stat-glyph { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; color: var(--card-accent); background: var(--card-soft); font-weight: 900; }
.stat-card > strong { display: block; margin-top: 14px; font-size: clamp(1.5rem, 2.8vw, 1.95rem); letter-spacing: -0.05em; line-height: 1; }
.stat-card > small { display: block; margin-top: 7px; color: #8992a2; font-size: 0.73rem; }
.accent-blue { --card-accent: var(--blue); --card-soft: var(--blue-soft); }
.accent-orange { --card-accent: var(--orange); --card-soft: var(--orange-soft); }
.accent-teal { --card-accent: var(--teal); --card-soft: var(--teal-soft); }
.accent-navy { --card-accent: var(--navy); --card-soft: #edf0f4; }

.panel { border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow); }
.order-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(310px, 0.8fr); gap: 18px; align-items: start; }
.catalog-panel { min-width: 0; padding: 24px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
.keyboard-hint { color: #8b94a2; font-size: 0.74rem; }
.category-tabs {
  display: flex;
  gap: 8px;
  margin: 24px 0 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.category-tab {
  position: relative;
  flex: 0 0 auto;
  padding: 0 4px 14px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  scroll-snap-align: start;
}
.category-tab + .category-tab { margin-left: 18px; }
.category-tab[aria-selected="true"] { color: var(--ink); }
.category-tab[aria-selected="true"]::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--orange); content: ""; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.product-card {
  display: flex;
  min-height: 332px;
  min-width: 0;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fcfdff;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.product-card:hover { transform: translateY(-2px); border-color: #cbd4e2; box-shadow: 0 10px 22px rgba(23,32,51,0.07); }
.product-visual {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  color: #d8e7c6;
  background: linear-gradient(145deg, #09100d, #172119);
  font-weight: 850;
  letter-spacing: 0.08em;
}
.product-visual img { width: 100%; height: 100%; object-fit: cover; }
.product-visual-card { height: 138px; margin: -16px -16px 16px; border-bottom: 1px solid #202a22; }
.product-visual-card.product-visual-placeholder { font-size: 1.25rem; }
.product-visual-cart { width: 46px; height: 46px; border-radius: 10px; font-size: 0.65rem; }
.product-visual-inventory { width: 42px; height: 42px; border-radius: 9px; font-size: 0.6rem; }
.product-visual-history { width: 31px; height: 31px; border: 2px solid white; border-radius: 8px; font-size: 0.52rem; box-shadow: 0 2px 6px rgba(19,34,56,0.14); }
.product-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sku { color: #8791a0; font-size: 0.7rem; font-weight: 750; letter-spacing: 0.08em; }
.stock-pill, .availability {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 0 8px;
  border-radius: 99px;
  color: #23795f;
  background: #eaf8f3;
  font-size: 0.66rem;
  font-weight: 750;
}
.stock-pill.low, .availability.low { color: #9b5c11; background: #fff3df; }
.stock-pill.out, .availability.out { color: var(--danger); background: #fdeeed; }
.product-card h3 { margin: 18px 0 5px; font-size: 1rem; line-height: 1.32; }
.product-dose { color: var(--muted); font-size: 0.74rem; font-weight: 700; }
.product-price { color: var(--ink); font-size: 1.04rem; font-weight: 800; }
.product-price { margin-top: 6px; }
.product-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: auto; padding-top: 16px; }
.qty-control { display: flex; align-items: center; gap: 4px; }
.qty-button, .add-button, .stock-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
  font-weight: 800;
}
.qty-button { width: 30px; height: 30px; border-radius: 8px; }
.qty-value { min-width: 22px; text-align: center; font-size: 0.84rem; font-weight: 800; }
.add-button { width: 34px; height: 34px; border: 0; border-radius: 9px; color: white; background: var(--navy); font-size: 1.05rem; }
.add-button:hover { background: var(--orange); }
.qty-button:disabled, .add-button:disabled, .stock-button:disabled { cursor: not-allowed; opacity: 0.38; }

.cart-panel {
  position: sticky;
  top: 20px;
  overflow: hidden;
  border-radius: 18px;
  color: white;
  background: var(--navy);
  box-shadow: 0 14px 32px rgba(19,34,56,0.2);
}
.cart-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 24px 24px 18px; }
.cart-head .eyebrow { color: #93a2b7; }
.count-badge { padding: 7px 9px; border-radius: 8px; color: #b9c5d4; background: rgba(255,255,255,0.08); font-size: 0.7rem; font-weight: 750; }
.cart-items { min-height: 168px; max-height: 340px; padding: 0 24px; overflow-y: auto; }
.empty-cart { display: grid; min-height: 158px; place-items: center; border: 1px dashed rgba(255,255,255,0.15); border-radius: 12px; color: #94a2b5; text-align: center; }
.empty-cart strong { display: block; margin-bottom: 5px; color: #c7d0dd; font-size: 0.86rem; }
.empty-cart span { display: block; max-width: 190px; font-size: 0.75rem; line-height: 1.5; }
.cart-item { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 15px 0; border-bottom: 1px solid rgba(255,255,255,0.09); }
.cart-item-name { min-width: 0; font-size: 0.84rem; font-weight: 750; }
.cart-item-name small { display: block; margin-top: 4px; color: #8f9db0; font-weight: 500; }
.cart-item-side { text-align: right; }
.cart-item-side strong { display: block; font-size: 0.84rem; }
.remove-item { margin-top: 5px; padding: 0; border: 0; color: #aeb9c8; background: transparent; font-size: 0.68rem; text-decoration: underline; text-underline-offset: 3px; }
.cart-summary { margin-top: 20px; padding: 20px 24px 24px; background: rgba(0,0,0,0.13); }
.cart-summary > div { display: flex; justify-content: space-between; gap: 10px; font-size: 0.82rem; }
.cart-summary .tax-row { margin-top: 8px; color: #94a2b5; font-size: 0.7rem; }
.cart-summary .total-row { align-items: baseline; margin-top: 18px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 1rem; font-weight: 800; }
.total-row strong { font-size: 1.45rem; letter-spacing: -0.04em; }
.primary-button {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 18px;
  border: 0;
  border-radius: 11px;
  color: white;
  background: var(--orange);
  font-size: 0.84rem;
  font-weight: 800;
  transition: filter 160ms ease, transform 160ms ease;
}
.primary-button:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.42; }
.cart-note { margin: 12px 0 0; color: #8e9caf; font-size: 0.67rem; line-height: 1.4; text-align: center; }

.inventory-section, .history-section { margin-top: 18px; padding: 24px; scroll-margin-top: 24px; }
.inventory-heading { align-items: center; }
.search-box { display: flex; width: min(330px, 100%); min-height: 42px; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; color: #7c8798; background: #fafbfd; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 0.82rem; }
.table-wrap { margin-top: 20px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th { padding: 11px 12px; color: #7b8595; background: #f7f8fa; font-size: 0.69rem; letter-spacing: 0.05em; text-align: left; text-transform: uppercase; }
th:first-child { border-radius: 9px 0 0 9px; }
th:last-child { border-radius: 0 9px 9px 0; text-align: right; }
td { padding: 14px 12px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.product-cell strong, .product-cell small { display: block; }
.product-cell small { margin-top: 3px; color: #8a94a3; font-size: 0.68rem; }
.inventory-product { display: flex; min-width: 220px; align-items: center; gap: 11px; }
.dose-label { color: #4f5d72; font-weight: 750; white-space: nowrap; }
.stock-editor { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.stock-button { width: 31px; height: 31px; border-radius: 8px; }
.stock-input { width: 58px; height: 31px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); text-align: center; font-size: 0.78rem; font-weight: 750; }
.stock-input::-webkit-outer-spin-button, .stock-input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.empty-row { padding: 34px 12px; color: var(--muted); text-align: center; }
.order-history { margin-top: 20px; }
.history-empty { padding: 28px 12px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 0.82rem; text-align: center; }
.history-item { display: grid; grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.7fr) auto; align-items: center; gap: 20px; padding: 15px 6px; border-bottom: 1px solid #edf0f4; }
.history-item:last-child { border-bottom: 0; }
.history-id strong, .history-id small { display: block; }
.history-id strong { font-size: 0.8rem; }
.history-id small, .history-products { margin-top: 3px; color: var(--muted); font-size: 0.72rem; }
.history-products { display: flex; align-items: center; gap: 10px; }
.history-products > span { min-width: 0; }
.history-thumbs { display: flex; flex: 0 0 auto; padding-left: 3px; }
.history-thumbs .product-visual + .product-visual { margin-left: -8px; }
.history-total { font-weight: 850; }

.toast { position: fixed; z-index: 50; top: 24px; right: 24px; max-width: min(390px, calc(100vw - 48px)); padding: 14px 18px; border: 1px solid #ffc5b1; border-radius: 11px; color: #7f3014; background: #fff4ef; box-shadow: var(--shadow); font-size: 0.82rem; font-weight: 650; }
.success-dialog { width: min(420px, calc(100vw - 34px)); padding: 34px; border: 0; border-radius: 20px; color: var(--ink); box-shadow: 0 24px 80px rgba(19,34,56,0.28); text-align: center; }
.success-dialog::backdrop { background: rgba(12,24,40,0.62); backdrop-filter: blur(4px); }
.success-dialog h2 { margin-bottom: 12px; font-size: 1.6rem; }
.success-dialog p:not(.eyebrow) { color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.success-dialog .primary-button { margin-top: 24px; }
.success-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 20px; place-items: center; border-radius: 50%; color: white; background: var(--teal); font-size: 1.4rem; font-weight: 900; box-shadow: 0 8px 20px rgba(21,154,140,0.24); }

@media (max-width: 1120px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-layout { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  .product-grid { grid-template-columns: repeat(3, minmax(160px, 1fr)); overflow-x: auto; }
}

@media (max-width: 760px) {
  .sidebar { width: 78px; padding: 22px 12px; }
  .brand { justify-content: center; }
  .brand > span:last-child, .side-link:not(.active)::after, .side-link { font-size: 0; }
  .side-nav { margin-top: 42px; }
  .side-link { justify-content: center; padding: 0; }
  .nav-icon { font-size: 1.2rem; }
  .sidebar-foot { justify-content: center; padding: 14px 0; }
  .sidebar-foot > span:last-child { display: none; }
  main { width: calc(100% - 78px); margin-left: 78px; padding: 24px 16px 56px; }
  .keyboard-hint { display: none; }
  .inventory-heading { align-items: flex-start; flex-direction: column; }
  .search-box { width: 100%; }
  .history-item { grid-template-columns: 1fr auto; }
  .history-products { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 540px) {
  .sidebar { position: static; width: 100%; height: auto; padding: 12px 16px; flex-direction: row; align-items: center; justify-content: space-between; }
  .brand > span:last-child { display: block; }
  .side-nav { display: flex; margin: 0; }
  .side-link { width: 42px; min-height: 42px; }
  .side-link.active { background: rgba(255,255,255,0.1); }
  .side-link.active::after, .sidebar-foot { display: none; }
  main { width: 100%; margin-left: 0; padding: 22px 14px 50px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { min-height: 122px; padding: 16px; }
  .stat-card > strong { font-size: 1.45rem; }
  .catalog-panel, .inventory-section, .history-section { padding: 18px; }
  .product-grid { grid-template-columns: 1fr; overflow: visible; }
  .product-card { min-height: 360px; }
  .product-visual-card { height: 172px; }
  .category-tabs { gap: 0; justify-content: flex-start; }
  .category-tab + .category-tab { margin-left: 6px; }
  .category-tab { font-size: 0.78rem; }
  .cart-head, .cart-items { padding-right: 18px; padding-left: 18px; }
  .cart-summary { padding: 18px; }
  .sync-state { padding: 0 11px; }
  .sync-state span:last-child { display: none; }
  th:nth-child(2), td:nth-child(2) { display: none; }
  .cart-item { grid-template-columns: 42px minmax(0, 1fr) auto; }
  .product-visual-cart { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
