:root {
    --bg: #f4f4f9;
    --text: #1f2937;
    --card-bg: #ffffff;
    --muted: #6b7280;
    --border: #d9dde5;
    --input-bg: #ffffff;
    --sidebar-bg: #333333;
    --sidebar-text: #ffffff;
    --tab-hover: #e9ecef;
    --row-hover: #f1f1f1;
    --hint-bg: #eef4ff;
    --hint-border: #cddfff;
    --content-max-width: 1760px;
    --btn-std-width: 190px;
    --btn-std-height: 40px;
}

html.theme-dark,
body.theme-dark {
    --bg: #0f172a;
    --text: #e5e7eb;
    --card-bg: #111827;
    --muted: #94a3b8;
    --border: #334155;
    --input-bg: #0b1220;
    --sidebar-bg: #020617;
    --sidebar-text: #e5e7eb;
    --tab-hover: #1f2937;
    --row-hover: #172133;
    --hint-bg: #0b2545;
    --hint-border: #1d4f91;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
}

body.boot-loading {
    overflow: hidden;
}

body.boot-loading > *:not(.boot-loader) {
    visibility: hidden;
}

.boot-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(244, 244, 249, 0.97);
    transition: opacity 0.22s ease;
}

html.theme-dark .boot-loader,
body.theme-dark .boot-loader {
    background: rgba(15, 23, 42, 0.96);
}

html.theme-dark img[src*="simple-icons"],
body.theme-dark img[src*="simple-icons"] {
    filter: invert(1) brightness(1.2);
}

html.theme-dark #grace-accept-modal > div,
body.theme-dark #grace-accept-modal > div {
    background: #0f172a !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}

html.theme-dark #grace-accept-modal h2,
body.theme-dark #grace-accept-modal h2 {
    color: #f8fafc !important;
}

html.theme-dark #grace-accept-text,
body.theme-dark #grace-accept-text {
    color: #cbd5e1 !important;
}

body.boot-ready .boot-loader {
    opacity: 0;
    pointer-events: none;
}

.boot-loader-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
}

.boot-loader-card p {
    margin: 0;
    color: var(--text);
    font-weight: 600;
}

.boot-loader-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0, 123, 255, 0.2);
    border-top-color: #007bff;
    border-radius: 50%;
    animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin {
    to {
        transform: rotate(360deg);
    }
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

header h1 {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.2;
}

.app-brand-logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    flex: 0 0 auto;
}

.header-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-controls .notifications-bell {
    margin-right: 0;
    display: flex;
    align-items: center;
}

.header-user-menu {
    position: relative;
    margin-left: 2px;
}

.header-user-btn {
    width: auto;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-weight: 600;
}

.header-user-btn:hover {
    background: var(--tab-hover);
}

.header-user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
    padding: 6px;
    display: none;
    z-index: 1200;
}

.header-user-dropdown.open {
    display: block;
}

.header-user-dropdown button {
    width: 100%;
    margin: 0;
    text-align: left;
}

.btn-theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.btn-theme-toggle:hover {
    background: var(--tab-hover);
}

.password-field-wrap {
    position: relative;
    display: block;
    width: 100%;
}

.password-field-wrap input {
    width: 100%;
    box-sizing: border-box;
    padding-right: 52px;
}

