/**
 * SGR Suite - Frontend Styles v2.0.0
 *
 * Themed with CSS custom properties (--sgr-*).
 * The Card Customizer injects a :root block overriding these defaults.
 *
 * @package SGR_Suite
 * @since   2.0.0
 */

/* =============================================
   1. Container
   ============================================= */

.regalias-grid-container *,
.regalias-grid-container *::before,
.regalias-grid-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.regalias-grid-container {
    color: #444;
    line-height: 1.6;
    margin: 20px 0;
    background-color: var(--sgr-container-bg, #fffcf3);
    padding: var(--sgr-container-padding, 20px);
    border-radius: 8px;
}

/* =============================================
   2. Text Intro
   ============================================= */

.regalias-text-intro {
    max-width: 1140px;
    margin: 2% auto 3%;
    text-align: center;
}

/* =============================================
   3. Error Box
   ============================================= */

.regalias-grid-error-box {
    background: #fee;
    border: 2px solid #dc2626;
    border-radius: 8px;
    padding: 20px;
    color: #991b1b;
    text-align: center;
    font-weight: bold;
}

/* =============================================
   4. Stats Bar
   ============================================= */

.regalias-grid-stats-bar {
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
}

.regalias-grid-stat-item {
    text-align: center;
    min-width: 120px;
    flex: 1;
    padding: 10px;
    border-radius: 8px;
}

.regalias-grid-stat-number {
    font-size: var(--sgr-stat-number-size, 36px);
    font-weight: 900;
    color: var(--sgr-stat-number-color, #334155);
    line-height: 1;
    margin-bottom: 5px;
}

.regalias-grid-stat-label {
    font-size: 13px;
    color: #444;
    font-weight: 600;
    text-transform: uppercase;
}

/* =============================================
   5. Search Input
   ============================================= */

.regalias-grid-search-container {
    max-width: 1140px;
    margin: 0 auto;
}

.regalias-grid-search-input,
.regalias-grid-container input[type="search"] {
    width: 100%;
    padding: 20px 25px;
    font-size: var(--sgr-search-font-size, 25px);
    font-weight: 700;
    border: 2px solid var(--sgr-search-border, #348afb);
    background: transparent;
    border-radius: 0;
    outline: none;
}

.regalias-grid-search-input:focus {
    border-color: #1d4ed8;
    box-shadow: 0 0 0 1px #1d4ed8;
}

/* =============================================
   6. Filters
   ============================================= */

.regalias-grid-filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    max-width: 1140px;
    margin: 0 auto 30px;
}

.regalias-grid-filter-item {
    flex: 1;
    min-width: 200px;
}

.regalias-grid-filter-item label {
    display: block;
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
    font-size: 14px;
}

.regalias-grid-select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--sgr-search-border, #348afb);
    border-radius: 0;
    font-size: 14px;
    background: #fff;
}

/* =============================================
   7. Grid
   ============================================= */

.regalias-grid-proyectos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--sgr-grid-min-width, 320px), 1fr));
    gap: var(--sgr-grid-gap, 25px);
    max-width: 1140px;
    margin: auto;
}

/* =============================================
   8. Cards
   ============================================= */

