/* =========================================================
   Evobike CRM/POS — estilos base compartidos por todos los módulos
   ========================================================= */

:root {
  /* Marca */
  --bg: #0A0A0A;
  --card: #111827;
  --card-2: #1F2937;
  --border: #243044;
  --green: #22C55E;
  --green-600: #16A34A;
  --green-soft: rgba(34, 197, 94, 0.12);
  --text: #FFFFFF;
  --text-2: #9CA3AF;
  --text-3: #6B7280;
  --danger: #EF4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --warning: #F59E0B;

  /* Tipografía */
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.375rem;
  --fs-xl: 2rem;

  /* Espaciado y forma */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --gap: 16px;

  /* Táctil: mínimo recomendado 48px */
  --touch: 56px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 600;
  transition: background-color 0.15s, transform 0.08s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-primary {
  background: var(--green);
  color: #052E16;
}

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

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

.btn-ghost:hover {
  background: var(--card-2);
}

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

/* Botones grandes para acciones principales en tableta */
.btn-xl {
  min-height: 68px;
  font-size: var(--fs-lg);
  border-radius: var(--r-lg);
}

.btn-xl small {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 500;
  opacity: 0.8;
}

/* ---------- Tarjetas ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* ---------- Estado de conexión ---------- */

.net-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  color: var(--text-2);
}

.net-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.net-badge.offline {
  color: var(--warning);
}

.net-badge.offline::before {
  background: var(--warning);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 14px 20px;
  border-radius: var(--r-md);
  background: var(--card-2);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-color: var(--danger);
}

/* ---------- Búsqueda, chips, campos y modales (venta, inventario…) ---------- */

.search {
  position: relative;
  margin-bottom: 12px;
}

.search svg {
  position: absolute;
  left: 16px;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translateY(-50%);
  fill: var(--text-3);
  pointer-events: none;
}

.search input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 52px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card);
  font-size: var(--fs-md);
}

.search input:focus,
.field-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 1.25rem;
}

.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-2);
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.chip[aria-pressed='true'] {
  background: var(--green);
  border-color: var(--green);
  color: #052E16;
}

.btn-sm {
  min-height: 44px;
  padding: 0 14px;
  font-size: var(--fs-sm);
}

.hint {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.field-input {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-2);
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
}

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--card);
}

.modal-box h2 {
  margin: 0 0 16px;
  font-size: var(--fs-lg);
}

.form {
  display: grid;
  gap: 14px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.form-msg {
  min-height: 1.3em;
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-sm);
}

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

/* ---------- Panel lateral (detalle y formularios de inventario, clientes…) ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.6);
}

.sheet-box {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.2s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateX(40px);
    opacity: 0;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: calc(72px + var(--safe-top));
  padding: var(--safe-top) calc(16px + var(--safe-right)) 0 20px;
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 {
  flex: 1;
  margin: 0;
  font-size: var(--fs-lg);
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 20px calc(24px + var(--safe-bottom));
}

.sheet-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 20px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

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

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0 0 20px;
}

.kv dt {
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.kv dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.det-section {
  margin: 0 0 10px;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hist {
  margin: 0;
  padding: 0;
  list-style: none;
}

.hist li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.hist li:last-child {
  border-bottom: 0;
}

.hist .h-main {
  font-weight: 600;
}

.hist .h-sub {
  color: var(--text-2);
  font-size: var(--fs-xs);
}

.hist .h-amt {
  grid-row: span 2;
  align-self: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hist .cancel {
  color: var(--danger);
}

/* ---------- Formularios del panel ---------- */

/* Igual que .form label, para grupos con botones (un <label> activaría el primer botón). */
.form .field {
  display: grid;
  gap: 6px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.seg {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card-2);
}

.seg button {
  min-height: 48px;
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: var(--fs-sm);
}

.seg button[aria-pressed='true'] {
  background: var(--green);
  color: #052E16;
}

.form select.field-input,
.form textarea.field-input {
  appearance: none;
}

.form textarea.field-input {
  min-height: 88px;
  padding: 12px 14px;
  resize: vertical;
}

.form select.field-input {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 599px) {
  .row-2 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Ticket imprimible (corte de caja, entrega de servicio) ---------- */

.ticket-wrap {
  display: grid;
  gap: 16px;
  max-width: 460px;
  margin: 0 auto;
}

.ticket-ok {
  text-align: center;
}

.ticket-ok .check {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--green);
  color: #052E16;
  font-size: 2rem;
  font-weight: 700;
}

.ticket-ok h2 {
  margin: 0;
  font-size: var(--fs-lg);
}

.ticket-ok p {
  margin: 4px 0 0;
  color: var(--text-2);
}

.ticket-80 {
  padding: 18px;
  border-radius: var(--r-md);
  background: #fff;
  color: #111;
  font-family: 'Courier New', ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.ticket-80 .t-c {
  text-align: center;
}

.ticket-80 .t-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.ticket-80 hr {
  margin: 8px 0;
  border: 0;
  border-top: 1px dashed #999;
}

.ticket-80 dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 10px;
  margin: 0;
}

.ticket-80 dd {
  margin: 0;
  text-align: right;
}

.ticket-80 .t-total {
  font-size: 15px;
  font-weight: 700;
}

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

/* ---------- Impresión (rollo de 80 mm): solo el ticket ---------- */

@media print {
  @page {
    size: 80mm auto;
    margin: 4mm;
  }

  body {
    background: #fff !important;
  }

  body * {
    visibility: hidden;
  }

  #ticket,
  #ticket * {
    visibility: visible;
    color: #000 !important;
  }

  #ticket {
    position: absolute;
    left: 0;
    top: 0;
    width: 72mm;
    padding: 0;
    border-radius: 0;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
