/* =============================================================
   Logística Casadei — Design System
   Paleta: azul oscuro #1a2744, blanco, grises
   ============================================================= */

/* --- Variables --- */
:root {
  --color-primary:       #111111;
  --color-primary-light: #222222;
  --color-primary-hover: #000000;
  --color-accent:        #111111;
  --color-accent-hover:  #000000;

  --color-rojo:     #e74c3c;
  --color-amarillo: #f39c12;
  --color-verde:    #27ae60;

  --color-bg:        #f4f6f9;
  --color-surface:   #ffffff;
  --color-border:    #e2e6ec;
  --color-border-2:  #cdd3dc;

  --color-text:        #1a2744;
  --color-text-muted:  #6b7a99;
  --color-text-light:  #9ba8bf;

  --shadow-sm:   0 1px 3px rgba(26,39,68,.08);
  --shadow-md:   0 2px 8px rgba(26,39,68,.12);
  --shadow-lg:   0 4px 20px rgba(26,39,68,.14);
  --shadow-xl:   0 8px 40px rgba(26,39,68,.18);

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;

  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;

  --header-h: 60px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); }

/* =============================================================
   LAYOUT — Header de navegación
   ============================================================= */

.app-header {
  background: var(--color-primary);
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex-shrink: 0;
}
.header-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .875rem;
}
.header-logo-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  flex-shrink: 0;
}
.header-logo-text {
  color: white;
  font-size: .9375rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
}
.header-logo-sub {
  color: rgba(255,255,255,.55);
  font-size: .7rem;
  font-weight: 400;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex: 1;
}
.header-nav a {
  color: rgba(255,255,255,.75);
  font-size: .875rem;
  font-weight: 500;
  padding: .375rem .75rem;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}
.header-nav a:hover,
.header-nav a.active {
  background: rgba(255,255,255,.12);
  color: white;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
}
.header-user {
  color: rgba(255,255,255,.65);
  font-size: .8125rem;
}

/* =============================================================
   PÁGINA — Contenedor principal
   ============================================================= */

.page-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -.02em;
}
.page-subtitle {
  font-size: .875rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}

