/* ══════════════════════════════════════════
   TOKENS
   ══════════════════════════════════════════ */
:root {
  --bg: #0a0b10;
  --bg-soft: #0e1017;
  --surface: #15171f;
  --surface-2: #1b1e28;
  --border: #262a36;
  --text: #eef0f4;
  --text-dim: #9096a8;
  --text-faint: #565c6e;

  --accent: #ffb020;
  --accent-ink: #241904;
  --accent-soft: rgba(255, 176, 32, 0.14);

  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);

  --coral: #ff5d7e;
  --coral-soft: rgba(255, 93, 126, 0.14);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(255, 176, 32, 0.08), transparent),
    radial-gradient(900px 500px at 100% 0%, rgba(45, 212, 191, 0.06), transparent),
    var(--bg);
}

a { color: inherit; }
button { font-family: inherit; }

/* ══════════════════════════════════════════
   TOPBAR
   ══════════════════════════════════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 11, 16, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.btn-icon-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-icon-back:hover { background: var(--surface-2); }
.btn-icon-back:active { transform: scale(0.94); }

.brand {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark { color: var(--accent); font-size: 15px; }

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

/* ══════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-block { width: 100%; }

.icon-refresh { transition: transform 0.4s; }
.btn-ghost:active .icon-refresh { transform: rotate(180deg); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}
.link-btn:hover { color: var(--coral); }

/* ══════════════════════════════════════════
   LAYOUT / VIEWS
   ══════════════════════════════════════════ */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 100px;
}

.view { animation: fade-up 0.35s ease both; }

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

.lead {
  color: var(--text-dim);
  margin: 0 0 20px;
  font-size: 15px;
}

.view-productos { display: flex; flex-direction: column; gap: 18px; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 14px;
  line-height: 1.6;
}

/* ══════════════════════════════════════════
   CATEGORY GRID
   ══════════════════════════════════════════ */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.category-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-align: center;
  animation: fade-up 0.4s ease both;
  animation-delay: calc(var(--i, 0) * 30ms);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.category-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  background: var(--surface-2);
}
.category-card:active { transform: translateY(0) scale(0.98); }

.category-icon { font-size: 26px; }
.category-name { font-size: 13px; font-weight: 600; color: var(--text); }

