:root {
  --bg: #f7f6fb;
  --panel: #ffffff;
  --ink: #1e1b2e;
  --muted: #6a6580;
  --line: #e5e1ef;
  --brand: #7c3aed;
  --brand-strong: #6d28d9;
  --accent: #c026d3;
  --soft: #f1e9fe;
  --danger: #b91c1c;
  --card-soft: #faf8fd;
  --input-bg: #ffffff;
  --tab-bg: #f3f0fa;
  --secondary-bg: #eceaf3;
  --pill-bg: #ffffff;
  --edit-bg: rgba(255, 255, 255, 0.94);
  --img-bg: #f2eff8;
  --shadow: 0 18px 45px rgba(46, 26, 71, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.dark {
  --bg: #0f0d17;
  --panel: #1a1626;
  --ink: #ece9f5;
  --muted: #9d97b3;
  --line: #2c2740;
  --brand: #a855f7;
  --brand-strong: #c084fc;
  --accent: #e879f9;
  --soft: #2a1f45;
  --danger: #f87171;
  --card-soft: #211c31;
  --input-bg: #17131f;
  --tab-bg: #17131f;
  --secondary-bg: #2a2540;
  --pill-bg: #17131f;
  --edit-bg: rgba(30, 24, 45, 0.94);
  --img-bg: #ffffff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.topbar {
  align-items: center;
  background: linear-gradient(120deg, #151226 0%, #221436 60%, #341042 100%);
  color: #fff;
  display: flex;
  justify-content: space-between;
  min-height: 92px;
  padding: 18px clamp(16px, 4vw, 42px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  align-items: center;
  background: transparent;
  border: 0;
  color: inherit;
  display: flex;
  gap: 14px;
  padding: 0;
  text-align: left;
  transition: opacity 160ms ease, transform 160ms ease;
}

.brand:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.brand:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.72);
  outline-offset: 5px;
}

.brand-logo {
  border-radius: 50%;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.45);
  height: 58px;
  width: 58px;
}

.brand-name {
  font-size: 26px;
  letter-spacing: 1px;
  margin: 0;
}

.brand-name span {
  background: linear-gradient(120deg, #e879f9, #a855f7);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}

.brand .eyebrow {
  margin: 3px 0 0;
}

.topbar h1,
.panel-head h2 {
  font-size: 28px;
  line-height: 1.05;
  margin: 0;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #c4b5fd;
}

.top-actions,
.toolbar,
.panel-head,
.quantity-row,
.meta,
.split {
  align-items: center;
  display: flex;
  gap: 10px;
}

.segmented {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  display: flex;
  padding: 3px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #dce7e4;
  min-width: 42px;
  padding: 8px 10px;
}

.segmented button.active {
  background: #fff;
  color: #1e1b2e;
}

.icon-button,
.primary,
.secondary,
.icon-only {
  align-items: center;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
}

.icon-button {
  background: #fff;
  color: #1e1b2e;
}

#adminToggle {
  transition: box-shadow 180ms ease, transform 180ms ease, background 180ms ease;
}

#adminToggle:hover {
  box-shadow: 0 12px 28px rgba(168, 85, 247, 0.26);
  transform: translateY(-1px);
}

.icon-only {
  background: var(--soft);
  color: var(--brand-strong);
  width: 42px;
}

.icon-only.ghost {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
}

.export-actions {
  display: flex;
  gap: 8px;
}

.primary {
  background: var(--brand);
  color: #fff;
  width: 100%;
}

.secondary {
  background: var(--secondary-bg);
  color: var(--ink);
}

.compact {
  min-height: 38px;
  padding: 0 12px;
  width: auto;
}

.full {
  width: 100%;
}

.layout {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 1fr) 400px;
  padding: 22px clamp(16px, 4vw, 42px) 40px;
}

.admin-page {
  animation: adminReveal 320ms ease both;
  margin: 0 auto;
  max-width: 880px;
  padding: 22px clamp(16px, 4vw, 42px) 40px;
  width: 100%;
}

@keyframes adminReveal {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.admin-page #loginForm {
  max-width: 420px;
}

.admin-page .orders-list {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.admin-page .orders-list .empty-state {
  grid-column: 1 / -1;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.search {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex: 1;
  gap: 8px;
  max-width: 520px;
  padding: 0 12px;
}

.search input,
select,
.admin-form input,
.admin-form textarea,
.order-form input,
.order-form textarea {
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
  width: 100%;
}

.search input {
  border: 0;
  outline: 0;
}

select {
  max-width: 210px;
}

.stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 18px;
}

#remainingDebt,
#adminDebt {
  color: var(--accent);
}

.stats div,
.order-panel,
.admin-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats div {
  padding: 16px;
}

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

.stats strong {
  display: block;
  font-size: 25px;
  margin-top: 4px;
}

