:root {
  --bg-top: #f5efe2;
  --bg-bottom: #d8e4dc;
  --card: #fffdfa;
  --text: #15221d;
  --muted: #4d5e56;
  --primary: #0f766e;
  --accent: #ca8a04;
  --dark: #1f2937;
  --danger: #b91c1c;
  --ok: #166534;
  --radius: 16px;
  --shadow: 0 14px 30px rgba(20, 32, 29, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 85% -10%, #f7c57f 0%, transparent 40%),
    radial-gradient(800px 560px at -10% 100%, #85c7c2 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

html {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  width: min(100%, 560px);
  margin: 0;
  padding: 18px 14px 28px;
  position: relative;
  animation: reveal 0.65s ease-out;
}

@media (max-height: 720px) {
  body {
    align-items: flex-start;
  }
}

.hero {
  margin-bottom: 12px;
  padding-right: 72px;
  min-height: 52px;
  display: flex;
  align-items: center;
}

.eyebrow {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 6px 0;
  font-size: clamp(1.6rem, 5vw, 2rem);
  line-height: 1.1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: color-mix(in srgb, var(--card) 88%, white 12%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(18, 43, 36, 0.1);
  padding: 0 16px 16px 16px;
  overflow-x: hidden;
}

label {
  display: block;
  margin: 12px 0 8px;
  font-weight: 600;
  font-size: 0.9rem;
}

input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  html {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  border: 1px solid rgba(18, 43, 36, 0.18);
  border-radius: 12px;
  background: #ffffff;
  padding: 12px;
  font-size: 1rem;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  touch-action: manipulation;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

input[readonly] {
  background: #f7f7f7;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.row.single {
  grid-template-columns: 1fr;
}

.search-results {
  margin-top: 8px;
  border: 1px solid rgba(18, 43, 36, 0.15);
  border-radius: 12px;
  background: #ffffff;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 10px 18px rgba(20, 32, 29, 0.12);
}

.search-result-item {
  width: 100%;
  border: none;
  border-bottom: 1px dashed rgba(18, 43, 36, 0.12);
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: #eef6f5;
}

.search-result-code {
  font-family: "DM Mono", monospace;
  color: #0f766e;
}

.search-result-name {
  margin-top: 2px;
  font-weight: 700;
  color: #1f2937;
}

.search-result-units {
  display: block;
  margin-top: 2px;
  font-size: 0.82rem;
  color: #4d5e56;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  font-family: "DM Mono", monospace;
  font-size: 0.86rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(1px) scale(0.995);
}

.primary {
  background: var(--primary);
  color: #ecfeff;
}

.ghost {
  background: #eef6f5;
  color: #134e4a;
}

.accent {
  background: var(--accent);
  color: #231207;
}

.dark {
  background: var(--dark);
  color: #f8fafc;
}

.quick-menu {
  position: absolute;
  right: 14px;
  top: 18px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.quick-menu-toggle {
  width: 52px;
  height: 52px;
  padding: 0;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  line-height: 0;
  color: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.2s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}

.quick-menu-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(31, 41, 55, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.quick-menu-toggle::before,
.quick-menu-toggle::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 2px;
  border-radius: 99px;
  background: #f8fafc;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.quick-menu-toggle::before {
  box-shadow: 0 -6px 0 #f8fafc, 0 6px 0 #f8fafc;
}

.quick-menu-toggle::after {
  opacity: 0;
}

.quick-menu-toggle[aria-expanded="true"]::before {
  transform: rotate(45deg);
  box-shadow: none;
}

.quick-menu-toggle[aria-expanded="true"]::after {
  opacity: 1;
  transform: rotate(-45deg);
}

.quick-menu-panel {
  display: grid;
  gap: 10px;
  min-width: 220px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(18, 43, 36, 0.18);
  box-shadow: 0 18px 36px rgba(20, 32, 29, 0.2);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(246, 251, 249, 0.96) 100%);
  backdrop-filter: blur(8px);
  transform-origin: top right;
  animation: menuDrop 0.2s ease-out;
}

.quick-menu-panel[hidden] {
  display: none;
}

.quick-menu-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(18, 43, 36, 0.08);
  box-shadow: 0 4px 10px rgba(18, 43, 36, 0.08);
  transition: transform 0.18s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.quick-menu-item:hover {
  transform: translateX(-2px);
  box-shadow: 0 8px 16px rgba(18, 43, 36, 0.14);
  filter: saturate(1.05);
}

.add-product-btn {
  margin-top: 12px;
  width: 100%;
}

#bloqueBaja {
  min-width: 0;
}

#fechaBaja {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  min-height: 46px;
  line-height: 1.2;
  font-size: 1rem;
  font-family: "Space Grotesk", sans-serif;
}

#fechaBaja::-webkit-date-and-time-value {
  text-align: left;
}

#fechaBaja::-webkit-datetime-edit {
  padding: 0;
  line-height: 1.2;
}

.history-card {
  margin-top: 14px;
  background: color-mix(in srgb, var(--card) 88%, white 12%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(18, 43, 36, 0.1);
  padding: 12px;
}

.history-card h2 {
  margin: 4px 4px 10px;
  font-size: 0.95rem;
}

.history-wrapper {
  max-height: 170px;
  overflow-y: auto;
  border: 1px solid rgba(18, 43, 36, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.history-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 8px;
  background: #edf5f2;
  color: #23443c;
  border-bottom: 1px solid rgba(18, 43, 36, 0.12);
}

.history-table tbody td {
  padding: 8px;
  border-bottom: 1px dashed rgba(18, 43, 36, 0.12);
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table tbody tr.history-clickable {
  cursor: pointer;
}

.history-table tbody tr.history-clickable:hover {
  background: #eef6f5;
}

.history-empty td {
  text-align: center;
  color: var(--muted);
}

.confirm-menu {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.confirm-menu-card {
  width: min(100%, 520px);
  background: #fffefc;
  border-radius: 18px;
  border: 1px solid rgba(18, 43, 36, 0.12);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
  padding: 18px;
  animation: reveal 0.2s ease-out;
}

.confirm-code {
  margin: 0;
  font-family: "DM Mono", monospace;
  font-size: 0.96rem;
  color: #14532d;
}

.confirm-name {
  margin: 6px 0 8px;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  line-height: 1.15;
}

.confirm-detail {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.stepper-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}

.stepper-btn {
  padding: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  border: 1px solid rgba(18, 43, 36, 0.12);
}

.confirm-summary {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef6f5;
  border: 1px solid rgba(18, 43, 36, 0.12);
  color: #134e4a;
  font-weight: 600;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hidden {
  display: none !important;
}

.status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(18, 43, 36, 0.12);
  min-height: 44px;
  display: flex;
  align-items: center;
  white-space: pre-line;
  color: var(--muted);
}

.status.ok {
  color: var(--ok);
  border-color: rgba(22, 101, 52, 0.28);
}

.status.error {
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.26);
}

.status.warning {
  color: #92400e;
  border-color: rgba(202, 138, 4, 0.35);
}

.status .status-content {
  display: block;
}

.status .invalid-highlight {
  color: var(--danger);
}

@media (max-width: 360px) {
  .screen {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-height: 100dvh;
    padding: 10px 8px 14px;
    overflow: hidden;
  }

  .hero {
    margin-bottom: 8px;
    padding-right: 54px;
    min-height: 38px;
  }

  h1 {
    margin: 0;
    font-size: 1.28rem;
  }

  .card {
    padding: 0 10px 10px 10px;
  }

  .history-card {
    padding: 10px;
  }

  label {
    margin: 8px 0 6px;
    font-size: 0.82rem;
  }

  input {
    padding: 10px;
    font-size: 0.95rem;
  }

  .btn {
    padding: 10px 12px;
    font-size: 0.8rem;
  }

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

  .search-results {
    max-height: 180px;
  }

  #fechaBaja {
    font-size: 0.95rem;
    width: 100%;
    max-width: 100%;
  }

  .quick-menu-toggle {
    width: 46px;
    height: 46px;
  }

  .quick-menu-panel {
    min-width: 180px;
  }

  .history-card {
    margin-top: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
  }

  .history-card h2 {
    flex: 0 0 auto;
  }

  .history-wrapper {
    height: auto;
    max-height: none;
    min-height: 0;
    flex: 1 1 auto;
  }

  .status {
    margin-top: 8px;
    min-height: 36px;
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .confirm-menu {
    padding: 10px;
  }

  .confirm-menu-card {
    padding: 12px;
  }

  .confirm-name {
    font-size: 1.15rem;
  }

  .confirm-detail,
  .confirm-summary {
    font-size: 0.86rem;
  }

  .confirm-grid,
  .confirm-actions {
    grid-template-columns: 1fr;
  }

  .stepper-row {
    grid-template-columns: 44px 1fr 44px;
  }
}

@media (max-width: 768px) {
  .screen {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-height: 100dvh;
    padding-top: 12px;
    padding-bottom: 18px;
    overflow: hidden;
  }

  .hero {
    padding-right: 60px;
    min-height: 40px;
    margin-bottom: 10px;
  }

  .card {
    padding: 0 12px 12px 12px;
  }

  .history-card {
    padding: 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
  }

  .history-wrapper {
    height: auto;
    max-height: none;
    min-height: 0;
    flex: 1 1 auto;
  }

  .history-card h2 {
    margin: 2px 4px 8px;
    font-size: 0.9rem;
  }

  .quick-menu {
    right: 12px;
    top: 18px;
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

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

@keyframes menuDrop {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }

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