.password-field-wrap .password-toggle-btn {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    min-width: 30px;
    margin: 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 0;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.password-field-wrap .password-toggle-btn:hover {
    color: var(--text);
    background: var(--tab-hover);
}

.password-field-wrap .password-toggle-btn:focus-visible {
    outline: none;
    color: var(--text);
    border-color: var(--border);
    background: var(--tab-hover);
}

.password-field-wrap .password-toggle-btn svg {
    width: 18px;
    height: 18px;
    display: block;
    fill: currentColor;
}

.password-field-wrap input::-ms-reveal {
    display: none;
}

/* sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 100vh;
    height: 100dvh;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    transition: width 0.3s, transform 0.3s ease;
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.sidebar.collapsed {
    width: 64px;
}
.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 48px 0 0 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-height: 0;
    padding-bottom: 12px;
    overscroll-behavior: contain;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar,
.sidebar ul::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}
.sidebar li {
    padding: 15px;
}
.sidebar li a {
    color: var(--sidebar-text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    border-radius: 6px;
    padding: 8px 10px;
}
.sidebar li .menu-btn {
    color: var(--sidebar-text);
    background: transparent;
    border: none;
    appearance: none;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    border-radius: 6px;
    padding: 8px 10px;
    width: 100%;
    cursor: pointer;
    font: inherit;
    text-align: left;
}
.sidebar li .menu-btn:hover,
.sidebar li a:hover {
    background: rgba(255, 255, 255, 0.12);
}
.sidebar li .menu-btn:focus,
.sidebar li .menu-btn:active {
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}
.menu-icon {
    min-width: 20px;
    text-align: center;
}
.menu-label {
    display: inline-block;
}
.sidebar li a.menu-link-active {
    background-color: #0d6efd;
    border-radius: 4px;
}
.sidebar.collapsed .menu-label {
    display: none;
}
#toggle-btn {
    position: relative;
    top: 0;
    right: 0;
    background: var(--sidebar-bg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--sidebar-text);
    font-size: 20px;
    cursor: pointer;
    width: calc(100% - 20px);
    height: 36px;
    margin: 10px;
    border-radius: 6px;
    z-index: 1100;
}

#mobile-toggle-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    width: 42px;
    height: 42px;
    margin: 0;
    padding: 0;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 1301;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.main-content {
    margin-left: 220px;
    transition: margin-left 0.3s;
    padding: 12px 14px;
}
.main-content.collapsed {
    margin-left: 64px;
}

.container {
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
}

h1 { text-align: center; color: var(--text); margin: 0; }

.card {
    background: var(--card-bg);
    color: var(--text);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    overflow: hidden;
}

.form-group { margin-bottom: 15px; }
.branding-logo-preview-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.branding-logo-preview {
    width: 92px;
    height: 92px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.filters-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.filters-row > input,
.filters-row > select,
.filters-row > button {
    flex: 1;
    min-width: 150px;
}
.filters-row > datalist {
    display: none;
}

.cuadre-filters-row {
    align-items: flex-end;
}
.cuadre-filters-row .cuadre-field {
    flex: 1 1 180px;
    min-width: 180px;
}
.cuadre-filters-row .cuadre-actions {
    flex: 0 0 auto;
    min-width: 140px;
}
.cuadre-filters-row .cuadre-actions .btn-save {
    width: auto;
    min-width: 140px;
    margin-top: 0;
}

label { display: block; margin-bottom: 5px; font-weight: bold; }

input, select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    border-radius: 4px;
    box-sizing: border-box; /* Importante para el padding */
}

textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    border-radius: 4px;
    box-sizing: border-box;
}

.btn-save {
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-size: 16px;
}