.product-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.product-card {
  animation: cardIn 260ms ease both;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(18, 32, 29, 0.08);
  min-width: 0;
  overflow: hidden;
  position: relative;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.product-card:hover {
  box-shadow: 0 18px 40px rgba(124, 58, 237, 0.18);
  transform: translateY(-3px);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .product-card { animation: none; }
}

.badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  left: 10px;
  padding: 4px 9px;
  position: absolute;
  top: 10px;
  z-index: 2;
}

.badge.out {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
}

.badge.low {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
}

.badge.available {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.product-card.is-out img {
  opacity: 0.55;
}

.icon-button,
.primary,
.secondary,
.icon-only,
.quantity-row button,
.segmented button {
  transition: filter 140ms ease, transform 140ms ease, background 140ms ease;
}

.primary:hover,
.secondary:hover,
.icon-button:hover,
.icon-only:hover,
.quantity-row button:hover {
  filter: brightness(1.06);
}

.primary:active,
.secondary:active,
.icon-only:active,
.quantity-row button:active {
  transform: scale(0.97);
}

.product-card img {
  aspect-ratio: 4 / 3;
  background: var(--img-bg);
  cursor: zoom-in;
  display: block;
  height: auto;
  object-fit: contain;
  padding: 10px;
  width: 100%;
}

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

.sku {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  margin: 0;
}

.product-card h3 {
  font-size: 15px;
  line-height: 1.25;
  margin: 0;
  min-height: 58px;
}

.meta {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 8px;
}

.price {
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
}

.stock-pills {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
}

.stock-pills span {
  align-items: center;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 6px;
  justify-content: space-between;
  min-height: 34px;
  padding: 7px 8px;
}

.stock-pills strong {
  color: var(--ink);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quantity-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
}

.quantity-row button {
  background: var(--soft);
  border: 0;
  border-radius: 8px;
  color: var(--brand-strong);
  height: 42px;
}

.quantity-row input {
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 42px;
  text-align: center;
  width: 100%;
}

.edit-button {
  background: var(--edit-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  display: none;
  height: 38px;
  position: absolute;
  right: 10px;
  top: 10px;
  width: 38px;
  z-index: 2;
}

body.admin-on .edit-button {
  display: grid;
  place-items: center;
}

.side-panel {
  display: grid;
  gap: 16px;
  height: fit-content;
  position: sticky;
  top: 16px;
}

.order-panel,
.admin-panel {
  padding: 16px;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.cart-list,
.orders-list {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.cart-item,
.order-item {
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px;
}

.cart-item strong,
.order-item strong {
  font-size: 14px;
}

.cart-item span,
.order-item span {
  color: var(--muted);
  font-size: 13px;
}

.admin-tabs {
  background: var(--tab-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
  padding: 4px;
}

.admin-tabs button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 0 10px;
}

.admin-tabs button.active {
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(18, 32, 29, 0.08);
  color: var(--ink);
  font-weight: 800;
}

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

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

.admin-summary div {
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.admin-summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.admin-summary strong {
  display: block;
  font-size: 22px;
  margin-top: 4px;
}

.admin-section-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 4px;
}

.admin-section-head h3 {
  font-size: 17px;
  line-height: 1.2;
  margin: 0;
}

.order-topline,
.order-meta,
.form-actions,
.file-field {
  align-items: center;
  display: flex;
  gap: 8px;
}

.order-topline {
  justify-content: space-between;
}

.order-topline span {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  color: #9a3412;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
}

.order-topline span.delivered {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.order-topline span.preparing {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.deliver-lines {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.deliver-line {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 6px 8px;
}

.deliver-line > span {
  font-size: 12px;
  line-height: 1.3;
}

.deliver-line small {
  color: var(--muted);
  white-space: nowrap;
}

.deliver-line input {
  flex: 0 0 62px;
  min-height: 34px;
  padding: 4px 8px;
  text-align: center;
  width: 62px;
}

.deliver-line.done {
  color: var(--muted);
  font-size: 12px;
}

.order-item .deliver {
  background: #ecfdf5;
  color: #047857;
}

body.dark .order-item .deliver {
  background: #0c2e22;
  color: #6ee7b7;
}

.order-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.order-item .remove {
  background: #fee2e2;
  color: var(--danger);
}

.payments-summary {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 640px) {
  .payments-summary {
    grid-template-columns: 1fr;
  }
}

.payment-delete {
  height: 34px;
  min-height: 34px;
  width: 34px;
}

.payment-chart {
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.chart-progress-head {
  align-items: baseline;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  justify-content: space-between;
  text-transform: uppercase;
}

.chart-progress-head strong {
  color: var(--brand-strong);
  font-size: 16px;
}

.chart-progress {
  background: var(--line);
  border-radius: 999px;
  height: 10px;
  margin: 6px 0 4px;
  overflow: hidden;
}

.chart-progress span {
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: 999px;
  display: block;
  height: 100%;
  transition: width 400ms ease;
}

.chart-progress-legend {
  color: var(--muted);
  display: flex;
  font-size: 11px;
  justify-content: space-between;
}

.chart-bars {
  align-items: flex-end;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 5px;
  height: 60px;
  margin-top: 10px;
  padding-top: 10px;
}

.chart-bar {
  align-items: flex-end;
  display: flex;
  flex: 1;
  height: 100%;
  justify-content: center;
}

.chart-bar span {
  background: linear-gradient(180deg, var(--accent), var(--brand));
  border-radius: 4px 4px 0 0;
  display: block;
  min-height: 4px;
  width: 100%;
}

.order-meta {
  color: var(--muted);
  flex-wrap: wrap;
  font-size: 13px;
}

.order-meta span {
  background: var(--pill-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
}

.order-item p,
.order-item small {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.order-item small {
  color: var(--ink);
}

.empty-state {
  background: var(--card-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
  text-align: center;
}

.product-editor {
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: -4px 0 0;
}

.file-field {
  background: var(--input-bg);
  border: 1px dashed var(--brand);
  border-radius: 8px;
  color: var(--brand-strong);
  justify-content: center;
  min-height: 44px;
  overflow: hidden;
  padding: 0 12px;
  position: relative;
}

.file-field input {
  inset: 0;
  opacity: 0;
  position: absolute;
}

.form-actions {
  align-items: stretch;
}

.form-actions .secondary {
  flex: 0 0 auto;
}

.order-form,
.admin-form {
  display: grid;
  gap: 10px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.cart-total {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), rgba(217, 70, 239, 0.12));
  border: 1px solid rgba(124, 58, 237, 0.18);
  border-radius: 8px;
  display: grid;
  font-size: 14px;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  padding: 10px;
}

.cart-total span {
  color: var(--muted);
  display: grid;
  gap: 2px;
}

.cart-total strong {
  color: var(--brand-strong);
  font-size: 16px;
}

.admin-form select {
  max-width: none;
}

.footer {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 10px;
  justify-content: center;
  padding: 10px 16px 30px;
}

.footer img {
  height: 26px;
  width: 26px;
}

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

.lightbox {
  background: rgba(15, 10, 28, 0.88);
  display: grid;
  inset: 0;
  padding: 24px;
  place-items: center;
  position: fixed;
  z-index: 40;
}

.lightbox figure {
  display: grid;
  gap: 12px;
  justify-items: center;
  margin: 0;
}

.lightbox img {
  background: #fff;
  border-radius: 12px;
  max-height: 80vh;
  max-width: min(92vw, 900px);
  object-fit: contain;
  padding: 14px;
}

.lightbox figcaption {
  color: #ece7f8;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.lightbox-close {
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  border-radius: 8px;
  color: #fff;
  display: grid;
  height: 44px;
  place-items: center;
  position: absolute;
  right: 18px;
  top: 18px;
  width: 44px;
}

.toast {
  background: #1a1528;
  border-radius: 8px;
  bottom: 18px;
  color: #fff;
  left: 50%;
  max-width: min(460px, calc(100vw - 32px));
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 18px);
  transition: 180ms ease;
  z-index: 20;
}

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

.hidden-admin {
  display: none;
}

svg {
  height: 18px;
  width: 18px;
}

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

  .side-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .toolbar,
  .admin-section-head,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    display: block;
    gap: 12px;
    min-height: 78px;
    padding: 12px 16px;
  }

  .brand {
    min-width: 0;
    padding-right: 58px;
  }

  .brand-logo {
    height: 46px;
    width: 46px;
  }

  .brand-name {
    font-size: 25px;
    line-height: 1;
  }

  .brand .eyebrow {
    font-size: 10px;
    max-width: 210px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-actions {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    margin-top: 10px;
    position: static;
  }

  .top-actions .segmented {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 3px;
  }

  .top-actions .segmented button {
    min-height: 36px;
    min-width: 38px;
    padding: 0 9px;
  }

  .top-actions .icon-only,
  #adminToggle {
    border-radius: 999px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    width: 42px;
  }

  #adminToggle {
    background: radial-gradient(circle at 28% 24%, #fff 0, #fff 34%, #f5e8ff 100%);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72), 0 10px 24px rgba(168, 85, 247, 0.35);
    color: #5b21b6;
    position: absolute;
    right: 16px;
    top: 17px;
  }

  #adminToggle span {
    display: none;
  }

  #adminToggle:active {
    box-shadow: 0 0 0 6px rgba(168, 85, 247, 0.18), 0 8px 20px rgba(168, 85, 247, 0.28);
    transform: scale(0.94);
  }

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

  .split {
    flex-direction: column;
  }

  select,
  .search {
    max-width: none;
    width: 100%;
  }

  .admin-tabs,
  .admin-summary {
    grid-template-columns: 1fr;
  }
}