/* =============================================================
   BOTONES
   ============================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4375rem;
  font-size: .875rem;
  font-weight: 500;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-2);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-bg); border-color: #b4bdd1; }

.btn-danger {
  background: #fef2f2;
  color: var(--color-rojo);
  border-color: #fecaca;
}
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-warning {
  background: #fffbeb;
  color: #b45309;
  border-color: #fde68a;
}
.btn-warning:hover:not(:disabled) { background: #fef3c7; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
  padding: .375rem .625rem;
}
.btn-ghost:hover:not(:disabled) { background: var(--color-bg); color: var(--color-text); }

.btn-sm {
  font-size: .8125rem;
  padding: .3125rem .75rem;
}
.btn-icon {
  padding: .375rem;
  aspect-ratio: 1;
  justify-content: center;
}

.btn-whatsapp {
  background: #25d366;
  color: white;
  border-color: #25d366;
}
.btn-whatsapp:hover:not(:disabled) { background: #1da851; border-color: #1da851; }

.btn-logout {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.2);
  font-size: .8125rem;
  padding: .375rem .875rem;
}
.btn-logout:hover { background: rgba(255,255,255,.18); color: white; }

/* =============================================================
   CARDS — Summary cards del dashboard
   ============================================================= */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
  margin-bottom: .875rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .5rem .875rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.stat-card-clickable {
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .1s;
}
.stat-card-clickable:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
  transform: translateY(-1px);
}
.stat-card-icon {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
}
.stat-card-icon.blue   { background: #f3f4f6; color: var(--color-accent); }
.stat-card-icon.red    { background: #fef2f2; color: var(--color-rojo); }
.stat-card-icon.yellow { background: #fffbeb; color: var(--color-amarillo); }
.stat-card-icon.green  { background: #f0fdf4; color: var(--color-verde); }

.stat-card-body {}
.stat-card-value {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  color: var(--color-text);
}
.stat-card-label {
  font-size: .6875rem;
  color: var(--color-text-muted);
  margin-top: .15rem;
}

/* =============================================================
   TABLAS
   ============================================================= */

.table-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  gap: 1rem;
  flex-wrap: wrap;
}
.table-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}
.table-filters {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  background: #f8f9fb;
  color: var(--color-text-muted);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody td {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8faff; }

.td-actions {
  display: flex;
  gap: .375rem;
  align-items: center;
}
.td-mono {
  font-family: 'Consolas', monospace;
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .03em;
}

/* =============================================================
   SEMÁFOROS
   ============================================================= */

.semaforo {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  font-size: .8125rem;
}
.semaforo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.semaforo-label { color: var(--color-text-muted); }

.semaforo-rojo    .semaforo-label { color: var(--color-rojo); font-weight: 600; }
.semaforo-amarillo .semaforo-label { color: #b45309; font-weight: 500; }
.semaforo-verde   .semaforo-label { color: var(--color-verde); }

/* Badge de estado en tabla */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3125rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .1875rem .5625rem;
  border-radius: 100px;
  line-height: 1.4;
}
.badge-rojo    { background: #fef2f2; color: var(--color-rojo); }
.badge-amarillo { background: #fffbeb; color: #92400e; }
.badge-verde   { background: #f0fdf4; color: #166534; }
.badge-gray    { background: #f1f5f9; color: #64748b; }

/* =============================================================
   FORMULARIOS
   ============================================================= */

.form-group {
  margin-bottom: 1rem;
}
.form-label {
  display: block;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: .375rem;
}
.form-label .required { color: var(--color-rojo); margin-left: .125rem; }
.form-input,
.form-select {
  width: 100%;
  padding: .5625rem .875rem;
  font-size: .9375rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7a99' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2.5rem;
}
.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input::placeholder { color: var(--color-text-light); }
.form-hint {
  font-size: .75rem;
  color: var(--color-text-muted);
  margin-top: .3125rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-file-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .875rem;
  border: 1px dashed var(--color-border-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.form-file-label:hover { border-color: var(--color-accent); color: var(--color-accent); background: #f3f4f6; }
input[type="file"] { display: none; }
.form-file-name {
  font-size: .8125rem;
  color: var(--color-text-muted);
  margin-top: .375rem;
  font-style: italic;
}

/* =============================================================
   MODALES
   ============================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  animation: slideUp .18s ease;
}
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 960px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}
.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}
.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: #f8f9fb;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* =============================================================
   PANEL DE DOCUMENTOS
   ============================================================= */

.doc-list { display: flex; flex-direction: column; gap: .625rem; }

.doc-item {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: .875rem 1rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color .15s;
}
.doc-item:hover { border-color: var(--color-border-2); }

.doc-item-info { flex: 1; min-width: 0; }
.doc-item-nombre {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item-venc {
  font-size: .8125rem;
  color: var(--color-text-muted);
  margin-top: .125rem;
}
.doc-item-meta {
  font-size: .75rem;
  color: var(--color-text-light);
  margin-top: .125rem;
}

.doc-item-actions { display: flex; gap: .375rem; align-items: center; flex-shrink: 0; }

/* =============================================================
   ESTADOS: carga / vacío / error
   ============================================================= */

.state-container {
  padding: 3.5rem 1.5rem;
  text-align: center;
  color: var(--color-text-muted);
}
.state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: .4;
}
.state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: .375rem;
}
.state-desc { font-size: .875rem; }

.skeleton {
  background: linear-gradient(90deg, #e8ecf2 25%, #f1f4f8 50%, #e8ecf2 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* =============================================================
   FILTROS
   ============================================================= */

.filter-bar {
  display: flex;
  gap: .625rem;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 160px;
  font-size: .8125rem;
  padding: .4375rem .875rem;
}
.filter-bar .form-select { min-width: 140px; padding-right: 2.25rem; }

/* Banner "Último procesado" de la cola: el display va acá y no inline, porque un
   display:flex inline le gana al atributo hidden y el recuadro quedaba siempre visible y vacío. */
#ultimo-procesado:not([hidden]) { display: flex; }

/* =============================================================
   LOGIN PAGE
   ============================================================= */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 1.5rem;
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo-icon {
  width: 56px;
  height: 56px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  margin-bottom: .875rem;
}
.login-logo-img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 50%;
  display: block;
  margin: 0 auto .875rem;
}
.login-logo-name {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: -.03em;
}
.login-logo-sub {
  font-size: .8125rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}
.login-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 1.5rem;
}
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--color-rojo);
  border-radius: var(--radius-sm);
  padding: .625rem .875rem;
  font-size: .875rem;
  margin-bottom: 1rem;
}
.login-error.hidden { display: none; }

/* =============================================================
   PORTAL PÚBLICO
   ============================================================= */

.portal-page {
  min-height: 100vh;
  background: var(--color-bg);
}
.portal-header {
  background: var(--color-primary);
  padding: 1.5rem;
  text-align: center;
}
.portal-header-logo {
  display: inline-flex;
  align-items: center;
  gap: .625rem;
  margin-bottom: .75rem;
}
.portal-header-icon {
  width: 36px;
  height: 36px;
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .9375rem;
}
.portal-header-name {
  color: rgba(255,255,255,.7);
  font-size: .875rem;
  font-weight: 500;
}
.portal-empresa {
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
}
.portal-body {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
.portal-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.portal-section-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: .625rem;
}
.portal-section-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}
.portal-section-body { padding: 1rem 1.25rem; }

.portal-doc-item {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: .875rem 0;
  border-bottom: 1px solid var(--color-border);
}
.portal-doc-item:last-child { border-bottom: none; }
.portal-doc-info { flex: 1; }
.portal-doc-nombre { font-size: .9375rem; font-weight: 600; }
.portal-doc-fecha { font-size: .8125rem; color: var(--color-text-muted); margin-top: .125rem; }

.portal-upload-area {
  border: 2px dashed var(--color-border-2);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.portal-upload-area:hover { border-color: var(--color-accent); background: #f3f4f6; }
.portal-upload-area input { display: none; }
.portal-upload-icon { font-size: 1.75rem; color: var(--color-text-light); margin-bottom: .5rem; }
.portal-upload-text { font-size: .875rem; color: var(--color-text-muted); }
.portal-upload-text strong { color: var(--color-accent); }

.portal-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  color: #166534;
}
.portal-success i { font-size: 1.75rem; margin-bottom: .5rem; }

@media (max-width: 480px) {
  .portal-doc-item {
    flex-wrap: wrap;
    gap: .5rem .75rem;
  }
  .portal-doc-actions {
    width: 100%;
  }
  .portal-doc-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* =============================================================
   TOAST / NOTIFICACIONES
   ============================================================= */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
}
.toast {
  display: flex;
  align-items: center;
  gap: .625rem;
  background: var(--color-text);
  color: white;
  border-radius: var(--radius-md);
  padding: .875rem 1.25rem;
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
  max-width: 360px;
}
.toast-success { background: #166534; }
.toast-error   { background: var(--color-rojo); }
.toast-info    { background: var(--color-accent); }
.toast-hide {
  animation: fadeOut .3s ease forwards;
}
@keyframes fadeOut { to { opacity: 0; transform: translateY(8px); } }

/* =============================================================
   UTILIDADES
   ============================================================= */

.hidden { display: none !important; }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: .8125rem; }
.font-mono { font-family: 'Consolas', monospace; }

.section-spacer { margin-bottom: 2rem; }

.tag {
  display: inline-flex;
  align-items: center;
  background: #f1f5f9;
  color: var(--color-text-muted);
  font-size: .75rem;
  font-weight: 500;
  padding: .125rem .5rem;
  border-radius: 100px;
  text-transform: capitalize;
}
.tag-primary { background: #f3f4f6; color: var(--color-accent); }

/* Separador de sección */
.section-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
  margin-bottom: .875rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* Link de portal copiable */
.portal-link-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: #f8f9fb;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  font-size: .8125rem;
  font-family: 'Consolas', monospace;
  color: var(--color-text-muted);
  word-break: break-all;
}
.portal-link-box .btn { flex-shrink: 0; }

/* =============================================================
   RESPONSIVE
   ============================================================= */

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
}

@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100%; }
  .table-wrap { max-width: 100%; overflow-x: auto; }

  .page-container { padding: .75rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .stat-card { padding: .65rem .75rem; gap: .5rem; }
  .stat-card-value { font-size: 1.25rem; }
  .stat-card-label { font-size: .7rem; }
  .stat-card-icon { width: 32px; height: 32px; font-size: .8rem; }

  .form-row { grid-template-columns: 1fr; }

  .modal { max-width: 100%; }
  .modal-overlay { padding: .75rem; align-items: flex-end; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 90vh; }

  .header-nav { display: none; }

  .table-filters { width: 100%; }
  .filter-bar .form-input,
  .filter-bar .form-select { flex: 1; min-width: 100px; }

  .td-actions { flex-wrap: wrap; }

  /* Empresa cards compactas */
  .empresa-card-header { padding: .5rem .75rem; gap: .3rem; align-items: flex-start; }
  .ec-left { flex-wrap: wrap; gap: .2rem; align-items: flex-start; flex: 1; min-width: 0; }
  .ec-info { min-width: 0; flex: 1; }
  .ec-nombre { font-size: .85rem; white-space: normal; overflow: visible; text-overflow: unset; line-height: 1.2; }
  .ec-sub { font-size: .68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .ec-ultima { display: none; }
  .ec-counters { width: 100%; display: flex; flex-wrap: nowrap; gap: .25rem; order: 3; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ec-counters::-webkit-scrollbar { display: none; }
  .ec-counter { font-size: .65rem; padding: .15rem .45rem; white-space: nowrap; flex-shrink: 0; }
  .ec-right { display: flex; gap: .25rem; flex-shrink: 0; align-self: flex-start; padding-top: .1rem; align-items: center; }
  .ec-right .btn-whatsapp { display: none; }
  .ec-right .btn-secondary { padding: .28rem .4rem; font-size: 0; line-height: 1; border-radius: .375rem; }
  .ec-right .btn-secondary i { font-size: .8rem; }
  .ec-resumen { display: none; }
  .ec-semaforo { width: 10px; height: 10px; margin-top: .25rem; flex-shrink: 0; }
  .ec-toggle { padding: 0 .2rem; }

  /* Auditoría móvil */
  .filtros-secundarios { gap: .5rem; }
  .filtros-secundarios select { min-width: 0; width: 100%; }
  .filtros-secundarios .form-group { flex: 1 1 calc(50% - .25rem); min-width: 0; }
  .audit-card { padding: .875rem; max-width: 100%; box-sizing: border-box; }
  .periodo-btns { gap: .25rem; }
  .periodo-btn { padding: .3rem .55rem; font-size: .75rem; }
  .ranking-bar-wrap { width: 50px; }
  .ranking-card-hdr { flex-direction: column; align-items: flex-start; gap: .4rem; }
  .ranking-nombre { font-size: .8rem; }
  .ranking-count { font-size: .8rem; min-width: 1.5rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn { text-align: center; justify-content: center; }

  .login-card { padding: 1.5rem; }

  .stat-card-icon { width: 36px; height: 36px; font-size: .9375rem; }
}

/* =============================================================
   FILTROS BAR (dashboard)
   ============================================================= */

.filtros-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  position: sticky;
  top: var(--header-h);
  background: var(--color-bg);
  z-index: 10;
  padding: .5rem 0;
}
.filtros-bar-left { flex: 1; min-width: 200px; }
.filtros-bar-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: nowrap;
}
.search-wrap {
  position: relative;
}
.search-wrap i {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: .875rem;
  pointer-events: none;
}
.search-wrap .form-input {
  padding-left: 2.25rem;
  width: 100%;
}
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-height: 380px;
  overflow-y: auto;
}
.search-result-item {
  padding: .7rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: .75rem;
  transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f0f4ff; }
.search-result-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; flex-shrink: 0;
}
.search-result-icon.empresa { background: #f3f4f6; color: var(--color-accent); }
.search-result-icon.chofer  { background: #f0fdf4; color: var(--color-verde); }
.search-result-icon.unidad  { background: #fff7ed; color: #f97316; }
.search-result-body { flex: 1; min-width: 0; }
.search-result-title { font-weight: 600; font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-sub   { font-size: .775rem; color: var(--color-text-muted); margin-top: .1rem; }
.search-result-badge {
  font-size: .65rem; font-weight: 700; padding: .15rem .45rem;
  border-radius: 99px; flex-shrink: 0; text-transform: uppercase; letter-spacing: .04em;
}
.search-result-badge.empresa { background: #f3f4f6; color: var(--color-accent); }
.search-result-badge.chofer  { background: #f0fdf4; color: var(--color-verde); }
.search-result-badge.unidad  { background: #fff7ed; color: #f97316; }
.search-no-results { padding: .75rem 1rem; color: var(--color-text-muted); font-size: .875rem; }

/* =============================================================
   EMPRESA CARDS (dashboard)
   ============================================================= */

.empresa-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: .375rem;
  overflow: hidden;
  transition: box-shadow .15s;
}
.empresa-card:hover { box-shadow: var(--shadow-md); }

/* Header (clickable) */
.empresa-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .625rem 1rem;
  cursor: pointer;
  user-select: none;
  gap: .75rem;
}
.empresa-card-header:hover { background: #f8f9fb; }

.ec-left {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex: 1;
  min-width: 0;
}
.ec-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

/* Dot de estado de la empresa */
.ec-semaforo {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}

.ec-info { min-width: 0; }
.ec-nombre {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ec-sub {
  font-size: .8125rem;
  color: var(--color-text-muted);
}
.ec-ultima {
  font-size: .75rem;
  color: var(--color-text-light);
  margin-top: .125rem;
  margin-top: .125rem;
}

/* Contadores de estado */
.ec-counters {
  display: flex;
  gap: .375rem;
  flex-wrap: wrap;
}
.ec-counter {
  font-size: .75rem;
  font-weight: 600;
  padding: .2rem .625rem;
  border-radius: 100px;
}
.ec-counter.rojo      { background: #fef2f2; color: var(--color-rojo); }
.ec-counter.amarillo  { background: #fffbeb; color: #b45309; }
.ec-counter.verde     { background: #f0fdf4; color: #166534; }
.ec-counter.azul      { background: #eff6ff; color: #1d4ed8; }
.ec-counter.gris      { background: #f1f5f9; color: #64748b; }

/* Resumen unidades/choferes */
.ec-resumen {
  display: flex;
  gap: .75rem;
  font-size: .8125rem;
  color: var(--color-text-muted);
}
.ec-resumen span { display: flex; align-items: center; gap: .3rem; }

/* Botón colapsar */
.ec-toggle {
  color: var(--color-text-muted);
  transition: color .15s;
}
.ec-toggle:hover { color: var(--color-text); }

/* Body colapsable */
.empresa-card-body {
  border-top: 1px solid var(--color-border);
  overflow: hidden;
  max-height: 9999px;
  transition: max-height .25s ease;
}
.empresa-card-body.collapsed {
  max-height: 0;
  border-top: none;
}

/* Secciones dentro de la card */
.ec-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.ec-section:last-child { border-bottom: none; }

.ec-section-title {
  font-size: .8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.ec-count {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  font-size: .7rem;
  font-weight: 700;
  padding: .1rem .5rem;
  color: var(--color-text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.ec-empty {
  font-size: .875rem;
  color: var(--color-text-light);
  font-style: italic;
}

/* Tabla interna de la card */
.ec-table-wrap { overflow-x: auto; }
.ec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.ec-table thead th {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  padding: .375rem .625rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  background: #f8f9fb;
}
.ec-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
}
.ec-table tbody tr:last-child { border-bottom: none; }
.ec-table tbody tr:hover { background: #f8f9fb; }
.ec-table td {
  padding: .625rem .625rem;
  vertical-align: middle;
}

/* Dot en filas de la tabla */
.ec-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: .5rem;
  vertical-align: middle;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .ec-left { flex-wrap: wrap; }
  .ec-resumen { display: none; }
  .filtros-bar-right .btn { display: none; }
  .ec-table thead { display: none; }
  .ec-table td { display: block; padding: .25rem .625rem; }
  .ec-table td:first-child { padding-top: .625rem; font-weight: 600; }
  .ec-table td:last-child  { padding-bottom: .625rem; }
}

/* =============================================================
   EMPRESAS — grid de cards
   ============================================================= */

/* ── Empresas — vista lista ────────────────────────────────── */
.emp-grid {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.emp-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .625rem 1rem;
  transition: background .12s, box-shadow .12s;
}
.emp-card:hover {
  background: var(--color-surface-hover, #f8fafc);
  box-shadow: var(--shadow-sm);
}

/* dot de estado */
.emp-estado-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}

/* nombre + responsable */
.emp-card-body {
  flex: 1;
  min-width: 0;
}
.emp-nombre {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.emp-responsable {
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-top: .1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* badges */
.emp-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  flex-shrink: 0;
}
.emp-badge {
  font-size: .72rem;
  font-weight: 600;
  padding: .175rem .55rem;
  border-radius: 100px;
  white-space: nowrap;
}
.emp-badge.rojo     { background: #fef2f2; color: var(--color-rojo); }
.emp-badge.amarillo { background: #fffbeb; color: #b45309; }
.emp-badge.verde    { background: #f0fdf4; color: #166534; }
.emp-badge.sin-datos { background: #f1f5f9; color: var(--color-text-muted); }

/* stats inline */
.emp-stats {
  display: flex;
  gap: 1rem;
  flex-shrink: 0;
}
.emp-stat {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  color: var(--color-text-muted);
}
.emp-stat-val {
  font-weight: 700;
  color: var(--color-text);
}
.emp-stat-lbl {
  display: flex;
  align-items: center;
  gap: .25rem;
}

/* acciones */
.emp-card-footer {
  display: flex;
  align-items: center;
  gap: .375rem;
  flex-shrink: 0;
}
.emp-contacto { display: none; }   /* WA/email se accede por Teléfonos */
.emp-acciones {
  display: flex;
  align-items: center;
  gap: .375rem;
}
/* menu editar/eliminar */
.emp-card-top {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-shrink: 0;
}
.emp-card-menu {
  display: flex;
  gap: .25rem;
  opacity: 0;
  transition: opacity .15s;
}
.emp-card:hover .emp-card-menu { opacity: 1; }

@media (max-width: 640px) {
  .emp-stats  { display: none; }
  .emp-badges { display: none; }

  .emp-card {
    flex-wrap: wrap;
    gap: .375rem .5rem;
    padding: .625rem .75rem;
    align-items: center;
  }

  /* Fila 1: dot + nombre + menú editar */
  .emp-estado-dot { order: 1; flex-shrink: 0; }
  .emp-card-body  { order: 2; flex: 1 1 0; min-width: 0; }
  /* card-top está último en el DOM → order:3 lo sube a la fila 1 */
  .emp-card-top   { order: 3; }
  .emp-card-menu  { opacity: 1; }

  /* Fila 2: botones de acción full-width */
  .emp-card-footer {
    order: 4;
    width: 100%;
    flex-wrap: wrap;
    gap: .375rem;
  }
  .emp-acciones {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: .375rem;
  }
  .emp-acciones .btn {
    flex: 1 1 auto;
    justify-content: center;
    font-size: .78rem;
    padding: .4rem .5rem;
    min-width: 0;
  }
}

/* Input con prefijo (ej: ícono WhatsApp) */
.input-with-prefix {
  position: relative;
}
.input-with-prefix .input-prefix {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #25d366;
  font-size: .9375rem;
  pointer-events: none;
}
.input-with-prefix .form-input {
  padding-left: 2.25rem;
}

@media (max-width: 480px) {
  .emp-card-menu { opacity: 1; }
}

/* =============================================================
   SEARCH BAR
   ============================================================= */

.search-bar-wrapper {
  margin-bottom: 1rem;
}

.search-bar-input {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: .5rem .875rem;
  max-width: 360px;
  transition: border-color .15s;
}

.search-bar-input:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(17,17,17,.08);
}

.search-bar-input i {
  color: var(--color-text-muted);
  flex-shrink: 0;
  font-size: .875rem;
}

.search-bar-input input {
  border: none;
  outline: none;
  background: transparent;
  font-size: .875rem;
  color: var(--color-text);
  width: 100%;
}

.search-bar-input input::placeholder {
  color: var(--color-text-muted);
}

/* =============================================================
   MOBILE BOTTOM NAVIGATION
   ============================================================= */

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-primary);
  height: 62px;
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(0,0,0,.25);
  border-top: 1px solid rgba(255,255,255,.1);
}

.mobile-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.55);
  text-decoration: none;
  font-size: .6875rem;
  font-weight: 500;
  gap: 3px;
  transition: color .15s;
  padding: 6px 0;
}

.mobile-bottom-nav a i {
  font-size: 1.2rem;
}

.mobile-bottom-nav a.active,
.mobile-bottom-nav a:hover {
  color: white;
}

.mobile-bottom-nav a.active i {
  color: var(--color-accent);
}

@media (max-width: 768px) {
  .mobile-bottom-nav { display: flex; }
  .page-container { padding-bottom: 74px; }
}

.btn-alertas-on {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  font-weight: 600;
}
.btn-alertas-on:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}
@media (prefers-color-scheme: dark) {
  .btn-alertas-on { background: #1e3a5f; color: #93c5fd; border-color: #2563eb; }
  .btn-alertas-on:hover { background: #1e40af33; }
}
:root[data-theme="dark"] .btn-alertas-on { background: #1e3a5f; color: #93c5fd; border-color: #2563eb; }
:root[data-theme="light"] .btn-alertas-on { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

/* =============================================================
   VINCULACIONES (dashboard)
   ============================================================= */

.vinc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-top: 1.5rem;
  margin-bottom: .875rem;
  overflow: hidden;
}

.vinc-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .625rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

.vinc-title {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--color-text);
  flex: 1;
}

.vinc-body {
  padding: .375rem 0;
}

.vinc-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .4rem 1rem;
}

.vinc-row + .vinc-row {
  border-top: 1px solid var(--color-border);
}

.vinc-phone {
  display: flex;
  align-items: center;
  gap: .375rem;
  flex-shrink: 0;
  min-width: 140px;
}

.vinc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}

.vinc-tag {
  display: inline-flex;
  align-items: center;
  padding: .2rem .625rem;
  border-radius: 100px;
  font-size: .75rem;
  font-weight: 600;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

@media (prefers-color-scheme: dark) {
  .vinc-tag { background: #1e3a5f; color: #93c5fd; border-color: #2563eb; }
}
:root[data-theme="dark"] .vinc-tag { background: #1e3a5f; color: #93c5fd; border-color: #2563eb; }
:root[data-theme="light"] .vinc-tag { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

@media (max-width: 640px) {
  .vinc-row { flex-direction: column; align-items: flex-start; gap: .375rem; }
  .vinc-phone { min-width: unset; }
}

/* ── Acceso de solo lectura (tabla lectores, ver js/auth.js) ─────
   La base ya no le deja cambiar nada; esto esconde los botones que
   escriben para que no los vea. Al agregar un botón que cambia datos,
   sumarlo acá. */
body.solo-lectura .header-actions::before {
  content: "Solo lectura";
  margin-right: .5rem;
  padding: .2rem .6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
@media (max-width: 480px) {
  body.solo-lectura .header-actions::before {
    content: "Lectura";
    margin-right: 0;
    padding: .15rem .45rem;
    font-size: .6875rem;
  }
}
body.solo-lectura #portal-link-box,
body.solo-lectura [onclick*="abrirNuev"],
body.solo-lectura [onclick*="abrirEditar"],
body.solo-lectura [onclick*="abrirAgregarDoc"],
body.solo-lectura [onclick*="abrirSubdoc"],
body.solo-lectura [onclick*="eliminar"],
body.solo-lectura [onclick*="modalEliminarTelefono"],
body.solo-lectura [onclick*="modalAgregarTelefono"],
body.solo-lectura [onclick*="agregarTelefono"],
body.solo-lectura [onclick*="verificarDoc"],
body.solo-lectura [onclick*="verificarTodos"],
body.solo-lectura [onclick*="rechazarDoc"],
body.solo-lectura [onclick*="toggleActiv"],
body.solo-lectura [onclick*="toggleAlertas"],
body.solo-lectura [onclick*="activarEmpresa"],
body.solo-lectura [onclick*="copiarPortalLink"],
body.solo-lectura [onclick*="abrirModalPortal"],
body.solo-lectura [onclick*="editarPortal"],
body.solo-lectura [onclick*="togglePortal"],
body.solo-lectura [onclick*="abrirModalF"],
body.solo-lectura [onclick*="abrirModalPolizas"],
body.solo-lectura [onclick*="actualizarColaConRecarga"],
body.solo-lectura [onclick*="procesarCola"],
body.solo-lectura [onclick*="reintentar"],
body.solo-lectura [onclick*="omitir"],
body.solo-lectura [onclick*="EditSchedule"],
body.solo-lectura [id^="btn-guardar"],
body.solo-lectura [onclick*="guardar"] {
  display: none !important;
}