.category-count {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.category-count.is-empty { background: var(--surface-2); color: var(--text-faint); }

/* ══════════════════════════════════════════
   ADD PANEL / TOOLBAR
   ══════════════════════════════════════════ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.add-form .input { flex: 1; min-width: 160px; }

.input, .select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-faint); }

.form-msg { margin: 8px 0 0; font-size: 13px; min-height: 16px; }
.form-msg.ok { color: var(--teal); }
.form-msg.err { color: var(--coral); }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-field {
  flex: 1;
  min-width: 220px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon { position: absolute; left: 12px; color: var(--text-faint); pointer-events: none; }
.search-field input { width: 100%; padding-left: 36px; }

.select { min-width: 160px; }

/* ══════════════════════════════════════════
   PRODUCT GRID / CARD
   ══════════════════════════════════════════ */
.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

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

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}
.card.animate-in {
  animation: fade-up 0.4s ease both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.card:hover { border-color: #363b4a; }
.card--cached { border-color: var(--border); }

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}
.card-delete {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: none;
  background: rgba(10, 11, 16, 0.65);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-delete:hover { background: var(--coral); color: #fff; }

.card-media {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  display: block;
}
.card-media-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: var(--surface-2);
  color: var(--text-faint);
}

.card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card-alias {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card-attrs { font-size: 12px; color: var(--text-dim); }

.card-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.card-sku { font-size: 11px; color: var(--text-faint); }
.card-loading-msg, .card-error-msg { font-size: 12px; color: var(--text-dim); }

.card-prices { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.price-row { display: flex; align-items: baseline; gap: 6px; font-size: 13px; }
.price-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); width: 44px; flex-shrink: 0; }
.price-old { text-decoration: line-through; color: var(--text-faint); font-size: 12px; }
.price-normal { font-weight: 700; }
.price-offer { font-weight: 800; color: var(--coral); font-size: 15px; }
.price-cmr { font-weight: 700; color: var(--teal); }
.price-empty { color: var(--text-faint); }

.card-shipping, .card-installments {
  font-size: 11px;
  color: var(--text-dim);
}
.card-warranty {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}
.warranty-label { color: var(--text-faint); }
.warranty-item { color: var(--text-dim); }

.stock-badge {
  align-self: flex-start;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  margin-top: 2px;
}
.stock--ok { background: var(--teal-soft); color: var(--teal); }
.stock--low { background: var(--coral-soft); color: var(--coral); }
.stock--unknown, .stock--loading { background: var(--surface-2); color: var(--text-faint); }

.card-updated {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 2px;
}
.card-updated--stale { color: var(--coral); }

.card-footer {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card-link { font-size: 12px; font-weight: 600; color: var(--text-dim); text-decoration: none; }
.card-link:hover { color: var(--accent); }

.btn-order {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn-order:hover { border-color: var(--accent); }
.btn-order--added { background: var(--teal-soft); color: var(--teal); border-color: transparent; }

/* ══════════════════════════════════════════
   ORDER PANEL (desktop sidebar)
   ══════════════════════════════════════════ */
.order-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 78px;
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
}

.order-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.order-panel-title { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; }

.pill {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
}
.pill.zero { background: var(--surface-2); color: var(--text-faint); }

.order-empty {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.order-category {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 8px 2px 2px;
}

.order-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.order-thumb { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 6px; flex-shrink: 0; }
.order-thumb-placeholder {
  width: 40px; height: 40px; border-radius: 6px; flex-shrink: 0;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 16px;
}

.order-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.order-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-sku { font-size: 10px; color: var(--text-faint); }
.order-price { font-size: 12px; font-weight: 700; color: var(--accent); }
.order-size { font-size: 11px; color: var(--text-dim); }

.order-changes { margin-top: 3px; display: flex; flex-direction: column; gap: 1px; }
.order-change-line { font-size: 10px; color: var(--coral); }
.order-change-date { font-size: 10px; color: var(--text-faint); }

.order-remove {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 2px;
  flex-shrink: 0;
}
.order-remove:hover { color: var(--coral); }

/* ══════════════════════════════════════════
   FAB (mobile)
   ══════════════════════════════════════════ */
.fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 30;
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 13px 18px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab.has-items { animation: pop 0.3s ease; }
@keyframes pop { 0% { transform: scale(0.9); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* ══════════════════════════════════════════
   SHEETS / MODALS
   ══════════════════════════════════════════ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 5, 8, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }

.sheet {
  width: 100%;
  max-width: 440px;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 18px;
  transform: translateY(16px);
  transition: transform 0.2s;
}
.sheet-overlay.open .sheet { transform: translateY(0); }

@media (min-width: 720px) {
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-title { font-weight: 700; font-size: 15px; }
.sheet-close { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 4px; }

.sheet-question { font-size: 13px; color: var(--text-dim); margin: 0 0 8px; }

.size-options { display: flex; gap: 8px; margin-bottom: 4px; }
.size-option {
  flex: 1;
  padding: 14px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.size-option:hover { border-color: var(--accent); }

.qty-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.qty-btn {
  width: 38px; height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.qty-row input {
  flex: 1;
  text-align: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 15px;
  font-weight: 700;
}

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .order-panel { display: none; }
  .fab { display: flex; }
}

@media (max-width: 480px) {
  .main { padding: 16px 14px 90px; }
  .category-grid { grid-template-columns: repeat(3, 1fr); }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-actions .btn-label { display: none; }
  .topbar-actions .btn { padding: 10px; }
  .brand { font-size: 16px; }
}
