:root {
  color-scheme: light;
  --page: #f6f3ed;
  --surface: #ffffff;
  --surface-soft: #fbf8f2;
  --text: #201b17;
  --muted: #766b60;
  --line: #e3dbcf;
  --line-strong: #d3c6b7;
  --brand: #8d2118;
  --brand-hover: #70170f;
  --brand-soft: #fff1ed;
  --olive: #4f6042;
  --olive-hover: #3d4c32;
  --gold: #b9872e;
  --danger: #af2b22;
  --danger-hover: #8e1f18;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 45px rgb(62 48 36 / 10%);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
  background: var(--page);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 15px;
  background: var(--brand);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

button:hover {
  background: var(--brand-hover);
}

button:active {
  transform: translateY(1px);
}

button.ghost {
  background: white;
  color: var(--text);
  border: 1px solid var(--line-strong);
}

button.ghost:hover {
  background: var(--surface-soft);
}

button.secondary {
  background: var(--olive);
}

button.secondary:hover {
  background: var(--olive-hover);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: var(--danger-hover);
}

input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 11px;
  background: white;
  color: var(--text);
}

input:focus {
  outline: 3px solid rgb(141 33 24 / 16%);
  border-color: var(--brand);
}

input::placeholder {
  color: #a2968a;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 18px;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: 132px;
  max-height: 82px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 5px;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 22px;
}

.status {
  min-width: 150px;
  text-align: right;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.session-box {
  display: flex;
  gap: 12px;
  align-items: center;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 22px 32px 32px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 0.7fr) minmax(420px, 1fr);
  gap: 16px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.inline-form,
.filters {
  display: grid;
  gap: 12px;
  align-items: end;
}

.inline-form {
  grid-template-columns: minmax(180px, 1fr) auto;
}

.filters {
  grid-template-columns: minmax(180px, 1fr) 120px auto;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  color: var(--text);
}

.check input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}

.table-wrap {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1eadf;
  color: #4a4037;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
}

tbody tr:hover {
  background: var(--surface-soft);
}

tr.expiring {
  background: var(--danger-soft);
}

tr.expiring td:first-child {
  box-shadow: inset 4px 0 0 var(--danger);
}

.total {
  width: 150px;
  font-weight: 800;
}

.lots {
  color: var(--muted);
  line-height: 1.45;
}

