/* ====================================================
   PATRIMONIAL — Hoja de estilos principal
   Fondo blanco/claro · Portilla Consultores
   ==================================================== */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: #f5f7fa;
    color: #222;
    font-size: 14px;
    line-height: 1.5;
}

/* ---------- LAYOUT ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #0d3b66 0%, #14467a 100%);
    color: #e8eef5;
    padding: 0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand {
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex; align-items: center; gap: 12px;
}
.sidebar .brand .logo {
    width: 38px; height: 38px; background: #fff; color: #0d3b66;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 18px;
}
.sidebar .brand h2 { margin: 0; font-size: 15px; color: #fff; }
.sidebar .brand .sub { font-size: 11px; color: #a8c4e0; }

.sidebar nav { padding: 12px 0; }
.sidebar nav .section {
    font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
    color: #7fa3c8; padding: 14px 18px 6px; font-weight: 700;
}
.sidebar nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; color: #cfddec; text-decoration: none;
    font-size: 13.5px; border-left: 3px solid transparent;
    transition: all .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active {
    background: rgba(255,255,255,0.1); color: #fff;
    border-left-color: #4ea3e0; font-weight: 600;
}
.sidebar nav a .ico { width: 18px; text-align: center; }

.main {
    flex: 1;
    padding: 0;
    min-width: 0;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e3e8ed;
    padding: 14px 28px;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 18px; color: #0d3b66; font-weight: 600; }
.topbar .user { font-size: 13px; color: #555; }
.topbar .user a { color: #0d6efd; text-decoration: none; margin-left: 12px; }
.topbar .user a:hover { text-decoration: underline; }

.content { padding: 24px 28px; }

/* ---------- CARDS ---------- */
.card {
    background: #fff;
    border: 1px solid #e3e8ed;
    border-radius: 10px;
    margin-bottom: 20px;
    overflow: hidden;
}
.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid #eef2f6;
    display: flex; justify-content: space-between; align-items: center;
    background: #fafbfc;
}
.card-head h3 { margin: 0; font-size: 15px; color: #0d3b66; font-weight: 600; }
.card-body { padding: 18px; }

/* ---------- STATS ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    background: #fff;
    border: 1px solid #e3e8ed;
    border-radius: 10px;
    padding: 16px 18px;
    border-left: 4px solid #0d3b66;
}
.stat .label { font-size: 11px; text-transform: uppercase; color: #888; letter-spacing: .8px; }
.stat .value { font-size: 24px; font-weight: 700; color: #0d3b66; margin-top: 4px; }
.stat .hint { font-size: 11px; color: #888; margin-top: 4px; }
.stat.green { border-left-color: #14a44d; }
.stat.green .value { color: #14a44d; }
.stat.red { border-left-color: #c12c2c; }
.stat.red .value { color: #c12c2c; }
.stat.orange { border-left-color: #e07a00; }
.stat.orange .value { color: #e07a00; }
.stat.purple { border-left-color: #7c3aed; }
.stat.purple .value { color: #7c3aed; }

/* ---------- TABLAS ---------- */
table.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
table.tbl th {
    background: #f1f4f8;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: #2c4a6b;
    border-bottom: 2px solid #d6dde4;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
table.tbl td {
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f6;
    vertical-align: middle;
}
table.tbl tbody tr:hover { background: #f9fbfd; }
table.tbl .actions { text-align: right; white-space: nowrap; }
.empty-row { text-align: center; color: #999; padding: 32px !important; font-style: italic; }

/* ---------- BOTONES ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    background: #0d3b66; color: #fff;
    border: none; border-radius: 6px;
    font-size: 13px; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: background .15s, transform .05s;
}
.btn:hover { background: #0a2c4f; }
.btn:active { transform: scale(.98); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-success { background: #14a44d; }
.btn-success:hover { background: #0f8a3f; }
.btn-danger { background: #c12c2c; }
.btn-danger:hover { background: #9a2222; }
.btn-warn { background: #e07a00; }
.btn-secondary { background: #6c757d; }
.btn-secondary:hover { background: #555e66; }
.btn-outline { background: transparent; color: #0d3b66; border: 1.5px solid #0d3b66; }
.btn-outline:hover { background: #0d3b66; color: #fff; }

/* ---------- FORMS ---------- */
.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 768px) {
    .form-grid.cols-2, .form-grid.cols-3, .form-grid.cols-4 {
        grid-template-columns: 1fr;
    }
}
.form-field { display: flex; flex-direction: column; min-width: 0; }
.form-field label {
    font-size: 12px; font-weight: 600; color: #2c4a6b;
    margin-bottom: 5px; text-transform: uppercase; letter-spacing: .3px;
}
.form-field input[type=text],
.form-field input[type=number],
.form-field input[type=date],
.form-field input[type=email],
.form-field select,
.form-field textarea {
    padding: 9px 11px;
    border: 1.5px solid #d6dde4;
    border-radius: 6px;
    font-size: 13.5px;
    background: #fff;
    font-family: inherit;
    transition: border .15s;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none; border-color: #0d6efd;
}
.form-field textarea { min-height: 70px; resize: vertical; }
.form-field .hint { font-size: 11px; color: #888; margin-top: 3px; }
.form-field.full { grid-column: 1 / -1; }
.form-actions {
    margin-top: 18px; padding-top: 14px;
    border-top: 1px solid #eef2f6;
    display: flex; gap: 10px; justify-content: flex-end;
}

/* ---------- BADGES ---------- */
.badge {
    display: inline-block;
    padding: 3px 9px;
    background: #eef2f6;
    color: #2c4a6b;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.conyuge { background: #e0f0ff; color: #0d3b66; }
.badge.declarante { background: #fff0d9; color: #c47200; }
.badge.copropiedad { background: #f0e0ff; color: #5b21b6; }
.badge.tipo { background: #e7fae7; color: #14a44d; }

/* ---------- MODAL ---------- */
.modal-bg {
    display: none;
    position: fixed; inset: 0;
    background: rgba(13,59,102,0.55);
    z-index: 100;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    width: 100%; max-width: 1200px;
    max-height: 92vh;
    overflow-x: hidden;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-head {
    padding: 16px 22px;
    border-bottom: 1px solid #eef2f6;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; background: #fff;
}
.modal-head h3 { margin: 0; color: #0d3b66; font-size: 17px; }
.modal-close {
    background: none; border: none; font-size: 22px;
    cursor: pointer; color: #888;
}
.modal-body { padding: 22px 26px; overflow-x: hidden; }
.modal-body form { width: 100%; min-width: 0; }
.modal-body .form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px 18px;
    width: 100%;
}
.modal-body .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.modal-body .form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.modal-body .form-field { min-width: 0; }
.modal-body .form-field input,
.modal-body .form-field select,
.modal-body .form-field textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.modal-body .form-field.full { grid-column: 1 / -1; }
@media (max-width: 900px) {
    .modal-body .form-grid,
    .modal-body .form-grid.cols-2,
    .modal-body .form-grid.cols-4 { grid-template-columns: 1fr; }
}

/* ---------- ALERTS ---------- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13.5px;
    border-left: 4px solid;
}
.alert-info { background: #e7f3ff; color: #0d3b66; border-color: #0d6efd; }
.alert-success { background: #e7faea; color: #0f6b2f; border-color: #14a44d; }
.alert-warning { background: #fff8e1; color: #8a5a00; border-color: #e0a800; }
.alert-error { background: #fdecec; color: #8b1c1c; border-color: #c12c2c; }

/* ---------- TOAST ---------- */
.toast {
    position: fixed; bottom: 22px; right: 22px;
    background: #14a44d; color: #fff;
    padding: 13px 20px; border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.18);
    z-index: 200;
    animation: slideIn .25s;
}
.toast.error { background: #c12c2c; }
@keyframes slideIn {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---------- UTIL ---------- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #888; }
.text-mono { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 18px; } .mt-4 { margin-top: 28px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 10px; }

/* ---------- PRINT / PDF ---------- */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { padding: 0; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    body { background: #fff; }
}

/* ===================================================================
   OVERRIDE FINAL — FORZAR ANCHO DE INPUTS EN MODALES
   (corrige scroll horizontal aún cuando hay estilos inline en los
   inputs que vienen con style="border:2px solid...")
   =================================================================== */
.modal *, .modal *::before, .modal *::after { box-sizing: border-box; }
.modal-bg.open { padding: 16px; }
.modal { box-sizing: border-box; }
.modal-body { box-sizing: border-box; max-width: 100%; }
.modal-body form { box-sizing: border-box; width: 100%; max-width: 100%; }
.modal-body .form-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.modal-body .form-field {
    min-width: 0 !important;
    max-width: 100% !important;
}
/* fuerza TODOS los inputs/selects/textarea adentro del modal */
.modal-body input,
.modal-body select,
.modal-body textarea {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}
/* etiquetas dentro del modal no deben empujar el grid */
.modal-body label {
    word-break: break-word;
    overflow-wrap: break-word;
}
