/* R&H Distribuciones — design tokens */
:root {
  --ryh-azul-claro: #1AC0F0;
  --ryh-azul-corp:  #1A4FB8;
  --ryh-azul-oscuro:#0E2A6B;
  --ryh-blanco:     #FFFFFF;

  --gris-fondo:     #F4F6FA;
  --gris-borde:     #D8DEE8;
  --gris-texto:     #1F2A44;
  --gris-suave:     #6B7388;

  --rojo:           #D64545;
  --verde:          #2EA56B;
  --ambar:          #E0A02F;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(14,42,107,.08);
  --shadow-md: 0 4px 12px rgba(14,42,107,.12);
  --shadow-lg: 0 8px 24px rgba(14,42,107,.18);

  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0);

  --gradient-corp: linear-gradient(135deg, var(--ryh-azul-corp) 0%, var(--ryh-azul-oscuro) 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--gris-fondo);
  color: var(--gris-texto);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 12px;
  background: var(--gradient-corp);
  color: var(--ryh-blanco);
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; flex-direction: column; line-height: 1; }
.brand-mark { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.brand-sub  { font-size: 9px; opacity: .85; letter-spacing: 2px; font-style: italic; margin-top: 2px; }
.icon-btn {
  background: transparent; color: var(--ryh-blanco); border: 0;
  width: 40px; height: 40px; border-radius: var(--radius-sm); font-size: 22px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.12); }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.net-pill {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
  background: var(--verde);
}
.net-pill.net-offline { background: var(--rojo); animation: pulse 1.5s infinite; }
.draft-pill {
  background: var(--ambar); color: #2a1c00; padding: 2px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 700; min-width: 20px; text-align: center;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ===== Layout ===== */
.screen { padding: 16px; max-width: 960px; margin: 0 auto; padding-bottom: calc(16px + var(--safe-bottom)); }
.view-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--topbar-h)); gap: 16px; color: var(--gris-suave);
}

/* ===== Loader ===== */
.loader {
  width: 36px; height: 36px; border: 4px solid var(--gris-borde);
  border-top-color: var(--ryh-azul-corp); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--gradient-corp);
  padding: 24px;
}
.login-card {
  background: var(--ryh-blanco); border-radius: var(--radius-lg);
  padding: 32px 24px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center; margin-bottom: 24px;
}
.login-logo .brand-mark { color: var(--ryh-azul-corp); font-size: 32px; }
.login-logo .brand-sub  { color: var(--ryh-azul-claro); font-size: 11px; }
.login-card h1 { font-size: 20px; margin: 0 0 16px; text-align: center; color: var(--ryh-azul-oscuro); }

/* ===== Form ===== */
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-field label { font-size: 13px; color: var(--gris-suave); font-weight: 600; }
.form-field input, .form-field select, .form-field textarea {
  font: inherit; padding: 12px 14px; border: 1.5px solid var(--gris-borde);
  border-radius: var(--radius-sm); background: var(--ryh-blanco); color: var(--gris-texto);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: var(--ryh-azul-corp);
  box-shadow: 0 0 0 3px rgba(26,79,184,.15);
}
.form-error { color: var(--rojo); font-size: 13px; margin-top: 4px; min-height: 18px; }

/* ===== Botones ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; padding: 12px 16px; min-height: 44px;
  border: 0; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--gris-borde); color: var(--gris-texto);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ryh-azul-corp); color: var(--ryh-blanco); }
.btn-primary:hover { background: var(--ryh-azul-oscuro); }
.btn-secondary { background: var(--ryh-azul-claro); color: var(--ryh-azul-oscuro); }
.btn-danger { background: var(--rojo); color: var(--ryh-blanco); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 20px; font-size: 16px; min-height: 52px; }

/* ===== Toasts ===== */
.toast-host {
  position: fixed; bottom: calc(16px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
  width: min(420px, calc(100% - 32px));
}
.toast {
  background: var(--ryh-azul-oscuro); color: var(--ryh-blanco);
  padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-md);
  pointer-events: auto; animation: toast-in .2s ease-out;
}
.toast.toast-error { background: var(--rojo); }
.toast.toast-success { background: var(--verde); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Utilidades ===== */
[hidden] { display: none !important; }
.text-center { text-align: center; }
.muted { color: var(--gris-suave); }

/* ===== Cards ===== */
.card {
  background: var(--ryh-blanco);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--gris-borde);
  color: var(--ryh-azul-oscuro);
}
.card-body { padding: 16px; }
.card-body.p0 { padding: 0; }

/* ===== Page head (back btn + title) ===== */
.page-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
}
.page-head h2 {
  font-size: 20px; margin: 0; color: var(--ryh-azul-oscuro);
}
.icon-btn-dark {
  color: var(--ryh-azul-oscuro);
  background: var(--gris-borde);
}
.icon-btn-dark:active { background: #c5cfe0; }

/* ===== Dashboard ===== */
.view-dashboard { padding-top: 8px; }
.dash-greeting { margin-bottom: 16px; }
.dash-greeting h2 { font-size: 22px; margin: 0; color: var(--ryh-azul-oscuro); }
.dash-greeting p { margin: 2px 0 0; font-size: 13px; }

.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  text-align: center;
}
.stat-num {
  font-size: 22px; font-weight: 800; color: var(--ryh-azul-corp);
  line-height: 1;
}

