/* css/styles.css */
/* Sistema de Estilos - Logística Villamir (Estilo Dynamics 365 / Fluent Design) */

@import url('https://fonts.googleapis.com/css2?family=Segoe+UI:wght@300;400;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');

:root {
    /* Dynamics 365 Color Palette */
    --header-bg: #002050;          /* Azul Oscuro Principal */
    --header-text: #ffffff;
    --sidebar-bg: #f3f2f1;          /* Gris Claro Barra Lateral */
    --sidebar-text: #323130;
    --sidebar-hover: #edebe9;
    --sidebar-active: #ffffff;
    --sidebar-border: #edebe9;
    
    --body-bg: #faf9f8;             /* Fondo de la Aplicación */
    --card-bg: #ffffff;             /* Fondo de Paneles/Tarjetas */
    --border-color: #edebe9;        /* Borde Gris Fino */
    --border-focus: #0078d4;        /* Azul Fluent Focus */
    
    /* Text Colors */
    --text-primary: #323130;
    --text-secondary: #605e5c;
    --text-muted: #a19f9d;
    
    /* Accent & Status Colors */
    --accent-blue: #0078d4;         /* Botón Primario */
    --accent-blue-hover: #106ebe;
    --accent-red: #d83b01;          /* Etapas Activas / Alertas */
    --accent-red-light: #fde7e9;
    --accent-green: #107c41;        /* Estatus Pagado */
    --accent-green-light: #dff6dd;
    --accent-yellow: #fff2cc;       /* Estatus Pendiente */
    --accent-yellow-text: #8a6d3b;
    
    /* Fonts */
    --font-primary: 'Segoe UI', 'Outfit', sans-serif;
    
    /* Shadows */
    --shadow-sm: 0 1.6px 3.6px 0 rgba(0,0,0,.132), 0 .3px .9px 0 rgba(0,0,0,.108);
    --shadow-md: 0 6.4px 14.4px 0 rgba(0,0,0,.132), 0 1.2px 3.6px 0 rgba(0,0,0,.108);
}

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

