/* ============================================================
   LLAMAPOS — Design System
   Filosofía: tokens primero, utilidades mínimas, sin magia.
   ============================================================ */

/* --- 1. TOKENS -------------------------------------------- */
:root {
  /* Escala de grises funcional */
  --color-bg:        #f5f5f5;
  --color-surface:   #ffffff;
  --color-border:    #e0e0e0;
  --color-text:      #1a1a1a;
  --color-muted:     #757575;

  /* Acento único — azul funcional, no decorativo */
  --color-accent:    #2563eb;
  --color-accent-h:  #1d4ed8;

  /* Semánticos */
  --color-success:   #16a34a;
  --color-danger:    #dc2626;
  --color-warning:   #d97706;

  /* Tipografía */
  --font-base:       -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:       'Courier New', monospace;
  --text-xs:         0.75rem;
  --text-sm:         0.875rem;
  --text-base:       1rem;
  --text-lg:         1.125rem;
  --text-xl:         1.25rem;
  --text-2xl:        1.5rem;
  --text-3xl:        1.875rem;

  /* Espaciado — escala 4pt */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-12: 3rem;

  /* Bordes */
  --radius:    4px;
  --radius-lg: 8px;

  /* Layout */
  --navbar-h: 56px;
  --sidebar-w: 240px;
}

/* --- 2. RESET --------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font-base);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-accent);
}
ul, ol { list-style: none; }
img { display: block; max-width: 100%; }

/* --- 3. LAYOUT -------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--navbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 100;
  overflow: hidden;
}

.navbar__brand {
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.navbar__nav {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
}
.navbar__nav::-webkit-scrollbar { display: none; }

.nav-link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--color-muted);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-link:hover  { background: var(--color-bg); color: var(--color-text); }
.nav-link.active { background: var(--color-bg); color: var(--color-accent); font-weight: 600; }

.main-content {
  margin-top: var(--navbar-h);
  padding: var(--space-6);
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* --- 4. COMPONENTES BASE ---------------------------------- */

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.1s, opacity 0.1s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--color-accent-h); }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-border); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--color-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--color-bg); color: var(--color-text); }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
.btn-block { width: 100%; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

/* Tabla */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 2px solid var(--color-border);
  color: var(--color-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
}
td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--color-bg); }

/* Badge */
.badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: 99px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: var(--color-success); }
.badge-danger  { background: #fee2e2; color: var(--color-danger); }
.badge-warning { background: #fef3c7; color: var(--color-warning); }
.badge-neutral { background: var(--color-bg); color: var(--color-muted); }

/* Form group */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }
.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }
.form-hint  { font-size: var(--text-xs); color: var(--color-muted); }
.form-error { font-size: var(--text-xs); color: var(--color-danger); }
input.error, select.error { border-color: var(--color-danger); }

/* Grid utilitario */
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Flex utilitario */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }

/* Texto */
.text-muted   { color: var(--color-muted); }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: var(--text-xs); }
.text-lg      { font-size: var(--text-lg); }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }
.font-mono    { font-family: var(--font-mono); }

/* Espaciado */
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }

/* --- 5. MODAL --------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(8px);
  transition: transform 0.15s;
}
.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}
.modal-title { font-size: var(--text-lg); font-weight: 600; }
.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--color-muted);
  font-size: var(--text-lg);
}
.modal-close:hover { background: var(--color-bg); color: var(--color-text); }
.modal-body   { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* --- 6. TOAST --------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 300;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-text);
  color: #fff;
  font-size: var(--text-sm);
  min-width: 240px;
  max-width: 360px;
  transform: translateX(120%);
  transition: transform 0.2s ease;
}
.toast.show { transform: translateX(0); }
.toast-success { background: var(--color-success); }
.toast-danger  { background: var(--color-danger); }
.toast-warning { background: var(--color-warning); color: var(--color-text); }

/* --- 7. EMPTY STATE --------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  color: var(--color-muted);
  gap: var(--space-3);
  text-align: center;
}
.empty-state__icon { font-size: 2.5rem; }
.empty-state__title { font-size: var(--text-lg); font-weight: 600; color: var(--color-text); }
.empty-state__desc  { font-size: var(--text-sm); max-width: 280px; }

/* --- 8. STAT CARD ----------------------------------------- */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.stat-card__label { font-size: var(--text-xs); color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-card__value { font-size: var(--text-3xl); font-weight: 700; margin-top: var(--space-1); font-family: var(--font-mono); }
.stat-card__sub   { font-size: var(--text-xs); color: var(--color-muted); margin-top: var(--space-1); }

/* --- 9. SEARCH BAR ---------------------------------------- */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.search-bar input { padding-left: var(--space-8); width: 100%; }
.search-bar__icon {
  position: absolute;
  left: var(--space-3);
  color: var(--color-muted);
  pointer-events: none;
  font-size: var(--text-sm);
}

/* --- 10. RESPONSIVE --------------------------------------- */

/* Tablas: nunca desbordan, siempre con scroll horizontal */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
table { min-width: 500px; } /* evita que las tablas se compriman demasiado */

/* Stat cards: colapsan a 2 columnas en tablet, 1 en mobile */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  :root { --navbar-h: 52px; }

  .main-content {
    padding: var(--space-3);
    /* En mobile con POS, añadimos espacio abajo para el sidebar flotante */
  }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* Navbar: brand más compacto */
  .navbar__brand { font-size: var(--text-sm); }
  .nav-link      { padding: var(--space-2) var(--space-2); font-size: var(--text-xs); }

  /* Cards: padding reducido */
  .card      { padding: var(--space-4); }
  .stat-card { padding: var(--space-4); }
  .stat-card__value { font-size: var(--text-2xl); }

  /* Modal: ocupa todo el ancho en mobile */
  .modal {
    max-width: 100% !important;
    margin: 0 var(--space-3);
    max-height: 95vh;
  }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* Botones de tabla: stack vertical */
  td .flex { flex-wrap: wrap; }

  /* Page header: stack vertical */
  .page-header { flex-direction: column; align-items: flex-start; gap: var(--space-3); }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Filtros de búsqueda */
  .flex.gap-4 { flex-direction: column; }
}