.btn-save:hover { background-color: #218838; }

.btn-save, .btn-cancel {
    margin-top: 8px;
}

table { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 900px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background-color: #007bff; color: white; }
tr:hover { background-color: var(--row-hover); }

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.menu-tree-editor-host {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    min-height: 220px;
    background: var(--card-bg);
}

.menu-tree-root {
    list-style: none;
    padding-left: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.menu-tree-main {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--card-bg);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.menu-tree-main-header {
    display: flex;
    gap: 12px;
    align-items: center;
    min-height: 34px;
}

.menu-tree-meta {
    opacity: 0.75;
    color: var(--muted);
}

.menu-tree-children {
    list-style: none;
    margin: 12px 0 0 0;
    padding-left: 18px;
    display: grid;
    gap: 10px;
}

.menu-tree-child {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    background: var(--tab-hover);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.menu-tree-actions {
    justify-self: end;
    display: grid;
    grid-template-columns: 32px;
    grid-template-rows: 28px 28px;
    gap: 4px;
}

.menu-tree-actions .btn-edit {
    margin-right: 0;
    width: 32px;
    min-width: 32px;
    height: 28px;
    padding: 0;
    line-height: 1;
}

.menu-tree-actions .btn-edit:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.menu-tree-detached {
    border: 1px dashed #f59e0b;
    border-radius: 8px;
    padding: 12px;
    background: var(--tab-hover);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.menu-tree-detached-row {
    display: flex;
    gap: 12px;
    align-items: center;
    min-height: 34px;
}

.menu-tree-label {
    flex: 1 1 auto;
}

.menu-tree-drag-handle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-weight: 700;
    line-height: 1.2;
    cursor: grab;
    user-select: none;
}

.menu-tree-drag-handle-main {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-color: rgba(255, 255, 255, 0.22);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
}

.menu-tree-drag-handle-main:hover {
    filter: brightness(1.08);
}

.menu-tree-drag-handle-sub {
    background: #f59e0b;
    color: #1f2937;
    border-color: #d97706;
    box-shadow: 0 2px 6px rgba(217, 119, 6, 0.25);
}

.menu-tree-drag-handle-sub:hover {
    background: #fbbf24;
}

.menu-tree-drag-handle-main::before,
.menu-tree-drag-handle-sub::before {
    display: inline-block;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
    border-radius: 999px;
    padding: 2px 6px;
}

.menu-tree-drag-handle-main::before {
    content: "MENU";
    background: rgba(255, 255, 255, 0.2);
    color: var(--sidebar-text);
}

.menu-tree-drag-handle-sub::before {
    content: "SUB";
    background: rgba(31, 41, 55, 0.16);
    color: #1f2937;
}

.menu-tree-dragging .menu-tree-drag-handle,
.menu-tree-drag-handle:active {
    cursor: grabbing;
}

.menu-tree-dragging {
    opacity: 0.6;
}

.menu-tree-drop-before {
    box-shadow: inset 0 3px 0 #22c55e;
    transform: translateY(4px);
}

.menu-tree-drop-after {
    box-shadow: inset 0 -3px 0 #22c55e;
    transform: translateY(-4px);
}

.menu-tree-drop-placeholder {
    list-style: none;
    border: 2px dashed #22c55e;
    border-radius: 8px;
    background: var(--tab-hover);
    margin: 8px 0;
}

.table-wrap-sm {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 12px;
}

.btn-pay {
    background-color: #007bff;
    color: white;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.btn-pay:hover { background-color: #0069d9; }

.btn-logout {
    background-color: #dc3545;
    color: white;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.btn-logout:hover { background-color: #c82333; }

.btn-edit, .btn-delete {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: white;
    margin-right: 5px;
}
.btn-edit { background-color: #1f6feb; }
.btn-edit:hover { background-color: #1558b0; }
.btn-delete { background-color: #dc3545; }
.btn-delete:hover { background-color: #c82333; }

.btn-cancel {
    background-color: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-size: 16px;
    margin-top: 10px;
}
.btn-cancel:hover { background-color: #5a6268; }

#form-plan #btn-delete-plan {
    display: block !important;
    width: 100% !important;
    margin-top: 8px;
    margin-right: 0 !important;
}

#form-branding #btn-reset-branding,
#form-branding #btn-reset-db-total {
    display: block;
    width: 100%;
    margin-top: 8px;
    margin-right: 0;
}

#form-branding .branding-danger-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

#form-branding .branding-danger-actions #btn-reset-branding,
#form-branding .branding-danger-actions #btn-reset-db-total {
    width: 100%;
    margin-top: 0;
}

/* Estandar global de dimensiones para botones principales. */
.btn-save,
.btn-cancel,
.btn-edit,
.btn-delete,
.btn-pay,
.btn-logout {
    min-width: var(--btn-std-width);
    min-height: var(--btn-std-height);
    height: var(--btn-std-height);
    padding: 0 12px;
    font-size: 16px;
    line-height: 1;
    box-sizing: border-box;
}

/* Estilos para el Sub-menú de pestañas */
.sub-menu {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
}

.tab-btn {
    background: none;
    border: none;
    font-size: 16px;
    padding: 10px 20px;
    cursor: pointer;
    color: var(--muted);
    font-weight: bold;
    border-radius: 4px;
}

.tab-btn:hover { background-color: var(--tab-hover); }

.tab-btn.active {
    background-color: #007bff;
    color: white;
}

.card-acceso {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
}

.form-acceso-main {
    display: grid;
    gap: 12px;
}

.form-acceso-main #acceso-busqueda {
    min-height: 56px;
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.4px;
}

.form-acceso-main .btn-save {
    min-height: 52px;
    font-size: 22px;
    font-weight: 700;
}

.resultado-acceso {
    margin-top: 18px;
    min-height: 200px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg);
    padding: 16px 18px;
    font-size: 24px;
    line-height: 1.35;
}

.resultado-acceso p {
    margin: 0 0 8px 0;
}

.hidden {
    display: none !important;
}
.hint-box {
    background: var(--hint-bg);
    border: 1px solid var(--hint-border);
    border-radius: 6px;
    padding: 10px;
    margin-top: 10px;
}

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(2, 6, 23, 0.66);
}

.app-modal-card {
    width: min(560px, 100%);
    max-height: 86vh;
    overflow: hidden;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.35);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    padding: 14px;
}

.app-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.app-modal-head h3 {
    margin: 0;
    font-size: 18px;
}

.app-modal-close {
    width: auto;
    margin-top: 0;
    padding: 8px 12px;
    font-size: 14px;
}

.app-modal-user-list {
    margin-top: 0;
    max-height: 50vh;
    overflow: auto;
    padding: 8px 10px;
}

/* Modal de servicios: mantener scroll sin mostrar barra vertical */
#service-detail-modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

#service-detail-modal-body::-webkit-scrollbar {
    width: 0;
    height: 0;
}

#service-detail-modal .app-modal-card {
    max-height: min(94vh, 980px);
}

#service-detail-modal .app-modal-user-list {
    max-height: 84vh;
    padding: 8px 6px 12px;
    background: var(--bg);
    border-radius: 8px;
}

#service-detail-modal-body > .card {
    margin-bottom: 0;
    border: 1px solid var(--border);
    box-shadow: none;
}

.sp-detail-header {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
        "photo"
        "name"
        "redes"
        "desc";
    gap: 14px;
    align-items: center;
    justify-items: center;
}

.sp-detail-photo-wrap {
    grid-area: photo;
    display: flex;
    justify-content: center;
}

.sp-detail-photo {
    width: 96px;
    height: 96px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.sp-detail-redes {
    grid-area: redes;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
}

.sp-detail-red-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--border);
    text-decoration: none;
}

.sp-detail-name {
    margin: 0 0 4px 0;
}

.sp-detail-name-wrap {
    grid-area: name;
    min-width: 0;
    text-align: center;
    width: 100%;
}

.sp-detail-description {
    grid-area: desc;
    margin-top: 8px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.sp-detail-services-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    align-items: start;
}

.sp-detail-service-card {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    margin-bottom: 2px;
}

.app-modal-actions {
    gap: 8px;
    margin-top: 0;
}

.app-modal-actions .btn-edit,
.app-modal-actions .btn-cancel,
.app-modal-actions .btn-save {
    width: auto;
    margin-top: 0;
}

/* Ajustes de alineacion para botones/filas en el modal de perfil */
#self-profile-modal .btn-edit,
#self-profile-modal .btn-cancel,
#self-profile-modal .btn-save {
    min-width: 0;
    width: auto;
    height: 36px;
    min-height: 36px;
    margin-top: 0;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#self-profile-modal .sp-profile-photo-actions,
#self-profile-modal .sp-serv-photo-actions,
#self-profile-modal .app-modal-actions {
    align-items: center;
}

