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

body {
    font-family: 'Inter', 'Montserrat', 'Segoe UI', sans-serif;
    background-color: var(--background);
    background-image:
        radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.06) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.6;
    padding-bottom: 100px;
}

.workspace-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Clinical Header Unified */
.clinical-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0.5rem;
    border-bottom: 2px solid var(--border-light);
    margin-bottom: 0.5rem;
}

.clinical-header h1 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 12px;
}

.clinical-header h1 span {
    color: var(--text-muted);
    font-weight: 400;
}

.header-nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.nav-link-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.25s ease;
    cursor: pointer;
}

.nav-link-btn:hover {
    background: var(--primary-ghost);
    border-color: var(--primary-soft);
    color: var(--primary);
    transform: translateY(-2px);
}

.nav-link-btn.logout {
    color: #ef4444;
    border-color: #fecaca;
}

.nav-link-btn.logout:hover {
    background: #fef2f2;
    border-color: #f87171;
    color: #dc2626;
}



/* Box Navigator - REPLICADO DE APP.PHP (ESTILO LIMPIO) */
.box-navigator {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.75rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    background: var(--surface);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* En móviles permitimos scroll desde el inicio */
@media (max-width: 768px) {
    .box-navigator {
        justify-content: flex-start;
    }
}

.box-navigator::-webkit-scrollbar {
    display: none;
    /* Oculta scrollbar en Chrome/Safari */
}

.box-btn {
    flex: 0 0 45px;
    min-width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.box-btn:hover {
    background: var(--primary-ghost);
    border-color: var(--primary-soft);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.box-btn.active {
    background: var(--primary);
    color: white !important;
    border-color: var(--primary);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
    transform: scale(1.05);
}

.box-navigator::-webkit-scrollbar {
    display: none;
}




/* Balance specific Card Layout */
.balance-card {
    background: var(--surface);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    width: 100%;
}

.balance-card h2 {
    color: #706000;
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Form Groups */
.input-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Disabled state - Solo visual, permitimos interacción para evitar 'bloqueos invisibles' */
.disabled {
    opacity: 0.6;
    filter: grayscale(0.4);
    cursor: not-allowed;
}

.disabled input {
    cursor: not-allowed;
}

.field-group label {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-styled {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface-soft);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: all 0.2s;
}

.input-styled:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-ghost);
}

.input-styled.readonly {
    background: #f8fafc;
    color: var(--text-muted);
    cursor: default;
}

/* Tables */
table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 1rem;
}

th {
    text-align: left;
    padding: 12px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 2px solid var(--border-light);
}

/* Ajuste de columnas para etiquetas largas */
.table__perdidas th:first-child,
.table__perdidas td:first-child,
.table__ingresos th:first-child,
.table__ingresos td:first-child {
    width: 60%;
    font-size: 0.9rem;
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
}

.table__perdidas th:last-child,
.table__perdidas td:last-child,
.table__ingresos th:last-child,
.table__ingresos td:last-child {
    width: 40%;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
}

tr:last-child td {
    border-bottom: none;
}

/* Calculator Icon */
.calculadora-icon {
    margin-left: 8px;
    color: var(--secondary);
    cursor: pointer;
    transition: transform 0.2s;
}

.calculadora-icon:hover {
    transform: scale(1.2);
    color: var(--primary);
}

/* Balance Colors */
.input-balance {
    font-weight: 800;
    text-align: center;
}

/* Buttons */
.btn-balance {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-delete {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.btn-delete:hover {
    background: #fee2e2;
    border-color: #f87171;
    transform: translateY(-2px);
}

/* Estilo para los botones de limpieza al final de las tarjetas */
.balance-card .btn-delete {
    width: 100%;
    margin-top: 1rem;
    justify-content: center;
    /* Centra icono y texto */
    padding: 14px;
    font-size: 0.9rem;
}

/* El Resumen Final debe destacar */
#box-summary {
    background: var(--primary-ghost);
    /* Un tono suave para diferenciarlo */
    border: 2px solid var(--primary-soft);
}

#box-summary label {
    color: var(--primary);
    font-weight: 800;
}

/* Floating Indicator (Modernized) */
#box-indicador-flotante {
    position: fixed;
    bottom: 25px;
    /* Ajustado para estar en la esquina inferior derecha */
    right: 25px;
    background: var(--primary);
    color: white;
    padding: 14px 24px;
    border-radius: 50px;
    font-weight: 800;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid white;
    animation: fadeInSlide 0.4s ease-out;
}

