/* =========================================================================
   Corex - Hoja de estilos principal
   Paleta inspirada en plataformas GRC modernas (sobria, profesional).
   ========================================================================= */

:root {
  --c-primary: #1e3a5f;
  --c-primary-dark: #152a46;
  --c-primary-light: #2563eb;
  --c-accent: #3b82f6;

  --c-success: #10b981;
  --c-warning: #f59e0b;
  --c-danger: #ef4444;
  --c-info: #0ea5e9;

  --c-bg: #f5f7fb;
  --c-surface: #ffffff;
  --c-border: #e5e7eb;
  --c-border-strong: #d1d5db;

  --c-text: #1f2937;
  --c-text-muted: #6b7280;
  --c-text-subtle: #9ca3af;

  --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-md: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --sidebar-w: 240px;
  --topbar-h: 58px;
}

html, body { height: 100%; }
body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

/* ==================== Layout general ===================== */
.app-shell { display: flex; min-height: 100vh; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center;
  padding: 0 1.25rem;
  z-index: 1030;
  box-shadow: var(--shadow-sm);
}
.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--c-primary);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.topbar .brand span.mark {
  display: inline-block; width: 28px; height: 28px;
  background: var(--c-primary);
  color: #fff; border-radius: 8px;
  text-align: center; line-height: 28px;
  margin-right: .55rem; font-weight: 700;
}
.topbar .module-title {
  margin-left: 1.5rem;
  color: var(--c-text-muted);
  font-size: .9rem;
  border-left: 1px solid var(--c-border);
  padding-left: 1rem;
}
.topbar .spacer { flex: 1; }
.topbar .user-chip {
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--c-text);
  text-decoration: none;
  font-size: .88rem;
}
.topbar .user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 600;
}