#self-profile-modal .sp-red-row {
    grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr) auto !important;
}

#self-profile-modal .sp-serv-head {
    grid-template-columns: minmax(0, 1fr) auto !important;
}

#self-profile-modal .sp-serv-media {
    grid-template-columns: 110px minmax(0, 1fr) !important;
}

@media (max-width: 768px) {
    #self-profile-modal .sp-red-row {
        grid-template-columns: 30px minmax(0, 1fr) !important;
    }
    #self-profile-modal .sp-red-url {
        grid-column: 1 / -1;
    }
    #self-profile-modal .sp-red-remove {
        grid-column: 1 / -1;
        justify-self: start;
    }
    #self-profile-modal .sp-serv-media {
        grid-template-columns: 1fr !important;
    }
    #self-profile-modal .sp-serv-photo-actions,
    .serv-photo-actions {
        grid-template-columns: 1fr !important;
    }

    #service-detail-modal {
        padding: 0;
        align-items: flex-end;
    }

    #service-detail-modal .app-modal-card {
        width: 100vw !important;
        max-height: 96dvh;
        border-radius: 16px 16px 0 0;
        padding: 12px;
    }

    #service-detail-modal .app-modal-user-list {
        max-height: 78dvh;
        padding: 8px 6px 16px;
    }

    .sp-detail-header {
        grid-template-columns: 1fr;
        grid-template-areas:
            "photo"
            "name"
            "redes"
            "desc";
        gap: 10px;
    }

    .sp-detail-redes {
        justify-content: center;
        max-width: 100%;
    }

    .sp-detail-services-grid {
        grid-template-columns: 1fr;
    }
}