.actions-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px;
}
.btn-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 12px; gap: 8px; min-height: 110px;
  background: var(--ryh-blanco); color: var(--ryh-azul-oscuro);
  border: 0; border-radius: var(--radius); cursor: pointer;
  font-weight: 600; font-size: 15px; box-shadow: var(--shadow-sm);
}
.btn-tile:active { transform: translateY(1px); }
.btn-tile.btn-primary { background: var(--ryh-azul-corp); color: var(--ryh-blanco); }
.tile-icon { font-size: 32px; line-height: 1; }

/* ===== Search ===== */
.search-box { position: relative; }
.search-box input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--gris-borde); border-radius: var(--radius-sm);
  font: inherit; background: var(--ryh-blanco);
}
.search-box input:focus {
  outline: none; border-color: var(--ryh-azul-corp);
  box-shadow: 0 0 0 3px rgba(26,79,184,.15);
}
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--ryh-blanco); border: 1px solid var(--gris-borde);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  max-height: 280px; overflow-y: auto; z-index: 20;
}
.search-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border: 0; background: transparent; cursor: pointer;
  border-bottom: 1px solid var(--gris-borde); font: inherit; color: var(--gris-texto);
}
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: var(--gris-fondo); }
.search-item:disabled { opacity: .4; cursor: not-allowed; }
.search-empty { padding: 12px; text-align: center; }

.selected-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  margin-top: 12px; padding: 12px;
  background: var(--gris-fondo); border-radius: var(--radius-sm);
}

/* ===== Items list (crear factura) ===== */
.items-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.item-row {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--gris-fondo); padding: 10px;
  border-radius: var(--radius-sm);
}
.item-info { font-size: 14px; }
.item-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px; align-items: end;
}
.item-controls label {
  display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--gris-suave);
}
.item-controls input {
  font: inherit; padding: 8px 10px;
  border: 1px solid var(--gris-borde); border-radius: var(--radius-sm);
  background: var(--ryh-blanco); width: 100%;
}
.item-subtotal {
  font-weight: 700; color: var(--ryh-azul-oscuro);
  align-self: end; padding: 6px 0; font-size: 14px;
  text-align: right;
}

/* ===== Totales ===== */
.totales-card { background: var(--ryh-blanco); }
.totales-grid {
  display: grid; grid-template-columns: 1fr; gap: 6px;
}
.totales-grid > div {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px;
}
.totales-grid .t-total {
  border-top: 1.5px solid var(--gris-borde); margin-top: 6px; padding-top: 8px;
  font-size: 18px; font-weight: 800; color: var(--ryh-azul-oscuro);
}

/* ===== Selector de listas de precio (4 listas POS Mario) ===== */
.lista-selector {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.btn-lista {
  font: inherit; font-weight: 700; font-size: 13px;
  padding: 10px 6px; border: 1.5px solid var(--gris-borde); border-radius: var(--radius-sm);
  background: var(--ryh-blanco); color: var(--gris-suave); cursor: pointer;
  transition: all 0.12s ease;
}
.btn-lista:active { transform: translateY(1px); }
.btn-lista.active {
  background: var(--ryh-azul-corp); color: var(--ryh-blanco);
  border-color: var(--ryh-azul-corp); box-shadow: var(--shadow-sm);
}

/* ===== Filters ===== */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: end;
  margin-bottom: 12px;
}
.filters .form-field { margin-bottom: 0; flex: 1 1 120px; }

/* ===== Lista facturas ===== */
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 12px 14px;
  background: var(--ryh-blanco); border: 0; border-bottom: 1px solid var(--gris-borde);
  text-align: left; cursor: pointer; font: inherit; color: var(--gris-texto);
}
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: var(--gris-fondo); }
.row-main { flex: 1; min-width: 0; }
.row-amount { font-weight: 700; color: var(--ryh-azul-oscuro); }

.pager {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-top: 12px; flex-wrap: wrap;
}

/* ===== Detalle factura ===== */
.kv {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px dashed var(--gris-borde); font-size: 14px;
}
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--gris-suave); }
.items-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.items-table th, .items-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--gris-borde);
}
.items-table th {
  text-align: left; background: var(--gris-fondo);
  color: var(--gris-suave); font-weight: 600;
}
.items-table .num { text-align: right; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge-pagada { background: var(--verde); color: white; }
.badge-pendiente { background: var(--ambar); color: #2a1c00; }
.badge-anulada { background: var(--rojo); color: white; }

.actions-row {
  display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
}

/* ===== Desktop tweaks ===== */
@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .totales-grid { grid-template-columns: 1fr 1fr; }
  .totales-grid .t-total { grid-column: 1 / -1; justify-content: space-between; }
  .actions-row { flex-direction: row; }
  .item-controls { grid-template-columns: 100px 140px 1fr auto; }
}
@media (min-width: 1024px) {
  .screen { padding: 24px 32px; }
  .actions-grid { grid-template-columns: repeat(4, 1fr); }
}
