/* ============================================================
   Plataforma Institucional MGSD — Design System
   Mancomunidad del Gran Santo Domingo
   ============================================================ */

:root {
    /* MGSD Brand Colors */
    --mgsd-navy:       #0c4a60;
    --mgsd-navy-dark:  #072f3e;
    --mgsd-blue:       #1a6a88;
    --mgsd-cyan:       #3498db;
    --mgsd-green:      #27ae60;
    --mgsd-gold:       #f39c12;
    
    /* Aliases for backward compatibility */
    --primary-color:   var(--mgsd-navy);
    --primary-hover:   var(--mgsd-navy-dark);
    --secondary-color: var(--mgsd-cyan);
    --accent-color:    var(--mgsd-green);

    /* Programa activo: inyectado dinámicamente vía style inline o JS */
    --programa-color:  var(--mgsd-green);

    /* Neutral Palette */
    --bg-light:        #f0f4f8;
    --bg-white:        #ffffff;
    --text-dark:       #1e2d3d;
    --text-muted:      #64748b;
    --border-color:    #e2e8f0;
    --border-light:    #f1f5f9;

    /* Semáforo */
    --semaforo-green-bg:     #d4edda;
    --semaforo-green-text:   #155724;
    --semaforo-green-border: #c3e6cb;
    --semaforo-yellow-bg:    #fff3cd;
    --semaforo-yellow-text:  #856404;
    --semaforo-yellow-border:#ffeeba;
    --semaforo-red-bg:       #f8d7da;
    --semaforo-red-text:     #721c24;
    --semaforo-red-border:   #f5c6cb;

    /* Shadows */
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg:  0 10px 30px rgba(0,0,0,0.10);
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-dark);
    background-color: var(--bg-light);
    overflow-x: hidden;
    font-size: 0.9375rem;
    line-height: 1.6;
}

/* ============================================================
   Sidebar Navigation
   ============================================================ */
.sidebar {
    background: linear-gradient(180deg, var(--mgsd-navy) 0%, var(--mgsd-navy-dark) 100%);
    min-height: 100vh;
    box-shadow: 3px 0 15px rgba(0,0,0,0.15);
    color: #fff;
    transition: all 0.3s ease;
    position: relative;
}

/* Subtle texture overlay */
.sidebar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.015'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

.sidebar .brand {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    position: relative;
    text-align: center;
}

.sidebar .brand-name {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #fff;
}

.sidebar .brand-programa {
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.25rem;
    opacity: 0.7;
}

.sidebar .brand-programa .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--programa-color, var(--mgsd-green));
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

.sidebar .nav-link {
    color: rgba(255,255,255,0.72);
    padding: 0.72rem 1.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    border-radius: 0 4px 4px 0;
    margin-right: 0.5rem;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.07);
    border-left-color: var(--mgsd-cyan);
}

.sidebar .nav-link.active {
    color: #fff;
    background: rgba(255,255,255,0.12);
    border-left-color: var(--programa-color, var(--mgsd-green));
    font-weight: 600;
}

.sidebar .nav-link i {
    width: 18px;
    text-align: center;
}

.sidebar .sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    padding: 1.25rem 1.5rem 0.4rem;
}

/* ============================================================
   Top Header Bar
   ============================================================ */
.topbar-programa-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--programa-color, var(--mgsd-green));
    background: color-mix(in srgb, var(--programa-color, var(--mgsd-green)) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--programa-color, var(--mgsd-green)) 30%, transparent);
    color: var(--programa-color, var(--mgsd-green));
    border-radius: 50px;
    padding: 0.3rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.topbar-programa-badge:hover {
    background: color-mix(in srgb, var(--programa-color, var(--mgsd-green)) 20%, transparent);
    color: var(--programa-color, var(--mgsd-green));
}

.topbar-programa-badge .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    border: none;
    border-radius: 12px;
    background: var(--bg-white);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-header {
    border-radius: 12px 12px 0 0 !important;
    border-bottom: 1px solid var(--border-light);
}

/* Metric cards */
.stat-card {
    border-left: 4px solid transparent;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 2rem;
    opacity: 0.75;
}

/* ============================================================
   Semáforo
   ============================================================ */
.semaforo-verde {
    background-color: var(--semaforo-green-bg);
    color: var(--semaforo-green-text);
    border: 1px solid var(--semaforo-green-border);
}

.semaforo-amarillo {
    background-color: var(--semaforo-yellow-bg);
    color: var(--semaforo-yellow-text);
    border: 1px solid var(--semaforo-yellow-border);
}

.semaforo-rojo {
    background-color: var(--semaforo-red-bg);
    color: var(--semaforo-red-text);
    border: 1px solid var(--semaforo-red-border);
}

