:root {
  --bg: #edf2f7;
  --bg-soft: #f8fafc;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(148, 163, 184, 0.18);
  --line-strong: rgba(148, 163, 184, 0.28);
  --primary: #0f172a;
  --primary-2: #1e293b;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fff7ed;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 18px 45px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 30px 70px rgba(15, 23, 42, 0.14);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.95), rgba(255,255,255,0) 28%),
    radial-gradient(circle at top right, rgba(203,213,225,.45), rgba(203,213,225,0) 25%),
    linear-gradient(180deg, #f8fafc 0%, #edf2f7 100%);
}

button,
input,
select {
  font: inherit;
}

.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px;
}

/* HERO */
.hero {
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
  padding: 28px;
  border-radius: 34px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 45%, #334155 100%);
  color: #fff;
  box-shadow: var(--shadow-lg);
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  pointer-events: none;
}

.hero::before {
  top: -72px;
  right: -30px;
  width: 240px;
  height: 240px;
}

.hero::after {
  bottom: -80px;
  left: 58%;
  width: 180px;
  height: 180px;
}

.hero-top {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(226,232,240,0.94);
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
  letter-spacing: -0.04em;
}

.hero p {
  max-width: 760px;
  margin: 12px 0 0;
  font-size: 15px;
  line-height: 1.6;
  color: rgba(226,232,240,0.94);
}

.hero-badges {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: white;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(10px);
}

/* LAYOUT */
.grid-stats,
.grid-main,
.manage-grid {
  display: grid;
  gap: 18px;
}

.grid-stats {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 18px;
}

.grid-main {
  grid-template-columns: minmax(0, 1.18fr) minmax(340px, 0.82fr);
}

.manage-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  align-items: start;
}

/* CARD */
.card {
  margin-bottom: 18px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.card-header {
  padding: 22px 22px 0;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.card-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.card-content {
  padding: 22px;
}

.space-y > * + * {
  margin-top: 14px;
}

/* STATS */
.stats-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.stats-card__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px;
}

.stats-card__label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.stats-card__value {
  margin-top: 6px;
  font-size: clamp(24px, 2.4vw, 32px);
  font-weight: 900;
  letter-spacing: -0.04em;
}

.stats-card__icon {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

/* HIGHLIGHTS */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.highlight-card {
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: 0 4px 12px rgba(15,23,42,0.02);
}

.highlight-card__label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.highlight-card__value {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.highlight-card__sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

/* TABS */
.tabs {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 8px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-sm);
}

.tab-btn,
.btn,
.icon-btn {
  appearance: none;
  transition: 0.18s ease;
  cursor: pointer;
}

.tab-btn,
.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.01em;
  box-shadow: 0 2px 8px rgba(15,23,42,0.03);
}

.tab-btn:hover,
.btn:hover,
.icon-btn:hover,
.product-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15,23,42,0.08);
}

.tab-btn.active,
.btn.primary,
.btn.filter-active {
  color: white;
  border-color: #111827;
  background: linear-gradient(135deg, #0f172a 0%, #1f2937 100%);
}

.btn.ghost {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.full-btn {
  width: 100%;
}

.btn:disabled,
.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* SECTIONS */
.section {
  display: none;
}

.section.active {
  display: block;
}

/* FORM ELEMENTS */
.search,
.select,
.input,
.qty-input,
.number-box,
.stepper__input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 15px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.96);
  color: var(--text);
  outline: none;
  font-size: 14px;
  font-weight: 600;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search:focus,
.select:focus,
.input:focus,
.qty-input:focus,
.number-box:focus,
.stepper__input:focus {
  border-color: rgba(51, 65, 85, 0.42);
  box-shadow: 0 0 0 4px rgba(148,163,184,0.14);
}

.sort-select {
  max-width: 240px;
}

/* QUICK SALE SCROLL AREA */
#sales .card-content {
  display: flex;
  flex-direction: column;
}

#salesProductGrid {
  max-height: 560px;
  overflow-y: auto;
  padding-right: 6px;
  align-content: start;
}

#salesProductGrid::-webkit-scrollbar {
  width: 8px;
}

#salesProductGrid::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 999px;
}

#salesProductGrid::-webkit-scrollbar-track {
  background: transparent;
}

/* PRODUCTS */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.product-card {
  position: relative;
  padding: 14px;
  min-height: 116px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: 0 4px 12px rgba(15,23,42,0.02);
  cursor: pointer;
}

.product-card.active {
  color: #fff;
  border-color: #0f172a;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  box-shadow: 0 18px 32px rgba(15,23,42,0.2);
}