.actions {
  width: 220px;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.empty {
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.app-dialog {
  width: min(760px, calc(100% - 28px));
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: transparent;
  box-shadow: 0 28px 90px rgb(0 0 0 / 22%);
}

.small-dialog {
  width: min(460px, calc(100% - 28px));
}

.app-dialog::backdrop {
  background: rgb(32 27 23 / 48%);
  backdrop-filter: blur(2px);
}

.dialog-card {
  padding: 20px;
  background: var(--surface);
  border-radius: 14px;
}

.dialog-card header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.dialog-copy {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.lot-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px auto;
  gap: 12px;
  align-items: end;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.quantity-form {
  margin-bottom: 18px;
}

.password-form {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.batch-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.batch-row {
  display: grid;
  grid-template-columns: 1fr 90px auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}

.batch-date {
  font-weight: 800;
}

.batch-actions {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 10px;
  background: #201b17;
  color: white;
  box-shadow: 0 18px 50px rgb(0 0 0 / 25%);
  font-weight: 700;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at top left, rgb(185 135 46 / 16%), transparent 34%),
    var(--page);
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  display: grid;
  justify-items: center;
  text-align: center;
}

.login-brand img {
  width: 150px;
  max-height: 90px;
  object-fit: contain;
  margin-bottom: 20px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-error {
  margin: 0;
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 1050px) {
  .toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .brand {
    gap: 12px;
  }

  .brand img {
    width: 92px;
  }

  h1 {
    font-size: 24px;
  }

  .status {
    min-width: auto;
    font-size: 12px;
  }

  .session-box {
    align-items: flex-end;
    flex-direction: column;
  }

  .workspace {
    padding: 14px;
    gap: 14px;
  }

  .toolbar,
  .inline-form,
  .filters,
  .lot-form,
  .batch-row {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td:last-child {
    border-bottom: 0;
  }

  .total,
  .actions {
    width: auto;
  }

  .row-actions,
  .batch-actions,
  .dialog-actions {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .row-actions button,
  .batch-actions button,
  .dialog-actions button {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .topbar {
    display: grid;
  }

  .status {
    text-align: left;
  }

  .session-box {
    align-items: flex-start;
  }

  td {
    grid-template-columns: 1fr;
  }
}

[hidden] { display: none !important; }
.inventory-menus { display: flex; gap: 8px; flex-wrap: wrap; }
.barcode { display: block; color: var(--muted); font-size: 12px; font-weight: 400; overflow-wrap: anywhere; }
.mobile-unit { display: none; }
.compact-action { display: none; }
select { width: 100%; min-height: 44px; font: inherit; padding: 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: white; }
.app-dialog { max-height: calc(100dvh - 28px); overflow-y: auto; }
@media (max-width: 760px) {
  .topbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand img { width: 56px; max-height: 44px; }
  .brand .eyebrow { display: none; }
  h1 { font-size: 20px; }
  .session-box { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
  .session-box button { min-height: 36px; padding: 0 10px; }
  .workspace { padding: 10px; gap: 10px; grid-template-rows: auto auto; align-content: start; }
  .toolbar { padding: 10px; gap: 10px; }
  .inventory-menus button { flex: 1; min-height: 44px; padding: 6px 8px; font-size: 13px; }
  .filters { grid-template-columns: minmax(0, 1fr) 85px; gap: 8px; }
  .check { grid-column: 1 / -1; min-height: 28px; }
  input { font-size: 16px; }
  tbody { gap: 3px; }
  tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-rows: auto auto; padding: 6px 8px; gap: 2px 8px; box-shadow: none; border-radius: 6px; align-items: center; }
  tbody td { display: block; padding: 0; border: 0; min-width: 0; }
  tbody td::before { display: none; }
  .article-title { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
  .article-title .barcode { display: none; }
  .total { text-align: right; }
  .mobile-unit { display: inline; }
  .lots { grid-column: 1 / 3; grid-row: 2; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  tbody td:last-child { grid-column: 3; grid-row: 1 / 3; }
  .row-actions { justify-content: flex-end; gap: 4px; flex-wrap: nowrap; }
  .row-actions button { flex: none; min-height: 36px; width: 36px; padding: 0; font-size: 22px; border-radius: 6px; }
  .desktop-action { display: none; }
  .compact-action { display: inline; }
  tr.expiring td:first-child { box-shadow: none; }
  tr.expiring { border-left: 4px solid var(--danger); }
  .batch-row { grid-template-columns: 1fr auto; gap: 8px; }
  .batch-actions { grid-column: 1 / -1; }
  .dialog-card { padding: 14px; }
}
.logout-icon { vertical-align: middle; }
.logout-text { margin-left: 6px; }
.code-entry { display: flex; gap: 6px; min-width: 0; }
.code-entry input { flex: 1; min-width: 0; }
.code-entry button { flex-shrink: 0; padding: 0 10px; }
.app-dialog { max-height: calc(var(--dialog-height, 100dvh) - 16px); }
@media (max-width: 760px) {
  .topbar { flex-wrap: nowrap; gap: 6px; }
  .brand { min-width: 0; gap: 8px; }
  .brand h1 { font-size: 18px; }
  .brand img { width: 42px; }
  .session-box { margin-left: auto; flex-shrink: 0; }
  #status, #passwordButton, .logout-text { display: none; }
  #logoutButton { width: 40px; height: 40px; padding: 0; }
  .article-title .barcode { display: block; font-size: 11px; line-height: 1.25; }
  .row-actions button { min-height: 40px; width: 40px; }
  .app-dialog { width: calc(100% - 12px); margin: auto; }
  .dialog-card { padding: 12px; }
  .dialog-card h2 { font-size: 18px; }
  .dialog-card header { margin-bottom: 4px; }
  .password-form { gap: 8px; margin-bottom: 0; }
  .dialog-copy, #scanMessage { margin: 0; font-size: 13px; }
  #scanFields { grid-template-columns: minmax(0, 1fr) 95px; }
  #scanNameLabel, #scanBatchLabel, #applyScan { grid-column: 1 / -1; }
  .dialog-actions { position: sticky; bottom: 0; background: white; padding-top: 8px; }
  .dialog-actions button { flex: 1; padding: 0 8px; }
  #scanExpiry { min-width: 0; }
}

.stock-count { display: inline-flex; align-items: center; justify-content: center; gap: 3px; min-width: 46px; min-height: 40px; padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-soft); color: var(--text); font-weight: 700; white-space: nowrap; }

@media (max-width: 760px) {
  tbody tr .total { grid-column: 2; grid-row: 1 / 3; align-self: center; }
}
@media (max-width: 760px) {
  tbody tr .lots { grid-column: 1; }
}

.filter-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-actions .check { margin: 0; }
#clearFilters { min-height: 36px; font-size: 13px; padding: 0 10px; }
button.withdraw { background: #a45d17; color: white; }
button.withdraw:hover { background: #824711; }
@media (max-width: 760px) {
  .filter-actions { grid-column: 1 / -1; justify-content: space-between; gap: 6px; }
}

.row-actions button[data-action="edit"] { background: #246394; border-color: #246394; color: white; }
.row-actions button[data-action="edit"]:hover { background: #194b73; border-color: #194b73; }

.scan-header-actions { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 760px) {
  #scanForm header { gap: 8px; flex-wrap: wrap; }
  .scan-header-actions button { padding: 0 10px; }
}

/* Las notificaciones se alojan dentro del diálogo activo para quedar en su capa. */
.toast {
  top: max(12px, env(safe-area-inset-top));
  bottom: auto;
  right: 12px;
  max-width: min(420px, calc(100vw - 24px));
  z-index: 1000;
  pointer-events: none;
  overflow-wrap: anywhere;
}
.shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
.workspace {
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
}
.table-wrap {
  min-height: 0;
  overflow: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}

.stock-count.out-of-stock { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); font-size: 12px; white-space: normal; max-width: 74px; text-align: center; line-height: 1.15; }
.toast {
  left: 50%;
  right: auto;
  top: max(18px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(520px, calc(100vw - 24px));
  padding: 16px 20px;
  border: 2px solid white;
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 8px 30px rgb(0 0 0 / 40%);
}
@media (max-width: 760px) {
  .toast { width: calc(100vw - 24px); }
}

.stock-count { width: 64px; height: 40px; min-width: 64px; padding: 4px; }
.stock-count.out-of-stock { width: 64px; height: 40px; max-width: 64px; }

.toast {
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  max-height: 32dvh;
  overflow-y: auto;
  pointer-events: auto;
}
.toast-notice {
  padding: 14px 18px;
  border: 2px solid white;
  border-radius: 12px;
  background: #201b17;
  color: white;
  box-shadow: 0 4px 12px rgb(0 0 0 / 25%);
}
#scanMessage:not(:empty) {
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  font-weight: 700;
}

.shell { grid-template-rows: auto minmax(0, 1fr) auto; }
.provider-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: calc(44px + env(safe-area-inset-bottom, 0px));
  padding: 0 12px env(safe-area-inset-bottom, 0px);
  background: white;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.provider-footer a { display: inline-flex; align-items: center; min-height: 44px; color: var(--text); text-decoration: none; }
.provider-footer a:hover { text-decoration: underline; }
.provider-footer img { display: block; object-fit: contain; }
.login-page { min-height: 100dvh; padding: 0; grid-template-rows: minmax(0, 1fr) auto; }
.login-page .login-shell { width: min(460px, 100%); padding: 20px; }
.login-page .provider-footer { width: 100%; }
.date-entry { display: flex; gap: 6px; min-width: 0; }
.date-entry input { min-width: 0; flex: 1; }
.date-open { flex: none; width: 44px; padding: 0; font-size: 24px; }
.calendar-dialog { width: min(420px, calc(100% - 12px)); }
.calendar-navigation { display: grid; grid-template-columns: 40px minmax(0, 1fr) 88px 40px; gap: 6px; margin-bottom: 12px; }
.calendar-navigation button { padding: 0; font-size: 24px; }
.calendar-navigation input, .calendar-navigation select { min-width: 0; padding: 6px; font-size: 16px; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar-weekdays { text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
button.calendar-day { min-height: 40px; padding: 0; }
button.calendar-day[aria-current="date"] { border: 2px solid var(--brand); }
button.calendar-day[aria-pressed="true"] { background: var(--brand); color: white; }
.calendar-help { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
/* Impide que el gesto al llegar al borde se propague a la recarga del navegador. */
html, body { overscroll-behavior-y: none; }
.table-wrap, .app-dialog, .toast { overscroll-behavior-y: none; }