#btn-cuadre-select-all,
#btn-cuadre-clear-all,
#btn-print-cuadre-all,
#btn-print-cuadre-none {
    width: 190px;
    min-width: 190px;
    max-width: 190px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 0 12px;
    margin-top: 0;
    margin-right: 0;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 190px;
    text-align: center;
}

#btn-open-cuadre-user-modal,
#btn-open-cuadre-print-modal {
    width: 100%;
    margin-top: 0;
    margin-right: 0;
    padding: 10px;
    min-height: 42px;
    font-size: 16px;
    box-sizing: border-box;
}

body.modal-open {
    overflow: hidden;
}

.option-check-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 6px 4px;
    margin: 0;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.08);
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.option-check-row + .option-check-row {
    margin-top: 4px;
}

.option-check-row span {
    flex: 1 1 auto;
}

.option-check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    margin: 0;
    padding: 0;
    flex: 0 0 18px;
    accent-color: #16a34a;
}

.option-check-row:hover {
    border-color: rgba(22, 163, 74, 0.45);
}

.option-check-row:has(input[type="checkbox"]:checked) {
    border-color: rgba(22, 163, 74, 0.85);
    background: rgba(22, 163, 74, 0.14);
    box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.25);
}

html.theme-dark .option-check-row,
body.theme-dark .option-check-row {
    border-color: rgba(100, 116, 139, 0.45);
    background: rgba(51, 65, 85, 0.35);
}

html.theme-dark .option-check-row:has(input[type="checkbox"]:checked),
body.theme-dark .option-check-row:has(input[type="checkbox"]:checked) {
    border-color: rgba(34, 197, 94, 0.9);
    background: rgba(22, 163, 74, 0.24);
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.3);
}

.perm-tree {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
    margin-top: 8px;
    align-items: start;
}
.perm-area {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card-bg);
    overflow: hidden;
}
.perm-area-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: var(--tab-hover);
    border-bottom: 1px solid var(--border);
}
.perm-parent {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    margin: 0;
}
.perm-toggle {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    width: 30px;
    height: 28px;
    cursor: pointer;
    line-height: 1;
    font-size: 14px;
}
.perm-toggle:hover {
    background: var(--tab-hover);
}
.perm-children {
    padding: 8px 12px 12px 32px;
    display: grid;
    gap: 6px;
}
.perm-area.collapsed .perm-children {
    display: none;
}
.perm-child {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    margin: 0;
}
.perm-parent input[type="checkbox"],
.perm-child input[type="checkbox"] {
    width: auto;
}

.activity-log {
    display: grid;
    gap: 10px;
    color: var(--text);
}
#activity-log-container {
    color: var(--text);
    background: transparent;
}
.activity-item {
    display: grid;
    grid-template-columns: 32px 90px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
}
.activity-icon {
    font-size: 18px;
    text-align: center;
}
.activity-time {
    color: var(--muted);
    font-weight: 600;
}
.activity-desc {
    color: var(--text);
}
.empty-state {
    color: var(--muted);
    margin: 8px 0 0;
}
html.theme-dark .activity-item,
body.theme-dark .activity-item {
    background: #0b1220;
    border-color: #334155;
}
html.theme-dark .activity-time,
body.theme-dark .activity-time {
    color: #93c5fd;
}
html.theme-dark #activity-log-container,
body.theme-dark #activity-log-container {
    color: #e5e7eb;
}
html.theme-dark .activity-desc,
html.theme-dark .empty-state,
body.theme-dark .activity-desc,
body.theme-dark .empty-state {
    color: #cbd5e1;
}

