:root {
  --yellow: #ffd51f;
  --yellow-soft: #fff5bd;
  --blue: #153f91;
  --blue-deep: #071f52;
  --red: #d4142a;
  --ink: #081832;
  --muted: #596477;
  --line: #d7deec;
  --surface: #ffffff;
  --soft: #f5f8fd;
  --ok: #0f8c55;
  --warn: #b7791f;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: #eef3f8;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: 310px;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, .55) 0 2px, transparent 3px),
    radial-gradient(ellipse at 88% 8%, rgba(21, 63, 145, .16) 0 58px, transparent 59px),
    linear-gradient(135deg, rgba(21, 63, 145, .14) 0 16%, transparent 16% 100%),
    var(--yellow-soft);
  z-index: -1;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 14px;
  color: var(--blue);
}

.app-header > div:first-child {
  min-width: 0;
}

.app-header h1,
.section-head h2,
.form-grid h3,
.history-grid h3 {
  margin: 0;
}

.app-header h1 {
  font-size: 30px;
  line-height: 1;
  color: var(--blue-deep);
}

.app-tagline {
  margin: 7px 0 0;
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
}

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

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border: 3px solid var(--blue);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 38% 28%, rgba(255, 255, 255, .58), transparent 32%),
    var(--yellow);
  box-shadow: inset 0 -14px 0 var(--red);
  overflow: hidden;
}

.brand-mark span {
  position: absolute;
  inset: 28px 0 14px;
  background: var(--blue);
}

.brand-mark strong {
  position: relative;
  color: white;
  font-size: 14px;
  text-shadow: 0 1px 5px rgba(0, 0, 0, .28);
}

.header-actions {
  display: flex;
  align-items: center;
  flex-direction: column-reverse;
  gap: 12px;
  justify-self: end;
  max-width: 100%;
}

.admin-toggle {
  min-width: 86px;
  max-width: 100%;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto 40px;
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  box-shadow: 0 8px 20px rgba(8, 24, 50, .06);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--yellow);
}

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

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  color: var(--blue-deep);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.tab {
  min-height: 44px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .62);
  color: var(--muted);
  padding: 10px 8px;
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  border-color: rgba(21, 63, 145, .25);
  color: var(--blue-deep);
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(8, 24, 50, .05);
}

.hidden {
  display: none !important;
}

.panel {
  display: none;
  border: 1px solid rgba(21, 63, 145, .14);
  border-radius: var(--radius);
  background: var(--surface);
  margin-top: 8px;
  padding: 14px;
  box-shadow: 0 12px 30px rgba(8, 24, 50, .07);
}

.panel.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
}

.primary,
.danger,
.file-button,
.ghost {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
}

.primary {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  box-shadow: 0 8px 16px rgba(21, 63, 145, .18);
}

.danger {
  color: white;
  background: var(--red);
}

.ghost {
  color: var(--blue);
  background: #eaf0ff;
}

.file-button {
  display: inline-flex;
  align-items: center;
  color: var(--blue);
  background: var(--yellow);
}

.file-button input {
  display: none;
}

.inventory-wrap {
  display: block;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

#stock .inventory-wrap {
  display: none;
}

.inventory-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.inventory-table th,
.inventory-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
}

.inventory-table th {
  background: #edf3ff;
  color: var(--blue-deep);
  font-size: 13px;
}

.inventory-table td.size-cell {
  width: 92px;
}

.stock-input {
  width: 72px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
}

.stock-number {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.stock-card-list {
  display: grid;
  gap: 12px;
}

.inline-stock {
  margin-top: 16px;
  border: 1px solid rgba(21, 63, 145, .16);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse at 96% -20%, rgba(255, 213, 31, .34), transparent 34%),
    #fbfcff;
  padding: 12px;
}

.inline-stock:empty {
  display: none;
}

.inline-stock-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.inline-stock-head span {
  display: block;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.inline-stock-head strong {
  display: block;
  margin-top: 4px;
  color: var(--blue-deep);
}

.stock-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(21, 63, 145, .14);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse at 92% -10%, rgba(255, 213, 31, .32), transparent 34%),
    var(--surface);
  padding: 12px;
  box-shadow: 0 10px 24px rgba(8, 24, 50, .07);
}

