@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ========================================
   VARIABLES CORPORATIVAS
======================================== */
:root {
    --primary:      #1e3a5f;
    --primary-light:#2d5293;
    --accent:       #2d6cdf;
    --accent-hover: #1a56c9;
    --success:      #198754;
    --danger:       #dc3545;
    --warning:      #fd7e14;
    --info:         #0dcaf0;
    --secondary:    #6c757d;

    --sidebar-w:    260px;
    --sidebar-bg:   #0f2440;
    --sidebar-text: #b8c8e0;
    --sidebar-active: rgba(45,108,223,.25);
    --topbar-h:     64px;
    --topbar-bg:    #ffffff;

    --bg-body:      #f0f4f8;
    --bg-card:      #ffffff;
    --border:       #e2e8f0;
    --text:         #1a202c;
    --text-muted:   #6b7280;
    --radius:       10px;
    --radius-lg:    16px;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
    --shadow:       0 4px 16px rgba(0,0,0,.10);
    --shadow-lg:    0 8px 32px rgba(0,0,0,.14);
    --transition:   0.2s ease;
}

/* ========================================
   RESET Y BASE
======================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ========================================
   LAYOUT PRINCIPAL
======================================== */
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.25);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    min-height: var(--topbar-h);
}

.sidebar-logo-icon {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.sidebar-logo-text strong {
    display: block;
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.sidebar-logo-text span {
    color: var(--sidebar-text);
    font-size: .72rem;
}

.sidebar-nav { flex: 1; padding: 16px 0; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.nav-section {
    padding: 6px 20px 2px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(255,255,255,.3);
    margin-top: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    color: var(--sidebar-text);
    font-size: .88rem;
    font-weight: 500;
    border-radius: 0;
    transition: all var(--transition);
    position: relative;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-item i { font-size: 1rem; width: 18px; flex-shrink: 0; }

.nav-item:hover {
    color: #ffffff;
    background: rgba(255,255,255,.07);
}

.nav-item.active {
    color: #ffffff;
    background: var(--sidebar-active);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: .65rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: .85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user-info .name {
    color: #fff;
    font-size: .83rem;
    font-weight: 600;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-info .rol {
    color: var(--sidebar-text);
    font-size: .72rem;
    text-transform: capitalize;
}

/* TOPBAR */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-h);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.topbar-breadcrumb {
    font-size: .8rem;
    color: var(--text-muted);
    flex: 1;
}
.topbar-breadcrumb a { color: var(--accent); }
.topbar-breadcrumb span { color: var(--text-muted); margin: 0 4px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.topbar-btn {
    width: 38px;
    height: 38px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    font-size: 1rem;
}
.topbar-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

.alert-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    font-size: .6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* MAIN CONTENT */
.main-content {
    padding: 28px;
    flex: 1;
}

/* ========================================
   CARDS
======================================== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}

.card-header h3 {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 24px; }
.card-body-compact { padding: 16px 24px; }

/* KPI CARDS */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}

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

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.kpi-icon.blue    { background: #dbeafe; color: #1d4ed8; }
.kpi-icon.green   { background: #dcfce7; color: #15803d; }
.kpi-icon.orange  { background: #ffedd5; color: #c2410c; }
.kpi-icon.red     { background: #fee2e2; color: #b91c1c; }
.kpi-icon.purple  { background: #ede9fe; color: #7c3aed; }
.kpi-icon.teal    { background: #ccfbf1; color: #0f766e; }

.kpi-info {}
.kpi-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
    letter-spacing: -0.5px;
}
.kpi-label {
    font-size: .77rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
}
.kpi-delta {
    font-size: .75rem;
    margin-top: 2px;
    font-weight: 600;
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* ========================================
   TABLAS
======================================== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
}

.table thead th {
    background: #f8fafc;
    padding: 13px 16px;
    text-align: left;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
    transition: background var(--transition);
}
.table tbody tr:hover { background: #f8fafc; }

.table .acciones { white-space: nowrap; text-align: right; }

/* ========================================
   BADGES DE ESTADO
======================================== */
.badge-estado {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .73rem;
    font-weight: 700;
    letter-spacing: .2px;
    white-space: nowrap;
}

/* ========================================
   BOTONES
======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 20px;
    border-radius: 8px;
    font-size: .87rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.btn:active { transform: translateY(0); }

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

.btn-dark { background: var(--primary); color: white; }
.btn-dark:hover { background: var(--primary-light); color: white; }

.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--accent);
}
.btn-outline:hover { background: var(--accent); color: white; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-body); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: .8rem; border-radius: 6px; }
.btn-xs { padding: 3px 8px; font-size: .75rem; border-radius: 5px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }

/* ========================================
   FORMULARIOS
======================================== */
.form-group { margin-bottom: 20px; }
.form-label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-label .req { color: var(--danger); }

.form-control, .form-select {
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .88rem;
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background: white;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    appearance: none;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(45, 108, 223, .12);
}

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }

.invalid-feedback {
    color: var(--danger);
    font-size: .78rem;
    margin-top: 4px;
}

.form-row { display: grid; gap: 16px; }
.form-row.col-2 { grid-template-columns: 1fr 1fr; }
.form-row.col-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.col-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

textarea.form-control { resize: vertical; min-height: 90px; }

/* ========================================
   ALERTAS / NOTIFICACIONES
======================================== */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: .88rem;
    margin-bottom: 20px;
    animation: fadeIn .3s ease;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.alert-danger  { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.alert-warning { background: #fff7ed; color: #c2410c; border: 1px solid #fdba74; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert i { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.alert-close { margin-left: auto; cursor: pointer; font-size: 1.1rem; opacity: .6; background: none; border: none; color: inherit; }

/* ========================================
   TIMELINE DE SEGUIMIENTO
======================================== */
.timeline { position: relative; padding-left: 32px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 24px;
}

.timeline-icon {
    position: absolute;
    left: -32px;
    top: 2px;
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: .72rem;
    border: 3px solid var(--bg-body);
}

.timeline-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    box-shadow: var(--shadow-sm);
}

.timeline-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.timeline-date {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ========================================
   COTIZACIÓN - ITEMS DINÁMICOS
======================================== */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
    background: #f8fafc;
    padding: 10px 12px;
    font-size: .73rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--secondary);
    font-weight: 700;
    text-align: left;
    border-bottom: 2px solid var(--border);
}
.items-table td { padding: 8px 6px; border-bottom: 1px solid #f0f0f0; vertical-align: top; }
.items-table .col-desc { width: 35%; }
.items-table .col-num  { width: 100px; }
.items-table .col-acc  { width: 50px; text-align: center; }

.totales-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    max-width: 380px;
    margin-left: auto;
}

.totales-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: .88rem;
    color: var(--text);
}

.totales-row.total-final {
    padding-top: 12px;
    margin-top: 4px;
    border-top: 2px solid var(--primary);
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary);
}

/* ========================================
   PÁGINA DE LOGIN
======================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f2440 0%, #1e3a5f 50%, #1a4a8a 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -20%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(45,108,223,.3) 0%, transparent 70%);
}

.login-box {
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0,0,0,.35);
    width: 100%;
    max-width: 420px;
    padding: 48px 40px;
    position: relative;
    z-index: 1;
}

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

.login-logo-icon {
    width: 64px;
    height: 64px;
    background: var(--accent);
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: white;
    margin-bottom: 16px;
    box-shadow: 0 8px 24px rgba(45,108,223,.4);
}

.login-logo h1 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.login-logo p {
    font-size: .83rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========================================
   UTILITIES
======================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-title i {
    color: var(--accent);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
.mt-3 { margin-top: 24px; }
.ms-auto { margin-left: auto; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.text-muted { color: var(--text-muted); }
.text-end { text-align: right; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.fw-600 { font-weight: 600; }
.fs-sm { font-size: .82rem; }
.fs-xs { font-size: .75rem; }
.w-100 { width: 100%; }

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Spinner */
.spinner {
    width: 18px; height: 18px;
    border: 2.5px solid rgba(255,255,255,.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Paginación */
.pagination { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pagination .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    background: white;
    transition: all var(--transition);
}
.pagination .page-link:hover { background: var(--accent); color: white; border-color: var(--accent); }
.pagination .page-link.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .page-link.disabled { opacity: .4; pointer-events: none; }

/* Chips de filtro */
.filter-bar {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 140px; flex: 1; }
.filter-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 3rem; opacity: .3; display: block; margin-bottom: 16px; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: .875rem; }

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
    .form-row.col-3, .form-row.col-4 { grid-template-columns: 1fr 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .main-content { padding: 16px; }
    .form-row.col-2 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr; }
}
