/* ---------- Design tokens ---------- */

:root {
  color-scheme: dark;
  --bg: #0b0d0e;
  --panel: #14181b;
  --panel-2: #1a2024;
  --line: #262d33;
  --line-strong: #3a434b;
  --text: #f2f5f6;
  --muted: #98a4ab;
  --accent: #d7b46a;
  --accent-hover: #e3c47f;
  --accent-ink: #1a1408;
  --accent-soft: rgba(215, 180, 106, 0.12);
  --accent-2: #4da3dd;
  --danger: #e07d7d;
  --ok: #6fcf97;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 70% -10%, #12161a, var(--bg)) fixed;
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ---------- Interactive states ---------- */

button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-s);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 700;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.ghost:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--line-strong);
}

input,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #0d1113;
  color: var(--text);
  padding: 8px 12px;
}

textarea {
  resize: vertical;
}

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible {
  outline-offset: 0;
  border-color: var(--accent-2);
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #0d1012;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-sub {
  color: var(--accent);
  font-weight: 600;
}

.app-header p {
  min-height: 18px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.ghost-link:hover {
  background: var(--panel-2);
  border-color: var(--line-strong);
}

/* ---------- Login ---------- */

.login-panel {
  max-width: 460px;
  margin: 12vh auto 0;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
}

.login-panel h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.login-hint {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.error {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- Toolbar, tabs, filters ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding-bottom: 2px;
}

.tabs button {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  border-radius: var(--radius-pill);
  padding: 0 16px;
  white-space: nowrap;
  font-weight: 600;
}

.tabs button:hover:not(.active) {
  background: var(--panel-2);
  border-color: var(--line-strong);
}

.tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 320px) 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.filters input[type="search"] {
  border-radius: var(--radius-pill);
  padding-left: 14px;
}

.tag-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding-bottom: 2px;
}

.tag-filters button {
  min-height: 30px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--muted);
  border-color: var(--line);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.tag-filters button:hover:not(.active) {
  color: var(--text);
  border-color: var(--line-strong);
}

.tag-filters button.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.product-list {
  display: grid;
  gap: 8px;
}

/* ---------- Product rows ---------- */

.product-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 150px 132px;
  gap: 14px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--panel);
}

.product-row:hover {
  border-color: var(--line-strong);
  background: var(--panel-2);
}

.product-row.in-cart {
  border-color: rgba(215, 180, 106, 0.55);
  box-shadow: inset 3px 0 0 var(--accent);
}

.product-thumb {
  position: relative;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #000;
  overflow: hidden;
}

.product-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-thumb.no-image {
  background: var(--accent-soft);
}

.product-thumb.no-image .product-image {
  display: none;
}

.product-thumb.no-image::after {
  content: attr(data-letter);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
  color: var(--accent);
  opacity: 0.6;
}

.product-info h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0;
}

.tags,
.product-meta span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.tags {
  font-size: 11.5px;
}

.product-meta {
  display: grid;
  gap: 4px;
}

.product-meta .price {
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Variant groups ---------- */

.product-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--panel);
  overflow: hidden;
}

.product-group:hover {
  border-color: var(--line-strong);
}

.product-group .group-head {
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.product-group.open .group-head {
  border-bottom: 1px solid var(--line);
}

.group-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.expand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.group-head:hover .expand,
.expand:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--line-strong);
  color: var(--text);
}

.product-group.open .chevron {
  transform: rotate(180deg);
}

.group-variants {
  background: #101417;
}

.variant-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 150px 132px;
  gap: 14px;
  align-items: center;
  padding: 8px 10px 8px 14px;
}

.variant-row:not(:first-child) {
  border-top: 1px solid var(--line);
}

.variant-row:hover {
  background: var(--panel-2);
}

.variant-row.in-cart {
  box-shadow: inset 3px 0 0 var(--accent);
}

.variant-row .product-thumb {
  width: 48px;
  height: 48px;
}

.variant-row .product-thumb.no-image::after {
  font-size: 16px;
}

.variant-name {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
}

.variant-row .product-meta .price {
  font-size: 13.5px;
}

/* ---------- Quantity stepper ---------- */

.qty-control {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--panel-2);
  overflow: hidden;
}

.qty-control button {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
}