.stock-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 18% 24%, rgba(21, 63, 145, .08) 0 9px, transparent 10px),
    radial-gradient(ellipse at 26% 24%, rgba(212, 20, 42, .08) 0 9px, transparent 10px),
    radial-gradient(ellipse at 78% 76%, rgba(21, 63, 145, .06) 0 8px, transparent 9px),
    radial-gradient(ellipse at 86% 76%, rgba(212, 20, 42, .06) 0 8px, transparent 9px);
  pointer-events: none;
}

.stock-card-head {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.stock-card-head strong {
  display: block;
  color: var(--blue-deep);
  font-size: 17px;
}

.stock-card-head small,
.stock-total span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.stock-total {
  min-width: 64px;
  border-radius: 6px;
  background: linear-gradient(180deg, #edf3ff, #ffffff);
  padding: 8px;
  text-align: center;
  border: 1px solid rgba(21, 63, 145, .1);
}

.stock-total strong {
  color: var(--blue-deep);
  font-size: 22px;
}

.size-chip-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.size-chip {
  position: relative;
  min-height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 4px;
  background: var(--soft);
}

.size-chip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.size-chip strong {
  color: var(--ink);
  font-size: 18px;
}

.size-chip.ok {
  background: #eaf7f0;
  border-color: rgba(15, 140, 85, .24);
}

.size-chip.low {
  background: #fff5d8;
  border-color: rgba(183, 121, 31, .24);
}

.size-chip.empty {
  background: #ffe7eb;
  border-color: rgba(212, 20, 42, .22);
}

.size-chip.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 63, 145, .14);
}

.low-stock {
  background: #fff5d8;
}

.zero-stock {
  background: #ffe7eb;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.edit-form {
  border: 1px solid rgba(21, 63, 145, .18);
  border-left: 5px solid var(--yellow);
  border-radius: var(--radius);
  background: #fbfcff;
  padding: 16px;
}

.form-grid h3,
.sizes-row {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 63, 145, .14);
  outline: 0;
}

.sizes-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.record-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.list-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.list-toolbar h3 {
  margin: 0;
}

.record {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  border: 1px solid rgba(21, 63, 145, .14);
  border-left: 5px solid var(--blue);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--soft);
  box-shadow: 0 8px 18px rgba(8, 24, 50, .05);
}

.record strong {
  display: block;
}

.record small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.record .record-product {
  color: var(--ink);
  font-weight: 700;
}

.record-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.record-actions button {
  flex: 1 1 150px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  color: white;
  background: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.badge.pendiente {
  background: var(--warn);
}

.badge.vendido {
  background: var(--ok);
}

.badge.cancelado {
  background: var(--red);
}

.history-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.search {
  max-width: none;
}

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

.json-preview {
  max-height: 420px;
  overflow: auto;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--blue-deep);
  color: #e6eaf5;
  padding: 14px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(360px, calc(100% - 32px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: var(--radius);
  background: var(--ok);
  color: white;
  padding: 15px 16px;
  font-weight: 700;
  box-shadow: 0 16px 34px rgba(8, 24, 50, .22);
  transition: .2s ease;
  z-index: 40;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (min-width: 700px) {
  .app-header {
    display: flex;
    align-items: center;
    gap: 24px;
    width: min(1180px, calc(100% - 28px));
    padding: 28px 0 18px;
  }

  .app-header h1 {
    font-size: clamp(38px, 5vw, 52px);
  }

  .brand-mark {
    width: 74px;
    height: 74px;
    flex-basis: 74px;
    border-width: 4px;
    box-shadow: inset 0 -18px 0 var(--red);
  }

  .brand-mark span {
    inset: 35px 0 18px;
  }

  .brand-mark strong {
    font-size: 22px;
  }

  .header-actions {
    flex-direction: row;
  }

  .app-shell {
    width: min(1180px, calc(100% - 28px));
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
  }

  .stat {
    padding: 14px;
  }

  .stat strong {
    font-size: 28px;
  }

  .tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0;
  }

  #stock .inventory-wrap {
    display: block;
  }

  .stock-card-list {
    display: none;
  }

  .tab {
    min-width: 108px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    padding: 11px 14px;
  }

  .panel {
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: 0;
    padding: clamp(18px, 3vw, 24px);
  }

  .section-head {
    align-items: center;
    flex-direction: row;
  }

  .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sizes-row {
    grid-template-columns: repeat(5, minmax(70px, 1fr));
  }

  .record {
    grid-template-columns: minmax(0, 1fr) auto;
  }

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

  .list-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
    align-items: end;
  }

  .search {
    max-width: 260px;
  }

  .list-toolbar .search {
    max-width: none;
  }
}
