.hidden { display: none !important; }

:root {
    /* Paleta de Colores - Premium Dark */
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #94a3b8;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --success: #22c55e;
    --danger: #ef4444;
    
    --radius-lg: 1.5rem;
    --radius-md: 1rem;
    --radius-sm: 0.5rem;
    
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
}

#main-content {
    flex: 1;
    padding-bottom: 120px; /* Asegura espacio para la barra de navegación en todas las pantallas */
    width: 100%;
}

/* Header */
.main-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-leave {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #f87171;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-leave:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

.btn-logout {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
}

.btn-leave .icon {
    font-size: 1rem;
}

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

.header-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-logo-small {
    height: 32px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.3));
}

.setup-header {
    text-align: center;
    margin-bottom: 2rem;
}

.app-logo-large {
    width: 180px;
    height: auto;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.4));
    animation: fadeInScale 0.8s ease-out;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Cards & Layout */
.view {
    display: none;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.setup-mode-selector {
    display: flex;
    background: rgba(0,0,0,0.4);
    border-radius: var(--radius-md);
    padding: 0.3rem;
    margin-bottom: 2.5rem;
    position: relative;
    z-index: 9999 !important; /* Prioridad máxima */
    pointer-events: auto !important;
}

.mode-tab {
    flex: 1;
    background: transparent;
    border: none;
    padding: 1.2rem 0.5rem;
    color: var(--text-muted);
    font-weight: 700;
    cursor: pointer;
    border-radius: calc(var(--radius-md) - 0.25rem);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.1rem;
    position: relative;
    z-index: 10000 !important;
    pointer-events: auto !important;
    user-select: none;
}

.mode-tab:active {
    transform: scale(0.95);
}

.mode-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

input {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Buttons */
.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 1.25rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

.btn-primary:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.btn-secondary {
    width: 100%;
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.divider {
    text-align: center;
    margin: 1.5rem 0;
    position: relative;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--glass-border);
}

.divider span {
    background: var(--bg-color);
    padding: 0 1rem;
    position: relative;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Navigation */
.main-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: space-around;
    padding: 0.75rem 0.5rem 2rem;
    border-top: 1px solid var(--glass-border);
    z-index: 100;
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.nav-icon {
    font-size: 1.5rem;
}

.nav-label {
    font-size: 0.75rem;
    font-weight: 600;
}

.hidden {
    display: none;
}

/* Resumen / Stats */
.summary-header {
    margin-bottom: 1.5rem;
    text-align: center;
}

.code-badge {
    display: inline-block;
    background: var(--primary);
    padding: 0.25rem 1rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.grid-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    border-radius: var(--radius-md);
}

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

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.friends-list h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

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

.empty-msg {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.875rem;
}

.participant-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    animation: fadeIn 0.3s ease forwards;
}

.p-name {
    font-weight: 600;
    font-size: 1rem;
}

.badge {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
    padding: 0.2rem 0.6rem;
    border-radius: 2rem;
    font-size: 0.7rem;
    font-weight: 700;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.menu-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.btn-icon-small {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.grid-menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.menu-item:active {
    background: var(--primary);
    transform: scale(0.95);
}

.item-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.item-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.item-price {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.last-orders {
    margin-top: 1.5rem;
}

.order-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.9rem;
}

/* Modales */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.modal-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    border-radius: var(--radius-lg);
    animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.participant-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    max-height: 50vh;
    overflow-y: auto;
}

.participant-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s;
}

.participant-btn:active {
    background: var(--primary);
}

.btn-edit-small {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.8rem;
    padding: 0.2rem;
    background: rgba(0,0,0,0.3);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

.participant-btn.selected {
    background: var(--primary) !important;
    border-color: white;
    transform: scale(1.05);
}

.participant-btn.is-me {
    border: 1.5px solid var(--primary);
}

.btn-shared {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    font-weight: 700;
    border: none;
}

.p-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.p-amount {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
}

.detail-list {
    margin: 1.5rem 0;
}

.total-row {
    margin-top: 1rem;
    padding-top: 1rem !important;
    border-top: 2px solid var(--glass-border) !important;
    color: var(--primary);
}

.participant-item.is-left {
    opacity: 0.5;
    filter: grayscale(1);
    background: rgba(0,0,0,0.2);
}

.participant-item.is-left .p-amount {
    color: var(--text-muted);
}

.payer-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

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

.debt-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--glass-border);
}

.change-box {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-md);
    border: 1px dashed var(--primary);
}

.coin-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

.coin-item {
    background: rgba(255,255,255,0.1);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 0.8rem;
}

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

.btn-delete-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-delete-small:hover {
    background: rgba(239, 68, 68, 0.2);
}

.payment-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--glass-border);
}

.p-header {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
}

.p-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.input-payment {
    width: 80px;
    padding: 0.4rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: white;
    text-align: right;
}

.method-btn {
    flex: 1;
    padding: 0.4rem;
    font-size: 0.75rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
}

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

.method-btn.bizum.active {
    background: #00AAAD; /* Color Bizum */
}

.payment-row.is-paid {
    opacity: 0.6;
    background: rgba(34, 197, 94, 0.05);
}


.settle-modes {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    padding: 1rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: white;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.pot-status {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 2rem;
    text-align: center;
}

.pot-item {
    display: flex;
    flex-direction: column;
    padding: 1rem 0.5rem;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm);
}

.pot-item.highlight {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--glass-border);
}

.pot-item .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
}

.pot-item .value {
    font-size: 1.1rem;
    font-weight: bold;
}

#pot-difference-container.status-ok {
    color: #22c55e;
}

#pot-difference-container.status-error {
    color: var(--danger);
}

.contribution-list {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.contribution-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.individual-status-list {
    margin: 1.5rem 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.status-row .name {
    font-weight: bold;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-row .details {
    text-align: right;
    display: flex;
    flex-direction: column;
    min-width: 90px;
}

.status-row .balance {
    font-size: 0.75rem;
    font-weight: bold;
}

.status-row.pending {
    border-left: 4px solid #f59e0b; /* Orange */
}

.status-row.settled {
    border-left: 4px solid #22c55e; /* Green */
    opacity: 0.8;
}

.name-col {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.btn-calc-small {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-calc-small:hover {
    background: var(--primary);
    transform: scale(1.1);
}

.pot-display-large {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(192, 132, 252, 0.2));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.pot-display-large .label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.pot-display-large .value {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    text-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.party-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.history-item.income {
    border-left: 3px solid var(--success);
}

.history-item.expense {
    border-left: 3px solid var(--danger);
}

.history-item.system {
    border-left: none;
    background: transparent;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
    border-bottom: 1px dashed var(--glass-border);
    margin: 1rem 0;
}

.history-item .amount {
    font-weight: 700;
}

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