.product-card.out-stock {
  opacity: 0.55;
  filter: grayscale(1);
  background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
}

.product-card.out-stock.active {
  opacity: 0.8;
  color: white;
  background: linear-gradient(135deg, #475569 0%, #64748b 100%);
  border-color: #64748b;
}

.product-card.active .muted {
  color: rgba(226,232,240,0.86);
}

.product-card__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.product-card__title {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.tiny {
  font-size: 12px;
}

/* FIELDS */
.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}

.selected-box {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.qty-wrap,
.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-input,
.number-box,
.stepper__input {
  width: 92px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  color: var(--text);
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(15,23,42,0.03);
}

.sale-total {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid #a7f3d0;
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}

.sale-total-value {
  display: block;
  margin-top: 6px;
  color: var(--success);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.helper-text {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

/* INVENTORY */
.inventory-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.inventory-header__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.inventory-toolbar {
  display: grid;
  gap: 12px;
}

.inventory-toolbar-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.filter-shell,
.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.list,
.inventory-list,
.history-list,
.insights-list {
  display: grid;
  gap: 12px;
}

.inventory-row,
.history-row,
.insight-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: 0 4px 12px rgba(15,23,42,0.02);
}

.inventory-row.low {
  background: linear-gradient(180deg, #fffdf3 0%, #fffbeb 100%);
  border-color: #fcd34d;
}

.inventory-row.out {
  background: linear-gradient(180deg, #fff6f6 0%, #fef2f2 100%);
  border-color: #fecaca;
}

.inventory-meta,
.history-meta {
  display: grid;
  gap: 6px;
}

.inventory-title {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.inventory-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.order-time {
  font-size: 12px;
  color: var(--muted);
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--stock {
  color: var(--text);
  background: #f8fafc;
  border-color: var(--line);
}

.badge--ok {
  color: white;
  background: #059669;
}

.badge--low {
  color: white;
  background: #f59e0b;
}

.badge--out {
  color: white;
  background: #dc2626;
}

/* MANAGE TAB CLEANUP */
#manage .card-content {
  padding-top: 18px;
}

.manage-fields {
  display: grid;
  gap: 10px;
}

#manage .input,
#manage .select {
  min-height: 42px;
  border-radius: 14px;
  font-size: 14px;
}

#manage .field-label {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 800;
}

#manage .stepper {
  gap: 10px;
  align-items: center;
  width: fit-content;
}

#manage .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 22px;
  flex: 0 0 44px;
}

#manage .number-box {
  width: 92px;
  height: 44px;
  border-radius: 14px;
  font-size: 16px;
}

#manage .btn {
  min-height: 44px;
  border-radius: 14px;
  width: fit-content;
  padding: 0 18px;
}

#manage .btn + .btn {
  margin-left: 8px;
}

#manage .custom-field {
  margin-top: 8px;
}

#manage .custom-field.hidden,
.custom-field.hidden,
.hidden {
  display: none;
}

/* NOTES */
.helper-box,
.note-card {
  padding: 15px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  color: #334155;
  line-height: 1.55;
  font-size: 14px;
}

.helper-box.warn,
.note-card--warn {
  color: #92400e;
  border-color: #fcd34d;
  background: linear-gradient(180deg, #fffdf3 0%, #fffbeb 100%);
}

#exportSheetsBtn {
  margin-top: 4px;
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(16px);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(15,23,42,0.96);
  color: white;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* RESPONSIVE */
@media (max-width: 1120px) {
  .grid-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-main,
  .manage-grid {
    grid-template-columns: 1fr;
  }

  .highlights-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .container {
    padding: 12px;
  }

  .hero {
    padding: 22px;
    border-radius: 28px;
  }

  .grid-stats {
    grid-template-columns: 1fr 1fr;
  }

  .product-grid {
    grid-template-columns: 1fr;
  }

  .inventory-toolbar-top {
    grid-template-columns: 1fr;
  }

  .inventory-row,
  .history-row,
  .insight-row {
    flex-direction: column;
    align-items: stretch;
  }

  .inventory-controls {
    justify-content: flex-start;
  }

  .tabs {
    top: 6px;
  }

  .highlights-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .grid-stats {
    grid-template-columns: 1fr;
  }

  .tab-btn,
  .btn {
    width: 100%;
  }

  .qty-wrap,
  .stepper {
    width: 100%;
  }

  .qty-input,
  .number-box,
  .stepper__input {
    flex: 1;
    width: auto;
  }

  #manage .stepper {
    width: 100%;
  }

  #manage .number-box {
    flex: 1;
    width: auto;
  }

  #manage .btn {
    width: 100%;
    margin-left: 0 !important;
  }
}