/* ═══════════════════════════════════════════════════════════════════════════
   ITSystem 2.0 — Estilos principales
   Paleta: verde primario #16a34a, grises neutros, blanco
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --primary:        #16a34a;
  --primary-dark:   #15803d;
  --primary-light:  #dcfce7;
  --primary-muted:  #86efac;

  --sidebar-bg:     #0f172a;
  --sidebar-width:  240px;
  --topbar-height:  56px;

  --bg-primary:     #ffffff;
  --bg-secondary:   #f1f5f9;
  --bg-card:        #ffffff;

  --text-primary:   #0f172a;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;

  --border:         #e2e8f0;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.05);
  --radius:         10px;
  --radius-sm:      6px;

  --transition:     .18s ease;
}

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin: 0; padding: 0;
  -webkit-font-smoothing: antialiased;
}

/* ── Bootstrap overrides ────────────────────────────────────────────────── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.text-primary { color: var(--primary) !important; }
.bg-primary   { background: var(--primary) !important; }
.form-control:focus, .form-select:focus {
  border-color: var(--primary-muted);
  box-shadow: 0 0 0 3px rgba(22,163,74,.15);
}
.badge { font-size: .7rem; font-weight: 600; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  transition: width var(--transition);
  z-index: 1000;
  overflow: hidden;
}

.sidebar.collapsed { width: 64px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  min-height: 60px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}
.sidebar-logo:hover { text-decoration: none; color: inherit; }

.logo-icon { font-size: 1.4rem; }
.logo-img { height: 28px; width: auto; flex-shrink: 0; }
.logo-text { font-size: .95rem; font-weight: 700; color: #fff; }

.sidebar-toggle {
  background: none; border: none;
  color: rgba(255,255,255,.4);
  cursor: pointer; padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: #fff; background: rgba(255,255,255,.08); }

.sidebar.collapsed .sidebar-toggle { transform: scaleX(-1); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-group-label { display: none; }

/* Usuario en sidebar */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .875rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name { font-size: .8rem; font-weight: 600; color: #fff; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: rgba(255,255,255,.45); margin: 0; }

/* Navegación */
.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-group { margin-bottom: .25rem; }

/* ── Etiqueta toggle del grupo ── */
.nav-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: .55rem 1rem .3rem;
  margin: 0;
  cursor: pointer;
  user-select: none;
  transition: color .2s, background .2s;
}
.nav-group-label:hover { color: rgba(255,255,255,.75); background: rgba(255,255,255,.05); }

/* Chevron */
.ng-chevron {
  font-size: .62rem;
  opacity: .55;
  transition: transform .22s ease;
  flex-shrink: 0;
}
.nav-group.ng-collapsed .ng-chevron { transform: rotate(-90deg); }

/* ── Items del grupo ── */
.nav-group-items {
  overflow: hidden;
  max-height: 600px;
  transition: max-height .28s ease, opacity .22s ease;
  opacity: 1;
}
.nav-group.ng-collapsed .nav-group-items {
  max-height: 0 !important;
  opacity: 0;
}

/* ── Sub-sección dentro de un grupo (ej: Reportes > Ventas) ── */
.nav-subsection-label {
  font-size: .58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.22);
  padding: .6rem 1rem .15rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,.05);
  margin-top: .25rem;
}
.nav-subsection-label:first-child { border-top: none; margin-top: 0; }

/* Cuando el sidebar completo está colapsado */
.sidebar.collapsed .nav-group-label { display: none; }
.sidebar.collapsed .nav-subsection-label { display: none; }
.sidebar.collapsed .nav-group-items { max-height: 600px !important; opacity: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1rem;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  border-radius: 0;
  transition: color var(--transition), background var(--transition);
  font-size: .82rem;
  white-space: nowrap;
}
.nav-item i { font-size: 1rem; flex-shrink: 0; width: 18px; text-align: center; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-item.active { color: #fff; background: var(--primary); }
.nav-item-danger { color: rgba(248,113,113,.7); }
.nav-item-danger:hover { color: #fca5a5; background: rgba(248,113,113,.1); }

/* Footer del sidebar */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.06);
  padding: .5rem 0;
}

/* ── Main wrapper ────────────────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left var(--transition);
}
.main-wrapper.sidebar-collapsed { margin-left: 64px; }

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 900;
  box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.breadcrumb { font-size: .8rem; }
.breadcrumb-item + .breadcrumb-item::before { content: "›"; color: var(--text-muted); }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.badge-company { background: var(--primary-light); color: var(--primary); font-size: .72rem; font-weight: 600; padding: .25rem .6rem; border-radius: 20px; }
.topbar-clock { font-size: .8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ── Alerts container ───────────────────────────────────────────────────── */
.alert-container { padding: .75rem 1.5rem 0; }
.alert { font-size: .84rem; }

/* ── Page content ───────────────────────────────────────────────────────── */
.page-content { padding: 1.25rem 1.5rem; flex: 1; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.page-subtitle { font-size: .82rem; margin: .2rem 0 0; }
.page-actions { display: flex; gap: .5rem; flex-shrink: 0; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .875rem;
  padding: .875rem 1.25rem;
}
.card-body { padding: 1.25rem; }

/* ── Metric cards ───────────────────────────────────────────────────────── */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.metric-card:hover { box-shadow: var(--shadow-md); }
.metric-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin: 0 0 .5rem; }
.metric-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.metric-sub { font-size: .75rem; color: var(--text-secondary); margin: .25rem 0 0; }
.metric-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.metric-icon-green { background: var(--primary-light); color: var(--primary); }
.metric-icon-blue { background: #dbeafe; color: #2563eb; }
.metric-icon-yellow { background: #fef9c3; color: #ca8a04; }
.metric-icon-red { background: #fee2e2; color: #dc2626; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table { font-size: .82rem; }
.table th { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); white-space: nowrap; }
.table-hover tbody tr:hover { background: #f8fafc; }
.table td { vertical-align: middle; }

/* ── Estado badges ──────────────────────────────────────────────────────── */
.badge-state-c   { background: #dbeafe; color: #1d4ed8; }
.badge-state-b   { background: #fef9c3; color: #a16207; }
.badge-state-ap  { background: #fce7f3; color: #9d174d; }
.badge-state-ae  { background: #ffedd5; color: #c2410c; }
.badge-state-no  { background: #fee2e2; color: #b91c1c; }
.badge-state-ok  { background: var(--primary-light); color: var(--primary-dark); }

/* ── Buttons pequeños ───────────────────────────────────────────────────── */
.btn-xs { padding: .2rem .45rem; font-size: .72rem; }
.btn-icon { background: none; border: none; padding: 0; }

/* ── Form inputs ────────────────────────────────────────────────────────── */
.form-control-sm, .form-select-sm { font-size: .8rem; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
  .page-content { padding: 1rem; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-actions { justify-content: flex-end; }

  /* Tablas anchas -> tarjetas apiladas, para no depender de scroll horizontal
     en pantallas angostas (listas de autorización, cotizaciones, facturas). */
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr {
    margin-bottom: .6rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    padding: .5rem .75rem;
  }
  .rtable tr:last-child { margin-bottom: 0; }
  .rtable td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    padding: .3rem 0;
    border: none !important;
    text-align: right;
  }
  .rtable td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .02em;
    text-align: left;
    flex-shrink: 0;
  }
}

/* ── Spinner overlay ────────────────────────────────────────────────────── */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
}
