:root {
  --page-bg: #f4f6f8;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #eef5fb;
  --ink: #1d1d1d;
  --muted: #6f6963;
  --line: #d8dde4;
  --teal: #6aa8d6;
  --teal-dark: #2f5f8a;
  --green: #2f8f46;
  --amber: #b26b00;
  --red: #b42318;
  --violet: #5568a9;
  --primary-ink: #ffffff;
  --shadow: 0 10px 24px rgba(25, 31, 38, 0.1);
  --phone-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  --app-font-family: Arial, Helvetica, sans-serif;
  --base-font-size: 15px;
  --small-font-size: 12px;
  --label-font-size: 13px;
  --title-font-size: 22px;
  --screen-title-size: 24px;
  --button-font-size: 14px;
  --mobile-max-width: 430px;
  --radius: 8px;
  --form-gap: 12px;
  --touch-target: 44px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--app-font-family);
  font-size: var(--base-font-size);
  line-height: 1.4;
}

.login-screen {
  align-items: center;
  background: var(--page-bg);
  display: grid;
  min-height: 100svh;
  padding: 18px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  display: grid;
  gap: 12px;
  margin: 0 auto;
  max-width: var(--mobile-max-width);
  padding: 20px;
  width: 100%;
}

.login-logo {
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  display: block;
  max-height: 118px;
  object-fit: contain;
  width: 100%;
}

.company-name {
  color: var(--muted);
  font-size: var(--small-font-size);
  font-weight: 700;
  margin: 0;
  text-transform: uppercase;
}

.login-card label {
  color: var(--muted);
}

button,
input,
select,
textarea {
  font: inherit;
}

#appFrame {
  background: var(--bg);
  margin: 0 auto;
  min-height: 100svh;
  width: 100%;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: auto minmax(0, 1fr);
  padding: 10px 12px 12px;
  position: static;
  z-index: 10;
}

.brand-row {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
  width: auto;
}

.top-logo {
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  display: block;
  flex: 0 0 31px;
  height: 44px;
  object-fit: cover;
  object-position: left center;
  width: 31px;
}

.top-actions {
  display: contents;
}

.top-controls {
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
}

.top-controls .ghost-button {
  padding-inline: 8px;
  width: 100%;
}

.user-pill {
  background: var(--surface-strong);
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 999px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
  justify-self: end;
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 7px 10px;
  white-space: normal;
}

.sync { white-space: nowrap; }

.topbar h1,
.section-heading h2,
.panel h3 {
  margin: 0;
}

.topbar h1 {
  font-size: var(--title-font-size);
}

.tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px 12px;
  position: static;
  z-index: 9;
}

.header-menu.is-hidden { display: none; }
.account-menu {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 10px 12px;
}

.tab,
.ghost-button,
.primary-button,
.submit-button,
.danger-button,
.small-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--button-font-size);
  min-height: var(--touch-target);
  white-space: nowrap;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.tab {
  background: #f8fafc;
  color: var(--muted);
  padding: 9px 13px;
  text-align: left;
  white-space: normal;
  width: 100%;
}

.tab.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--primary-ink);
  font-weight: 700;
}

.ghost-button {
  background: white;
  color: var(--teal-dark);
  padding: 8px 12px;
}

.text-button {
  align-self: start;
  background: transparent;
  border: 0;
  color: var(--teal-dark);
  cursor: pointer;
  font: inherit;
  min-height: 32px;
  padding: 5px 0 0;
  text-align: left;
}

.text-button:hover,
.text-button:focus-visible {
  text-decoration: underline;
}

.primary-button,
.submit-button {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--primary-ink);
  font-weight: 700;
  padding: 10px 14px;
}

.submit-button {
  width: 100%;
}

.small-button {
  background: white;
  color: var(--ink);
  min-height: 36px;
  padding: 7px 10px;
}

.small-button.danger {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--red);
}

