:root {
    --brand-50:  #eaf2fb;
    --brand-100: #d2e3f7;
    --brand-200: #a5c7ef;
    --brand-500: #4f7df3;
    --brand-600: #3d68d8;
    --brand-700: #2d52b3;
    --brand-900: #1a2f66;
    --ink-900: #0f172a;
    --ink-700: #334155;
    --ink-500: #64748b;
    --ink-300: #cbd5e1;
    --ink-100: #f1f5f9;
    --ink-50:  #f8fafc;
    --surface: #ffffff;
    --bg:      #f5f7fb;
    --success: #16a34a;
    --warning: #ea8a0a;
    --danger:  #dc2626;
    --info:    #0284c7;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
    --shadow-md: 0 4px 12px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
    --shadow-lg: 0 12px 32px rgba(15,23,42,.10);
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;
    --sidebar-w: 264px;
}

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink-900);
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; color: var(--ink-900); margin: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

a { color: var(--brand-500); text-decoration: none; }
a:hover { color: var(--brand-700); }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--ink-100);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 22px;
    border-bottom: 1px solid var(--ink-100);
    margin-bottom: 16px;
}

.sidebar-brand .logo {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    border-radius: 10px;
    color: #fff;
    display: grid; place-items: center;
    font-size: 1.15rem;
    box-shadow: 0 6px 14px rgba(79,125,243,.25);
    font-weight: 700;
}

.sidebar-brand .title { font-weight: 800; font-size: .98rem; line-height: 1.1; }
.sidebar-brand .subtitle { font-size: .72rem; color: var(--ink-500); }

.sidebar-profile-card {
    width: 100%;
    padding: 0 8px 12px;
    margin: 0 0 2px;
    border: 0;
    border-bottom: 1px solid var(--ink-100);
    background: transparent;
    color: var(--ink-900);
    display: grid;
    justify-items: center;
    gap: 8px;
    cursor: pointer;
    text-align: center;
}

.sidebar-profile-card:hover .sidebar-profile-photo {
    box-shadow: 0 5px 16px rgba(15, 23, 42, .24);
}

.sidebar-profile-photo {
    width: 92px;
    height: 92px;
    padding: 0;
    border: 3px solid #fff;
    border-radius: 50%;
    overflow: hidden;
    background: var(--ink-50);
    box-shadow: 0 4px 14px rgba(15, 23, 42, .16);
    flex: 0 0 auto;
    display: grid;
    place-items: center;
}

.sidebar-profile-photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-profile-initials {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    font-size: 1.35rem;
    font-weight: 700;
}

.sidebar-profile-info {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.sidebar-profile-info strong {
    font-size: .78rem;
    line-height: 1.25;
}

.sidebar-profile-info small {
    color: var(--ink-500);
    font-size: .7rem;
}

.profile-photo-large {
    width: min(100%, 420px);
    min-height: 260px;
    max-height: 65vh;
    margin: 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--ink-100);
    border-radius: var(--radius-sm);
    background: var(--ink-50);
}

.profile-photo-large img {
    display: block;
    width: 100%;
    height: 100%;
    max-height: 65vh;
    object-fit: contain;
}

.profile-photo-large span {
    width: 132px;
    height: 132px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    font-size: 2rem;
    font-weight: 700;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 16px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--ink-100);
}
.sidebar-user-avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    border-radius: 50%;
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700;
    font-size: .78rem;
    flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
    font-weight: 700;
    font-size: .82rem;
    color: var(--ink-900);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: .68rem;
    color: var(--brand-600);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.sidebar-user-email {
    font-size: .68rem;
    color: var(--ink-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-section-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-500);
    padding: 14px 12px 6px;
    font-weight: 600;
}

.sidebar .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-700);
    font-weight: 500;
    font-size: .9rem;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; color: var(--ink-500); }
.sidebar .nav-link:hover { background: var(--ink-50); color: var(--ink-900); }
.sidebar .nav-link:hover i { color: var(--brand-500); }
.sidebar .nav-link.active {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    box-shadow: 0 6px 14px rgba(79,125,243,.25);
}
.sidebar .nav-link.active i { color: #fff; }

.sidebar-submenu {
    margin: 6px 0 4px 20px;
    padding-left: 12px;
    border-left: 1px solid var(--ink-100);
}

.sidebar-submenu .nav-link {
    padding: 9px 10px;
    font-size: .86rem;
}

.sidebar-submenu .nav-link.active {
    background: var(--brand-50);
    color: var(--brand-700);
    box-shadow: none;
}

.sidebar-submenu .nav-link.active i {
    color: var(--brand-700);
}

.sidebar-caret {
    width: auto !important;
    font-size: .8rem !important;
    transition: transform .15s ease;
}

.nav-link[aria-expanded="true"] .sidebar-caret {
    transform: rotate(180deg);
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 8px 4px;
    border-top: 1px solid var(--ink-100);
    font-size: .78rem;
    color: var(--ink-500);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky; top: 0; z-index: 1020;
    background: rgba(255,255,255,.85);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--ink-100);
    padding: 12px 22px;
    display: flex; align-items: center; gap: 14px;
}

.topbar .page-title { font-weight: 700; color: var(--ink-900); font-size: 1rem; flex: 1; }

.content { padding: 22px; flex: 1; overflow-y: auto; }

