:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --text: #1f2a2e;
  --muted: #68777d;
  --line: #dce4e2;
  --primary: #247c68;
  --primary-dark: #17614f;
  --accent: #b5854a;
  --danger: #b74444;
  --shadow: 0 12px 30px rgba(31, 42, 46, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.4;
}

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

button {
  cursor: pointer;
}

.auth-locked .app-header,
.auth-locked .main-nav,
.auth-locked .app-shell {
  display: none;
}

.access-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

body:not(.auth-locked) .access-screen {
  display: none;
}

.access-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-card h1 {
  margin: 0;
}

.session-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.password-toggle:active {
  transform: translateY(-50%) scale(0.94);
}

.password-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.password-toggle svg {
  display: block;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-header h1,
.section-heading h2,
.panel-heading h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.menu-toggle,
.nav-link,
.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.file-input {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}

.menu-toggle {
  background: var(--surface-soft);
  color: var(--text);
}

.main-nav {
  display: none;
  position: sticky;
  top: 73px;
  z-index: 15;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.main-nav.open {
  display: grid;
}

.nav-link {
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
}

.nav-link.active {
  background: var(--primary);
  color: #ffffff;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 36px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.summary-grid,
.list-grid,
.department-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.summary-card,
.item-card,
.department-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-card,
.item-card,
.department-card {
  padding: 16px;
}

.summary-card p,
.item-card p,
.department-card p {
  margin: 5px 0;
  color: var(--muted);
}

.summary-card strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 1.8rem;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
}

.panel-heading {
  margin-bottom: 12px;
}

.form-grid,
.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

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

.field-help {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.3;
}

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

textarea {
  resize: vertical;
}

.full-span {
  grid-column: 1 / -1;
}

.form-actions,
.card-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  background: var(--accent);
  color: #ffffff;
}

.ghost-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.danger-btn {
  background: var(--danger);
  color: #ffffff;
}

.compact-btn {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.file-input {
  display: inline-grid;
  place-items: center;
  background: var(--surface-soft);
  color: var(--text);
}

.file-input input {
  display: none;
}

.muted,
.form-message {
  color: var(--muted);
}

.form-message.success,
#exportMessage.success {
  color: var(--primary);
  font-weight: 700;
}

.form-message.error,
#exportMessage.error {
  color: var(--danger);
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  margin: 6px 0;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

.stock-mini-list,
.department-stock-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.department-stock-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.86rem;
}

.department-stock-row strong {
  color: var(--text);
}

