* {
    box-sizing: border-box;
}

:root {
    --app-bg: #f4f6f9;
    --app-surface: #ffffff;
    --app-border: #e3e8ef;
    --app-text: #1f2937;
    --app-muted: #6b7280;
    --app-primary: #2563eb;
    --app-primary-soft: #eff6ff;
    --app-sidebar: #111827;
    --app-sidebar-hover: #1f2937;
    --app-success: #15803d;
    --app-warning: #b45309;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    min-height: 100vh;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    min-height: 100vh;
}

.app-navbar {
    height: 64px;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-left,
.navbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.sidebar-toggle {
    border: 0;
    background: transparent;
    font-size: 22px;
    color: var(--app-text);
    padding: 6px;
}

.brand {
    font-weight: 800;
    font-size: 20px;
}

.navbar-user {
    color: var(--app-muted);
    font-size: 14px;
}

.navbar-action {
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    border-radius: 7px;
    padding: 8px 12px;
}

.app-body {
    display: flex;
    min-height: calc(100vh - 64px);
}

.app-sidebar {
    width: 250px;
    background: var(--app-sidebar);
    color: #fff;
    flex: 0 0 250px;
    transition: width .2s ease, transform .2s ease;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-title {
    font-size: 20px;
    font-weight: 800;
}

.sidebar-subtitle {
    font-size: 12px;
    opacity: .65;
    margin-top: 4px;
}

.sidebar-menu {
    padding: 10px;
}

.sidebar-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    margin-bottom: 4px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: rgba(255,255,255,.88);
    text-align: left;
}

.sidebar-item:hover {
    background: var(--app-sidebar-hover);
}

.sidebar-item.active {
    background: rgba(255,255,255,.12);
}

.sidebar-icon {
    width: 24px;
    text-align: center;
}

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

.app-content {
    flex: 1;
    padding: 24px;
}

.app-footer {
    border-top: 1px solid var(--app-border);
    background: var(--app-surface);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    color: var(--app-muted);
    font-size: 13px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 22px;
}

.breadcrumb {
    color: var(--app-muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.page-header h1 {
    margin: 0 0 6px;
    font-size: 28px;
}

.page-header p {
    margin: 0;
    color: var(--app-muted);
}

.page-actions {
    display: flex;
    gap: 8px;
}

.btn {
    border: 1px solid var(--app-border);
    background: #fff;
    border-radius: 7px;
    padding: 9px 13px;
}

.btn-secondary {
    color: var(--app-text);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.dashboard-card,
.content-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 10px;
}

.dashboard-card {
    min-height: 120px;
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.dashboard-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--app-primary-soft);
    font-size: 22px;
}

.dashboard-card-label {
    display: block;
    color: var(--app-muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.dashboard-card strong {
    display: block;
    font-size: 24px;
}

.dashboard-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.content-card {
    padding: 18px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h2 {
    margin: 0 0 5px;
    font-size: 18px;
}

.card-header p {
    margin: 0;
    color: var(--app-muted);
    font-size: 13px;
}

.empty-state {
    min-height: 220px;
    border: 1px dashed var(--app-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--app-muted);
    text-align: center;
}

.empty-state-icon {
    font-size: 34px;
    margin-bottom: 5px;
}

.status-list,
.finance-list {
    display: grid;
    gap: 12px;
}

.status-list > div,
.finance-list > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--app-border);
}

.status-list > div:last-child,
.finance-list > div:last-child {
    border-bottom: 0;
}

.status-list span,
.finance-list span {
    color: var(--app-muted);
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.quick-action {
    border: 1px solid var(--app-border);
    background: #fff;
    border-radius: 7px;
    padding: 12px;
    text-align: left;
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 7px;
}

.flash-success {
    background: #e8f7ed;
    border: 1px solid #b7e4c7;
}

.flash-error {
    background: #ffe8e8;
    border: 1px solid #efb4b4;
}

.sidebar-collapsed .app-sidebar {
    width: 72px;
    flex-basis: 72px;
}

.sidebar-collapsed .sidebar-header {
    padding-left: 10px;
    padding-right: 10px;
}

.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .sidebar-subtitle,
.sidebar-collapsed .sidebar-item span:last-child {
    display: none;
}

.sidebar-collapsed .sidebar-item {
    justify-content: center;
}

@media (max-width: 1050px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .app-sidebar {
        position: fixed;
        top: 64px;
        bottom: 0;
        left: 0;
        z-index: 900;
        transform: translateX(-100%);
    }

    .app-sidebar.is-open {
        transform: translateX(0);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .navbar-user {
        display: none;
    }

    .app-content {
        padding: 16px;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }
}

.text-right { text-align: right; }
.text-muted { color: var(--app-muted); }

.btn-primary {
    background: var(--app-primary);
    color: #fff;
    border-color: var(--app-primary);
}

.btn-small {
    padding: 6px 9px;
    font-size: 12px;
    margin-left: 4px;
}

.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.table-summary {
    color: var(--app-muted);
    font-size: 14px;
}

.table-search {
    width: min(320px, 100%);
    border: 1px solid var(--app-border);
    border-radius: 7px;
    padding: 9px 12px;
    background: #fff;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--app-border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--app-muted);
    letter-spacing: .02em;
}

.data-table tbody tr:hover {
    background: #fafbfd;
}

.status-badge,
.mini-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.status-active {
    background: #e8f7ed;
    color: var(--app-success);
}

.status-inactive {
    background: #f1f3f5;
    color: var(--app-muted);
}

.mini-badge {
    margin-left: 5px;
    background: var(--app-primary-soft);
    color: var(--app-primary);
}

.actions-cell {
    white-space: nowrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-section-title {
    grid-column: 1 / -1;
    font-size: 16px;
    font-weight: 700;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--app-border);
}

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

.form-group label {
    font-size: 13px;
    font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    border: 1px solid var(--app-border);
    border-radius: 7px;
    padding: 10px 11px;
    background: #fff;
}

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

.form-checkbox {
    justify-content: flex-end;
}

.form-checkbox label {
    display: flex;
    gap: 8px;
    align-items: center;
    min-height: 39px;
}

.form-checkbox input {
    width: auto;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.detail-list {
    display: grid;
    gap: 12px;
}

.detail-list > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--app-border);
}

.detail-list span {
    color: var(--app-muted);
}

.simple-list {
    display: grid;
    gap: 10px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.simple-list li,
.address-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--app-border);
}

.address-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.address-item span,
.address-item small {
    color: var(--app-muted);
}

@media (max-width: 850px) {
    .form-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .table-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .table-search {
        width: 100%;
    }
}

/* ============================================================
   DATATABLES - ESTÁNDAR SIGDA
   ============================================================ */

.content-card .dt-container {
    font-size: 13px;
}

.content-card .dt-layout-row {
    margin: 0;
    padding: 0 0 14px 0;
}

.content-card .dt-layout-row:last-child {
    padding-top: 14px;
    padding-bottom: 0;
}

.content-card .dt-search input,
.content-card .dt-length select {
    border: 1px solid var(--app-border) !important;
    border-radius: 7px !important;
    font-size: 13px !important;
    box-shadow: none !important;
}

.content-card .dt-search input {
    min-width: 260px;
    margin-left: 7px !important;
    padding: 7px 10px !important;
}

.content-card .dt-length select {
    padding: 6px 28px 6px 9px !important;
    margin: 0 5px !important;
}

.content-card .dt-info {
    color: var(--app-muted);
    font-size: 12px;
}

.content-card .dt-paging .dt-paging-button {
    border-radius: 6px !important;
    font-size: 12px;
    min-width: 32px;
}

.content-card .dt-paging .dt-paging-button.current {
    background: var(--app-primary) !important;
    color: #fff !important;
    border-color: var(--app-primary) !important;
}

.sigda-table {
    margin-bottom: 0 !important;
}

.sigda-table thead th {
    background: #fafbfc !important;
    border-bottom: 1px solid var(--app-border) !important;
    color: #687385 !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: .035em;
    white-space: nowrap;
}

.sigda-table tbody td {
    font-size: 13px;
    padding: 9px 10px !important;
}

.sigda-table tbody tr:hover {
    background: #f8fafc !important;
}

.table-id {
    color: #7b8492;
    font-size: 12px;
}

.action-menu-button {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: #6b7280;
    font-size: 21px;
    line-height: 1;
    display: inline-grid;
    place-items: center;
}

.action-menu-button:hover,
.action-menu-button:focus {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #111827;
}

.action-dropdown {
    min-width: 175px;
    padding: 5px !important;
    border: 1px solid var(--app-border) !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .12) !important;
}

.action-dropdown .dropdown-item {
    border-radius: 6px;
    font-size: 12px;
    padding: 8px 10px;
}

.action-dropdown .dropdown-item:hover {
    background: #f8fafc;
}

.action-icon {
    display: inline-block;
    width: 22px;
    text-align: center;
    margin-right: 5px;
}

.client-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.client-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--app-primary-soft);
    color: var(--app-primary);
    font-size: 12px;
    font-weight: 700;
    flex: 0 0 32px;
}

