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

:root {
    --color-primary: #3e9caa;
    --color-accent: #4ab3c1;
    --color-text: #585857;
    --color-text-light: #6a6a6a;
    --color-bg: #f8f9fa;
    --color-white: #ffffff;
    --color-border: #e0e0e0;
    --color-success: #10b981;
    --color-error: #e74c3c;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    -webkit-touch-callout: none;
    touch-action: pan-y;
    position: fixed;
    width: 100%;
    height: 100%;
}

#app {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ============================================
   APP HEADER - Oculto: libera espacio para datos (cabecera verde desactivada)
   ============================================ */
.app-header {
    display: none !important;
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    min-height: 56px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-header-logo {
    height: 36px;
    width: auto;
    filter: brightness(0) invert(1);
    opacity: 0.95;
}

.app-brand-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.05rem;
}

.app-brand-name {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.app-brand-tagline {
    font-size: 0.7rem;
    opacity: 0.9;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    height: 48px;
    width: auto;
}

.app-header h1 {
    font-size: 1.2rem;
}

.app-header p {
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    padding-bottom: 4.5rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    position: relative;
    /* Asegurar que sticky funcione correctamente en móviles */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.pull-refresh-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--color-white);
    z-index: 1000;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-size: 0.9rem;
    color: var(--color-text-light);
    pointer-events: none;
}

.pull-refresh-indicator.visible {
    transform: translateY(0);
}

.pull-refresh-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.screen {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    position: relative;
    min-height: 100%;
    overflow: visible;
}

.screen-login {
    padding: 0;
    justify-content: center;
}

/* Login Screen Styles */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1.5rem;
    background: var(--color-white);
}

.login-logo {
    margin-bottom: 2rem;
    animation: fadeInDown 0.6s ease;
}

.login-logo-img {
    height: 120px;
    width: auto;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

.login-card {
    background: var(--color-white);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    animation: fadeInUp 0.6s ease;
}

.login-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
    text-align: center;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-light);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.login-card .form label {
    margin-bottom: 1rem;
}

.login-card .form label span {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.9rem;
}

.login-card .form input {
    padding: 0.875rem;
    font-size: 1rem;
    border: 2px solid var(--color-border);
    transition: border-color 0.2s ease;
}

.login-card .form input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.btn-login {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    margin-top: 1rem;
    box-shadow: 0 4px 12px rgba(62, 156, 170, 0.3);
}

.btn-login:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(62, 156, 170, 0.3);
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* App Top Bar - Barra de pantalla (título + menú + filtros), compacta */
.app-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 15;
    min-height: 48px;
    padding-top: calc(0.4rem + env(safe-area-inset-top, 0px));
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    gap: 0.5rem;
    flex-shrink: 0;
}

.screen-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
    flex: 1;
    text-align: center;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.icon-btn {
    background: transparent;
    border: none;
    padding: 0.35rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    border-radius: 10px;
    transition: background-color 0.2s ease, color 0.2s ease;
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
}

.icon-btn:hover,
.icon-btn:active {
    background: rgba(62, 156, 170, 0.12);
    color: var(--color-primary);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* Menú hamburguesa: aspecto de botón principal en la barra */
.app-top-bar .icon-btn:first-of-type {
    background: rgba(62, 156, 170, 0.08);
}

.app-top-bar .icon-btn:first-of-type:hover,
.app-top-bar .icon-btn:first-of-type:active {
    background: rgba(62, 156, 170, 0.18);
}

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

.icon-btn.btn-primary:hover,
.icon-btn.btn-primary:active {
    background: var(--color-accent);
}

/* Filter Panel */
.filter-panel {
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem;
    position: sticky;
    top: 48px;
    z-index: 12;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin: 0;
}

.app-top-bar + .filter-panel {
    margin-top: 0;
}

.filter-panel.hidden {
    display: none;
}

.filter-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.search-input {
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    font-size: 0.95rem;
}

.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.autocomplete-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.2s;
}

