:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --info: #0ea5e9;
    --bg: #f1f5f9;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: .9em; }

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100; transition: transform .25s ease; overflow-y: auto;
}
.sidebar-header { padding: 1.25rem 1.5rem; display: flex; align-items: center; gap: .75rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo svg { width: 32px; height: 32px; color: var(--primary); }
.sidebar-title { color: #fff; font-size: 1.15rem; font-weight: 600; }
.sidebar-nav { flex: 1; padding: 1rem 0; display: flex; flex-direction: column; gap: 2px; }
.nav-section-label { padding: .75rem 1.5rem .25rem; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #475569; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem; color: var(--sidebar-text); font-size: .9rem; transition: all .15s; border-left: 3px solid transparent; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); text-decoration: none; }
.nav-item.active { background: rgba(37,99,235,.15); color: var(--sidebar-text-active); border-left-color: var(--primary); }
.sidebar-spacer { flex: 1; }
.nav-logout { border-top: 1px solid rgba(255,255,255,.08); margin-top: .5rem; padding-top: .75rem; }

.main-content { flex: 1; margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    background: var(--card-bg); border-bottom: 1px solid var(--border); padding: .75rem 1.5rem;
    display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 50; min-height: 56px;
    box-shadow: var(--shadow);
}
.sidebar-toggle { background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-muted); display: none; }
.sidebar-toggle svg { width: 24px; height: 24px; }
.topbar-title { font-weight: 600; font-size: 1rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.user-badge { background: #eef2ff; color: var(--primary); padding: .25rem .75rem; border-radius: 999px; font-size: .8rem; font-weight: 500; }
.content { padding: 1.5rem; flex: 1; }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.text-muted { color: var(--text-muted); font-size: .9rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); display: flex; align-items: center; gap: 1rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon-blue { background: #eff6ff; color: var(--primary); }
.stat-icon-green { background: #f0fdf4; color: var(--success); }
.stat-icon-primary { background: #eef2ff; color: #6366f1; }
.stat-icon-red { background: #fef2f2; color: var(--danger); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .8rem; color: var(--text-muted); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 1024px) { .dashboard-grid { grid-template-columns: 1fr; } }

.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-body.p-0 { padding: 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); background: #f8fafc; }
.table tbody tr:hover { background: #f8fafc; }
.table td.actions-cell { white-space: nowrap; }
.table .text-nowrap { white-space: nowrap; }

.pagination { display: flex; gap: 4px; padding: 1rem; justify-content: center; flex-wrap: wrap; }
.page-link { padding: .35rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: .85rem; }
.page-link:hover { background: var(--bg); text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.badge-success { background: #f0fdf4; color: #166534; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-warning { background: #fffbeb; color: #92400e; }
.badge-info { background: #eff6ff; color: #1e40af; }

.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem 1rem; border: none; border-radius: var(--radius-sm); font-size: .85rem; font-weight: 500; cursor: pointer; transition: all .15s; text-decoration: none; line-height: 1.4; white-space: nowrap; }
.btn:hover { text-decoration: none; opacity: .9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-lg { padding: .6rem 1.5rem; font-size: .95rem; }
.btn-block { width: 100%; justify-content: center; }

.form-grid { max-width: 900px; }
.form-section { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .35rem; color: var(--text); }
.form-input {
    width: 100%; padding: .55rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: .9rem; font-family: inherit; color: var(--text); background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-input::placeholder { color: #94a3b8; }
textarea.form-input { resize: vertical; min-height: 80px; }
select.form-input { cursor: pointer; appearance: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.col { min-width: 0; }
.form-actions { padding-top: 1rem; display: flex; gap: .75rem; align-items: center; }
.help-text { font-size: .8rem; color: var(--text-muted); margin-top: .35rem; }

.search-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; width: 100%; }
.search-input-group { position: relative; flex: 1; min-width: 200px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: #94a3b8; pointer-events: none; }
.search-input-group .form-input { padding-left: 36px; }

.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }

.alertas-list { display: flex; flex-direction: column; gap: .5rem; }
.alerta-item { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem 1rem; border-radius: var(--radius-sm); background: #f8fafc; border: 1px solid var(--border); }
.alerta-icon { flex-shrink: 0; width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.alerta-icon svg { width: 20px; height: 20px; }
.alerta-content { flex: 1; }
.alerta-msg { font-size: .9rem; margin-bottom: .2rem; }
.alerta-meta { font-size: .8rem; color: var(--text-muted); }
.alerta-item.alerta-warning { border-left: 3px solid var(--warning); }
.alerta-item.alerta-info { border-left: 3px solid var(--info); }
.alerta-item.alerta-danger { border-left: 3px solid var(--danger); }
.alerta-item.alerta-warning .alerta-icon { background: #fffbeb; color: var(--warning); }
.alerta-item.alerta-info .alerta-icon { background: #eff6ff; color: var(--info); }
.alerta-item.alerta-danger .alerta-icon { background: #fef2f2; color: var(--danger); }

.status-list { display: flex; flex-direction: column; gap: .5rem; }
.status-item { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.status-item:last-child { border-bottom: none; }
.status-count { font-weight: 600; font-size: 1.1rem; }

.contract-preview { max-width: 1000px; margin: 0 auto; }
.contract-content { font-size: .95rem; line-height: 1.7; }
.contract-content h1 { font-size: 1.3rem; text-align: center; margin-bottom: 1.5rem; }
.contract-content h2 { font-size: 1.1rem; margin-top: 1.5rem; margin-bottom: .75rem; }
.contract-content p { margin-bottom: .5rem; }
.contract-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.contract-content table td, .contract-content table th { padding: .5rem .75rem; border: 1px solid #000; }
.contract-content .signature-area { margin-top: 3rem; display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.contract-content .signature-line { border-top: 1px solid #000; padding-top: .5rem; text-align: center; font-size: .85rem; margin-top: 4rem; }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; box-shadow: var(--shadow-md); animation: slideIn .25s ease; max-width: 400px; }
.toast-success { background: #166534; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }
.toast-warning { background: #92400e; color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
.login-container { width: 100%; max-width: 400px; padding: 1rem; }
.login-card { background: var(--card-bg); border-radius: var(--radius); padding: 2rem; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.login-header { text-align: center; margin-bottom: 1.5rem; }
.login-logo { display: inline-flex; padding: .75rem; border-radius: 16px; background: #eef2ff; margin-bottom: .75rem; }
.login-logo svg { width: 40px; height: 40px; color: var(--primary); }
.login-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .25rem; }
.login-header p { color: var(--text-muted); font-size: .9rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form .form-group { margin-bottom: 0; }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .row { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
    .card-header { flex-direction: column; align-items: stretch; }
    .search-form { flex-direction: column; align-items: stretch; }
    .pagination { gap: 2px; }
    .page-link { padding: .3rem .55rem; font-size: .8rem; }
}

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.ine-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: zoom-in; display: block; }
.ine-thumb:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.75); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: #fff; border-radius: var(--radius); padding: 1.25rem; max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; position: relative; animation: zoomIn .2s ease; }
.modal-close { position: absolute; top: 6px; right: 12px; border: none; background: transparent; font-size: 2rem; line-height: 1; cursor: pointer; color: var(--text-muted); }
.modal-close:hover { color: var(--text); }
.modal-title { font-weight: 600; font-size: 1rem; margin-bottom: .75rem; padding-right: 2rem; }
.modal-box img { width: 100%; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
@keyframes zoomIn { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
