@tailwind base;
@tailwind components;
@tailwind utilities;

/*
 * MBtaller — sistema de diseño v1.0
 *
 * Principio: la jerarquía la da el espacio y el tamaño, no el color ni la
 * sombra. Color sólo donde significa algo (acción primaria, estado de una OT,
 * error). Todo lo demás es neutro.
 *
 * El sistema lo usan mecánicos en celular, tablet y computadora, muchas veces
 * con las manos sucias y a contraluz. Por eso: objetivos táctiles grandes,
 * contraste alto y una sola acción primaria evidente por pantalla.
 */

@layer base {
  :root {
    /* Lienzo y superficies */
    --background: 240 20% 99%;
    --surface: 0 0% 100%;
    --surface-sunken: 240 10% 96.5%;

    --card: 0 0% 100%;
    --card-foreground: 240 6% 10%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 6% 10%;

    /* Texto */
    --foreground: 240 6% 10%;
    --muted: 240 10% 96.5%;
    --muted-foreground: 240 4% 42%;
    --subtle-foreground: 240 4% 56%;

    /* Acento: azul único, reservado a la acción primaria y al estado activo */
    --primary: 211 100% 45%;
    --primary-foreground: 0 0% 100%;
    --primary-soft: 211 100% 96%;

    --secondary: 240 10% 96.5%;
    --secondary-foreground: 240 6% 10%;
    --accent: 240 10% 96.5%;
    --accent-foreground: 240 6% 10%;

    /* Semánticos */
    --destructive: 0 72% 48%;
    --destructive-foreground: 0 0% 100%;
    --destructive-soft: 0 86% 97%;
    --success: 152 60% 36%;
    --success-foreground: 0 0% 100%;
    --success-soft: 152 60% 96%;
    --warning: 38 92% 42%;
    --warning-foreground: 0 0% 100%;
    --warning-soft: 38 92% 96%;

    /* Trazos */
    --border: 240 6% 90%;
    --border-strong: 240 6% 82%;
    --input: 240 6% 88%;
    --ring: 211 100% 45%;

    --radius: 0.75rem;

    /* Alto real de la barra inferior en móvil, incluida el área segura de iOS */
    --bottom-nav-height: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  }

  .dark {
    --background: 240 8% 6%;
    --surface: 240 6% 10%;
    --surface-sunken: 240 6% 8%;

    --card: 240 6% 10%;
    --card-foreground: 0 0% 98%;
    --popover: 240 6% 12%;
    --popover-foreground: 0 0% 98%;

    --foreground: 0 0% 98%;
    --muted: 240 5% 16%;
    --muted-foreground: 240 5% 65%;
    --subtle-foreground: 240 5% 52%;

    --primary: 211 100% 58%;
    --primary-foreground: 240 8% 6%;
    --primary-soft: 211 60% 16%;

    --secondary: 240 5% 16%;
    --secondary-foreground: 0 0% 98%;
    --accent: 240 5% 16%;
    --accent-foreground: 0 0% 98%;

    --destructive: 0 72% 58%;
    --destructive-foreground: 0 0% 100%;
    --destructive-soft: 0 50% 16%;
    --success: 152 55% 46%;
    --success-foreground: 0 0% 100%;
    --success-soft: 152 40% 14%;
    --warning: 38 92% 55%;
    --warning-foreground: 240 8% 6%;
    --warning-soft: 38 50% 15%;

    --border: 240 5% 20%;
    --border-strong: 240 5% 28%;
    --input: 240 5% 22%;
    --ring: 211 100% 58%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  html {
    scroll-behavior: smooth;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  body {
    @apply bg-background text-foreground antialiased;
    font-feature-settings: 'cv11', 'ss01';
    font-variant-numeric: tabular-nums;
    overflow-x: hidden;
    /* Deja espacio a la barra inferior de navegación en móvil */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /*
   * Los títulos usan tracking negativo como en el texto display de Apple: a
   * tamaño grande las letras necesitan juntarse para leerse como una palabra.
   */
  h1,
  h2,
  h3 {
    @apply tracking-tight;
  }

  ::selection {
    background: hsl(var(--primary) / 0.18);
  }

  /* Foco visible y consistente en todo el sistema */
  :focus-visible {
    @apply outline-none ring-2 ring-ring ring-offset-2 ring-offset-background;
  }

  /* Respeta a quien pidió menos movimiento en su sistema operativo */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer components {
  /*
   * Objetivo táctil mínimo. 44px es el mínimo de Apple; acá usamos 48px porque
   * el sistema se usa con guantes y en movimiento.
   */
  .btn-touch {
    @apply min-h-[48px] min-w-[48px] text-base font-medium;
  }

  /* Etiqueta pequeña en mayúsculas: discreta, nunca con tracking exagerado */
  .eyebrow {
    @apply text-[11px] font-semibold uppercase tracking-wider text-subtle-foreground;
  }

  /*
   * DEPRECADO: este bloque `.estado-*` queda reemplazado por
   * `ui/badge.tsx` (variante `estado`), que centraliza el mismo mapeo de
   * color por estado de OT en un componente tipado en vez de clases sueltas.
   * Se deja intacto mientras las páginas migran una por una; borrar recién
   * cuando ninguna pantalla lo referencie.
   */
  .estado-badge {
    @apply inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-sm font-medium;
  }

  .estado-borrador {
    @apply bg-muted text-muted-foreground;
  }

  .estado-en_proceso {
    @apply bg-amber-50 text-amber-800;
  }

  .estado-cotizada {
    @apply bg-violet-50 text-violet-800;
  }

  .estado-aprobada {
    @apply bg-emerald-50 text-emerald-800;
  }

  .estado-terminada {
    @apply bg-cyan-50 text-cyan-900;
  }

  .estado-entregada {
    @apply bg-green-50 text-green-800;
  }

  .offline-banner {
    @apply bg-warning-soft px-4 py-2 text-center text-sm font-medium text-amber-900;
  }

  .sync-pending {
    @apply bg-warning text-warning-foreground;
  }

  .sync-success {
    @apply bg-success text-success-foreground;
  }

  /* Superficie base: borde hairline y una sombra apenas perceptible */
  .app-surface {
    @apply rounded-2xl border border-border bg-surface shadow-sm;
  }

  /*
   * Contenedor para tablas y cualquier contenido más ancho que la pantalla.
   * Sin esto la tabla empuja el layout y aparece scroll horizontal en toda la
   * página — el bug clásico en celular.
   */
  .scroll-x {
    @apply -mx-3 overflow-x-auto overscroll-x-contain px-3 md:mx-0 md:px-0;
    scrollbar-width: thin;
  }

  .form-input-lg {
    @apply h-12 px-4 text-base;
  }

  .form-label-lg {
    @apply mb-2 text-base font-medium;
  }

  .wizard-step {
    @apply flex items-center gap-2;
  }

  .wizard-step-circle {
    @apply flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold;
  }

  .wizard-step-active {
    @apply bg-primary text-primary-foreground;
  }

  .wizard-step-completed {
    @apply bg-success text-success-foreground;
  }

  .wizard-step-pending {
    @apply bg-muted text-muted-foreground;
  }

  .damage-marker {
    @apply absolute h-7 w-7 -translate-x-1/2 -translate-y-1/2 transform cursor-pointer rounded-full border-2 border-white shadow-md;
  }

  .signature-pad {
    @apply rounded-xl border-2 border-dashed border-border-strong bg-surface;
  }

  .signature-pad canvas {
    @apply h-full w-full;
  }
}

@layer utilities {
  .loading-shimmer {
    @apply animate-pulse bg-muted;
  }

  /* Deja libre la barra inferior de navegación en celular */
  .pb-bottom-nav {
    padding-bottom: var(--bottom-nav-height);
  }

  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /*
   * Elevación sutil al hover, con guard de `hover:hover` para que en
   * pantallas táctiles (donde "hover" es en realidad el tap) la tarjeta no se
   * quede levantada después de tocarla.
   */
  @media (hover: hover) {
    .hover-lift {
      @apply transition-[transform,box-shadow] duration-150;
    }

    .hover-lift:hover {
      @apply -translate-y-0.5 shadow-md;
    }
  }

  /*
   * Ritmo vertical para listas donde no aplica `gap` de flex/grid (por
   * ejemplo contenido con `dangerouslySetInnerHTML` o hijos condicionales
   * mezclados con texto suelto). Margen solo entre hermanos, nunca en el
   * primero, para no desalinear el contenedor padre.
   */
  .stack > * + * {
    margin-top: 0.75rem;
  }
}

@media print {
  .no-print {
    display: none !important;
  }

  /* Oculta todo el chrome de la aplicación */
  nav,
  aside,
  header:not(.print-header),
  [data-sidebar],
  [class*="sidebar"],
  [class*="dashboard-shell"],
  [class*="DashboardShell"],
  [class*="offline-indicator"],
  [class*="toast"],
  [role="dialog"] {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
    background-image: none !important;
    padding-bottom: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  @page {
    size: letter;
    margin: 16mm 14mm;
  }

  body {
    font-size: 12px;
    line-height: 1.5;
    color: #000;
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    break-after: avoid;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  img {
    max-width: 100% !important;
  }
}