.autocomplete-item:hover,
.autocomplete-item:focus {
    background: var(--color-bg);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.filter-select {
    flex: 1;
    min-width: 120px;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    font-size: 0.85rem;
    background: var(--color-white);
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
}

.search-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    font-size: 0.875rem;
    position: relative;
    background: var(--color-white);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stats-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-select {
    flex: 1;
    min-width: 120px;
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    font-size: 0.875rem;
    background: var(--color-white);
}

.card {
    background: var(--color-white);
    border-radius: 8px;
    padding: 0.6rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 0.5rem;
}

.card h2,
.card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--color-primary);
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.btn-compact {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

canvas {
    width: 100% !important;
    height: 300px !important;
    max-height: 300px;
    display: block;
}

.card canvas {
    min-height: 300px;
    max-height: 300px;
}

#chartMonthly,
#chartQuarterly,
#chartYearComparison,
#chartByOffice,
#chartByPaymentType {
    height: 300px !important;
    width: 100% !important;
}

.form label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.form input,
.form select,
.form textarea {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s ease;
    text-decoration: none;
}

.btn-compact {
    padding: 0.45rem 0.7rem;
    font-size: 0.85rem;
}

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

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

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

.btn-primary:hover {
    background: #2d8a96;
}

.btn-outline:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.toolbar input[type="search"] {
    flex: 1;
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.list-item {
    padding: 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-white);
}

.list-item h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.list-item p {
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.list-actions {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.table-wrapper {
    background: var(--color-white);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    margin: 0 0 0.5rem 0;
    display: flex;
    flex-direction: column;
    position: relative;
    flex: 1;
    min-height: 0;
}

/* Contenedor con scroll: la cabecera de la tabla queda fija al hacer scroll */
.table-scroll-area {
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 48px - 3.5rem);
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.table-row {
    display: grid;
    grid-template-columns: var(--table-cols, 1fr);
    min-width: var(--table-min-width, 520px);
    align-items: center;
    min-height: 44px;
    position: relative;
}

/* Cabecera de tabla fija al hacer scroll dentro de .table-scroll-area */
.table-header {
    background: #eef1f4;
    font-weight: 700;
    border-bottom: 2px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 4;
    margin: 0;
    flex-shrink: 0;
    order: 1;
    width: 100%;
    display: grid;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* El top se calcula dinámicamente con JavaScript */

.table-body {
    display: flex;
    flex-direction: column;
    order: 2;
    position: relative;
    flex: 1;
    min-height: 0;
    margin-top: 0;
    padding-top: 0;
    margin-top: 0;
    padding-top: 0;
}

.table-body .table-row {
    border-bottom: 1px solid var(--color-border);
    transition: background-color 0.2s ease;
}

.table-visits-done .table-body .table-row:hover {
    background-color: #f8f9fa;
}

.table-body .table-row:last-child {
    border-bottom: none;
}

.table-cell {
    padding: 0.5rem 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
    min-height: 44px;
}

.table-header .table-cell {
    align-items: center;
    justify-content: flex-start;
    min-height: 44px;
}

/* Primera columna fija al hacer scroll horizontal */
.table-cell.sticky {
    position: sticky;
    left: 0;
    background: var(--color-white);
    z-index: 2;
    border-right: 1px solid var(--color-border);
    min-width: 120px;
    max-width: 200px;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.04);
}

.table-header .table-cell.sticky {
    background: #eef1f4;
    z-index: 5;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.table-empty {
    padding: 1rem;
    text-align: center;
    color: var(--color-text-light);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-error);
    flex-shrink: 0;
}

.status-ok {
    background: var(--color-success);
}

.status-alert {
    background: var(--color-error);
}

.status-warning {
    background: #f59e0b;
}

.status-error {
    background: var(--color-error);
}

.status-muted {
    background: #6b7280;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge.status-ok {
    background: var(--color-success);
}

.badge.status-warning {
    background: #f59e0b;
}

.badge.status-error {
    background: var(--color-error);
}

.badge.status-muted {
    background: #6b7280;
}

.cell-primary {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.cell-subtitle {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.table-visits {
    --table-cols: 160px 130px 110px;
    --table-min-width: 400px;
}

.table-visits .table-body .table-row:hover {
    background-color: #f8f9fa;
}

.table-visits-done {
    --table-cols: 150px 120px 100px 90px 100px 110px;
    --table-min-width: 670px;
}

.table-patients {
    --table-cols: 180px 130px 100px;
    --table-min-width: 410px;
}

/* Ocultar cualquier columna Email en la tabla de pacientes */
.table-patients .table-header .table-cell:nth-child(2):contains("Email"),
.table-patients .table-header .table-cell:nth-child(2)[data-label="Email"] {
    display: none !important;
}

.table-expenses {
    --table-cols: 72px 88px 145px 105px 90px 98px;
    --table-min-width: 598px;
}

/* Columna Estado compacta: icono + texto corto */
.table-expenses .table-cell.sticky {
    min-width: 0;
    width: 72px;
    max-width: 72px;
}

.expense-estado-cell {
    padding: 0.25rem 0.35rem;
}

.expense-estado-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
}

.expense-estado-badge .estado-icon {
    flex-shrink: 0;
}

.expense-estado-badge .expense-estado-label {
    line-height: 1;
}

.expense-estado-badge.status-ok {
    background: var(--color-success);
}

.expense-estado-badge.status-warning {
    background: #d97706;
}

.expense-estado-badge.status-error {
    background: var(--color-error);
}

.expense-estado-badge.status-muted {
    background: #6b7280;
}

.table-expenses .table-body .table-row:hover {
    background-color: #f8f9fa;
}

.pagination {
    background: var(--color-white);
    border-top: 1px solid var(--color-border);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
}

.stat-card {
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-white);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--color-text-light);
    margin-bottom: 0.25rem;
}

.stat-card strong {
    font-size: 1.1rem;
    color: var(--color-primary);
}

.message {
    padding: 0.75rem;
    border-radius: 8px;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.message.error {
    background: #fee2e2;
    color: #b91c1c;
}

.message.success {
    background: #d1fae5;
    color: #065f46;
}

.app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--color-white);
    border-top: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 0.4rem 0.5rem;
    gap: 0.25rem;
    z-index: 10;
}