.muted {
    color: var(--muted);
}

.dashboard-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.dashboard-quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* En el topbar del dashboard, los botones no deben ocupar todo el ancho */
.dashboard-quick-actions .btn-save,
.dashboard-quick-actions .btn-cancel,
.dashboard-quick-actions .btn-edit {
    width: auto;
    margin-top: 0;
}

.dashboard-main-widget {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 10px;
    min-height: 0;
}

.dashboard-main-widget-head {
    display: grid;
    gap: 4px;
}

.dashboard-main-widget-title {
    margin: 0;
}

.dashboard-main-widget-time {
    margin: 0;
}

.dashboard-main-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-content: start;
    min-height: 0;
}

.dashboard-main-actions .btn-save,
.dashboard-main-actions .btn-cancel,
.dashboard-main-actions .btn-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 var(--btn-std-width);
    width: var(--btn-std-width);
    max-width: var(--btn-std-width);
    box-sizing: border-box;
    margin: 0;
    min-width: var(--btn-std-width);
    min-height: var(--btn-std-height);
    height: auto;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
    overflow-wrap: anywhere;
}

.dashboard-main-actions #btn-dashboard-refresh,
.dashboard-main-actions a[href="pagos.html"],
.dashboard-main-actions a[href="actividad.html"] {
    flex-basis: 100%;
    width: 100%;
    min-width: 0;
}

.dashboard-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    align-content: stretch;
    gap: 12px;
    margin-bottom: 0;
    height: 100%;
    min-height: 0;
}

#dashboard-widgets {
    --dashboard-columns: 12;
    display: grid;
    grid-template-columns: repeat(var(--dashboard-columns), minmax(0, 1fr));
    grid-auto-rows: 56px;
    grid-auto-flow: row dense;
    align-items: stretch;
    gap: 12px;
}

#dashboard-widgets > [data-widget] {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

#dashboard-widgets > [data-widget] > .card {
    margin-bottom: 0;
    height: 100%;
    overflow: auto;
}
body.dashboard-designer-preview-mode #dashboard-widgets > [data-widget]:not([data-widget="kpis"]) > .card {
    border: 2px dashed #60a5fa;
}
html.theme-dark body.dashboard-designer-preview-mode #dashboard-widgets > [data-widget]:not([data-widget="kpis"]) > .card,
body.theme-dark.dashboard-designer-preview-mode #dashboard-widgets > [data-widget]:not([data-widget="kpis"]) > .card {
    border-color: #3b82f6;
}

.dashboard-kpi {
    margin: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    overflow: hidden;
}

.dashboard-kpi span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.dashboard-kpi strong {
    font-size: 24px;
}

.dashboard-kpi small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.dashboard-main-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.dashboard-button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--btn-std-width), 100%), 1fr));
    gap: 8px;
}

.dashboard-button-grid a,
.dashboard-button-grid button {
    display: block;
    box-sizing: border-box;
    text-align: center;
    margin-top: 0;
    width: 100%;
    min-width: 0;
    min-height: var(--btn-std-height);
    height: auto;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
}

.dashboard-list {
    display: grid;
    gap: 6px;
}

.dashboard-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    font-size: 13px;
    overflow-wrap: anywhere;
}

#tabla-vencer-hoy .dashboard-row,
#tabla-vencer-manana .dashboard-row,
#tabla-vencidos .dashboard-row {
    grid-template-columns: 80px 2fr 1.4fr 1fr;
}

#dashboard-actividad .dashboard-row {
    grid-template-columns: 1.5fr 1fr 2fr;
}

