/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 20px 0;
}

header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.user-info {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    color: var(--text-secondary);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 1.5rem;
}

/* Forms */
form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

input[type="text"],
input[type="number"],
select {
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
}

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

.form-group label {
    font-weight: 500;
    color: var(--text-primary);
}

.inline-form {
    flex-direction: row;
    gap: 10px;
}

.inline-form input {
    flex: 1;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--secondary-color);
    color: white;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
}

.btn:hover {
    opacity: 0.9;
}

/* Checkbox Group */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 5px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Lists */
.participants-list,
.expenses-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.participant-item,
.expense-item {
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.expense-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

.expense-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.expense-amount {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
}

.expense-meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Balance Summary */
.balance-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
}

.balance-positive {
    color: var(--success-color);
    font-weight: 600;
}

.balance-negative {
    color: var(--danger-color);
    font-weight: 600;
}

/* Share Link */
.share-link {
    display: flex;
    gap: 10px;
}

.share-link input {
    flex: 1;
    background: var(--background);
}

/* Total */
.total {
    text-align: right;
    font-size: 1.25rem;
    font-weight: 600;
    padding-top: 15px;
    border-top: 2px solid var(--border-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    text-align: center;
    max-width: 600px;
}

.modal-content h2 {
    text-align: center;
    color: var(--primary-color);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

/* Setup Modal Specific */
.participants-setup-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px 0;
}

.participant-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.participant-input-group input {
    flex: 1;
}

.participant-input-group .remove-participant {
    padding: 8px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.participant-input-group .remove-participant:hover {
    opacity: 0.8;
}

/* Loading & Error */
.loading,
.error {
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin-top: 20px;
}

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

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

.hidden {
    display: none !important;
}

/* Help Text */
.help-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Enhanced Balance Summary */
.balance-overview {
    margin-bottom: 30px;
}

.balance-overview h3,
.settlements-section h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: transform 0.2s;
}

.balance-item:hover {
    transform: translateX(5px);
    background: #f1f5f9;
}

.balance-person {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.person-name {
    font-weight: 600;
    color: var(--text-primary);
}

.person-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.balance-positive {
    color: var(--success-color);
    font-weight: 700;
    font-size: 1.1rem;
}

.balance-negative {
    color: var(--danger-color);
    font-weight: 700;
    font-size: 1.1rem;
}

/* Settlements Section */
.settlements-section {
    margin-top: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    color: white;
}

.settlements-section h3 {
    color: white;
    border-bottom-color: rgba(255, 255, 255, 0.3);
    font-size: 1.25rem;
}

#settlements-list {
    margin-top: 15px;
}

.settlement-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s;
}

.settlement-item:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.02);
}

.settlement-flow {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.05rem;
    flex: 1;
}

.settlement-from {
    font-weight: 600;
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.settlement-arrow {
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.8);
}

