/* ═══════════════════════════════════════════════
   VerificaEPS — Sistema de Verificación de Derechos
   Design System & Global Styles
   ═══════════════════════════════════════════════ */

:root {
    --blue-900: #0d1f4e;
    --blue-800: #0d2d6e;
    --blue-700: #1a3a8f;
    --blue-600: #2347a8;
    --blue-500: #3056c4;
    --blue-400: #5b7de0;
    --blue-100: #dce5f7;
    --blue-50:  #eef2fc;
    
    --red-600:  #c0392b;
    --red-500:  #e74c3c;
    --red-100:  #fde8e8;
    
    --green-500: #27ae60;
    --green-100: #d5f0e0;
    
    --amber-500: #f39c12;
    --amber-100: #fef3cd;
    
    --gray-900: #111827;
    --gray-800: #1f2937;
    --gray-700: #374151;
    --gray-600: #4b5563;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50:  #f9fafb;
    --white:    #ffffff;
    
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.1), 0 4px 8px rgba(0,0,0,.05);
    
    --font-sans: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'DM Mono', 'Fira Code', monospace;
    
    --transition: 0.18s ease;
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── App Shell ── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(175deg, var(--blue-900) 0%, var(--blue-800) 100%);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.brand-icon {
    flex-shrink: 0;
}

.brand-name {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -.01em;
}

.brand-sub {
    display: block;
    font-size: 0.7rem;
    color: rgba(255,255,255,.5);
    letter-spacing: .02em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.35);
    padding: 10px 10px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    color: rgba(255,255,255,.7);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}

.nav-item:hover {
    background: rgba(255,255,255,.08);
    color: var(--white);
}

.nav-item.active {
    background: rgba(255,255,255,.15);
    color: var(--white);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--red-500);
    border-radius: 2px;
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .8;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    flex-shrink: 0;
}

.user-name {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: .68rem;
    color: rgba(255,255,255,.45);
}

.user-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    border-radius: 8px;
    color: rgba(255,255,255,.6);
    text-decoration: none;
    transition: all var(--transition);
}

.icon-btn:hover { background: rgba(255,255,255,.1); color: white; }
.icon-btn.danger:hover { background: rgba(231,76,60,.2); color: var(--red-500); }

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-600);
    padding: 4px;
}

.page-breadcrumb {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    color: var(--gray-500);
}

.page-breadcrumb a { color: var(--blue-700); text-decoration: none; }
.page-breadcrumb a:hover { text-decoration: underline; }
.page-breadcrumb .sep { color: var(--gray-400); }

.badge-role {
    font-size: .7rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge-role.admin { background: var(--blue-100); color: var(--blue-700); }
.badge-role.consulta { background: var(--green-100); color: var(--green-500); }

.content-area {
    flex: 1;
    padding: 28px 30px;
    max-width: 1400px;
    width: 100%;
}

/* ── Flash Messages ── */
.flash-container { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }

.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: .875rem;
    font-weight: 500;
    position: relative;
    animation: slideIn .2s ease;
}

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

.alert-success { background: var(--green-100); color: #166534; border-left: 3px solid var(--green-500); }
.alert-danger  { background: var(--red-100);   color: #991b1b; border-left: 3px solid var(--red-500); }
.alert-warning { background: var(--amber-100); color: #92400e; border-left: 3px solid var(--amber-500); }
.alert-info    { background: var(--blue-50);   color: var(--blue-800); border-left: 3px solid var(--blue-500); }

.alert-icon { flex-shrink: 0; }
.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
    opacity: .5;
    line-height: 1;
}
.alert-close:hover { opacity: 1; }

/* ── Cards ── */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title svg { color: var(--blue-700); }

.card-body {
    padding: 24px;
}

/* ── Page Header ── */
.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -.02em;
    line-height: 1.2;
}

.page-subtitle {
    font-size: .875rem;
    color: var(--gray-500);
    margin-top: 4px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font-sans);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1;
}

.btn-primary {
    background: var(--blue-700);
    color: white;
}
.btn-primary:hover { background: var(--blue-800); box-shadow: 0 4px 14px rgba(26,58,143,.3); }

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-danger {
    background: var(--red-500);
    color: white;
}
.btn-danger:hover { background: var(--red-600); }

.btn-success {
    background: var(--green-500);
    color: white;
}

.btn-outline {
    background: transparent;
    color: var(--blue-700);
    border: 1.5px solid var(--blue-700);
}
.btn-outline:hover { background: var(--blue-50); }

.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

.btn:disabled, .btn[disabled] {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Forms ── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

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

.form-group.full-width { grid-column: 1 / -1; }

label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--gray-700);
    letter-spacing: .01em;
}