.stock-status {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.stock-none {
  background: #f7d7d7;
  color: #8f1f1f;
}

.stock-review {
  background: #ffe1dc;
  color: #b23524;
}

.stock-low {
  background: #fff0c2;
  color: #8a5a00;
}

.stock-healthy {
  background: #dff3e9;
  color: #17614f;
}

.stock-inactive {
  background: #e8ecec;
  color: #68777d;
}

.history-table {
  display: none;
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.history-table th {
  background: var(--surface-soft);
  color: var(--text);
}

.history-cards {
  display: grid;
  gap: 12px;
}

.movement-voided {
  opacity: 0.68;
}

.movement-voided td,
.movement-voided p,
.movement-voided h3 {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(31, 42, 46, 0.45);
}

.modal-card {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-card h3 {
  margin-top: 0;
}

@media (min-width: 760px) {
  .menu-toggle {
    display: none;
  }

  .main-nav {
    display: flex;
    flex-wrap: wrap;
    top: 73px;
  }

  .nav-link {
    text-align: center;
  }

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

  .department-summary,
  .list-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid,
  .filter-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .history-table {
    display: table;
  }

  .history-cards {
    display: none;
  }
}

@media (min-width: 1040px) {
  .department-summary,
  .list-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}


/* =========================================================
   RESPONSIVE MOBILE FIX — LEVANO HOME
   Objetivo: mejorar usabilidad móvil sin tocar lógica JS
   ========================================================= */

/* Evita desbordes horizontales generales */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Previene zoom automático en iOS al enfocar campos */
input,
select,
textarea,
button {
  font-size: 16px;
}

/* Imágenes, tablas o elementos grandes no deben romper viewport */
table,
.history-table,
.panel,
.item-card,
.department-card,
.summary-card,
.access-card {
  max-width: 100%;
}

/* Ajuste móvil principal */
@media (max-width: 759px) {
  body {
    background: #eef3f2;
  }

  .app-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 10px 12px;
    padding: 14px 14px 12px;
  }

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

  .app-header h1 {
    font-size: clamp(1.7rem, 8vw, 2.15rem);
    line-height: 1.12;
    letter-spacing: -0.03em;
  }

  .app-header .eyebrow {
    font-size: 0.72rem;
  }

  .session-box {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
    font-size: 0.82rem;
  }

  .session-box span {
    min-width: 0;
    flex: 1;
    line-height: 1.25;
  }

  .session-box .compact-btn {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.82rem;
    background: #ffffff;
  }

  .menu-toggle {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    min-width: 72px;
    min-height: 44px;
    border-radius: 10px;
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(36, 124, 104, 0.22);
  }

  .main-nav {
    top: 132px;
    padding: 10px 14px 14px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .main-nav.open {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .nav-link {
    min-height: 42px;
    padding: 9px 10px;
    border-radius: 10px;
    font-size: 0.88rem;
    text-align: center;
  }

  .app-shell {
    width: 100%;
    padding: 14px 12px 32px;
  }

  .section-heading {
    display: block;
    margin-bottom: 14px;
  }

  .section-heading h2 {
    font-size: 1.35rem;
    line-height: 1.2;
  }

  .summary-grid,
  .department-summary,
  .list-grid,
  .form-grid,
  .filter-grid {
    gap: 10px;
  }

  .summary-card,
  .item-card,
  .department-card,
  .panel {
    border-radius: 12px;
    box-shadow: 0 8px 22px rgba(31, 42, 46, 0.06);
  }

  .summary-card,
  .item-card,
  .department-card {
    padding: 15px;
  }

  .summary-card strong {
    font-size: 1.75rem;
  }

  .panel {
    padding: 14px;
  }

  label {
    font-size: 0.88rem;
  }

  input,
  select,
  textarea {
    min-height: 46px;
    border-radius: 10px;
    padding: 11px 12px;
  }

  .form-actions,
  .card-actions,
  .export-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn,
  .file-input {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .department-stock-row {
    border-radius: 10px;
    font-size: 0.84rem;
  }

  .stock-mini-list {
    overflow-wrap: anywhere;
  }

  .history-cards .item-card {
    overflow-wrap: anywhere;
  }

  .modal-card {
    width: min(100%, 440px);
    border-radius: 14px;
  }
}

/* =========================================================
   HOTFIX MOBILE UI — LEVANO HOME
   Corrige header, sesión, menú y tarjetas en móvil
   ========================================================= */

@media (max-width: 759px) {
  .app-header {
    grid-template-columns: 1fr auto;
    align-items: start;
    padding: 18px 18px 14px;
    gap: 14px;
  }

  .app-header h1 {
    font-size: 2.15rem;
    line-height: 1.05;
    letter-spacing: -0.04em;
  }

  .app-header .eyebrow {
    font-size: 0.72rem;
    margin-bottom: 6px;
  }

  .menu-toggle {
    width: auto;
    min-width: 74px;
    min-height: 48px;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 1rem;
  }

  .session-box {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #eef5f3;
  }

  .session-box span {
    display: block;
    min-width: 0;
    font-size: 0.92rem;
    line-height: 1.25;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
  }

  .session-box .ghost-btn,
  .session-box .compact-btn {
    width: auto;
    min-width: 112px;
    max-width: 140px;
    min-height: 42px;
    padding: 8px 12px;
    font-size: 0.86rem;
    border-radius: 10px;
    background: #ffffff;
    text-align: center;
  }

  .app-shell {
    padding: 18px 14px 32px;
  }

  .section-heading {
    margin-bottom: 16px;
  }

  .section-heading h2 {
    font-size: 1.75rem;
    line-height: 1.1;
  }

  .summary-grid {
    gap: 12px;
  }

  .summary-card {
    min-height: auto;
    padding: 18px 20px;
    border-radius: 14px;
  }

  .summary-card p {
    margin: 0;
    font-size: 1rem;
    line-height: 1.25;
  }

  .summary-card strong {
    margin-top: 14px;
    font-size: 2rem;
    line-height: 1;
  }

  .main-nav {
    top: 154px;
  }

  .main-nav.open {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .nav-link {
    width: 100%;
    min-height: 44px;
    font-size: 0.9rem;
  }

  .form-actions .primary-btn,
  .form-actions .secondary-btn,
  .form-actions .ghost-btn,
  .form-actions .danger-btn,
  .card-actions .primary-btn,
  .card-actions .secondary-btn,
  .card-actions .ghost-btn,
  .card-actions .danger-btn,
  .export-actions .primary-btn,
  .export-actions .secondary-btn,
  .export-actions .ghost-btn,
  .export-actions .danger-btn,
  .file-input {
    width: 100%;
  }
}

/* =========================================================
   MOBILE STICKY HEADER — LEVANO HOME
   Mantiene header y menú accesibles durante el scroll
   ========================================================= */

@media (max-width: 759px) {
  .app-header {
    position: sticky;
    top: 0;
    z-index: 80;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }

  .main-nav {
    position: sticky;
    top: 158px;
    z-index: 70;
    max-height: calc(100vh - 170px);
    overflow-y: auto;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px rgba(31, 42, 46, 0.08);
  }

  .main-nav.open {
    animation: levanoMenuDrop 0.18s ease-out;
  }

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

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

/* =========================================================
   MOBILE FIXED HEADER — LEVANO HOME
   Header siempre visible durante el scroll
   ========================================================= */

@media (max-width: 759px) {
  .app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    width: 100%;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 24px rgba(31, 42, 46, 0.08);
  }

  .main-nav {
    position: fixed;
    top: 178px;
    left: 0;
    right: 0;
    z-index: 95;
    width: 100%;
    max-height: calc(100vh - 178px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 14px 28px rgba(31, 42, 46, 0.10);
  }

  .app-shell {
    padding-top: 198px;
  }
}

@media (max-width: 759px) {
  .menu-toggle[aria-expanded="true"] {
    min-width: 58px;
    width: 58px;
    padding: 10px;
    font-size: 1.35rem;
    line-height: 1;
    background: #1f2a2e;
    color: #ffffff;
  }
}