.client-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.client-info strong {
    color: #1f2937;
    font-size: 13px;
    font-weight: 600;
}

.client-info small {
    color: #9ca3af;
    font-size: 11px;
}

.credit-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 6px;
    background: #eff6ff;
    color: #2563eb;
    font-size: 11px;
    font-weight: 700;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-active {
    background: #ecfdf3;
    color: #15803d;
}

.status-inactive {
    background: #f3f4f6;
    color: #6b7280;
}

@media (max-width: 700px) {
    .content-card .dt-search input {
        min-width: 180px;
        width: 100%;
        margin-left: 0 !important;
    }

    .content-card .dt-layout-row {
        gap: 10px;
    }
}

/* Toast global SIGDA */
.sigda-toast-popup {
    font-size: 13px !important;
}

.action-icon {
    width: 20px;
    text-align: center;
    font-size: 14px;
    margin-right: 7px;
}

.action-view {
    color: #2563eb;
}

.action-edit {
    color: #f59e0b;
}

.action-danger-icon {
    color: #dc2626;
}

.action-success-icon {
    color: #16a34a;
}

.table-code { font-size: 12px; font-weight: 700; color: #475569; }

/* ============================================================
   COLORES DE ICONOS DEL MENÚ SIGDA
   ============================================================ */

.sidebar-icon {
    width: 24px;
    min-width: 24px;
    text-align: center;
    font-size: 15px;
    transition: transform .15s ease, filter .15s ease;
}

.sidebar-item:hover .sidebar-icon {
    transform: scale(1.08);
    filter: brightness(1.08);
}

.menu-blue { color: #60a5fa; }
.menu-cyan { color: #22d3ee; }
.menu-orange { color: #fb923c; }
.menu-purple { color: #a78bfa; }
.menu-teal { color: #2dd4bf; }
.menu-green { color: #4ade80; }
.menu-indigo { color: #818cf8; }
.menu-amber { color: #fbbf24; }
.menu-sky { color: #38bdf8; }
.menu-pink { color: #f472b6; }
.menu-lime { color: #a3e635; }
.menu-violet { color: #c084fc; }
.menu-slate { color: #94a3b8; }

.sidebar-item.active {
    background: rgba(255, 255, 255, .12);
}

.sidebar-item.active .sidebar-icon {
    filter: brightness(1.1);
}

@media (max-width: 760px) {
    .sidebar-icon {
        font-size: 16px;
    }
}

/* ============================================================
   SELECT2 SIGDA
   ============================================================ */

.select-with-button {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.select-with-button .select2-container {
    flex: 1;
    min-width: 0;
}

.select-add-button {
    width: 42px;
    flex: 0 0 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.select2-container--default .select2-selection--single {
    height: 38px;
    border: 1px solid var(--app-border);
    border-radius: 7px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    font-size: 13px;
    padding-left: 11px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

.select2-dropdown {
    border-color: var(--app-border);
    font-size: 13px;
}

.select2-results__option {
    padding: 8px 10px;
}

.select2-results__option--highlighted {
    background-color: var(--app-primary) !important;
}

.action-pdf {
    color: #dc3545 !important;
}



/* ============================================================
   SUBMENÚS DEL SIDEBAR SIGDA
   ============================================================ */

.sidebar-separator {
    height: 1px;
    margin: 10px 4px;
    background: rgba(255,255,255,.08);
}

.sidebar-group {
    margin-bottom: 4px;
}

.sidebar-group-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: rgba(255,255,255,.88);
    text-align: left;
    cursor: pointer;
}

.sidebar-group-toggle:hover,
.sidebar-group-toggle.active {
    background: var(--app-sidebar-hover);
}

.sidebar-group-main {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.sidebar-group-chevron {
    font-size: 11px;
    opacity: .7;
    transition: transform .18s ease;
}

.sidebar-group.is-open .sidebar-group-chevron {
    transform: rotate(180deg);
}

.sidebar-submenu {
    padding: 4px 0 4px 38px;
}

.sidebar-subitem {
    min-height: 34px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    margin: 2px 0;
    border-radius: 6px;
    color: rgba(255,255,255,.72);
    text-decoration: none;
    font-size: 13px;
}

.sidebar-subitem:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}

.sidebar-subitem.active {
    color: #fff;
    background: rgba(255,255,255,.11);
}

.sidebar-subitem.disabled {
    opacity: .48;
    cursor: not-allowed;
}

.sidebar-subitem small {
    display: block;
    margin-left: 5px;
    font-size: 9px;
    opacity: .75;
}

.sidebar-subitem.disabled .sidebar-label {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}

.sidebar-subitem-dot {
    width: 8px;
    height: 8px;
    min-width: 8px;
    border-radius: 50%;
}

.sidebar-collapsed .sidebar-group-toggle {
    justify-content: center;
}

.sidebar-collapsed .sidebar-group-main {
    justify-content: center;
}

.sidebar-collapsed .sidebar-group-chevron,
.sidebar-collapsed .sidebar-submenu {
    display: none !important;
}

.sidebar-collapsed .sidebar-group-toggle .sidebar-label,
.sidebar-collapsed .sidebar-subitem .sidebar-label {
    display: none;
}

/* Usuario actual en navbar */
.navbar-user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
}

.navbar-user-role {
    margin-top: 3px;
    font-size: 11px;
    color: #64748b;
}

.navbar-logout {
    color: #dc3545;
    text-decoration: none;
}

.navbar-logout:hover {
    color: #b02a37;
}

/* ============================================================
   LOGIN SIGDA
   ============================================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--app-bg);
}

.login-card {
    width: min(420px, 100%);
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 14px;
    padding: 30px;
    box-shadow: 0 12px 35px rgba(15, 23, 42, .08);
}

.login-card h1 {
    margin: 0 0 6px;
    text-align: center;
    font-size: 28px;
    font-weight: 800;
    color: var(--app-text);
}

.login-card > p {
    margin: 0 0 24px;
    text-align: center;
    color: var(--app-muted);
}

.login-card form {
    display: grid;
    gap: 16px;
}

.login-card form > div {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.login-card label {
    font-size: 13px;
    font-weight: 600;
    color: var(--app-text);
}

.login-card input {
    width: 100%;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--app-text);
    outline: none;
}

.login-card input:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.login-card button[type="submit"] {
    width: 100%;
    border: 1px solid var(--app-primary);
    border-radius: 8px;
    padding: 11px 14px;
    background: var(--app-primary);
    color: #fff;
    font-weight: 700;
    margin-top: 4px;
}

.login-card button[type="submit"]:hover {
    filter: brightness(.96);
}

.login-error {
    margin-bottom: 16px;
    padding: 11px 13px;
    border: 1px solid #efb4b4;
    border-radius: 8px;
    background: #ffe8e8;
    color: #b42318;
    font-size: 13px;
}

.btn.btn-success {
    background-color: #198754 !important;
    border-color: #198754 !important;
    color: #ffffff !important;
}

.btn.btn-success:hover,
.btn.btn-success:focus,
.btn.btn-success:active {
    background-color: #157347 !important;
    border-color: #146c43 !important;
    color: #ffffff !important;
}