: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;
}

.nowrap {
	white-space: nowrap;
}

/* ---------- 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; }

/* ---------- Stepper (flujo de estados) ---------- */
.stepper { display: flex; gap: 8px; margin-bottom: 24px; }
.step { flex: 1; text-align: center; padding: 12px 8px; border-bottom: 4px solid #d9e2ec; color: var(--color-text-light); }
.step.completed { border-color: var(--color-success); color: var(--color-success); }
.step.current { border-color: var(--color-primary); color: var(--color-primary); font-weight: 700; }
.step-num { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: #eef2f7; color: var(--color-text-light); font-weight: 700; margin-bottom: 6px; }
.step.completed .step-num { background: var(--color-success); color: #fff; }
.step.current .step-num { background: var(--color-primary); color: #fff; }
.step-label { display: block; font-size: 13px; }

/* ---------- Items de causación ---------- */
.items-table { min-width: 1200px; }
.items-table select,
.items-table input { width: 100%; padding: 6px 8px; font-size: 13px; border: 1px solid #c9d4df; border-radius: 6px; font-family: var(--font); }
.items-table .item-tipo,
.items-table .item-codigo { min-width: 130px; }
.items-table .item-desc { min-width: 240px; }
.items-table .item-cantidad { min-width: 90px; }
.items-table .item-precio,
.items-table .item-descuento { min-width: 130px; }
.items-table td { vertical-align: middle; }
.items-table .item-total { font-weight: 600; white-space: nowrap; }
.items-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 12px; flex-wrap: wrap; }
.items-sum { font-size: 14px; }
.item-tipo { width: 80px !important; }
.item-codigo { width: 80px !important; }
.item-desc { width: 200px !important; }

/* Bloques de item (fila básica + fila de impuestos) */
.items-table .item-taxes td { background: #f7fafd; }
.items-table tbody.item-block tr.item-taxes td { border-bottom: 2px solid #e3e9f0; }
.tax-row { display: flex; flex-wrap: wrap; gap: 12px; }
.tax-field { display: flex; flex-direction: column; gap: 3px; min-width: 150px; flex: 1; }
.tax-field label { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--color-text-light); }
.tax-field select { width: 100%; }
.detail-value { font-size: 14px; color: var(--color-text); }
.doc-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ---------- 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;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    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-logo-img {
    display: block;
    width: 100%;
    max-width: 200px;
}

.sidebar-logo-img svg {
    display: block;
    width: 100%;
    height: auto;
}

.auth-logo-img {
    display: block;
    width: 190px;
    margin: 0 auto 16px;
}
.auth-logo-img svg {
    display: block;
    width: 100%;
    height: auto;
}

.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); }

.nav-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.nav-toggle:hover { color: rgba(255, 255, 255, 0.8); }
.nav-caret { font-size: 10px; transition: transform 0.15s ease; }
.nav-group.collapsed .nav-caret { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-body { display: none; }

.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; }
.th-check { width: 40px; text-align: center; }
.th-check input { width: auto; }

.text-warn { color: #e67e22; font-weight: 600; }
.text-danger { color: var(--color-error); font-weight: 600; }
.text-ok { color: var(--color-success); font-weight: 600; }

.impuestos-list { list-style: none; font-size: 12px; line-height: 1.6; }
.impuestos-list li { display: flex; justify-content: space-between; gap: 12px; white-space: nowrap; }
.impuesto-nombre { color: var(--color-text-light); }
.impuesto-valor { font-weight: 600; }
.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; }

.seleccion-info {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 7px 14px;
    border: 1px solid #d3dbe4;
    border-radius: var(--radius);
    background: #f7f9fc;
    font-size: 13px;
    color: var(--color-text-light);
}
.seleccion-info[hidden] { display: none; }
.seleccion-info strong { color: var(--color-text); font-size: 14px; }
.seleccion-info-total strong { color: var(--color-primary); }

.app-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 0;
    width: calc(100% - 32px);
    max-width: 640px;
    margin: auto;
    box-shadow: var(--shadow);
}
.app-dialog::backdrop { background: rgba(21, 34, 56, 0.5); }
.rem-factura-dialog {
    padding: 32px 36px;
    max-width: 760px;
    max-height: 90vh;
    overflow-y: auto;
}
.rem-factura-dialog h3 { margin-bottom: 10px; }
.rem-factura-dialog .role-desc { margin-bottom: 18px; }
.dialog-form { padding: 24px; }
.dialog-form h3 { margin-bottom: 6px; }
.dialog-sub { font-size: 14px; color: var(--color-text-light); margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- 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); }
.badge-warn { background: #fff3e0; color: #e67e22; }

.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; }
.form-card-full { max-width: 100%; }
.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-full { grid-column: 1 / -1; }
.city-picker { position: relative; }
.city-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.city-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: #eef4fb; border: 1px solid #cfe0f2; color: #1d4e79;
    border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px;
}
.city-chip-x { border: none; background: transparent; color: #1d4e79; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.city-add { display: flex; gap: 8px; }
.city-add .city-search-input { flex: 1; }
.city-results {
    position: absolute; z-index: 20; left: 0; right: 0; margin-top: 4px;
    background: var(--color-white); border: 1px solid #c9d4df; border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .12); max-height: 240px; overflow-y: auto;
}
.city-result {
    display: block; width: 100%; text-align: left; padding: 8px 12px;
    background: transparent; border: none; cursor: pointer; font-size: 14px; font-family: var(--font);
}
.city-result:hover { background: #f2f7fc; }
.city-result-empty { padding: 8px 12px; color: #7a8a99; font-size: 13px; }

.puc-resultados { max-height: 260px; overflow-y: auto; margin-top: 8px; border: 1px solid #c9d4df; border-radius: var(--radius); }
.puc-result { display: block; width: 100%; text-align: left; padding: 8px 12px; background: transparent; border: none; border-bottom: 1px solid #eef2f7; cursor: pointer; font-size: 14px; font-family: var(--font); }
.puc-result:hover { background: #f2f7fc; }
[hidden] { display: none !important; }
.item-codigo-puc { display: flex; gap: 6px; align-items: center; }
.item-codigo-puc .item-codigo-puc-input { flex: 1; }

.doc-item { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 2px; }
.doc-meta { color: #7a8a99; }
.exam-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.exam-list li { display: flex; justify-content: space-between; gap: 14px; }
.exam-val { color: #7a8a99; white-space: nowrap; }
.btn-icon-sm { border: none; background: transparent; color: var(--color-error); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.upload-form { display: flex; align-items: center; gap: 8px; }
.upload-form input[type="file"] { max-width: 170px; font-size: 12px; padding: 4px; }

.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; }

.permiso-filtro { margin-bottom: 12px; }
.permisos-modulos { display: flex; flex-direction: column; gap: 14px; }
.permiso-modulo { border: 1px solid #e3e9f0; border-radius: var(--radius); padding: 12px 14px; background: #fbfdff; }
.permiso-modulo-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.permiso-modulo-head strong { font-size: 14px; color: var(--color-primary-dark); }
.permiso-todos { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #5b6b7c; cursor: pointer; white-space: nowrap; }
.permiso-todos input { width: auto; }

/* ---------- 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; }

.cartera-cards { grid-template-columns: repeat(4, 1fr); }
.cartera-cards .stat-card { border-left: 5px solid #c9d4df; }
.cartera-verde { border-left-color: #2ecc71 !important; }
.cartera-naranja { border-left-color: #f39c12 !important; }
.cartera-naranja-rojo { border-left-color: #e67e22 !important; }
.cartera-rojo { border-left-color: #c0392b !important; }
.cartera-verde .stat-value { color: #1e8449; }
.cartera-naranja .stat-value { color: #b9770e; }
.cartera-naranja-rojo .stat-value { color: #ca6f1e; }
.cartera-rojo .stat-value { color: #a93226; }
@media (max-width: 900px) { .cartera-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .cartera-cards { grid-template-columns: 1fr; } }

.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; }
}