.dashboard-alerts {
    display: grid;
    gap: 8px;
}
.dashboard-alert-item {
    width: 100%;
}
.dashboard-alert-item .dash-badge {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.dash-badge {
    display: inline-block;
    padding: 8px 10px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.35;
    border: 1px solid transparent;
}

.dash-badge-warning {
    background: #fff4db;
    border-color: #f7c46c;
    color: #5f3b00;
}

.dash-badge-info {
    background: #e7f2ff;
    border-color: #9cc5ff;
    color: #07357f;
}

.dash-badge-error {
    background: #ffe6e6;
    border-color: #f2aaaa;
    color: #7f1111;
}

html.theme-dark .dash-badge-warning,
body.theme-dark .dash-badge-warning {
    background: #3f3111;
    border-color: #8d6c2e;
    color: #ffd98a;
}

html.theme-dark .dash-badge-info,
body.theme-dark .dash-badge-info {
    background: #0e2545;
    border-color: #275a9d;
    color: #bfdbfe;
}

html.theme-dark .dash-badge-error,
body.theme-dark .dash-badge-error {
    background: #3f1c24;
    border-color: #7f3342;
    color: #fecaca;
}

.mini-bars {
    display: grid;
    gap: 6px;
}

.mini-bar-row {
    display: grid;
    grid-template-columns: 48px 1fr 70px;
    align-items: center;
    gap: 8px;
}

.mini-bar-track {
    height: 8px;
    border-radius: 99px;
    background: #dbe4ef;
    overflow: hidden;
}

.mini-bar-fill {
    height: 100%;
    background: #0d6efd;
    border-radius: 99px;
}

html.theme-dark .mini-bar-track,
body.theme-dark .mini-bar-track {
    background: #1f2b3f;
}

.ui-presenter-cards {
    display: none;
    gap: 10px;
    margin-top: 10px;
}

.ui-presenter-card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px;
    background: #ffffff;
}

.ui-presenter-title {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #0f172a;
}

.ui-presenter-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.ui-presenter-label {
    color: #475569;
    font-size: 12px;
}

.ui-presenter-value {
    font-weight: 600;
    color: #0f172a;
    text-align: right;
}

.ui-presenter-toggle {
    margin-top: 6px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}

.ui-presenter-cards.is-disabled {
    display: none !important;
}

.ui-presenter-row-clickable td {
    cursor: pointer;
}

.ui-presenter-modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.62);
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
}

.ui-presenter-modal.hidden {
    display: none;
}

.ui-presenter-modal-card {
    width: 100%;
    max-width: 460px;
    max-height: 86vh;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ui-presenter-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
}

.ui-presenter-modal-head h3 {
    margin: 0;
    font-size: 15px;
    color: #0f172a;
}

.ui-presenter-modal-head button {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #0f172a;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
}

.ui-presenter-modal-body {
    padding: 10px 12px;
    overflow: auto;
}

.ui-presenter-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.ui-presenter-modal-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 8px 0;
    border-bottom: 1px dashed #e2e8f0;
}

.ui-presenter-modal-label {
    color: #475569;
    font-size: 12px;
}

.ui-presenter-modal-value {
    color: #0f172a;
    font-weight: 700;
    font-size: 13px;
}