.form-control {
    padding: 9px 13px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: .9rem;
    color: var(--gray-900);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
    outline: none;
}

.form-control:focus {
    border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(48, 86, 196, .1);
}

.form-control::placeholder { color: var(--gray-400); }

select.form-control { cursor: pointer; }

.form-hint {
    font-size: .75rem;
    color: var(--gray-500);
    margin-top: 2px;
}

/* ── Tables ── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
}

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

thead {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

th {
    padding: 11px 16px;
    text-align: left;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-600);
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--blue-50); }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
}

.badge-active   { background: var(--green-100); color: #166534; }
.badge-inactive { background: var(--gray-100);  color: var(--gray-600); }
.badge-contrib  { background: var(--blue-100);  color: var(--blue-700); }
.badge-subs     { background: #fce7f3; color: #9d174d; }
.badge-warning  { background: var(--amber-100); color: #92400e; }
.badge-error    { background: var(--red-100);   color: #991b1b; }

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

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    padding: 20px 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: box-shadow var(--transition);
}

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

.stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue   { background: var(--blue-50);  color: var(--blue-700); }
.stat-icon.red    { background: var(--red-100);  color: var(--red-600); }
.stat-icon.green  { background: var(--green-100); color: var(--green-500); }
.stat-icon.amber  { background: var(--amber-100); color: var(--amber-500); }

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1;
    letter-spacing: -.03em;
}

.stat-label {
    font-size: .75rem;
    color: var(--gray-500);
    margin-top: 4px;
    font-weight: 500;
}

/* ── Progress Bar ── */
.progress-wrapper {
    margin: 16px 0;
}

.progress-bar-track {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue-700), var(--blue-500));
    border-radius: 4px;
    transition: width .3s ease;
    position: relative;
    overflow: hidden;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    top: 0; left: -100%; right: -100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer { to { transform: translateX(200%); } }

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
    color: var(--gray-600);
    margin-top: 6px;
    font-weight: 500;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-top: 16px;
    justify-content: center;
}

.page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
    background: var(--white);
    transition: all var(--transition);
    padding: 0 8px;
}

.page-link:hover { border-color: var(--blue-500); color: var(--blue-700); }
.page-link.active { background: var(--blue-700); color: white; border-color: var(--blue-700); }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Patient Detail ── */
.patient-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
}

.patient-avatar {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    flex-shrink: 0;
}

.patient-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -.02em;
}

.patient-id {
    font-size: .875rem;
    color: var(--gray-500);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-400); }
.detail-value { font-size: .95rem; color: var(--gray-900); font-weight: 500; }

/* ── Search Box ── */
.search-box {
    position: relative;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}

.search-box .form-control {
    padding-left: 38px;
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: white;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 240px;
    overflow-y: auto;
    margin-top: 4px;
    display: none;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: .875rem;
    border-bottom: 1px solid var(--gray-100);
    transition: background var(--transition);
}

.autocomplete-item:hover, .autocomplete-item.active { background: var(--blue-50); }
.autocomplete-item:last-child { border-bottom: none; }

/* ── Login ── */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-700) 60%, #2d5ccc 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    top: -50%; left: -20%;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: rgba(255,255,255,.03);
    pointer-events: none;
}

.auth-page::after {
    content: '';
    position: absolute;
    bottom: -30%; right: -10%;
    width: 500px; height: 500px;
    border-radius: 50%;
    background: rgba(255,255,255,.04);
    pointer-events: none;
}

.auth-card {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 60px rgba(0,0,0,.3);
    padding: 48px 44px;
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
}

.auth-logo-icon {
    width: 46px; height: 46px;
    background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gray-900);
    margin-bottom: 6px;
    letter-spacing: -.03em;
}

.auth-subtitle {
    font-size: .85rem;
    color: var(--gray-500);
    margin-bottom: 28px;
}

.auth-form .form-group { margin-bottom: 16px; }

.input-icon-wrapper {
    position: relative;
}

.input-icon-wrapper svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
    width: 17px; height: 17px;
}

.input-icon-wrapper .form-control { padding-left: 38px; }

.remember-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 20px;
    font-size: .85rem;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--gray-600);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: .8rem;
    color: var(--gray-400);
}

/* ── Upload Zone ── */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--gray-50);
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--blue-500);
    background: var(--blue-50);
}

.upload-zone svg { color: var(--blue-400); margin-bottom: 12px; }
.upload-zone-title { font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.upload-zone-hint { font-size: .82rem; color: var(--gray-500); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar-toggle { display: flex; }
    
    .main-content { margin-left: 0; }
    
    .content-area { padding: 20px 16px; }
    
    .page-header { flex-direction: column; align-items: flex-start; }
    
    .form-grid { grid-template-columns: 1fr; }
    
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 32px 24px; }
}