body {
    font-family: var(--font-primary);
    background-color: var(--body-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- BARRA SUPERIOR (HEADER) --- */
.main-header {
    background-color: var(--header-bg);
    color: var(--header-text);
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.app-launcher {
    cursor: pointer;
    font-size: 16px;
    opacity: 0.85;
    transition: opacity 0.2s;
}
.app-launcher:hover { opacity: 1; }

.app-title {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.app-title span {
    font-weight: 300;
    opacity: 0.8;
}

.header-search {
    flex: 0 1 400px;
    position: relative;
    margin: 0 20px;
}
.header-search input {
    width: 100%;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 4px;
    padding: 0 12px 0 36px;
    color: white;
    font-family: var(--font-primary);
    font-size: 13px;
    transition: background-color 0.2s, border 0.2s;
}
.header-search input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}
.header-search input:focus {
    background-color: #ffffff;
    color: var(--text-primary);
    outline: none;
}
.header-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
    font-size: 13px;
}
.header-search input:focus + i {
    color: var(--text-secondary);
    opacity: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 18px;
}
.header-icon {
    cursor: pointer;
    font-size: 16px;
    opacity: 0.85;
    position: relative;
}
.header-icon:hover { opacity: 1; }

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.avatar {
    width: 32px;
    height: 32px;
    background-color: var(--accent-red);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

/* --- CONTENEDOR PRINCIPAL --- */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- BARRA LATERAL (SIDEBAR) --- */
.sidebar {
    width: 220px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding-top: 12px;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 50px;
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 8px 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar.collapsed .sidebar-section-title {
    opacity: 0;
    padding: 0;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    gap: 12px;
    border-left: 4px solid transparent;
    transition: background-color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.sidebar-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    color: var(--text-secondary);
}

.sidebar-item:hover a {
    background-color: var(--sidebar-hover);
}

.sidebar-item.active a {
    background-color: var(--sidebar-active);
    color: var(--text-primary);
    font-weight: 600;
    border-left-color: var(--accent-red);
}
.sidebar-item.active i {
    color: var(--accent-red);
}

.sidebar.collapsed .sidebar-item span {
    display: none;
}

/* --- AREA DE CONTENIDO --- */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--body-bg);
    overflow: hidden;
}

/* --- BARRA DE ACCIÓN (ACTION BAR) --- */
.action-bar {
    background-color: var(--card-bg);
    height: 48px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.action-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}
.divider-v {
    width: 1px;
    height: 20px;
    background-color: var(--border-color);
}

.action-bar-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: 4px;
    font-family: var(--font-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid #8a8886;
    background-color: #ffffff;
    color: var(--text-primary);
}

.btn:hover {
    background-color: #f3f2f1;
    border-color: #323130;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    border-color: var(--accent-blue-hover);
    color: white;
}

.btn-danger {
    background-color: #fde7e9;
    color: #a80000;
    border-color: #fde7e9;
}
.btn-danger:hover {
    background-color: #f3b6b7;
    border-color: #f3b6b7;
}

.btn i {
    font-size: 12px;
}

/* --- ETAPAS DEL PROYECTO (PROJECT STAGES) --- */
.stages-wrapper {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.stages-label {
    background-color: var(--accent-red);
    color: white;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 2px;
    letter-spacing: 0.5px;
}

.stages-timeline {
    display: flex;
    flex: 1;
    justify-content: space-between;
    position: relative;
    padding: 0 40px;
}

.stages-timeline::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50px;
    right: 50px;
    height: 2px;
    background-color: var(--border-color);
    transform: translateY(-50%);
    z-index: 1;
}

.stage-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 2;
    cursor: pointer;
}

.stage-circle {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #ffffff;
    border: 2px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.stage-node.completed .stage-circle {
    border-color: var(--accent-blue);
    background-color: var(--accent-blue);
}
.stage-node.completed .stage-circle::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: white;
    font-size: 8px;
}

.stage-node.active .stage-circle {
    border-color: var(--accent-red);
    background-color: #ffffff;
}
.stage-node.active .stage-circle::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-red);
}

.stage-name {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.2s;
}
.stage-node.active .stage-name {
    color: var(--accent-red);
    font-weight: 700;
}
.stage-node.completed .stage-name {
    color: var(--accent-blue);
}