@media (max-height: 820px) {
    .sidebar {
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
    }

    .sidebar ul {
        margin-top: 48px;
        max-height: none;
        height: calc(100dvh - 56px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 900px) {
    body {
        padding: 0;
    }

    .sidebar {
        width: 240px;
        transform: translateX(-100%);
        overflow-x: hidden;
        overflow-y: auto;
        height: 100dvh;
    }

    .sidebar ul {
        max-height: none;
        height: calc(100dvh - 56px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

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

    .sidebar.collapsed {
        width: 64px;
    }

    .sidebar.collapsed.mobile-open {
        width: 64px;
    }

    #toggle-btn {
        display: none;
    }
    #mobile-toggle-btn {
        display: inline-flex;
        position: static;
        top: auto;
        left: auto;
        margin: 0;
        box-shadow: none;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
    }

    .main-content,
    .main-content.collapsed {
        margin-left: 0;
        padding-top: 8px;
    }

    header {
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    header h1 {
        display: block;
        order: 2;
        flex: 1 0 100%;
        width: 100%;
        margin: 0;
        text-align: left;
        font-size: clamp(1rem, 4.6vw, 1.2rem);
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .btn-logout {
        min-width: 0;
        width: auto;
    }

    .header-controls {
        order: 1;
        margin-left: auto;
        width: auto;
        justify-content: flex-end;
        flex-wrap: nowrap;
    }

    .app-brand-logo,
    #mobile-toggle-btn {
        order: 1;
    }

    .container {
        max-width: 100%;
    }

    .card {
        padding: 14px;
        overflow: hidden;
    }

    /* Regla global mobile para tablas:
       - Sin scroll horizontal
       - Ajuste a ancho de pantalla
       - Mostrar solo 4 columnas clave */
    .table-wrap {
        overflow-x: hidden;
    }

    .table-wrap table {
        min-width: 100% !important;
        width: 100%;
        table-layout: fixed;
    }

    .table-wrap table th,
    .table-wrap table td {
        font-size: 11px;
        padding: 7px 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .table-wrap table th:nth-child(n+5),
    .table-wrap table td:nth-child(n+5) {
        width: 0 !important;
        max-width: 0 !important;
        min-width: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        font-size: 0 !important;
        line-height: 0 !important;
        color: transparent !important;
        overflow: hidden !important;
        white-space: nowrap !important;
    }

    th, td {
        padding: 8px;
        font-size: 12px;
    }

    .sub-menu {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        gap: 6px;
        margin-top: 8px;
        padding-bottom: 4px;
    }

    .tab-btn {
        width: auto;
        flex: 0 0 auto;
        min-width: 0;
        white-space: nowrap;
        font-size: 14px;
        padding: 8px 12px;
    }

    .card-acceso {
        max-width: 100%;
    }

    .form-acceso-main #acceso-busqueda {
        min-height: 48px;
        font-size: 22px;
    }

    .form-acceso-main .btn-save {
        min-height: 46px;
        font-size: 18px;
    }

    .resultado-acceso {
        min-height: 150px;
        font-size: 18px;
        padding: 12px;
    }

    .filters-row {
        flex-direction: column;
        align-items: stretch;
    }
    .cuadre-filters-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        align-items: end;
    }
    .cuadre-filters-row .cuadre-field {
        min-width: 0;
        width: 100%;
    }
    .cuadre-filters-row .cuadre-actions {
        grid-column: 1 / -1;
    }
    .header-user-btn {
        font-size: 12px;
        padding: 7px 8px;
    }
    .cuadre-filters-row .cuadre-actions,
    .cuadre-filters-row .cuadre-actions .btn-save {
        width: 100%;
        min-width: 0;
    }

    .perm-tree {
        grid-template-columns: 1fr;
    }

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

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

    #dashboard-widgets {
        grid-template-columns: 1fr !important;
        grid-auto-rows: auto;
    }

    #dashboard-widgets > [data-widget] {
        overflow: visible;
    }

    #dashboard-widgets > [data-widget] > .card {
        height: auto;
        max-height: none;
        overflow: visible;
    }

    body.page-servicios .main-content {
        padding-top: 8px;
    }

    body.page-servicios header {
        align-items: center;
        gap: 8px;
    }

    body.page-servicios .header-controls {
        width: auto;
        margin-left: auto;
        gap: 6px;
    }

    body.page-servicios .app-brand-logo {
        width: 34px;
        height: 34px;
    }

    body.page-servicios #mobile-toggle-btn {
        width: 36px;
        height: 36px;
    }

    .dashboard-row,
    #tabla-vencer-hoy .dashboard-row,
    #tabla-vencer-manana .dashboard-row,
    #tabla-vencidos .dashboard-row,
    #dashboard-actividad .dashboard-row {
        grid-template-columns: 1fr;
    }

    body.page-cuadre .table-wrap {
        overflow-x: hidden;
    }

    body.page-cuadre #tabla-cuadre-pagos,
    body.page-cuadre #tabla-cuadre-ventas,
    body.page-cuadre #tabla-cuadre-gastos {
        min-width: 100% !important;
        width: 100%;
        table-layout: fixed;
    }

    body.page-cuadre #tabla-cuadre-pagos th,
    body.page-cuadre #tabla-cuadre-pagos td,
    body.page-cuadre #tabla-cuadre-ventas th,
    body.page-cuadre #tabla-cuadre-ventas td,
    body.page-cuadre #tabla-cuadre-gastos th,
    body.page-cuadre #tabla-cuadre-gastos td {
        font-size: 11px;
        padding: 7px 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ui-presenter-cards {
        display: grid;
    }

    .ui-presenter-mobile-fit {
        min-width: 100% !important;
        width: 100%;
        table-layout: fixed;
    }

    .ui-presenter-mobile-hidden-cell {
        display: none;
    }

    
}



