:root {
    --color-primary: #1d6fb8;
    --color-primary-dark: #155a93;
    --color-bg: #eef2f7;
    --color-sidebar: #152238;
    --color-text: #22303e;
    --color-text-light: #5b6b7c;
    --color-white: #ffffff;
    --color-error: #c0392b;
    --color-success: #27ae60;
    --radius: 8px;
    --shadow: 0 4px 18px rgba(21, 34, 56, 0.12);
    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
}

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

body {
    font-family: var(--font);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Página de autenticación ---------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--color-sidebar) 0%, var(--color-primary-dark) 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 32px;
}

.auth-header { text-align: center; margin-bottom: 24px; }

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.auth-header h1 { font-size: 22px; color: var(--color-text); }
.auth-header p { font-size: 14px; color: var(--color-text-light); margin-top: 6px; }

.auth-footer { text-align: center; margin-top: 24px; font-size: 12px; color: var(--color-text-light); }

/* ---------- Formularios ---------- */
.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-text);
}

.field input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #c9d4df;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(29, 111, 184, 0.18);
}

.field input.input-error { border-color: var(--color-error); }

/* ---------- Botones ---------- */
.btn {
    display: inline-block;
    padding: 11px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    text-align: center;
}

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

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

.btn-danger { background: var(--color-error); color: var(--color-white); }
.btn-danger:hover { background: #a93226; }

.btn-success { background: var(--color-success); color: var(--color-white); }
.btn-success:hover { background: #219a52; }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-icon {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--color-text);
    padding: 4px 8px;
}

/* ---------- Alertas ---------- */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error { background: #fdecea; color: var(--color-error); border: 1px solid #f5c6c0; }
.alert-success { background: #e9f9ef; color: var(--color-success); border: 1px solid #b8e6c8; }
.alert-neutral { background: #eef2f7; color: var(--color-text-light); border: 1px solid #d9e2ec; }

.hidden { display: none; }
.nota-ok { background: #e9f9ef; border-left: 4px solid var(--color-success); padding: 10px 14px; border-radius: 4px; font-size: 13px; margin-top: 12px; }

/* ---------- Conciliación (dos columnas) ---------- */
.conc-matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.conc-col h3 { font-size: 15px; margin-bottom: 10px; }
.conc-col form select { width: 100%; margin-bottom: 6px; }
.conc-col form .btn { width: 100%; }
@media (max-width: 900px) {
    .conc-matrix { grid-template-columns: 1fr; }
}

/* ---------- Layout aplicación ---------- */
.app-page { background: var(--color-bg); }

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

.sidebar {
    width: 230px;
    background: var(--color-sidebar);
    color: var(--color-white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 15px;
}

.sidebar-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--color-primary);
    font-weight: 700;
    font-size: 14px;
}

.sidebar-nav { padding: 12px 0; }

.nav-item {
    display: block;
    padding: 12px 18px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: #fff; }
.nav-item.active { background: rgba(29, 111, 184, 0.25); border-left-color: var(--color-primary); color: #fff; }

.nav-section { padding: 16px 18px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: rgba(255, 255, 255, 0.45); }

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

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--color-white);
    padding: 12px 24px;
    border-bottom: 1px solid #e3e9f0;
}

.topbar-title { font-size: 16px; flex: 1; }

.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 14px; font-weight: 600; }
.inline-form { display: inline; }

.content { padding: 28px 24px; }

.welcome { margin-bottom: 24px; }
.welcome h3 { font-size: 20px; margin-bottom: 4px; }
.welcome p { color: var(--color-text-light); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 24px; }

.card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(21, 34, 56, 0.06);
    padding: 20px;
}
.card h4 { font-size: 14px; color: var(--color-text-light); margin-bottom: 8px; }
.card p { font-size: 15px; word-break: break-word; }

/* ---------- Error ---------- */
.error-card { text-align: center; }
.error-card h1 { font-size: 28px; margin-bottom: 8px; }
.error-card p { margin-bottom: 20px; color: var(--color-text-light); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; background: var(--color-white); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(21, 34, 56, 0.06); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #e3e9f0; vertical-align: middle; }
.table thead th { background: #f7fafd; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--color-text-light); }
.table tbody tr:hover { background: #f7fafd; }
.table tbody tr:last-child td { border-bottom: none; }
.th-acciones { width: 200px; }
.td-acciones { display: flex; gap: 8px; align-items: center; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.toolbar h3 { font-size: 18px; }
.toolbar-actions { display: flex; gap: 8px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #e9f9ef; color: var(--color-success); }
.badge-error { background: #fdecea; color: var(--color-error); }
.badge-neutral { background: #eef2f7; color: var(--color-text-light); }
.badge-ok { background: #eaf3fb; color: var(--color-primary); }

.th-right { text-align: right; }

/* ---------- Formulario tarjeta ---------- */
.form-card { max-width: 620px; padding: 28px; margin-bottom: 24px; }
.form-card .auth-form { margin-top: 4px; }
.form-card h3 { font-size: 15px; margin: 22px 0 14px; padding-bottom: 8px; border-bottom: 1px solid #e3e9f0; }
.form-card h3:first-child { margin-top: 0; }
.req { color: var(--color-error); }
.form-card-wide { max-width: 900px; }
.field-error { display: block; color: var(--color-error); font-size: 12px; margin-top: 4px; }
.hint { display: block; color: var(--color-text-light); font-size: 12px; margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

.field textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #c9d4df;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(29, 111, 184, 0.18); }

.field select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #c9d4df;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    background: var(--color-white);
    cursor: pointer;
}
.field select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(29, 111, 184, 0.18); }

.field input[type="file"] { padding: 8px 12px; background: #f7fafd; cursor: pointer; }

.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox-item input { width: auto; }
.checkbox-item small { display: block; color: var(--color-text-light); }
.checkbox-item code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 11px; }

.permiso-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Tarjetas de roles ---------- */
.role-card h4 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.role-desc { font-size: 13px; color: var(--color-text-light); margin-bottom: 10px; }
.permiso-list { list-style: none; }
.permiso-list li { padding: 5px 0 5px 22px; position: relative; font-size: 13px; color: #b0b8c1; }
.permiso-list li::before { content: "✕"; position: absolute; left: 0; color: #c3cbd4; }
.permiso-list li.tiene { color: var(--color-text); }
.permiso-list li.tiene::before { content: "✓"; color: var(--color-success); }

/* ---------- Filtros ---------- */
.filter-card { padding: 20px; margin-bottom: 24px; }
.filter-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; align-items: end; }
.filter-actions { display: flex; gap: 8px; }

/* ---------- Paginación ---------- */
.paginacion { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.paginacion-info { font-size: 13px; color: var(--color-text-light); }
.paginacion-botones { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- Indicadores (dashboard) ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(21, 34, 56, 0.06);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-label { font-size: 13px; color: var(--color-text-light); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--color-text); }
.stat-meta { font-size: 12px; color: var(--color-text-light); }
.pending-note { color: var(--color-primary); font-style: italic; }
.sub-stats .stat-card { box-shadow: none; background: #f7fafd; border: 1px solid #e3e9f0; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h3 { font-size: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.25s; z-index: 20; }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 20px 16px; }
    .topbar { padding: 10px 16px; }
    .user-name { display: none; }
    .td-acciones { flex-direction: column; align-items: stretch; }
    .form-grid, .permiso-grid { grid-template-columns: 1fr; }
}