:root {
  color-scheme: dark;
  --bg: #080808;
  --surface: #121212;
  --surface-2: #191919;
  --surface-3: #242424;
  --line: rgba(255,255,255,.14);
  --line-strong: rgba(240,162,2,.42);
  --text: #f7f7f7;
  --muted: #b9b9b9;
  --accent: #f0a202;
  --accent-2: #ffcf5a;
  --success: #25d366;
  --danger: #e3342f;
  --info: #62c7e8;
  --shadow: 0 24px 70px rgba(0,0,0,.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(240,162,2,.16), transparent 30%),
    linear-gradient(90deg, rgba(98,199,232,.05), transparent 45%),
    var(--bg);
}

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

a {
  color: inherit;
  text-decoration: none;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 900;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 18px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand img {
  width: 118px;
  height: auto;
  filter: drop-shadow(0 0 28px rgba(255,160,0,.3));
}

.kicker {
  margin: 0 0 5px;
  color: var(--accent-2);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: .95;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

nav a,
nav button {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  padding: 10px 13px;
}

nav a:first-child,
.primary,
.confirm {
  color: #101010;
  background: var(--accent);
  border-color: var(--accent);
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 18px 36px;
}

.summary,
.tools,
.stock-card,
.history,
dialog {
  border: 1px solid var(--line);
  background: rgba(18,18,18,.9);
  box-shadow: var(--shadow);
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary div {
  min-height: 92px;
  padding: 15px;
  border-left: 1px solid var(--line);
}

.summary div:first-child {
  border-left: 0;
}

.summary span,
label span,
.stock-meta span,
.movement span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.summary strong {
  font-size: clamp(1.25rem, 3vw, 2.2rem);
}

.accent {
  color: var(--accent);
}

.danger {
  color: var(--danger);
}

.success {
  color: var(--success);
}

.tools {
  display: grid;
  grid-template-columns: 1fr 220px auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
  padding: 14px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240,162,2,.16);
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin: 22px 0 12px;
}

.section-head p:last-child {
  max-width: 360px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.4;
  text-align: right;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stock-card {
  display: grid;
  gap: 14px;
  min-height: 100%;
  padding: 15px;
}

.stock-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.stock-card h3 {
  margin-bottom: 5px;
  font-size: 1.05rem;
}

.status {
  display: inline-grid;
  min-height: 32px;
  place-items: center;
  border: 1px solid rgba(37,211,102,.35);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--success);
  background: rgba(37,211,102,.1);
  font-size: .76rem;
  font-weight: 900;
  white-space: nowrap;
}

.status.low {
  color: var(--accent-2);
  border-color: rgba(240,162,2,.45);
  background: rgba(240,162,2,.1);
}

.status.negative,
.status.empty {
  color: #ff8b86;
  border-color: rgba(227,52,47,.45);
  background: rgba(227,52,47,.12);
}

.stock-number {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  color: var(--accent-2);
  background: rgba(240,162,2,.08);
}

.stock-number strong {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: .95;
}

.stock-number small {
  color: var(--muted);
  font-weight: 800;
}

.stock-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stock-meta > div,
.stock-meta label {
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.18);
}

.min-input {
  min-height: 38px;
  padding: 8px 10px;
}

.stock-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stock-actions button {
  min-height: 42px;
}

.stock-actions button[data-action="entrada"] {
  color: #06140a;
  background: var(--success);
  border-color: var(--success);
}

.stock-actions button[data-action="salida"] {
  color: #fff;
  background: rgba(227,52,47,.18);
  border-color: rgba(227,52,47,.55);
}

.history {
  margin-top: 18px;
  padding: 15px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

#movementCount {
  color: var(--muted);
  font-weight: 800;
}

.movement-list {
  display: grid;
  gap: 9px;
  max-height: 420px;
  overflow: auto;
  padding-right: 3px;
}

.movement {
  display: grid;
  grid-template-columns: 150px minmax(170px, 1fr) 120px minmax(170px, 1fr) 132px;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.18);
}

.movement strong {
  display: block;
}

.movement .qty {
  font-weight: 950;
}

.movement.entrada .qty {
  color: var(--success);
}

.movement.salida .qty {
  color: #ff8b86;
}

.movement.ajuste .qty {
  color: var(--info);
}

.empty {
  padding: 20px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(0,0,0,.18);
  text-align: center;
}

.stock-grid > .empty {
  grid-column: 1 / -1;
}

.movement small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

dialog {
  width: min(540px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 0;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0,0,0,.72);
}

form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.two-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.confirm {
  width: 100%;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #101010;
  background: var(--accent);
  box-shadow: var(--shadow);
  font-weight: 900;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}

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

@media (max-width: 1040px) {
  .top,
  .tools,
  .section-head {
    grid-template-columns: 1fr;
  }

  .top {
    display: block;
  }

  nav {
    justify-content: flex-start;
    margin-top: 16px;
  }

  .tools {
    display: grid;
  }

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

  .movement {
    grid-template-columns: 130px minmax(160px, 1fr) 110px;
  }

  .movement .note,
  .movement .date {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .summary,
  .stock-grid,
  .stock-meta,
  .stock-actions,
  .two-fields {
    grid-template-columns: 1fr;
  }

  .summary div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .summary div:first-child {
    border-top: 0;
  }

  .section-head {
    display: block;
  }

  .section-head p:last-child {
    margin-top: 8px;
    text-align: left;
  }

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

@media print {
  body {
    color: #111;
    background: #fff;
  }

  nav,
  .tools,
  .stock-actions,
  dialog,
  .toast {
    display: none;
  }

  .summary,
  .stock-card,
  .history,
  .movement {
    border-color: #ddd;
    background: #fff;
    box-shadow: none;
  }

  .brand img {
    width: 90px;
    filter: none;
  }
}