.app-nav button {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem 0.25rem;
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.app-nav button.active {
    color: var(--color-primary);
    font-weight: 700;
}

/* ============================================
   Menú hamburguesa (modal)
   ============================================ */
.menu-modal-header {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    margin-top: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.menu-modal-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: -0.02em;
}

.menu-modal-user {
    font-size: 0.8rem;
    color: var(--color-text-light);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-nav,
.menu-actions {
    margin-bottom: 1rem;
}

.menu-nav:last-child,
.menu-actions:last-child {
    margin-bottom: 0;
}

.menu-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    display: block;
}

.menu-nav-grid {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.menu-item {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: none;
    background: var(--color-bg);
    font-size: 0.95rem;
    color: var(--color-text);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
    background: rgba(62, 156, 170, 0.12);
    color: var(--color-primary);
}

.menu-item:disabled {
    cursor: default;
    opacity: 0.9;
}

.menu-item-active {
    background: rgba(62, 156, 170, 0.15);
    color: var(--color-primary);
    font-weight: 600;
}

.menu-item-active .menu-icon {
    color: var(--color-primary);
}

.menu-icon {
    flex-shrink: 0;
    color: var(--color-text-light);
}

.menu-item-active .menu-icon {
    color: var(--color-primary);
}

.menu-item-badge {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    background: var(--color-primary);
    color: var(--color-white);
}

.menu-actions .menu-item {
    margin-bottom: 0.35rem;
}

.menu-actions .menu-item:last-child {
    margin-bottom: 0;
}

.menu-item-link {
    text-decoration: none;
}

.menu-item-danger {
    background: rgba(231, 76, 60, 0.08);
    color: #c0392b;
}

.menu-item-danger:hover,
.menu-item-danger:focus-visible {
    background: rgba(231, 76, 60, 0.15);
    color: #a93226;
}

.menu-item-danger .menu-icon {
    color: #c0392b;
}

/* Legacy: keep .menu-list for any other modal content */
.menu-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    z-index: 20;
    overflow-y: auto;
}

.modal-content {
    background: var(--color-white);
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    border-radius: 12px;
    padding: 0.75rem;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
}

@media (max-width: 768px) {
    .modal-content {
        max-height: 90vh;
        padding: 0.6rem;
        border-radius: 8px;
    }
}

.modal-body-wrapper {
    overflow-y: auto;
    flex: 1;
    padding-right: 0.25rem;
}

.modal-body-wrapper::-webkit-scrollbar {
    width: 6px;
}

.modal-body-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.modal-body-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.modal-body-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    border: none;
    background: transparent;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--color-text-light);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 21;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Modal PDF: sin bordes, máximo espacio para el visor */
.modal.modal-pdf .modal-content {
    max-width: 98vw;
    max-height: 98vh;
    padding: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
}