.semaforo-indicador {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.semaforo-indicador.verde    { background: #28a745; box-shadow: 0 0 8px #28a74588; }
.semaforo-indicador.amarillo { background: #ffc107; box-shadow: 0 0 8px #ffc10788; }
.semaforo-indicador.rojo     { background: #dc3545; box-shadow: 0 0 8px #dc354588; }

/* ============================================================
   Status Badges
   ============================================================ */
.badge-estado {
    font-size: 0.78rem;
    padding: 0.35em 0.8em;
    border-radius: 50px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.estado-borrador   { background: #e2e8f0; color: #475569; }
.estado-enviado    { background: #dbeafe; color: #1e40af; }
.estado-revision   { background: #fef3c7; color: #92400e; }
.estado-enrevision { background: #fef3c7; color: #92400e; }
.estado-aprobado   { background: #dcfce7; color: #166534; }
.estado-observado  { background: #fae8ff; color: #86198f; }
.estado-rechazado  { background: #fee2e2; color: #991b1b; }

/* ============================================================
   Signature Pad
   ============================================================ */
.signature-pad-container {
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    background: #fff;
    position: relative;
}

.signature-pad {
    width: 100%;
    height: 200px;
    cursor: crosshair;
}

/* ============================================================
   Program Selection Cards (hub)
   ============================================================ */
.programa-card {
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-white);
    text-decoration: none;
    display: block;
    position: relative;
    overflow: hidden;
}

.programa-card:hover {
    border-color: var(--programa-color, var(--mgsd-green));
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.12);
    text-decoration: none;
}

.programa-card.active {
    border-color: var(--mgsd-green);
    background: #f0fdf4;
}

/* ============================================================
   Tables
   ============================================================ */
.table > :not(caption) > * > * {
    padding: 0.85rem 1rem;
}

.table-hover > tbody > tr:hover > * {
    background-color: #f8fafc;
}

/* ============================================================
   Forms
   ============================================================ */
.form-control, .form-select {
    border-color: var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--mgsd-cyan);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--mgsd-navy);
    border-color: var(--mgsd-navy);
}

.btn-primary:hover {
    background: var(--mgsd-navy-dark);
    border-color: var(--mgsd-navy-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(12,74,96,0.3);
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
    .no-print, .sidebar, header, nav, .btn, .alert, .modal {
        display: none !important;
    }

    body {
        background: #fff !important;
        font-size: 12pt;
        color: #000;
    }

    .print-container {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
    }

    table { page-break-inside: auto; }
    tr { page-break-inside: avoid; page-break-after: auto; }

    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
    }

    .print-logo { max-width: 180px; margin-bottom: 10px; }

    .signature-box {
        border-top: 1px solid #000;
        margin-top: 50px;
        text-align: center;
    }
}

.print-header { display: none; }

/* ============================================================
   Login / Restricted Accounts Pages
   ============================================================ */
.login-bg {
    background: linear-gradient(135deg, var(--mgsd-navy) 0%, var(--mgsd-blue) 50%, var(--mgsd-navy-dark) 100%);
    position: relative;
    overflow: hidden;
}

/* Decorative blobs */
.login-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    opacity: 0.18;
}

.login-blob-1 { width: 500px; height: 500px; background: var(--mgsd-green); top: -150px; left: -150px; }
.login-blob-2 { width: 400px; height: 400px; background: var(--mgsd-cyan); bottom: -100px; right: -100px; }
.login-blob-3 { width: 300px; height: 300px; background: var(--mgsd-gold); top: 50%; right: 30%; transform: translateY(-50%); }

/* Panel container */
.login-panel {
    display: flex;
    flex-direction: row;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0,0,0,0.35);
    width: 100%;
    max-width: 860px;
    margin: 2rem;
    position: relative;
    z-index: 1;
    animation: loginFadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(30px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Brand panel (left) */
.login-brand-panel {
    background: linear-gradient(160deg, var(--mgsd-navy) 0%, var(--mgsd-navy-dark) 100%);
    flex: 1;
    padding: 3rem 2.5rem;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.login-brand-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

.login-brand-content { position: relative; width: 100%; }

.mgsd-logo-wrap { margin-bottom: 1.75rem; }
.mgsd-logo-wrap img { drop-shadow: 0 4px 20px rgba(0,0,0,0.3); }

.login-brand-title {
    font-size: 2rem; font-weight: 800; color: #fff;
    line-height: 1.2; letter-spacing: -0.5px; margin-bottom: 0.5rem;
}

.login-brand-sub {
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem; margin-bottom: 2.5rem; line-height: 1.5;
}

.login-brand-features { display: flex; flex-direction: column; gap: 0.85rem; }
.feature-item { display: flex; align-items: center; gap: 0.75rem; color: rgba(255,255,255,0.85); font-size: 0.9rem; font-weight: 500; }
.feature-item i { color: var(--mgsd-green); font-size: 1.1rem; flex-shrink: 0; }

/* Form panel (right) */
.login-form-panel {
    background: #fff;
    flex: 1;
    padding: 3rem 2.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-form-header { margin-bottom: 2rem; }
.login-form-title { font-size: 1.6rem; font-weight: 800; color: var(--mgsd-navy); margin-bottom: 0.3rem; letter-spacing: -0.3px; }
.login-form-subtitle { color: var(--text-muted); font-size: 0.875rem; margin: 0; }

/* Error alert */
.login-alert-error {
    background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px;
    padding: 0.75rem 1rem; color: #991b1b; font-size: 0.875rem;
    display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem;
}

/* Fields */
.login-field { margin-bottom: 1.25rem; }
.login-label { display: block; font-size: 0.82rem; font-weight: 600; color: #374151; margin-bottom: 0.4rem; }
.login-input-wrap { position: relative; display: flex; align-items: center; }
.login-input-icon { position: absolute; left: 1rem; color: #94a3b8; font-size: 0.95rem; pointer-events: none; z-index: 1; }
.login-input { width: 100%; border: 1.5px solid #e2e8f0; border-radius: 10px; padding: 0.75rem 1rem 0.75rem 2.75rem; font-size: 0.9rem; color: #1e2d3d; background: #f8fafc; transition: all 0.2s ease; outline: none; font-family: inherit; }
.login-input:focus { border-color: var(--mgsd-cyan); background: #fff; box-shadow: 0 0 0 3px rgba(52,152,219,0.15); }
.login-pass-input { padding-right: 3rem; }
.login-toggle-pass { position: absolute; right: 0.85rem; background: none; border: none; color: #94a3b8; cursor: pointer; padding: 0.25rem; font-size: 1rem; transition: color 0.2s; }
.login-toggle-pass:hover { color: var(--mgsd-navy); }

/* Submit button */
.login-submit-btn { width: 100%; background: linear-gradient(135deg, var(--mgsd-navy) 0%, var(--mgsd-blue) 100%); color: #fff; border: none; border-radius: 12px; padding: 0.9rem 1.5rem; font-size: 0.95rem; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 0.6rem; cursor: pointer; margin-top: 0.75rem; transition: all 0.25s ease; font-family: inherit; letter-spacing: 0.2px; }
.login-submit-btn:hover { background: linear-gradient(135deg, var(--mgsd-navy-dark) 0%, var(--mgsd-navy) 100%); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(12,74,96,0.35); }
.login-submit-btn:active { transform: translateY(0); }

.login-footer-text { text-align: center; color: #94a3b8; font-size: 0.75rem; margin-top: 2rem; line-height: 1.5; }
.hover-primary:hover { color: var(--mgsd-navy) !important; }

/* Responsive adjustments */
@media (max-width: 768px) {
    /* Reducir el tamaño base de la tipografía para proporcionar el texto en móviles */
    html {
        font-size: 14px;
    }
    
    .login-panel { flex-direction: column; max-width: 420px; }
    .login-brand-panel.hide-mobile { display: none; }
    .login-brand-panel { padding: 2rem 1.5rem; }
    .login-form-panel { padding: 2rem 1.5rem; }
    
    /* Controlar desbordamiento de textos largos y reducir títulos */
    body {
        overflow-x: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    h1, .h1 { font-size: 1.5rem !important; }
    h2, .h2 { font-size: 1.3rem !important; }
    h3, .h3 { font-size: 1.15rem !important; }
    h4, .h4 { font-size: 1.05rem !important; }
    h5, .h5, .card-title { font-size: 1rem !important; }
    h6, .h6 { font-size: 0.9rem !important; }

    /* Responsive Tables (Stack / Colapsables) */
    .table-responsive table,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive tr,
    .table-responsive td {
        display: block;
        width: 100%;
    }

    .table-responsive thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-responsive tr {
        border: 1px solid var(--border-color);
        margin-bottom: 1.25rem;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
        overflow: hidden;
    }

    .table-responsive td {
        border: none;
        border-bottom: 1px solid var(--border-light);
        position: relative;
        padding: 0.85rem 1rem 0.85rem 45% !important;
        text-align: right;
        min-height: 50px;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }

    .table-responsive td:last-child {
        border-bottom: 0;
    }

    .table-responsive td::before {
        content: attr(data-label);
        position: absolute;
        left: 1rem;
        width: 40%;
        padding-right: 10px;
        white-space: normal;
        text-align: left;
        font-weight: 700;
        color: var(--mgsd-navy-dark);
        font-size: 0.85rem;
        top: 50%;
        transform: translateY(-50%);
    }

    .table-responsive td .btn-group {
        display: inline-flex;
    }
}