/* --- ESPACIO DE TRABAJO SCROLLABLE --- */
.workspace {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* --- METRICAS DE DASHBOARD (KPI CARDS) --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.kpi-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-info h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}
.kpi-icon-box {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.kpi-blue { background-color: rgba(0, 120, 212, 0.1); color: var(--accent-blue); }
.kpi-red { background-color: rgba(216, 59, 1, 0.1); color: var(--accent-red); }
.kpi-green { background-color: rgba(16, 124, 65, 0.1); color: var(--accent-green); }
.kpi-yellow { background-color: rgba(255, 193, 7, 0.15); color: #b78103; }

/* --- CONTENEDORES DE PANELES (CARDS) --- */
.panel-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel-body {
    padding: 20px;
}

/* --- TABLAS (DATA GRID) --- */
.table-container {
    overflow-x: auto;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}
.data-table th {
    background-color: #faf9f8;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 2px solid var(--border-color);
}
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}
.data-table tbody tr {
    transition: background-color 0.1s;
}
.data-table tbody tr:hover {
    background-color: #f3f2f1;
    cursor: pointer;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-pagado {
    background-color: var(--accent-green-light);
    color: var(--accent-green);
}
.badge-pendiente {
    background-color: var(--accent-yellow);
    color: var(--accent-yellow-text);
}
.badge-local {
    background-color: #e1dfdd;
    color: #323130;
}
.badge-foraneo {
    background-color: #d2e3f7;
    color: #005a9e;
}

/* --- FORMULARIOS (GRID LAYOUT) --- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}
@media (max-width: 900px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
}

.form-section-title {
    grid-column: 1 / -1;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-blue);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    margin-top: 10px;
    margin-bottom: 5px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.form-group label span.required {
    color: var(--accent-red);
    margin-left: 2px;
}

.form-control {
    height: 32px;
    border: 1px solid #a19f9d;
    border-radius: 2px;
    padding: 0 8px;
    font-family: var(--font-primary);
    font-size: 13px;
    color: var(--text-primary);
    background-color: #ffffff;
    transition: border-color 0.15s ease-in-out;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    border-width: 1.5px;
}

.form-control-row {
    display: flex;
    gap: 8px;
}
.form-control-row .form-control {
    flex: 1;
}

.read-only-box {
    display: flex;
    align-items: center;
    background-color: #f3f2f1;
    border: 1px solid #edebe9;
    color: var(--text-secondary);
    padding: 0 10px;
    height: 32px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 2px;
}

/* --- CARGA DE ARCHIVOS --- */
.upload-container {
    grid-column: 1 / -1;
    border: 2px dashed #a19f9d;
    border-radius: 4px;
    padding: 24px;
    text-align: center;
    background-color: #faf9f8;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.upload-container:hover {
    border-color: var(--accent-blue);
    background-color: #f3f9fe;
}

.upload-icon {
    font-size: 32px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.upload-text {
    font-size: 13px;
    color: var(--text-secondary);
}
.upload-text strong {
    color: var(--accent-blue);
}

.file-list {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.file-item {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    box-shadow: var(--shadow-sm);
}

.file-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}
.file-item-info i {
    color: #f40f02; /* PDF Red */
    font-size: 16px;
}
.file-item-name {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 130px;
    font-weight: 600;
}

.file-item-actions {
    display: flex;
    gap: 6px;
}
.btn-file-action {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 2px;
    transition: color 0.15s;
}
.btn-file-action:hover {
    color: var(--accent-blue);
}
.btn-file-action.delete-file:hover {
    color: var(--accent-red);
}

/* --- MODAL DEL VISUALIZADOR DE PDF --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 999;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: #ffffff;
    width: 80%;
    height: 85%;
    border-radius: 4px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title {
    font-size: 14px;
    font-weight: 600;
}
.close-modal {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
}
.close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    padding: 0;
    background-color: #525659; /* PDF Viewer default grey */
}
.modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* --- SECCIÓN DE REPORTES / ANALÍTICOS --- */
.report-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}
@media (max-width: 1000px) {
    .report-grid { grid-template-columns: 1fr; }
}

.chart-container {
    height: 320px;
    position: relative;
}

/* --- ANIMACIONES --- */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}

/* --- NOTIFICACIONES TOAST --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.toast {
    background-color: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: 4px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.25s ease-out;
}

.toast.toast-success {
    border-left: 4px solid var(--accent-green);
}
.toast.toast-error {
    border-left: 4px solid var(--accent-red);
}

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

/* --- PDF SLOTS GRID --- */
.pdf-slots-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    margin-top: 15px;
}
.pdf-slot {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    background-color: #f9fafb;
    transition: all 0.2s ease;
    padding: 10px;
    position: relative;
    overflow: hidden;
}
.pdf-slot:hover {
    border-color: var(--accent-blue);
    background-color: #f0f7ff;
}
.pdf-slot.filled {
    border: 2px solid var(--accent-blue);
    background-color: #ffffff;
    cursor: default;
}
.pdf-slot-icon {
    font-size: 24px;
    color: #9ca3af;
    margin-bottom: 8px;
}
.pdf-slot.filled .pdf-slot-icon {
    color: var(--accent-red);
}
.pdf-slot-text {
    font-size: 12px;
    color: #6b7280;
    font-weight: 500;
}
.pdf-slot-name {
    font-size: 11px;
    color: var(--text-primary);
    font-weight: 600;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}
.pdf-slot-actions {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}
.pdf-slot-actions .btn {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
}
@media (max-width: 900px) {
    .pdf-slots-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .pdf-slots-grid { grid-template-columns: repeat(2, 1fr); }
}