.modal.modal-pdf .modal-body-wrapper {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.modal-pdf-body {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.modal-pdf-iframe {
    flex: 1;
    width: 100%;
    min-height: 60vh;
    border: none;
}

.modal-pdf-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.5rem;
    background: var(--color-white);
    flex-shrink: 0;
}

.modal.modal-pdf .modal-close {
    top: 0.25rem;
    right: 0.25rem;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}

.modal.modal-pdf .modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* Prevenir selección de texto en modo app */
input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
}

/* Ocultar scrollbars pero mantener funcionalidad */
.app-main::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

/* Asegurar que el contenido ocupe toda la altura disponible */
html {
    height: 100%;
    height: -webkit-fill-available;
}

@media (min-width: 900px) {
    .app-main {
        max-width: 900px;
        margin: 0 auto;
    }
}

/* Sticky de cabecera y primera columna activo también en móvil para mejor lectura */

/* Estilos para modo fullscreen */
@media (display-mode: fullscreen) {
    body {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
}

@media (display-mode: standalone) {
    body {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-white);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

.loading-screen p {
    color: var(--color-text-light);
    font-size: 0.95rem;
}

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

/* ============================================
   DASHBOARD / ESTADÍSTICAS AVANZADAS
   ============================================ */

/* KPIs Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.kpi-card {
    background: var(--color-white);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text);
}

.kpi-comparison {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.kpi-comparison.positive {
    color: #16a34a;
}

.kpi-comparison.negative {
    color: #dc2626;
}

.kpi-income { border-left: 4px solid #16a34a; }
.kpi-expenses { border-left: 4px solid #dc2626; }
.kpi-result { border-left: 4px solid #2563eb; }
.kpi-visits { border-left: 4px solid #f59e0b; }

/* Stats Tabs */
.stats-tabs {
    display: flex;
    background: var(--color-bg-light);
    margin: 0 0.75rem 0.75rem;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.stats-tab {
    flex: 1;
    padding: 0.5rem 0.25rem;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s;
}

.stats-tab.active {
    background: var(--color-white);
    color: var(--color-primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Stats Views */
.stats-view {
    padding: 0 0.75rem 0.75rem;
}

.stats-view.hidden {
    display: none;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 0.75rem 0;
}

/* Stats Table */
.stats-table {
    background: var(--color-white);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 0.75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.stats-table-header {
    display: grid;
    grid-template-columns: 1.5fr repeat(3, 1fr);
    background: var(--color-bg-light);
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
}

.stats-table-row {
    display: grid;
    grid-template-columns: 1.5fr repeat(3, 1fr);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
}

.stats-table-row:last-child {
    border-bottom: none;
}

.stats-table-row.total {
    background: var(--color-bg-light);
    font-weight: 600;
}

.stats-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stats-cell.right {
    text-align: right;
}

.stats-cell-label {
    font-size: 0.7rem;
    color: var(--color-text-light);
}

.stats-cell-value {
    font-weight: 500;
}

.stats-cell-comparison {
    font-size: 0.7rem;
}

.stats-cell-comparison.positive { color: #16a34a; }
.stats-cell-comparison.negative { color: #dc2626; }

/* Patient History Modal */
.patient-history-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1rem;
}

.patient-history-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.patient-history-contact {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.patient-history-contact a {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.85rem;
}

.patient-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.patient-stat-card {
    background: var(--color-bg-light);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
}

.patient-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
}

.patient-stat-label {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.patient-info-section {
    margin-bottom: 1rem;
}

.patient-info-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.patient-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.patient-info-item {
    background: var(--color-bg-light);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
}

.patient-info-item.full-width {
    grid-column: span 2;
}

.patient-info-label {
    font-size: 0.7rem;
    color: var(--color-text-light);
}

.patient-info-value {
    font-size: 0.85rem;
    color: var(--color-text);
    font-weight: 500;
}

.patient-visits-list {
    max-height: 300px;
    overflow-y: auto;
}

.patient-visit-item {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
}

.patient-visit-item:last-child {
    border-bottom: none;
}

.visit-status-paid {
    color: #16a34a;
}

.visit-status-pending {
    color: #f59e0b;
}

/* Floating Action Button (FAB) */
.fab {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.fab:active {
    transform: scale(0.95);
}

.fab svg {
    width: 24px;
    height: 24px;
}