.settlement-to {
    font-weight: 600;
    padding: 6px 12px;
    background: rgba(16, 185, 129, 0.2);
    border-radius: 6px;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.settlement-amount {
    font-size: 1.3rem;
    font-weight: 700;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    min-width: 100px;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.all-settled {
    text-align: center;
    padding: 30px;
    font-size: 1.2rem;
    background: rgba(16, 185, 129, 0.2);
    border-radius: 10px;
    border: 2px solid rgba(16, 185, 129, 0.3);
}

/* Mobile Responsive for Settlements */
@media (max-width: 600px) {
    .settlement-item {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .settlement-flow {
        flex-direction: column;
        gap: 10px;
    }
    
    .settlement-arrow {
        transform: rotate(90deg);
    }
    
    .settlement-amount {
        width: 100%;
    }
    
    .balance-person {
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }
    
    .person-status::before {
        content: "(";
    }
    
    .person-status::after {
        content: ")";
    }
}

/* Animation for settlement items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.settlement-item {
    animation: slideIn 0.3s ease-out;
}

.settlement-item:nth-child(1) { animation-delay: 0.1s; }
.settlement-item:nth-child(2) { animation-delay: 0.2s; }
.settlement-item:nth-child(3) { animation-delay: 0.3s; }
.settlement-item:nth-child(4) { animation-delay: 0.4s; }
.settlement-item:nth-child(5) { animation-delay: 0.5s; }

/* Expense Item Updates */
.expense-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.expense-info {
    flex: 1;
}

.expense-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Delete Button */
.btn-delete {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: var(--danger-color);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.8;
}

.btn-delete:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Settle Up Button */
.btn-settle {
    padding: 8px 16px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-settle:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.settlement-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Success Message */
.success {
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin-top: 20px;
    background: var(--success-color);
    color: white;
    animation: slideIn 0.3s ease-out;
}

/* Update settlement item for new button layout */
.settlement-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s;
}

.settlement-flow {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.05rem;
    flex: 1;
}

/* Mobile Responsive Updates */
@media (max-width: 600px) {
    .expense-header {
        flex-direction: column;
    }
    
    .expense-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .settlement-item {
        flex-direction: column;
        gap: 15px;
    }
    
    .settlement-actions {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-settle {
        width: 100%;
    }
    
    .settlement-amount {
        width: 100%;
        margin-bottom: 10px;
    }
}

/* Hover effect for expense items to show delete button more prominently */
.expense-item {
    transition: background 0.2s;
}

.expense-item:hover {
    background: #f8fafc;
}

.expense-item .btn-delete {
    opacity: 0.6;
}

.expense-item:hover .btn-delete {
    opacity: 1;
}

/* Settlement recorded animation */
@keyframes settlementSuccess {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(0.95);
        opacity: 0.7;
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.settlement-item.settling {
    animation: settlementSuccess 0.5s ease-out forwards;
}

/* Currency Input Group */
.input-group {
    display: flex;
    align-items: center;
    position: relative;
}

.currency-symbol {
    position: absolute;
    left: 15px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input[type="number"] {
    padding-left: 35px;
    width: 100%;
}

/* Participant Item with Remove Button */
.participant-item {
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-remove-participant {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: none;
    background: var(--danger-color);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: all 0.2s;
}

.btn-remove-participant:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Custom Modal Styles */
.modal-alert {
    max-width: 450px;
    text-align: center;
}

.modal-alert h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.4rem;
}

.modal-alert p {
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 20px;
    white-space: pre-wrap;
    text-align: center;
}

.modal-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 20px;
}

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

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

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

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

/* Modal backdrop animation */
.modal {
    backdrop-filter: blur(5px);
    background: rgba(0, 0, 0, 0.6);
}

.modal.active {
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 2000;
    animation: slideInUp 0.3s ease-out;
    box-shadow: var(--shadow-lg);
}

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

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

.toast.info {
    background: var(--primary-color);
}

@keyframes slideInUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.toast.hiding {
    animation: slideOutDown 0.3s ease-out forwards;
}

@keyframes slideOutDown {
    from {
        transform: translate(-50%, 0);
        opacity: 1;
    }
    to {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
}

/* QR Code Styles */
.qr-container {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 8px;
}

.qr-container #qr-code {
    padding: 15px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
}

/* Button icons styling */
.share-link .btn {
    min-width: 45px;
    font-size: 1.2rem;
    padding: 10px;
}

/* Edit Button Style */
.btn-edit {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: all 0.2s;
    margin-right: 5px;
}

.btn-edit:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Show edit and delete buttons together */
.expense-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* QR Code Modal Styles */
.modal-qr {
    max-width: 400px;
    text-align: center;
}

.modal-qr h2 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

#qr-code-display {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    padding: 20px;
    background: white;
    border-radius: 8px;
}

#qr-code-display img {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    background: white;
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 2rem;
    }
    
    .container {
        padding: 15px;
    }
    
    .card {
        padding: 20px;
    }
    
    .share-link {
        flex-direction: column;
    }
    
    .user-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    
    .participant-input-group {
        flex-direction: column;
    }
    
    .participant-input-group .remove-participant {
        width: 100%;
    }
}