.regalias-grid-card {
    border: 1px solid var(--sgr-card-border, #eee);
    background: var(--sgr-card-bg, #ffffff);
    border-radius: var(--sgr-card-radius, 0px);
    box-shadow: var(--sgr-card-shadow, none);
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    overflow: hidden;
}

.regalias-grid-card:hover {
    transform: translateY(var(--sgr-card-hover-translate, -5px));
    border-color: var(--sgr-card-hover-border, #348afb);
    box-shadow: var(--sgr-card-hover-shadow, 0 10px 20px rgba(0, 0, 0, 0.05));
}

/* =============================================
   9. Card Parts: image, content, badge, bpin, title, footer
   ============================================= */

/* Image */
.regalias-grid-card-image {
    height: var(--sgr-image-height, 200px);
    background: #f3f4f6;
    border-bottom: var(--sgr-image-border-bottom, 2px solid #348afb);
    overflow: hidden;
}

.regalias-grid-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Content */
.regalias-grid-card-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Badge */
.regalias-grid-card-badge {
    background: var(--sgr-badge-bg, #348afb);
    color: var(--sgr-badge-text, #ffffff);
    padding: 4px 10px;
    border-radius: var(--sgr-badge-radius, 0px);
    font-size: 12px;
    width: fit-content;
    margin-bottom: 10px;
}

/* Title */
.regalias-grid-card-title {
    font-size: var(--sgr-title-size, 18px);
    margin-bottom: 10px;
    line-height: 1.3;
    color: var(--sgr-title-color, #334155);
    flex: 1;
}

/* BPIN */
.regalias-grid-card-bpin {
    color: var(--sgr-bpin-color, #348afb);
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 10px;
}

/* Footer */
.regalias-grid-card-footer {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--sgr-footer-color, #666666);
    margin-top: auto;
}

/* Link */
.regalias-grid-card-link {
    color: var(--sgr-link-color, #348afb);
    font-weight: bold;
}

/* Contracts count */
.regalias-grid-card-contracts {
    font-weight: 600;
    color: #334155;
}

/* =============================================
   10. Modal (fixed overlay with .show class)
   ============================================= */

.regalias-grid-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.regalias-grid-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =============================================
   11. Modal Content
   ============================================= */

.regalias-grid-modal-content {
    background: var(--sgr-modal-bg, #fffcf3);
    width: 95%;
    max-width: var(--sgr-modal-max-width, 1000px);
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--sgr-card-radius, 0px);
    border: var(--sgr-modal-border, 2px solid #348afb);
    position: relative;
    animation: sgrSlideIn 0.3s;
}

@keyframes sgrSlideIn {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.regalias-grid-modal-close {
    position: absolute;
    top: 0;
    right: 0;
    padding: 10px 20px;
    font-size: 30px;
    cursor: pointer;
    background: #fff;
    border: none;
    border-bottom-left-radius: var(--sgr-card-radius, 0px);
    z-index: 100;
    color: #666;
    line-height: 1;
}

.regalias-grid-modal-close:hover {
    color: #000;
}

#regalias-grid-modal-body {
    padding: 30px;
}

/* =============================================
   12. Modal Info Grid and Info Cards
   ============================================= */

.regalias-modal-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.regalias-modal-info-card {
    background: var(--sgr-card-bg, #ffffff);
    border: 1px solid var(--sgr-card-border, #348afb);
    padding: 15px;
    border-radius: var(--sgr-card-radius, 0px);
}

.regalias-modal-info-label {
    font-weight: bold;
    color: #334155;
    font-size: 13px;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.regalias-modal-info-value {
    font-size: 15px;
    color: #444;
    word-break: break-word;
}

/* =============================================
   13. Progress Bar (Contracts)
   ============================================= */

.regalias-modal-progress-bar {
    height: 25px;
    background: #eee;
    border-radius: var(--sgr-card-radius, 0px);
    overflow: hidden;
    position: relative;
    border: 1px solid #ddd;
    margin-top: 8px;
}

.regalias-modal-progress-fill {
    height: 100%;
    background: var(--sgr-badge-bg, #348afb);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    transition: width 0.5s;
}

/* =============================================
   14. Accordion Sections
   ============================================= */

.regalias-modal-accordion-item {
    border: 1px solid var(--sgr-card-border, #348afb);
    border-radius: var(--sgr-card-radius, 0px);
    margin-bottom: 10px;
    background: var(--sgr-card-bg, #ffffff);
    overflow: hidden;
}

.regalias-modal-accordion-header {
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    background: #f8fafc;
    color: #334155;
}

.regalias-modal-accordion-header:hover {
    background: #f1f5f9;
}

.regalias-modal-accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.regalias-modal-accordion-content.active {
    max-height: 10000px;
}

.regalias-modal-accordion-body {
    padding: 20px;
    border-top: 1px solid #eee;
}

/* =============================================
   15. Image Gallery Grid
   ============================================= */

.regalias-modal-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.regalias-modal-image-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--sgr-card-radius, 0px);
    border: 1px solid #ccc;
    cursor: pointer;
    transition: transform 0.3s, opacity 0.3s;
}

.regalias-modal-image-item img:hover {
    opacity: 0.8;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* =============================================
   16. No Results Message
   ============================================= */

#regalias-grid-no-results-message {
    text-align: center;
    padding: 40px;
    color: #666;
    font-size: 18px;
}

/* =============================================
   17. CHART Styles
   ============================================= */

/* Wrapper */
.sgr-chart-wrapper {
    background: var(--sgr-card-bg, #ffffff);
    border: 1px solid var(--sgr-card-border, #e5e7eb);
    border-radius: var(--sgr-card-radius, 0px);
    margin: 20px 0;
    overflow: hidden;
}

.sgr-chart-wrapper:fullscreen {
    background: #fff;
    padding: 20px;
}

/* Toolbar - secop-suite style */
.sgr-chart-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 8px 15px;
    background: transparent;
    border-bottom: none;
}

.sgr-chart-title {
    display: none;
}

.sgr-chart-toolbar-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sgr-chart-toolbar-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    color: #4b5563;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.sgr-chart-toolbar-btn:hover {
    color: #1d4ed8;
}

.sgr-chart-toolbar-btn svg {
    flex-shrink: 0;
}

/* Share buttons */
.sgr-share-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.sgr-share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: #fff;
    text-decoration: none;
    transition: transform 0.2s, opacity 0.2s;
}

.sgr-share-btn:hover {
    transform: scale(1.1);
    opacity: 0.9;
}

.sgr-share-fb { background: #1877F2; }
.sgr-share-tw { background: #000000; }
.sgr-share-li { background: #0A66C2; }
.sgr-share-wa { background: #25D366; }

/* Container */
.sgr-chart-container {
    min-height: 300px;
    position: relative;
}

.sgr-chart-container svg {
    width: 100% !important;
}

/* Loading Spinner */
.sgr-chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: #6b7280;
}

.sgr-chart-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--sgr-badge-bg, #348afb);
    border-radius: 50%;
    animation: sgrSpin 0.8s linear infinite;
    margin-bottom: 15px;
}

@keyframes sgrSpin {
    to { transform: rotate(360deg); }
}

/* Error */
.sgr-chart-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    text-align: center;
    color: #991b1b;
    background: #fef2f2;
    padding: 30px;
}

/* ==========================================================================
   Leyenda personalizada — modos 'icons' y 'text' (v2.4.0 / v2.5.1)
   ========================================================================== */

.sgr-chart-icon-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    justify-content: center;
    align-items: center;
    padding: 14px 18px 16px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
}

.sgr-chart-icon-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
    white-space: nowrap;
    transition: transform .15s ease, box-shadow .15s ease;
}

/* Modo "solo iconos": chips compactos sin padding ni borde,
   sólo el cuadro coloreado con SVG. Título accesible vía tooltip. */
.sgr-chart-icon-legend--icons .sgr-chart-icon-legend-item {
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: help;
}

.sgr-chart-icon-legend--icons .sgr-chart-icon-legend-item:hover {
    transform: translateY(-2px);
}

/* Modo "solo texto": chip redondeado con un punto de color + label. */
.sgr-chart-icon-legend--text .sgr-chart-icon-legend-item {
    padding: 4px 12px 4px 10px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
}

.sgr-chart-icon-legend--text .sgr-chart-icon-legend-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.sgr-chart-icon-legend-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: #ffffff;
    flex-shrink: 0;
}

.sgr-chart-icon-legend-icon svg {
    width: 20px;
    height: 20px;
    display: block;
}

.sgr-chart-icon-legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.sgr-chart-icon-legend-label {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Las etiquetas del eje X (svg text) heredan el tamaño/rotación que
   aplique d3plus vía labelConfig; aquí sólo aseguramos legibilidad. */
.sgr-chart-container svg .d3plus-Axis text,
.sgr-chart-container svg .d3plus-Text text {
    font-family: inherit;
}

/* Data Modal */
.sgr-chart-data-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    align-items: center;
    justify-content: center;
}

.sgr-chart-data-modal.show {
    display: flex;
}

.sgr-chart-data-modal-content {
    background: var(--sgr-card-bg, #ffffff);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    border: var(--sgr-modal-border, 2px solid #348afb);
    border-radius: var(--sgr-card-radius, 0px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sgr-chart-data-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.sgr-chart-data-modal-header h3 {
    margin: 0;
    color: var(--sgr-title-color, #334155);
    font-size: 16px;
}

.sgr-chart-data-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    padding: 0 5px;
}

.sgr-chart-data-modal-close:hover {
    color: #1f2937;
}

/* Data Table */
.sgr-chart-data-modal-body {
    overflow: auto;
    flex: 1;
}

.sgr-chart-data-table {
    width: 100%;
    border-collapse: collapse;
}

.sgr-chart-data-table th,
.sgr-chart-data-table td {
    padding: 10px 15px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    font-size: 13px;
}

.sgr-chart-data-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #334155;
    text-transform: uppercase;
    font-size: 12px;
    position: sticky;
    top: 0;
}

.sgr-chart-data-table tbody tr:hover {
    background: #f9fafb;
}

/* =============================================
   18. Responsive (max-width: 768px)
   ============================================= */

@media (max-width: 768px) {

    .regalias-grid-stats-bar {
        flex-direction: column;
    }

    .regalias-grid-proyectos {
        grid-template-columns: 1fr;
    }

    .regalias-grid-search-input,
    .regalias-grid-container input[type="search"] {
        font-size: 18px;
        padding: 15px 20px;
    }

    .regalias-grid-filters-row {
        flex-direction: column;
    }

    .regalias-modal-info-grid {
        grid-template-columns: 1fr;
    }

    #regalias-grid-modal-body {
        padding: 15px;
    }

    .sgr-chart-toolbar {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .sgr-chart-data-modal-content {
        width: 98%;
    }

    .regalias-grid-stat-number {
        font-size: 28px;
    }

    .regalias-grid-card-title {
        font-size: 16px;
    }
}
