/* ═══════════════════════════════════════════════════════════
   PRAGMA SST — main.css
   Layout · Header · Horizontal Nav · Variables
═══════════════════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --blue-dark:    #003366;
  --blue-mid:     #0055a5;
  --blue-light:   #1a7fd4;
  --blue-soft:    #e8f0fb;
  --green:        #28a745;
  --green-light:  #d4edda;
  --orange:       #fd7e14;
  --red:          #dc3545;
  --yellow:       #ffc107;
  --cyan:         #17a2b8;

  --text-primary:   #1a1d23;
  --text-secondary: #5a6270;
  --text-muted:     #9aa3af;
  --border:         #dee2e8;
  --border-light:   #f0f2f5;
  --bg-body:        #f4f6f9;
  --bg-card:        #ffffff;
  --bg-header:      #ffffff;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.12);

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;

  --font-main:  'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono:  'IBM Plex Mono', monospace;

  --header-h:   60px;
  --nav-h:      72px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 14px;
  scroll-behavior: smooth;
  /* Bloquear scroll horizontal a nivel raíz */
  overflow-x: hidden;
  max-width: 100%;
}
body {
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  /* Ancho máximo igual al viewport, nunca más */
  max-width: 100vw;
  width: 100%;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--blue-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  min-width: 0;
  overflow: hidden;
  /* Fijar al ancho del viewport, no al del documento */
  width: 100%;
  max-width: 100vw;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  flex: 1 1 0;
  overflow: hidden;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 22px;
  filter: drop-shadow(0 0 6px rgba(255,255,255,.4));
  animation: spin 20s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex-shrink: 0;
}
.brand-name {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 2px;
}
.brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue-light);
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 3px;
  padding: 1px 5px;
  letter-spacing: 1px;
}

