:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

.app-container { max-width: 600px; margin: 0 auto; padding: 20px; }

/* Headers & Trust Badge */
.app-header { text-align: center; margin-bottom: 30px; }
.app-header h1 { margin: 0; color: var(--primary); font-size: 2.2rem; }
.subtitle { color: var(--text-muted); margin-top: 5px; }

.trust-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), #818cf8); /* Vibrant gradient */
    color: white;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 700;
    margin-top: 15px;
    border: 2px solid #ffffff; /* Crisp white border to separate from gray background */
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    animation: pulseBadge 2.5s infinite ease-in-out;
}
@keyframes pulseBadge {
    0% { transform: scale(1); box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3); }
    50% { transform: scale(1.04); box-shadow: 0 8px 16px rgba(79, 70, 229, 0.4); }
    100% { transform: scale(1); box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3); }
}
.small-header { display: flex; justify-content: space-between; align-items: flex-start; text-align: left; margin-bottom: 20px; }
.small-header h1 { font-size: 1.5rem; }
.quote-box { font-size: 0.85rem; color: var(--text-muted); font-style: italic; margin-top: 5px; }

/* Share Widget */
.share-widget { background: white; padding: 10px; border-radius: 12px; box-shadow: var(--card-shadow); text-align: center; }
.share-text { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 5px; }
.code-box {
    background: var(--bg-color); padding: 5px 10px; border-radius: 6px; font-family: monospace;
    font-size: 1.2rem; letter-spacing: 2px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 8px; color: var(--primary); border: 1px dashed var(--primary);
}

/* Cards & Inputs */
.card { background: var(--card-bg); border-radius: 16px; padding: 25px; margin-bottom: 20px; box-shadow: var(--card-shadow); }
.card h2 { margin-top: 0; font-size: 1.3rem; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }

.input-group { display: flex; gap: 10px; }
.input-group.stacked { flex-direction: column; }
.join-group { display: flex; flex-direction: column; gap: 10px; }

input[type="text"], input[type="number"], input[type="date"], select {
    padding: 12px 15px; border: 1px solid var(--border-color); border-radius: 12px;
    font-size: 1rem; outline: none; transition: border-color 0.2s; background: #f8fafc;
}
input:focus, select:focus { border-color: var(--primary); }