/* ===== Login ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #f5f6f8 0%, #e8ecf3 100%);
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 10px 40px rgba(79,125,243,.12);
    width: 100%; max-width: 420px;
}

.login-card .brand { text-align: center; margin-bottom: 22px; }
.login-card .brand .logo {
    margin: 0 auto 10px;
    width: 52px; height: 52px;
    font-size: 24px;
    border-radius: 12px;
}
.login-card h1 { font-size: 1.3rem; font-weight: 700; text-align: center; margin: 0 0 4px; }
.login-card p.sub { text-align: center; color: var(--ink-500); font-size: 0.85rem; margin: 0 0 24px; }

/* ===== Components ===== */
.card {
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--ink-100);
    padding: 14px 18px;
    font-weight: 600;
    color: var(--ink-900);
}

.card-body { padding: 18px; }

.stat-card {
    border: 1px solid var(--ink-100);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    transition: transform .15s, box-shadow .15s;
}

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

.stat-card .stat-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-500);
    font-weight: 600;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--ink-900);
    margin: 6px 0 2px;
    line-height: 1;
}

.stat-card .stat-icon {
    width: 42px; height: 42px;
    border-radius: 10px;
    display: grid; place-items: center;
    font-size: 1.25rem;
    margin-bottom: 12px;
}

.stat-icon.primary { background: var(--brand-50); color: var(--brand-700); }
.stat-icon.warning { background: #fef3c7; color: #b45309; }
.stat-icon.success { background: #dcfce7; color: #166534; }
.stat-icon.info    { background: #e0f2fe; color: #075985; }
.stat-icon.danger  { background: #fee2e2; color: #991b1b; }

/* ===== Buttons ===== */
.btn {
    border-radius: 10px;
    font-weight: 600;
    padding: .55rem 1.05rem;
    font-size: .88rem;
    transition: transform .12s, box-shadow .15s, background .15s;
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    border: none;
    cursor: pointer;
}

.btn:active { transform: translateY(1px); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 8px; }
.btn-lg { padding: .75rem 1.4rem; font-size: .95rem; border-radius: 12px; }

.btn-primary {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(79,125,243,.20);
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--brand-600), var(--brand-900));
    box-shadow: 0 6px 16px rgba(79,125,243,.28);
}

.btn-secondary { background: var(--ink-100); color: var(--ink-700); border-color: var(--ink-100); }
.btn-secondary:hover { background: var(--ink-300); color: var(--ink-900); border-color: var(--ink-300); }

.btn-outline-secondary { border: 1px solid var(--ink-300); color: var(--ink-700); background: transparent; }
.btn-outline-secondary:hover { background: var(--ink-100); }

.btn-outline-danger { border: 1px solid var(--danger); color: var(--danger); background: transparent; }
.btn-outline-danger:hover { background: #fee2e2; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #c87708; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* ===== Forms ===== */
.form-label { font-weight: 600; color: var(--ink-700); font-size: .82rem; margin-bottom: .35rem; }

.form-control, .form-select {
    border-radius: 10px;
    border: 1px solid var(--ink-300);
    padding: .55rem .85rem;
    font-size: .9rem;
    transition: border-color .15s, box-shadow .15s;
    background: #fff;
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 4px rgba(79,125,243,.12);
    outline: none;
}

textarea.form-control { min-height: 92px; }

/* ===== Tables ===== */
.table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--ink-100);
    box-shadow: var(--shadow-sm);
}

.table thead th {
    background: var(--ink-50);
    color: var(--ink-500);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 1px solid var(--ink-100);
    padding: 12px 14px;
}

.table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--ink-100);
    font-size: .88rem;
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--ink-50); }

/* ===== Badges ===== */
.badge {
    font-weight: 600;
    padding: .35em .7em;
    border-radius: 999px;
    font-size: .72rem;
    letter-spacing: .02em;
    display: inline-block;
}

.badge-soft-primary { background: var(--brand-50); color: var(--brand-700); }
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-warning { background: #fef3c7; color: #b45309; }
.badge-soft-danger  { background: #fee2e2; color: #991b1b; }
.badge-soft-info    { background: #e0f2fe; color: #075985; }
.badge-soft-secondary { background: var(--ink-100); color: var(--ink-700); }

.badge-rol-SUPERADMIN { background: #fee2e2; color: #991b1b; }
.badge-rol-ADMIN { background: var(--brand-50); color: var(--brand-700); }
.badge-rol-TECNICO_TICS { background: #fef3c7; color: #92400e; }
.badge-rol-USUARIO { background: #dcfce7; color: #166534; }

/* ===== Alerts ===== */
.alert {
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: .88rem;
    padding: 12px 16px;
}

.alert-success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert-info    { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert-danger  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

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

.page-header .lead-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--brand-50);
    color: var(--brand-700);
    display: grid; place-items: center;
    font-size: 1.25rem;
}

.page-header h2 { margin: 0; font-size: 1.4rem; }
.page-header .subtitle { color: var(--ink-500); font-size: .85rem; margin-top: 2px; }

/* ===== Responsive ===== */
@media (max-width: 767.98px) {
    .app-layout { flex-direction: column; }
    .sidebar { position: fixed; left: -280px; width: 280px; z-index: 100; transition: left .25s ease; height: 100vh; }
    .sidebar.open { left: 0; }
    .topbar .menu-btn { display: grid; }
    .content { padding: 16px; }
    .topbar { padding: 10px 14px; }
}

@media (max-width: 576px) {
    h2 { font-size: 1.2rem; }
    .stat-card .stat-value { font-size: 1.6rem; }
    .btn { padding: .55rem .9rem; }
}

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-500); }
