/* NubIA Contable - estilos base mobile-first
   El CSS de Tailwind viene por CDN; este archivo agrega los estilos
   personalizados para el drawer, las tablas responsive (cards en mobile)
   y los elementos que el CDN no resuelve. */

/* === Variables de marca (Klan1 Labs) === */
:root {
  --klan1-red: #D30F01;       /* color principal del logo Klan1#1labs */
  --klan1-red-dark: #A60B01;  /* hover / dark */
  --klan1-red-light: #FEE2E2; /* background de badges */
  --klan1-red-border: #FECACA;/* border de badges */
}

/* === Reset basico: evitar overflow horizontal en cualquier viewport === */
html, body { overflow-x: hidden; max-width: 100vw; }
*, *::before, *::after { box-sizing: border-box; }
img, video, svg { max-width: 100%; height: auto; }
/* Las tablas pueden hacer overflow horizontal si tienen mucho contenido;
   las dejamos fluir (overflow-x: auto en el contenedor del template) y
   NO forzamos height: auto, porque romperia el calculo de columnas
   automatico del navegador en viewports >= 640px. */

/* === Drawer lateral === */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: white;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.25s ease-out;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  display: flex;
  flex-direction: column;
}
/* En pantallas >= 768px el drawer es un sidebar estatico siempre visible.
   Esto aplica para tablets, laptops, desktops. En mobile sigue oculto. */
@media (min-width: 768px) {
  .drawer {
    transform: translateX(0);
    box-shadow: 1px 0 8px rgba(0,0,0,0.04);
  }
  /* Cuando esta abierto en desktop es posicion relativa (no fixed) */
  .drawer.open {
    transform: translateX(0);
    box-shadow: 1px 0 8px rgba(0,0,0,0.04);
  }
  /* En desktop no se muestra el backdrop (siempre esta visible) */
  .drawer-backdrop { display: none; }
  /* Contenido principal empuja a la derecha en desktop */
  body.with-drawer main { margin-left: 280px; }
  /* En desktop no se muestra el boton cerrar */
  .drawer #drawer-close { display: none; }
}
.drawer.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.15); }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer-link {
  display: block;
  padding: 14px 20px;
  color: #334155;
  font-size: 15px;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
}
.drawer-link:hover, .drawer-link:focus { background: #f1f5f9; color: #065f46; outline: none; }
.drawer-link.active { background: #ecfdf5; color: #065f46; border-left-color: #065f46; font-weight: 500; }
.drawer-link-secondary { font-size: 13px; color: #64748b; padding: 10px 20px; border-top: 1px solid #f1f5f9; margin-top: 4px; }

/* === Tablas responsive (cards en mobile) === */
/* Mobile-first: solo aplicamos el patron de cards en viewports < 640px.
   Para >= 640px la tabla HTML se muestra tal cual (que es lo que el
   template ya estructura con <thead> visible).

   Notas sobre los breakpoints:
   - 640px = sm: de Tailwind. A partir de ahi la tabla HTML se ve bien
     en cualquier viewport (incluyendo tablets 768px y desktop 1024+).
   - Si el contenido fuerza overflow horizontal (ej: concepto largo),
     el overflow-x: hidden del body lo recorta limpiamente.
*/
@media (max-width: 639.98px) {
  .table-responsive thead { display: none; }
  .table-responsive tbody tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
    background: white;
  }
  .table-responsive tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    gap: 12px;
  }
  .table-responsive tbody td:last-child { border-bottom: none; }
  .table-responsive tbody td::before {
    content: attr(data-label);
    font-weight: 500;
    color: #64748b;
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex: 0 0 auto;
    min-width: 90px;
    max-width: 45%;
    display: block;
  }
  .table-responsive tbody td[data-full] {
    display: block;
    text-align: right;
  }
  .table-responsive tbody td[data-full]::before { display: none; }
  .table-responsive tbody td { text-align: right; }
  .table-responsive tbody td[data-numeric] { font-variant-numeric: tabular-nums; }
  .table-responsive tbody td > a,
  .table-responsive tbody td > span {
    text-align: right;
    flex: 1 1 auto;
    min-width: 0;
  }
  .table-responsive tbody td > div {
    text-align: right;
  }
}

/* === Utilidades varias === */
.no-print { /* por si en el futuro hay print */ }
.mono { font-family: "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }

/* Touch target: 44x44 minimo para botones en mobile */
@media (max-width: 639.98px) {
  .touch-target { min-height: 44px; min-width: 44px; }
}

/* Para viewports >= 640px (tablets/desktop) la tabla HTML debe verse
   como tabla. Aseguramos que el thead se muestre y que el layout de
   tabla funcione correctamente, incluso si el contenido tiene celdas
   largas (con truncate via Tailwind). */
@media (min-width: 640px) {
  .table-responsive thead { display: table-header-group; }
  .table-responsive tbody tr { display: table-row; }
  .table-responsive tbody td {
    display: table-cell;
    text-align: left;
  }
  .table-responsive tbody td[data-numeric] { text-align: right; }
  .table-responsive tbody td[data-full] { text-align: right; }
  .table-responsive tbody td::before { display: none; }
}


/* === Menu colapsible (header drawer) === */
.menu-group-title-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 16px;
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.menu-group-title-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.menu-group-items {
    background: transparent;
}
.menu-group-items[hidden] {
    display: none;
}
.menu-group-chevron {
    color: #94a3b8;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 8px 36px;
    color: #334155;
    font-size: 14px;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.menu-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.menu-item.active {
    background: #fef2f2;
    color: #A60B01;
    border-left-color: #D30F01;
    font-weight: 500;
}
.menu-item-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.menu-item-badge {
    background: #D30F01;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

/* === User dropdown === */
#user-menu-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
}
#user-menu-toggle:focus {
    outline: 2px solid #D30F01;
    outline-offset: 1px;
}
#user-menu-dropdown {
    animation: dropdown-fade 0.15s ease-out;
}
@keyframes dropdown-fade {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