/* Buttons */
button { cursor: pointer; border: none; font-weight: 600; transition: background-color 0.2s, transform 0.1s; border-radius: 12px; }
button:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; padding: 12px 20px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-color); color: var(--text-main); padding: 12px 20px; border: 1px solid var(--border-color); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success { background: var(--success); color: white; padding: 12px 20px; }
.btn-danger { background: var(--danger); color: white; transition: background 0.2s; }
.btn-danger:hover { background: #dc2626; }
.full-width { width: 100%; margin-top: 15px; font-size: 1.1rem; }
.full-width-btn { width: 100%; padding: 12px; border-radius: 12px; display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 1.05rem; }

/* Dividers & Lists */
.divider { text-align: center; margin: 25px 0; position: relative; }
.divider::before { content: ''; position: absolute; left: 0; top: 50%; width: 100%; height: 1px; background: var(--border-color); z-index: 1; }
.divider span { background: var(--card-bg); padding: 0 15px; color: var(--text-muted); position: relative; z-index: 2; font-size: 0.9rem; font-weight: 600; }

.tag-list { list-style: none; padding: 0; margin: 20px 0 0 0; }
.tag-list li { display: flex; justify-content: space-between; align-items: center; background: #f8fafc; padding: 10px 15px; border-radius: 8px; border: 1px solid var(--border-color); }
.del-btn { background: none; color: var(--danger); padding: 5px; font-size: 1.1rem; }

/* Custom Dropdowns */
.expense-form .row { display: flex; gap: 10px; margin-bottom: 15px; }
.custom-select-container { position: relative; width: 100%; cursor: pointer; }
.custom-select-trigger { padding: 12px 15px; border: 1px solid var(--border-color); border-radius: 12px; background: #f8fafc; display: flex; justify-content: space-between; align-items: center; color: var(--text-muted); }
.custom-options-list { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid var(--border-color); border-radius: 12px; margin-top: 5px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); z-index: 100; display: none; max-height: 200px; overflow-y: auto; }
.custom-select-container.active .custom-options-list { display: block; }
.custom-option { padding: 12px 15px; transition: background 0.2s; }
.custom-option:hover { background: var(--bg-color); }
.custom-option.selected { background: #e0e7ff; color: var(--primary); font-weight: 600; }

.currency-select-container { flex-shrink: 0; width: 95px; margin-bottom: 0; }
.currency-select-container .custom-select-trigger { border-radius: 12px 0 0 12px; border-right: 1px solid #cbd5e1; background: #f1f5f9; height: 100%; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-weight: 600; color: var(--text-main); }
.currency-select-container .custom-options-list { width: 120px; }
.category-select-container { width: 140px; flex-shrink: 0; }
.category-select-container .custom-select-trigger { color: var(--text-main); }

/* Receipts */
.receipt-row { align-items: center; }
.receipt-upload-btn { background: var(--bg-color); border: 1px solid var(--border-color); padding: 10px 15px; border-radius: 12px; cursor: pointer; font-size: 0.9rem; color: var(--text-main); display: flex; align-items: center; gap: 8px; transition: background 0.2s; }
.receipt-upload-btn:hover { background: #e2e8f0; }
.receipt-name { font-size: 0.85rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.receipt-btn { background: #e0e7ff; color: var(--primary); border: none; padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 5px; width: 100%; justify-content: center; margin: 10px 0 0 0 !important; }
.receipt-btn:hover { background: #c7d2fe; }

/* Split Checkboxes UI */
.split-toggle-btn { width: 100%; background: #f8fafc; border: 1px solid var(--border-color); padding: 12px; text-align: left; display: flex; justify-content: space-between; color: var(--text-main); font-weight: normal; margin-bottom: 10px; }
.split-section { background: white; padding: 15px; border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 15px; }

.split-person-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    background: white; border: 1px solid var(--border-color); border-radius: 8px;
    cursor: pointer; transition: all 0.2s ease; margin-bottom: 0; min-width: 0;
}
.split-person-item:hover { background: #f8fafc; border-color: #cbd5e1; }
.split-person-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); margin: 0; flex-shrink: 0; }
.split-person-item .person-name { font-size: 0.95rem; color: var(--text-main); font-weight: 500; flex-grow: 1; user-select: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.split-checkboxes-container {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
    max-height: 180px; overflow-y: auto; overflow-x: hidden; padding-right: 5px;
    background: transparent; border: none; margin-top: 10px;
}
.split-checkboxes-container::-webkit-scrollbar { width: 6px; }
.split-checkboxes-container::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 10px; }

/* Live Split & Total Card */
.total-card {
    background: #4f46e5; padding: 16px 20px; border-radius: 12px;
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}
.total-label { color: #e0e7ff; font-size: 0.95rem; font-weight: 500; }
.total-amount { color: white; font-size: 1.4rem; font-weight: 700; }

.group-section { margin-bottom: 15px; border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }
.group-section h3 { background: #f8fafc; padding: 12px 15px; margin: 0; font-size: 0.95rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; color: var(--text-main); transition: background 0.2s; }
.group-section h3:hover { background: #e2e8f0; }
.balance-list { padding: 10px 15px; }
.balance-list.hidden { display: none; }
.balance-item { padding: 10px; margin-bottom: 8px; border-radius: 6px; font-size: 0.9rem; display: flex; justify-content: space-between; }
.positive-bg { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.negative-bg { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Settlements UI */
.settlement-section { margin-top: 20px; border-top: 2px dashed var(--border-color); padding-top: 20px; }
.settlement-item { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; background: white; border: 1px solid var(--border-color); padding: 14px 16px; border-radius: 12px; margin-bottom: 12px; gap: 12px; }
.settlement-actors { font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; gap: 10px; text-transform: capitalize; }
.settlement-actions-group { display: flex; align-items: center; gap: 15px; flex-shrink: 0; margin-left: auto; }
.settlement-amount { font-weight: 700; color: var(--text-main); font-size: 1.15rem; white-space: nowrap; }
.action-settle-btn { background: var(--success); color: white; padding: 8px 14px; font-size: 0.85rem; border-radius: 8px; display: flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
.action-settle-btn:hover { background: #059669; }

/* History & Filters */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { padding: 8px; border-radius: 8px; font-size: 0.9rem; }
.clear-filter-btn { background: var(--bg-color); color: var(--text-muted); padding: 8px 12px; border: 1px solid var(--border-color); }
.export-btn { background: #10b981; border: none; padding: 0 15px; border-radius: 6px; color: white; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; height: 38px; }
.export-btn:hover { background: #059669; }

.history-list { list-style: none; padding: 0; margin: 0; }
.history-item { background: #f8fafc; padding: 15px; border-radius: 12px; border: 1px solid var(--border-color); margin-bottom: 10px; display: flex; flex-direction: column !important; align-items: flex-start !important; }
.expense-details { width: 100%; }
.expense-title { display: block; font-weight: 600; font-size: 1.05rem; }
.expense-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; font-size: 0.85rem; color: var(--text-muted); align-items: center; }
.category-tag { background: white; padding: 2px 8px; border-radius: 12px; border: 1px solid var(--border-color); font-weight: 500; }
.location-badge { background: #e0f2fe; color: #0369a1; padding: 2px 8px; border-radius: 12px; font-weight: 500; }
.involved-meta { display: block; font-size: 0.8rem; color: #94a3b8; font-style: italic; }
.expense-cost { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.expense-amount { font-weight: 700; font-size: 1.2rem; color: var(--text-main); }
.expense-original-cost { font-size: 0.85rem; color: var(--text-muted); text-decoration: line-through; margin-right: 8px; }

/* FAQ Section */
.faq-section { margin-top: 40px; padding-bottom: 40px; width: 100%; }
.faq-title { text-align: center; color: var(--text-main); margin-bottom: 20px; font-size: 1.3rem; font-weight: 700; }
.faq-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.faq-card { background: white; border-radius: 12px; padding: 20px; box-shadow: var(--card-shadow); text-align: center; transition: transform 0.2s, box-shadow 0.2s; border: 1px solid var(--border-color); }
.faq-card:hover { transform: translateY(-5px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
.faq-icon { font-size: 2rem; color: var(--primary); margin-bottom: 12px; }
.faq-card h3 { font-size: 1.1rem; color: var(--text-main); margin-bottom: 8px; font-weight: 600; }
.faq-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin: 0; }
.faq-card:last-child:nth-child(odd) {
    grid-column: 1 / -1; 
    max-width: 50%;
    margin: 0 auto;
}
@media (max-width: 768px) {
    .faq-card:last-child:nth-child(odd) {
        max-width: 100%;
    }
}
/* Responsive Media Queries */
@media (max-width: 500px) {
    .expense-form .row { flex-direction: column; }
    .currency-select-container { width: 100%; }
    .currency-amount-group input[type="number"] { border-radius: 12px; margin-top: 5px; }
    .currency-select-container .custom-select-trigger { border-radius: 12px; border-right: 1px solid var(--border-color); }
    .currency-amount-group { flex-direction: column; }
    .export-btn { width: 100%; padding: 10px; }
    .faq-grid { grid-template-columns: 1fr; }
	.faq-card:last-child:nth-child(odd) {
        max-width: 100%;
    }
}

@media (max-width: 400px) {
    .split-checkboxes-container { grid-template-columns: 1fr; }
	.faq-card:last-child:nth-child(odd) {
        max-width: 100%;
    }
}
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6); /* Dark semi-transparent background */
    backdrop-filter: blur(4px); /* Modern blur effect */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.custom-modal {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 30px 25px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    text-align: center;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.custom-modal-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}
.custom-modal-icon.warning { color: #f59e0b; /* Yellow warning */ }
.custom-modal-icon.success { color: var(--success); /* Green success */ }

.custom-modal h3 {
    margin: 0 0 10px 0;
    font-size: 1.3rem;
    color: var(--text-main);
}

.custom-modal p {
    margin: 0 0 25px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.custom-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.custom-modal-actions button {
    flex: 1; /* Makes buttons equal width */
    padding: 12px;
    font-size: 1rem;
}
.share-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    height: 100%;
    min-height: 48px; /* Matches typical code-box height */
    width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
    transition: all 0.2s ease;
}

.share-btn:hover {
    background: #4338ca;
    transform: translateY(-2px);
    box-shadow: 0 6px 10px -1px rgba(79, 70, 229, 0.3);
}

.share-btn:active {
    transform: translateY(0);
}
.history-item.settlement-card {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
}

@keyframes flashNewItem {
    0% { 
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); 
        transform: scale(1.02);
    }
    50% { 
        box-shadow: 0 0 15px 5px rgba(16, 185, 129, 0.4); 
        background-color: #d1fae5;
    }
    100% { 
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); 
        transform: scale(1);
    }
}

.flash-highlight {
    animation: flashNewItem 3s ease-out forwards;
}