/* Ajuste específico para la fila de datos iniciales */
#box-data .input-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    /* Permite que quepan 2 en una fila en móviles medianos */
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Reducción de tamaño de etiquetas e inputs en el encabezado de datos */
#box-data .field-group label {
    font-size: 0.75rem;
    /* Texto más pequeño y compacto */
    margin-bottom: 0.25rem;
}

#box-data .input-styled {
    padding: 8px 12px;
    /* Menos padding para que sea menos alto */
    font-size: 0.9rem;
}

#selected-box h2 {
    font-size: 1.1rem;
    /* Reducido de 1.4rem */
    margin-bottom: 1rem;
    justify-content: center;
}

#selected-box i {
    font-size: 1rem;
}

@media (max-width: 480px) {

    /* Alineación del botón de borrar para que no cree una fila vacía gigante */
    #box-data .field-group:last-child {
        grid-column: 1 / -1;
        /* Ocupa todo el ancho al final */
        justify-content: center;
    }

    #borrar-datos-principal {
        padding: 8px 16px;
        font-size: 0.8rem;
        width: auto;
        /* No ocupa todo el ancho, solo lo necesario */
        align-self: center;
    }
}

@keyframes fadeInSlide {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive Grid for Balance Tables */
.balance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Calculator UI */
.calculadora-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 2000 !important;
    pointer-events: auto;
    /* El overlay debe capturar el clic para cerrar */
}

.calculadora-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--border-light);
    width: 100%;
    max-width: 340px;
    overflow: hidden;
    z-index: 10000 !important;
    /* Valor extremo para sobrepasar cualquier inline style */
    animation: scaleUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto !important;
}

@keyframes scaleUp {
    from {
        transform: translate(-50%, -40%) scale(0.9);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.calculadora-header {
    background: var(--primary-ghost);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-light);
}

.calculadora-header span {
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    font-size: 0.85rem;
}

.calculadora-cerrar {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.calculadora-display {
    width: calc(100% - 2rem);
    margin: 1rem;
    padding: 1.5rem 1rem;
    background: var(--surface-soft);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    text-align: right;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.calculadora-botones {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 1rem;
    padding-top: 0;
}

.calculadora-btn {
    padding: 14px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-main);
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.calculadora-btn:hover {
    background: var(--surface-soft);
    border-color: var(--border);
}

.calculadora-btn.operador {
    background: var(--primary-ghost);
    color: var(--primary);
    border-color: var(--primary-soft);
}

.calculadora-btn.igual {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    grid-column: span 4;
}

.calculadora-btn.limpiar {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

@media (max-width: 992px) {
    .balance-grid {
        grid-template-columns: 1fr;
        /* Una columna en tablets y móviles */
    }

    .balance-card {
        padding: 1.25rem 0.75rem;
        /* Reduce padding lateral en móvil */
    }

    /* Mejora la lectura de filas de datos */
    .table__perdidas th:first-child,
    .table__ingresos th:first-child {
        width: 70%;
        /* Más espacio para el nombre del concepto */
    }
}

@media (max-width: 768px) {
    body {
        padding: 0.5rem;
        padding-bottom: 90px;
    }

    .clinical-header {
        padding: 0.75rem 0.5rem;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .clinical-header h1 {
        font-size: 1.5rem !important;
        justify-content: center;
    }

    .header-nav {
        width: 100%;
        justify-content: center;
    }

    .balance-card {
        padding: 1rem 0.75rem;
        border-radius: var(--radius-md);
    }

    .balance-card h2 {
        font-size: 1.2rem;
        margin-bottom: 1.25rem;
    }

    .box-navigator {
        margin: 0 -0.5rem 1rem;
        width: calc(100% + 1rem);
        border-radius: 0;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        border-left: none;
        border-right: none;
        padding: 0.75rem 0.5rem;
        justify-content: flex-start;
    }

    .box-btn {
        min-width: 42px;
        height: 42px;
        padding: 5px;
        font-size: 0.9rem;
    }

    .btn-balance {
        min-height: 48px;
        justify-content: center;
    }

    .input-styled {
        font-size: 16px; /* Evita zoom en iOS */
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .workspace-container {
        gap: 1.25rem;
    }

    header.clinical-header h1 {
        font-size: 1.8rem;
    }

    .input-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #box-indicador-flotante {
        display: none !important;
    }

    .table__perdidas th:first-child,
    .table__perdidas td:first-child,
    .table__ingresos th:first-child,
    .table__ingresos td:first-child {
        font-size: 0.8rem;
    }

    .input-styled {
        padding: 12px;
        font-size: 16px;
        /* Evita zoom */
    }
}