.qty-control button:hover:not(:disabled) {
  background: var(--line);
  border: none;
}

.qty-control input {
  min-height: 36px;
  text-align: center;
  padding: 6px 2px;
  border: none;
  border-radius: 0;
  background: transparent;
  font-variant-numeric: tabular-nums;
}

.qty-control input:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent-2);
}

.qty::-webkit-inner-spin-button,
.qty::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.qty {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* ---------- Cart ---------- */

.cart-panel {
  position: sticky;
  top: 12px;
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
}

.cart-panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 16px;
}

.cart-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cart-empty {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.cart-lines {
  display: grid;
  gap: 8px;
  max-height: 36vh;
  overflow: auto;
  margin-bottom: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.cart-line {
  display: grid;
  gap: 3px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.cart-line strong {
  font-size: 13px;
}

.cart-line-detail {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cart-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 0 12px;
  border-top: 1px solid var(--line);
}

.cart-total strong {
  color: var(--accent);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.cart-panel textarea {
  margin-bottom: 12px;
}

#finalizeBottom {
  width: 100%;
}

/* ---------- Order confirmation ---------- */

.confirmation-panel {
  max-width: 640px;
  margin: 6vh auto 0;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ok);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
}

.confirmation-panel h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
  font-size: 22px;
}

.conf-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: rgba(111, 207, 151, 0.14);
  border: 1px solid rgba(111, 207, 151, 0.4);
  color: var(--ok);
  font-size: 15px;
}

.conf-lead {
  margin: 0 0 18px;
  color: var(--muted);
}

.conf-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#confRef {
  color: var(--text);
  font-weight: 600;
}

.conf-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

.conf-qty {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.conf-line-total {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.conf-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 0 4px;
}

.conf-total strong {
  color: var(--accent);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.conf-notes {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.conf-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.conf-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  text-align: right;
}

/* ---------- Messages ---------- */

.order-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--ok);
  font-size: 13px;
}

.order-message.is-error {
  color: var(--danger);
}

/* ---------- Admin ---------- */

.admin-layout h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.muted-line {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--panel);
  box-shadow: var(--shadow-1);
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.orders-table th,
.orders-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.orders-table tbody tr:last-child td {
  border-bottom: none;
}

.orders-table tbody tr:hover td {
  background: var(--panel-2);
}

.orders-table th {
  color: var(--muted);
  background: #0d1012;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.orders-table td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.orders-table td .status-pill {
  display: inline-block;
  margin-top: 0;
  padding: 3px 10px;
  border: 1px solid rgba(215, 180, 106, 0.35);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.orders-table td .status-pill.pill-ok {
  border-color: rgba(111, 207, 151, 0.4);
  background: rgba(111, 207, 151, 0.12);
  color: var(--ok);
}

.orders-table td .status-pill.pill-error {
  border-color: rgba(224, 125, 125, 0.4);
  background: rgba(224, 125, 125, 0.12);
  color: var(--danger);
}

.orders-table td .status-pill.pill-muted {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.retry-invoice {
  min-height: 26px;
  margin-left: 6px;
  padding: 0 10px;
  font-size: 11px;
}

.download-links {
  display: flex;
  gap: 8px;
}

.download-links a {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.download-links a:hover {
  background: var(--panel-2);
  border-color: var(--line-strong);
}

.empty-state {
  margin: 14px 0 0;
  color: var(--muted);
}

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .cart-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  main {
    padding: 12px 10px;
  }

  .app-header {
    flex-wrap: wrap;
    padding: 12px 14px;
  }

  .brand {
    font-size: 15px;
    letter-spacing: 0.06em;
  }

  .toolbar,
  .filters {
    grid-template-columns: 1fr;
    display: grid;
  }

  .product-row {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 10px;
  }

  .product-thumb {
    width: 64px;
    height: 64px;
  }

  .product-thumb.no-image::after {
    font-size: 22px;
  }

  .product-meta,
  .qty-control,
  .group-actions {
    grid-column: 1 / -1;
  }

  .variant-row {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
  }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  button,
  .ghost-link,
  input,
  textarea,
  .product-row,
  .variant-row,
  .product-group,
  .download-links a {
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
  }

  .chevron {
    transition: transform 0.15s ease;
  }
}
