* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    color: #333;
}

/* ══════════════════════════════════════════
   LAYOUT CON SIDEBAR
══════════════════════════════════════════ */

body.with-sidebar {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 56px 1fr;
    min-height: 100vh;
}

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */

.sidebar {
    grid-column: 1;
    grid-row: 1 / -1;
    background: #1e2430;
    color: #c8cdd6;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    z-index: 100;
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #2d3548;
}

.sidebar-logo {
    font-size: 22px;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #5a6478;
    padding: 10px 16px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: #9aa3b4;
    text-decoration: none;
    font-size: 13.5px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: #252d3d;
    color: #ffffff;
}

.nav-item.active {
    background: #252d3d;
    color: #ffffff;
    border-left-color: var(--color-acento, #4a9eff);
}

.nav-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid #2d3548;
}

.sidebar-version {
    font-size: 11px;
    color: #4a5268;
}

/* ══════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════ */

.topbar {
    position: fixed;
    top: 0;
    left: 240px;
    right: 0;
    height: 56px;
    background: #ffffff;
    border-bottom: 1px solid #e8eaed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 99;
    transition: left 0.3s ease;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.sidebar-toggle:hover {
    background: #f0f2f5;
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-user {
    font-size: 13.5px;
    color: #555;
}

.btn-logout {
    font-size: 13px;
    color: #888;
    text-decoration: none;
    padding: 5px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    transition: all 0.15s;
}

.btn-logout:hover {
    background: #f5f5f5;
    color: #333;
}

/* ══════════════════════════════════════════
   CONTENIDO PRINCIPAL
══════════════════════════════════════════ */

.main-content {
    margin-left: 240px;
    margin-top: 56px;
    padding: 28px;
    min-height: calc(100vh - 56px);
    transition: margin-left 0.3s ease;
}

/* ══════════════════════════════════════════
   FLASH MESSAGES
══════════════════════════════════════════ */

.flash-messages {
    margin-bottom: 20px;
}

.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 14px;
}

.flash-danger  { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
.flash-success { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
.flash-warning { background: #fff3cd; color: #664d03; border: 1px solid #ffecb5; }
.flash-info    { background: #cff4fc; color: #055160; border: 1px solid #b6effb; }

/* ══════════════════════════════════════════
   FORMS
══════════════════════════════════════════ */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #444;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    background: #fff;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primario);
    box-shadow: 0 0 0 3px rgba(46, 116, 182, 0.12);
}

.form-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    display: block;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input { width: auto; }
.form-check label { margin-bottom: 0; font-weight: normal; }

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */

.btn {
    padding: 9px 18px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.2s;
}

.btn:hover { opacity: 0.85; }
.btn-primary  { background: var(--color-primario); color: white; }
.btn-danger   { background: #dc3545; color: white; }
.btn-success  { background: #198754; color: white; }
.btn-secondary{ background: #6c757d; color: white; }
.btn-block    { width: 100%; text-align: center; }

/* ══════════════════════════════════════════
   LOGIN (sin sidebar)
══════════════════════════════════════════ */

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f2f5;
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    color: var(--color-primario);
    font-size: 22px;
    margin-bottom: 8px;
}

.login-header p {
    color: #888;
    font-size: 13px;
}

/* ══════════════════════════════════════════
   SIDEBAR COLAPSADO
══════════════════════════════════════════ */

body.sidebar-collapsed .sidebar {
    transform: translateX(-240px);
}

body.sidebar-collapsed .topbar {
    left: 0;
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
}

body.login-page {
    display: block;
}

/* ══════════════════════════════════════════
   PAGE HEADER
══════════════════════════════════════════ */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e2430;
}

/* ══════════════════════════════════════════
   FILTROS
══════════════════════════════════════════ */

.filtros-card {
    background: white;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.filtros-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.filtro-grupo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 160px;
}

.filtro-grupo label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filtro-acciones {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    min-width: auto;
}

/* ══════════════════════════════════════════
   TABLA
══════════════════════════════════════════ */

.tabla-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    overflow: hidden;
}

.tabla-info {
    padding: 12px 20px;
    font-size: 13px;
    color: #888;
    border-bottom: 1px solid #f0f0f0;
}

.tabla-wrapper {
    overflow-x: auto;
}

.tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.tabla thead tr {
    background: #f8f9fb;
    border-bottom: 2px solid #e8eaed;
}

.tabla th {
    padding: 11px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.col-header {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.col-header:hover { color: var(--color-primario); }
.col-header.activo { color: var(--color-primario); }

.tabla tbody tr {
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.1s;
}

.tabla tbody tr:hover { background: #f8fafd; }

.tabla td {
    padding: 10px 14px;
    color: #333;
    vertical-align: middle;
}

.tabla-vacia {
    text-align: center;
    color: #aaa;
    padding: 40px !important;
    font-size: 14px;
}

.acciones {
    white-space: nowrap;
}

.btn-accion {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.15s;
}

.btn-accion:hover { opacity: 0.8; }
.btn-editar { background: #e8f0fe; color: #1a73e8; }
.btn-eliminar { background: #fce8e6; color: #d93025; }
.btn-ver { background: #e6f4ea; color: #188038; }

/* ══════════════════════════════════════════
   PAGINACIÓN
══════════════════════════════════════════ */

.paginacion {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    border-top: 1px solid #f0f0f0;
}

.btn-pag {
    padding: 6px 14px;
    border-radius: 5px;
    background: #f0f2f5;
    color: #333;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.15s;
}

.btn-pag:hover { background: #e0e4ea; }

.pag-info {
    font-size: 13px;
    color: #888;
}

/* ══════════════════════════════════════════
   FORM CARD
══════════════════════════════════════════ */

.form-card {
    background: white;
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    max-width: 720px;
}

.form-acciones {
    display: flex;
    gap: 12px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f0;
}

/* ══════════════════════════════════════════
   CONTRATO HEADER
══════════════════════════════════════════ */

.contrato-header {
    background: white;
    border-radius: 8px;
    padding: 16px 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.contrato-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.contrato-codigo {
    font-size: 18px;
    font-weight: 700;
    color: #1e2430;
}

.contrato-estado {
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
}

.contrato-detalle {
    font-size: 13px;
    color: #666;
}

.contrato-header-stats {
    display: flex;
    gap: 24px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: #1e2430;
}

/* ══════════════════════════════════════════
   TABS
══════════════════════════════════════════ */

.tabs-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    overflow: hidden;
}

.tabs-nav {
    display: flex;
    border-bottom: 2px solid #e8eaed;
    background: #f8f9fb;
    overflow-x: auto;
}

.tab-btn {
    padding: 12px 20px;
    border: none;
    background: none;
    font-size: 13.5px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: all 0.15s;
}

.tab-btn:hover { color: var(--color-primario); }

.tab-btn.active {
    color: var(--color-primario);
    border-bottom-color: var(--color-primario);
    background: white;
}

.tab-content {
    display: none;
    padding: 24px;
}

.tab-content.active { display: block; }

/* ══════════════════════════════════════════
   SIDEBAR — SUBMENÚS DESPLEGABLES
══════════════════════════════════════════ */

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-width: 2;
}

.nav-group {
    margin-bottom: 1px;
}

.nav-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: none;
    border: none;
    color: #c8cdd6;
    font-size: 0.88rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    border-radius: 8px;
    transition: background 0.18s ease, color 0.18s ease;
}

.nav-group-toggle:hover {
    background: #2a3142;
    color: #fff;
}

.nav-group-toggle.active {
    color: #fff;
    background: #2a3142;
}

.nav-arrow {
    margin-left: auto;
    width: 14px;
    height: 14px;
    transition: transform 0.25s ease;
    opacity: 0.6;
}

.nav-group-toggle.open .nav-arrow {
    transform: rotate(90deg);
    opacity: 1;
}

.nav-group-items {
    display: grid;
    grid-template-rows: 0fr;
    overflow: hidden;
    transition: grid-template-rows 0.28s ease;
}

.nav-group-items.open {
    grid-template-rows: 1fr;
    margin-top: 2px;
    margin-bottom: 4px;
}

.nav-group-items-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-left: 14px;
}

.nav-subitem {
    padding: 8px 12px;
    font-size: 0.8rem;
    color: #9aa0ac;
    text-decoration: none;
    border-radius: 6px;
    border-left: 2px solid #333c50;
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.nav-subitem:hover {
    color: #fff;
    background: #2a3142;
    border-left-color: #4a90d9;
}

.nav-proximamente {
    color: #5a6070;
    font-style: italic;
    cursor: default;
    pointer-events: none;
}

/* ── Switches de configuración de módulos ── */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd2dc;
    border-radius: 24px;
    transition: background 0.25s;
}
.switch-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider {
    background: #4a90d9;
}
.switch input:checked + .switch-slider::before {
    transform: translateX(18px);
}
.switch input:disabled + .switch-slider {
    background: #4a90d9;
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Tarjetas de módulo en config ── */
.config-modulo-card {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e5e8ee);
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.config-modulo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border, #eef0f4);
}
.config-modulo-titulo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.config-modulo-titulo h3 {
    font-size: 1.05rem;
    margin: 0;
    font-weight: 600;
}
.config-badge-nucleo {
    font-size: 0.68rem;
    background: #eef0f4;
    color: #7a828f;
    padding: 2px 9px;
    border-radius: 10px;
    font-weight: 500;
}
.config-acciones-modulo {
    display: flex;
    gap: 0.5rem;
}
.config-btn-mini {
    border: 1px solid var(--border, #dde1e8);
    background: #fff;
    color: #5a6270;
    padding: 5px 12px;
    border-radius: 7px;
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s;
}
.config-btn-mini:hover {
    background: #f5f7fa;
    border-color: #c4cad3;
}
.config-submenu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.5rem;
}
.config-submenu-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.95rem;
    background: var(--bg-secondary, #f7f9fc);
    border-radius: 9px;
    transition: background 0.15s;
}
.config-submenu-row:hover {
    background: #eef2f7;
}
.config-submenu-nombre {
    font-size: 0.88rem;
    color: var(--text-primary, #2a2f3a);
}