.danger-button {
  background: #fff;
  border-color: var(--red);
  color: var(--red);
  font-weight: 700;
  padding: 8px 12px;
  width: 100%;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: var(--red);
  color: #fff;
}

.app-shell {
  margin: 0 auto;
  max-width: 100%;
  padding: 16px;
}

.view {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.is-hidden {
  display: none;
}

.section-heading {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.section-heading.compact {
  align-items: center;
}

.section-heading h2 {
  font-size: var(--screen-title-size);
}

.section-heading select {
  max-width: 48%;
}

.sync {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}

.form-grid,
.item-fields {
  display: grid;
  gap: var(--form-gap);
  grid-template-columns: 1fr;
}

label {
  color: var(--muted);
  display: grid;
  font-size: var(--label-font-size);
  gap: 6px;
}

input,
select {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: var(--touch-target);
  padding: 9px 10px;
  width: 100%;
}

.password-field {
  display: block;
  position: relative;
}

.password-field input {
  padding-right: 52px;
}

.password-reveal-button {
  background: transparent;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  min-height: 40px;
  padding: 8px;
  place-items: center;
  position: absolute;
  right: 2px;
  top: 50%;
  touch-action: manipulation;
  transform: translateY(-50%);
  user-select: none;
  width: 42px;
  -webkit-user-select: none;
}

.password-eye-icon {
  fill: none;
  height: 19px;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 19px;
}

.password-reveal-button:hover,
.password-reveal-button:focus-visible {
  color: var(--teal-dark);
}

.password-reveal-button[aria-pressed="true"] {
  background: var(--surface-strong);
  color: var(--teal-dark);
}

.svg-symbols {
  height: 0;
  overflow: hidden;
  position: absolute;
  width: 0;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 2px;
}

.item-builder {
  display: grid;
  gap: 12px;
}

.cart {
  display: grid;
  gap: 8px;
  min-height: 38px;
}

.cart-row {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr auto;
  padding: 10px;
}

.cart-row strong {
  display: block;
}

.cart-row span {
  color: var(--muted);
  font-size: 13px;
}

.orders-section {
  display: grid;
  gap: 10px;
}

.order-list {
  display: grid;
  gap: 10px;
}

.empty {
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

.order-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 14px;
}

.order-card > * {
  min-width: 470px;
}

.order-card header {
  align-items: start;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.order-no {
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 8px;
}

.badge.pending_review {
  background: #fff7ed;
  color: var(--amber);
}

.badge.pendiente {
  background: #fff7ed;
  color: var(--amber);
}

.badge.verified {
  background: #eef2ff;
  color: var(--violet);
}

.badge.aprobado {
  background: #f0fdf4;
  color: var(--green);
}

.badge.negado {
  background: #fef2f2;
  color: var(--red);
}

.badge.invoiced {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge.dispatched {
  background: #fefce8;
  color: #854d0e;
}

.badge.received {
  background: #f0fdf4;
  color: var(--green);
}

.badge.cancelled {
  background: #fef2f2;
  color: var(--red);
}

.line-items {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
  padding-top: 8px;
}

.line-item {
  display: grid;
  gap: 4px;
  grid-template-columns: minmax(70px, auto) 1fr auto;
}

.line-item small {
  color: var(--muted);
}

.toast {
  background: var(--ink);
  border-radius: var(--radius);
  bottom: 16px;
  color: white;
  left: 50%;
  max-width: calc(100% - 32px);
  opacity: 0;
  padding: 10px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 16px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 520px) {
  body {
    padding: 20px 0;
  }

  #appFrame {
    border: 1px solid #2b3036;
    border-radius: 24px;
    box-shadow: var(--phone-shadow);
    max-width: var(--mobile-max-width);
    min-height: calc(100svh - 40px);
    overflow: hidden;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: 1 / -1;
  }

  .item-fields {
    align-items: end;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-fields label:first-child,
  .item-fields .primary-button {
    grid-column: 1 / -1;
  }

}

/* Vista amplia para computadoras. La experiencia móvil permanece intacta. */
@media (min-width: 900px) {
  body {
    padding: 0;
  }

  #appFrame {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: none;
    min-height: 100svh;
    overflow: visible;
    position: relative;
  }

  .topbar {
    grid-template-columns: auto minmax(180px, 1fr) auto;
    padding: 12px max(24px, calc((100vw - 1280px) / 2 + 24px));
  }

  .top-controls {
    grid-column: auto;
    grid-template-columns: repeat(3, 124px);
    min-width: 0;
    width: auto;
  }

  .user-pill {
    max-width: 360px;
  }

  .tabs,
  .account-menu {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    grid-template-columns: 1fr;
    padding: 8px;
    position: absolute;
    top: 72px;
    width: 250px;
    z-index: 30;
  }

  .tabs {
    right: max(288px, calc((100vw - 1280px) / 2 + 288px));
  }

  .account-menu {
    grid-template-columns: 1fr;
    right: max(24px, calc((100vw - 1280px) / 2 + 24px));
  }

  .tabs .tab,
  .account-menu .tab {
    min-height: 38px;
    padding: 7px 10px;
  }

  .app-shell {
    max-width: 1280px;
    padding: 12px 24px 32px;
  }

  /* Jerarquía tipográfica uniforme para todas las vistas de escritorio. */
  .section-heading h2 {
    color: var(--ink);
    font-size: var(--screen-title-size);
    line-height: 1.2;
  }

  .panel h3 {
    color: var(--ink);
    font-size: 17px;
    line-height: 1.25;
  }

  .sync,
  .panel small {
    color: var(--muted);
    font-size: var(--small-font-size);
  }

  /* Respuesta visual para mouse, sin modificar la experiencia táctil móvil. */
  @media (hover: hover) and (pointer: fine) {
    button:not(:disabled),
    input:not(:disabled),
    select:not(:disabled),
    .check-select {
      transition: background-color 140ms ease, border-color 140ms ease,
        box-shadow 140ms ease, color 140ms ease;
    }

    .ghost-button:not(:disabled):hover,
    .small-button:not(:disabled):hover,
    .tab:not(.is-active):not(:disabled):hover,
    .account-admin-option:not(.is-active):not(:disabled):hover {
      background: #eef2f6;
      border-color: #bcc7d3;
      color: var(--teal-dark);
    }

    .primary-button:not(:disabled):hover,
    .submit-button:not(:disabled):hover,
    .tab.is-active:not(:disabled):hover,
    .account-admin-option.is-active:not(:disabled):hover {
      background: #5799ca;
      border-color: #5799ca;
    }

    .danger-button:not(:disabled):hover,
    .small-button.danger:not(:disabled):hover {
      background: #fef2f2;
      border-color: var(--red);
      color: var(--red);
    }

    input:not(:disabled):hover,
    select:not(:disabled):hover {
      background: #fbfdff;
      border-color: #aebdca;
    }

    .check-select:hover {
      background: #f3f6f9;
      border-radius: var(--radius);
      cursor: pointer;
    }
  }

  .view[data-panel="seller"] {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }

  .view[data-panel="seller"] > .section-heading,
  .view[data-panel="seller"] > .orders-section {
    grid-column: 1 / -1;
  }

  .item-fields {
    grid-template-columns: minmax(190px, 2fr) repeat(2, minmax(100px, 1fr));
  }

  .item-fields label:first-child {
    grid-column: auto;
  }

  .item-fields .primary-button {
    grid-column: 1 / -1;
  }

  .order-card > * {
    min-width: 0;
  }

  .view[data-panel="checks"] {
    grid-template-columns: 1fr;
  }

  .view[data-panel="checks"] > .section-heading {
    align-items: end;
    justify-content: flex-start;
  }

  .view[data-panel="checks"] > .section-heading .ghost-button {
    min-height: 36px;
    padding-block: 6px;
  }

  .view[data-panel="checks"] .check-actions {
    align-content: end;
    background: transparent;
    border: 0;
    box-shadow: none;
    justify-items: center;
    margin: -4px 0 4px;
    padding: 0;
  }

  .view[data-panel="checks"] .check-actions .submit-button {
    min-height: 40px;
    width: min(320px, 100%);
  }

  .view[data-panel="checks"] .check-search-panel {
    margin-bottom: 0;
    width: 100%;
  }

  .check-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view[data-panel="users"] {
    margin-inline: auto;
    max-width: none;
    width: 100%;
  }

  #newUserForm {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view[data-panel="users"] .account-admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .view[data-panel="users"] .account-admin-option {
    min-height: 38px;
    padding: 7px 12px;
    width: auto;
  }

  #newUserForm > .submit-button {
    justify-self: center;
    min-height: 40px;
    width: min(260px, 100%);
  }

  .managed-users {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr); }

  /* Safari en iPhone amplía automáticamente campos con texto menor a 16 px. */
  input,
  select,
  textarea {
    font-size: 16px;
  }
}
.access-options {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
  padding: 12px 14px 14px;
}
.access-options legend {
  color: var(--muted);
  font-size: var(--label-font-size);
  font-weight: 400;
  line-height: 1.4;
  padding: 0 4px;
}
.access-options label {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: row;
  font-size: var(--label-font-size);
  gap: 8px;
  margin-top: 8px;
}
.access-options input { width: auto; min-height: auto; }
.managed-users { display: grid; gap: 8px; margin-top: 14px; }
.managed-user { display: grid; gap: 3px; padding: 12px; border: 1px solid var(--line); border-radius: var(--border-radius); background: var(--surface); }
.managed-user small, .muted { color: var(--muted); }
.managed-user label { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.managed-user input { width: auto; min-height: auto; }
.managed-user .admin-password-reset label {
  align-items: stretch;
  display: grid;
  gap: 6px;
}
.managed-user .admin-password-reset input {
  min-height: var(--touch-target);
  width: 100%;
}
.managed-accesses { display: grid; gap: 6px; padding: 8px 0; }
.account-admin-nav { display: grid; gap: 8px; grid-template-columns: 1fr; margin-bottom: 12px; }
.account-admin-option {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--teal-dark);
  cursor: pointer;
  font-size: var(--button-font-size);
  min-height: var(--touch-target);
  padding: 9px 13px;
  text-align: left;
  width: 100%;
}
.account-admin-option.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--primary-ink);
  font-weight: 700;
}
.account-search-panel { margin-bottom: 12px; }
.account-search-panel small { color: var(--muted); display: block; margin-top: 8px; }
.check-actions { display: grid; gap: 10px; margin-bottom: 12px; }
.check-all-actions { margin-bottom: 0; margin-top: 12px; }
.check-search-panel { margin-bottom: 12px; }
.password-modal {
  align-items: center;
  background: rgba(20, 28, 36, 0.58);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 50;
}
.password-modal.is-hidden { display: none; }
.password-card { display: grid; gap: 12px; max-width: 390px; width: 100%; }
.password-card h2 { margin: 0; }
.password-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.admin-password-reset { border-top: 1px solid var(--line); display: grid; gap: 8px; padding-top: 10px; }
.admin-password-reset.is-hidden { display: none; }
.admin-password-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.check-actions label, .check-select { display: flex; flex-direction: row; align-items: center; gap: 9px; }
.check-actions input, .check-select input { min-height: auto; width: auto; }
.check-list { display: grid; gap: 10px; }
.check-list > .empty-state { grid-column: 1 / -1; }
.check-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px; }
.check-select { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.check-fields { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin: 12px 0 0; }
.check-fields div { min-width: 0; }
.check-fields dt { color: var(--muted); font-size: var(--small-font-size); }
.check-fields dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.check-fields .wide { grid-column: 1 / -1; }