.company-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-left: 1px solid rgba(255,255,255,.2);
  padding-left: 16px;
  min-width: 0;
  overflow: hidden;
}
.company-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.company-nit {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.btn-notif {
  position: relative;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-notif:hover { background: rgba(255,255,255,.2); }
.notif-icon { font-size: 16px; }
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 20px;
  padding: 4px 12px;
  min-width: 0;
  overflow: hidden;
}
.user-avatar { font-size: 14px; flex-shrink: 0; }
.user-email {
  font-size: 12px;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.btn-logout {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  font-family: var(--font-main);
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-logout:hover { background: #c82333; transform: translateY(-1px); }

/* ══════════════════════════════════════════
   NAVIGATION (HORIZONTAL TABS)
══════════════════════════════════════════ */
.app-nav {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  /* Evita que el nav desborde el viewport en móvil */
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.app-nav::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 48px;
  height: 100%;
  background: linear-gradient(to right, transparent, var(--bg-card));
  pointer-events: none;
  z-index: 1;
}

.nav-scroll-wrapper {
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.nav-scroll-wrapper::-webkit-scrollbar { display: none; }

.nav-tabs {
  display: flex;
  align-items: stretch;
  min-width: max-content;
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 88px;
  padding: 10px 14px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  font-family: var(--font-main);
  color: var(--text-secondary);
  position: relative;
}

.nav-tab:hover {
  background: var(--blue-soft);
  color: var(--blue-mid);
}

.nav-tab.active {
  background: var(--blue-soft);
  border-bottom-color: var(--blue-mid);
  color: var(--blue-dark);
}

.tab-icon { font-size: 18px; line-height: 1; }
.tab-label {
  font-size: 10px;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

.nav-tab.active .tab-label { font-weight: 700; color: var(--blue-dark); }

.nav-indicator {
  height: 3px;
  background: linear-gradient(90deg, var(--blue-mid), var(--blue-light));
  transition: width .3s ease;
}

/* ══════════════════════════════════════════
   MAIN CONTENT AREA
══════════════════════════════════════════ */
.app-main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  gap: 16px;
  color: var(--text-muted);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue-mid);
  border-radius: 50%;
  animation: rotate .7s linear infinite;
}
@keyframes rotate { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 680px;
  max-width: 96vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }
.modal-close {
  position: sticky;
  top: 0;
  float: right;
  margin: 12px 12px 0 0;
  background: var(--border-light);
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
}
.modal-content { padding: 24px; }

/* ══════════════════════════════════════════
   TOAST
══════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text-primary);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideLeft .25s ease;
  min-width: 280px;
}
@keyframes slideLeft { from { transform: translateX(20px); opacity: 0; } }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--orange); color: #fff; }
.toast.info    { background: var(--blue-mid); }

/* ══════════════════════════════════════════
   UTILITY
══════════════════════════════════════════ */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
}
.empty-state .empty-icon { font-size: 48px; opacity: .4; }
.empty-state p { font-size: 13px; max-width: 300px; line-height: 1.6; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* ══════════════════════════════════════════
   RESPONSIVE
   768px · 600px · 480px · 360px
══════════════════════════════════════════ */

@media (max-width: 768px) {
  .user-email    { display: none; }
  .user-pill     { padding: 4px 8px; }
  .app-header    { padding: 0 12px; gap: 8px; }
  .header-brand  { gap: 8px; }
  .company-name  { font-size: 12px; }
  .company-nit   { display: none; }
  .brand-name    { font-size: 17px; letter-spacing: 1px; }
  .app-main      { padding: 16px 12px; }
  .modal-box     { max-height: 92vh; }
  .modal-content { padding: 16px; }
  .toast-container { left: 12px; right: 12px; bottom: 16px; }
  .toast         { min-width: unset; width: 100%; }
}

/* ── 600px: ocultar company-info antes de que rompa el layout ── */
@media (max-width: 600px) {
  .company-info  { display: none; }
  .header-actions { gap: 8px; }
}

/* ── 480px mobile ── */
@media (max-width: 480px) {
  :root { --header-h: 52px; }

  .app-header    { padding: 0 10px; gap: 6px; }
  .brand-name    { font-size: 16px; letter-spacing: 1px; }
  .logo-icon     { font-size: 18px; }
  .brand-sub     { display: none; }
  .header-actions { gap: 6px; }

  /* logout: solo ✕ circular */
  .btn-logout {
    padding: 0;
    font-size: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .btn-logout::before { content: '✕'; font-size: 13px; }

  .btn-notif     { width: 32px; height: 32px; }

  .app-nav       { top: var(--header-h); }
  .nav-tab       { min-width: 72px; padding: 8px 10px; }
  .tab-icon      { font-size: 16px; }
  .tab-label     { font-size: 9px; }

  .app-main      { padding: 12px 8px; }

  .modal-overlay { align-items: flex-end; }
  .modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 12px 12px 0 0;
  }
  .modal-content { padding: 16px; }
}

/* ── 360px small mobile ── */
@media (max-width: 360px) {
  .brand-name    { font-size: 14px; }
  .logo-icon     { font-size: 16px; }
  .header-actions { gap: 4px; }
  .btn-notif     { width: 28px; height: 28px; }
  .btn-logout    { width: 28px; height: 28px; }
  .nav-tab       { min-width: 60px; padding: 7px 8px; }
  .tab-label     { font-size: 8px; }
  .app-main      { padding: 10px 6px; }
}

/* ── PHVA bar responsive ── */

/* La phva-bar hace scroll horizontal en móvil, nunca recorta */
.phva-bar {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* justify-content: flex-start para que el scroll tenga sentido */
  justify-content: flex-start !important;
  flex-wrap: nowrap;
}
.phva-bar::-webkit-scrollbar { display: none; }

/* El botón buscar se fija a la derecha sin empujar nada */
.phva-search-btn {
  margin-left: auto;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .phva-bar      { padding: 0 10px; gap: 4px; }
  .phva-btn      { padding: 4px 8px; font-size: 11px; }

  /* Ocultar texto y kbd del botón buscar, dejar solo el ícono */
  .phva-search-btn kbd { display: none; }
  .phva-search-btn .phva-search-label { display: none; }
  .phva-search-btn     { padding: 5px 9px; min-width: unset; }
}

@media (max-width: 480px) {
  .phva-bar      { padding: 0 8px; gap: 3px; }
  .phva-btn      { padding: 3px 6px; font-size: 10px; white-space: nowrap; }
  .phva-divider  { margin: 0 2px; }
}