/* ==================== Sidebar ===================== */
.sidebar {
  position: fixed;
  top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 1rem 0;
}
.sidebar .nav-section {
  padding: .5rem 1.25rem;
  font-size: .7rem; text-transform: uppercase;
  color: var(--c-text-subtle); letter-spacing: .08em;
  margin-top: .75rem;
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem 1.25rem;
  color: var(--c-text);
  font-weight: 500; font-size: .9rem;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.sidebar .nav-link i { width: 18px; color: var(--c-text-muted); font-size: 1rem; }
.sidebar .nav-link:hover { background: #f8fafc; color: var(--c-primary); }
.sidebar .nav-link.active {
  background: #eff6ff;
  color: var(--c-primary-light);
  border-left-color: var(--c-primary-light);
  font-weight: 600;
}
.sidebar .nav-link.active i { color: var(--c-primary-light); }
.sidebar .nav-link.nav-sub { padding-left: 2.75rem; font-size: .85rem; }
.sidebar .nav-link.nav-sub i { font-size: .85rem; }
.sidebar .nav-link.nav-sub-2 { padding-left: 3.5rem; font-size: .82rem; }
.sidebar .nav-link.nav-sub-2 i { font-size: .8rem; }
.sidebar .nav-link.muted { opacity: .5; pointer-events: none; }
.sidebar .nav-link.muted::after {
  content: 'pronto'; margin-left: auto;
  font-size: .65rem; background: #e5e7eb;
  color: var(--c-text-muted); padding: 1px 6px;
  border-radius: 4px; font-weight: 500;
}

.main-content {
  margin-left: var(--sidebar-w);
  padding-top: var(--topbar-h);
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
}
.main-inner { padding: 1.75rem 2rem; max-width: 100%; overflow-x: hidden; }

/* ==================== Page header ===================== */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 1.4rem; font-weight: 700; color: var(--c-text);
  margin: 0; letter-spacing: -0.01em;
}
.page-header .subtitle { color: var(--c-text-muted); font-size: .9rem; margin: .15rem 0 0; }
.breadcrumb-trail {
  font-size: .78rem; color: var(--c-text-subtle); margin-bottom: .25rem;
}
.breadcrumb-trail a { color: var(--c-text-muted); text-decoration: none; }
.breadcrumb-trail a:hover { color: var(--c-primary-light); }

/* ==================== Cards ===================== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.15rem 1.25rem; }

.kpi {
  display: flex; flex-direction: column; gap: .25rem;
  padding: 1.15rem 1.25rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.kpi:hover { box-shadow: var(--shadow-md); }
.kpi .label {
  color: var(--c-text-muted);
  font-size: .78rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: .04em;
  display: flex; align-items: center; gap: .4rem;
}
.kpi .value {
  font-size: 2rem; font-weight: 700; color: var(--c-text);
  line-height: 1.1; letter-spacing: -0.02em;
}
.kpi .hint { color: var(--c-text-subtle); font-size: .78rem; }
.kpi.kpi-success .value { color: var(--c-success); }
.kpi.kpi-warning .value { color: var(--c-warning); }
.kpi.kpi-danger .value { color: var(--c-danger); }

.feature-card {
  display: block; padding: 1.25rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  color: var(--c-text); text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  height: 100%;
}
.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #bfdbfe;
  color: var(--c-text);
}
.feature-card .icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: #eff6ff; color: var(--c-primary-light);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; margin-bottom: .85rem;
}
.feature-card h5 { font-size: .95rem; font-weight: 600; margin: 0 0 .25rem; }
.feature-card p { font-size: .82rem; color: var(--c-text-muted); margin: 0; }

/* ==================== Tables ===================== */
.table-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table { margin: 0; }
.table thead th {
  background: #f8fafc;
  color: var(--c-text-muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600;
  border-bottom: 1px solid var(--c-border);
  padding: .65rem 1rem;
}
.table tbody td {
  border-top: 1px solid var(--c-border);
  padding: .75rem 1rem;
  vertical-align: middle;
  font-size: .88rem;
}
.table tbody tr:hover { background: #f9fafb; }
.table-empty { padding: 2.5rem 1rem; text-align: center; color: var(--c-text-subtle); font-size: .88rem; }

/* ==================== Badges / estados ===================== */
.badge-state {
  font-size: .7rem; font-weight: 600;
  padding: .22rem .55rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid transparent;
}
.badge-state.borrador       { background: #f1f5f9; color: #475569; }
.badge-state.en_revision    { background: #fef3c7; color: #92400e; }
.badge-state.en_aprobacion  { background: #e0e7ff; color: #3730a3; }
.badge-state.observado      { background: #fee2e2; color: #b91c1c; }
.badge-state.aprobado       { background: #d1fae5; color: #065f46; }
.badge-state.publicado      { background: #dbeafe; color: #1e40af; }
.badge-state.obsoleto       { background: #e5e7eb; color: #6b7280; }

/* ==================== Forms ===================== */
.form-label { font-weight: 500; font-size: .85rem; color: var(--c-text); margin-bottom: .3rem; }
.form-control, .form-select {
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  font-size: .88rem; padding: .48rem .7rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--c-primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .15);
}

/* ==================== Buttons ===================== */
.btn { border-radius: var(--radius-sm); font-weight: 500; font-size: .88rem; padding: .45rem 1rem; }
.btn-primary { background: var(--c-primary-light); border-color: var(--c-primary-light); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-outline-secondary { border-color: var(--c-border-strong); color: var(--c-text); }
.btn-outline-secondary:hover { background: #f1f5f9; color: var(--c-text); border-color: var(--c-border-strong); }

/* ==================== Alerts ===================== */
.alert { border: none; border-radius: var(--radius-md); font-size: .9rem; box-shadow: var(--shadow-sm); }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info    { background: #dbeafe; color: #1e40af; }

/* ==================== Auth pages ===================== */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--c-bg);
}
.auth-side {
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dark) 100%);
  color: #fff;
  padding: 3rem;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-side .brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em;
}
.auth-side .brand .mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(255,255,255,.15);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.auth-side h1 {
  font-size: 2rem; font-weight: 700; margin: 2rem 0 1rem; letter-spacing: -0.02em;
}
.auth-side p.lead { color: rgba(255,255,255,.85); font-size: 1rem; max-width: 460px; }
.auth-side .meta { color: rgba(255,255,255,.65); font-size: .82rem; }
.auth-side .meta a { color: rgba(255,255,255,.85); }

.auth-form {
  display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.auth-form .form-card {
  width: 100%; max-width: 420px;
  background: var(--c-surface);
  padding: 2.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
}
.auth-form h2 { font-size: 1.3rem; font-weight: 700; margin: 0 0 .35rem; }
.auth-form .sub { color: var(--c-text-muted); font-size: .88rem; margin-bottom: 1.5rem; }

/* ==================== Footer ===================== */
.app-footer {
  text-align: center; color: var(--c-text-subtle);
  font-size: .78rem; padding: 1.5rem 1rem; border-top: 1px solid var(--c-border);
  margin-top: 2rem; background: var(--c-surface);
}

/* ==================== Responsive ===================== */
/* ==================== Mobile tables & lists ===================== */
@media (max-width: 767.98px) {
  .table-card { overflow-x: scroll; -webkit-overflow-scrolling: touch; }
  .table-card .table { min-width: 640px; white-space: nowrap; }
  .table-card .table td { white-space: normal; }
  .list-group { overflow-y: auto; max-height: 70vh; -webkit-overflow-scrolling: touch; }
  .page-header { flex-direction: column; }
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 1040;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(15,23,42,.4); z-index: 1039;
  }
  .sidebar-backdrop.open { display: block; }
  .main-content { margin-left: 0; }
  .main-inner { padding: 1.25rem; }
  .topbar .module-title { display: none; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { padding: 2rem; }
  .auth-side h1 { font-size: 1.5rem; }
}
@media (max-width: 576px) {
  .auth-form { padding: 1rem; }
  .auth-form .form-card { padding: 1.5rem; }
  .kpi .value { font-size: 1.6rem; }
}

.icon-btn { background: none; border: 0; color: var(--c-text-muted); padding: .4rem .5rem; border-radius: var(--radius-sm); }
.icon-btn:hover { background: #f1f5f9; color: var(--c-text); }
