/* assets/css/style.css */

/* --- Variables --- */
:root {
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --primary-color: #e5ca10;
    --primary-hover: #fce343;
    --text-main: #333333;
    --text-muted: #777777;
    --danger-color: #e74c3c;
    --border-color: #e0e0e0;

    --border-radius: 14px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

    --font-family: 'Inter', sans-serif;

    /* Maximum app width for desktop to keep it looking like a mobile app */
    --max-app-width: 480px;
}

/* --- Reset & Global --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

/* Container restricts width on desktop, full width on mobile */
.app-container {
    width: 100%;
    max-width: var(--max-app-width);
    background-color: var(--bg-color);
    min-height: 100vh;
    position: relative;
    padding: 20px;
    /* On larger screens, the container itself can look like a phone bezel or simply a card */
}

@media (min-width: 481px) {
    body {
        background-color: #e0e0e0;
        /* Darker bg outside the app */
        align-items: center;
        padding: 40px 0;
    }

    .app-container {
        border-radius: 20px;
        box-shadow: var(--shadow-lg);
        min-height: 80vh;
        /* Don't stretch fully on large screens if not needed */
        background-color: var(--bg-color);
        overflow: hidden;
    }
}

/* --- Typography --- */
h1,
h2,
h3,
h4 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

p {
    margin-bottom: 1rem;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.text-danger {
    color: var(--danger-color);
}

.text-success {
    color: var(--primary-color);
}

.fw-bold {
    font-weight: 700;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    text-decoration: none;
    gap: 8px;
    margin-bottom: 12px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover {
    background-color: rgba(46, 204, 113, 0.1);
}

.btn-danger {
    background-color: #fceceb;
    color: var(--danger-color);
}

.btn-danger:hover {
    background-color: #fadbd8;
}

.btn-link {
    background: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: underline;
    padding: 5px;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1rem;
    text-align: left;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
    background-color: var(--card-bg);
}

.form-control:focus {
    border-color: var(--primary-color);
}

/* --- Cards / List Items --- */
.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

/* Specific to Friends Grid */
.friends-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.friend-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.2s;
}

.friend-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.friend-name {
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.friend-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* --- Layout Elements --- */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 20px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.header-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}

.logout-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 15px;
    color: #cccccc;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    /* Bottom sheet style on mobile */
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--bg-color);
    width: 100%;
    max-width: var(--max-app-width);
    border-radius: 20px 20px 0 0;
    padding: 24px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

@media (min-width: 481px) {
    .modal-overlay {
        align-items: center;
    }

    .modal-content {
        border-radius: 20px;
        transform: scale(0.95);
        opacity: 0;
    }

    .modal-overlay.active .modal-content {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Checkboxes for expense sharing */
.checkbox-list {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 10px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.checkbox-item:last-child {
    border-bottom: none;
}

.checkbox-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    accent-color: var(--primary-color);
}

/* Expense List inside Event */
.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.expense-info {
    flex: 1;
}

.expense-name {
    font-weight: 500;
    display: block;
}

.expense-payer {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.expense-amount {
    font-weight: 600;
    color: var(--text-main);
}

/* Settlement List Output */
.settlement-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
}

.settlement-item i {
    color: var(--primary-color);
    margin: 0 10px;
}

/* Utilities */
.mb-1 {
    margin-bottom: 8px;
}

.mb-2 {
    margin-bottom: 16px;
}

.mb-3 {
    margin-bottom: 24px;
}

.mb-4 {
    margin-bottom: 32px;
}

.mt-2 {
    margin-top: 16px;
}

.mt-3 {
    margin-top: 24px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background-color: #fceceb;
    color: var(--danger-color);
    border: 1px solid #fadbd8;
}

.alert-success {
    background-color: rgba(46, 204, 113, 0.1);
    color: var(--primary-color);
    border: 1px solid rgba(46, 204, 113, 0.2);
}

/* ===== Shared Page Styles ===== */

.shared-section {
    margin-bottom: 24px;
}

.shared-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 0;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    margin-bottom: 15px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.shared-section-header:hover h3 {
    color: var(--primary-color) !important;
}

.shared-chevron {
    color: var(--text-muted);
    transition: transform 0.3s ease;
    font-size: 0.85rem;
}

.shared-chevron.collapsed {
    transform: rotate(180deg);
}

.shared-section-body {
    animation: sharedFadeIn 0.3s ease;
}

.shared-section-body.collapsed {
    display: none;
}

@keyframes sharedFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Expense Items */
.shared-expense-item {
    padding: 16px;
}

.shared-expense-border {
    border-top: 1px solid rgba(0,0,0,0.06);
}

.shared-expense-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.shared-expense-info {
    flex: 1;
}

.shared-expense-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
    margin-bottom: 3px;
}

.shared-expense-payer {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.shared-expense-amount {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

.shared-expense-participants {
    padding: 8px 10px;
    background: rgba(0,0,0,0.02);
    border-radius: 8px;
}

.shared-participant-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.shared-tag {
    background: rgba(229, 202, 16, 0.12);
    color: #8a7a0d;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid rgba(229, 202, 16, 0.25);
}

/* Friend Cards */
.shared-friend-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.06);
    transition: box-shadow 0.2s ease;
}

.shared-friend-card:hover {
    box-shadow: 0 3px 12px rgba(0,0,0,0.1);
}

.shared-friend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.shared-friend-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.shared-friend-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #d4b60e);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.shared-friend-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.shared-friend-stats {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.shared-balance-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.shared-balance-positive {
    background: rgba(46, 204, 113, 0.12);
    color: #1e8449;
}

.shared-balance-negative {
    background: rgba(231, 76, 60, 0.12);
    color: #c0392b;
}

.shared-balance-neutral {
    background: rgba(149, 165, 166, 0.15);
    color: #7f8c8d;
}

.shared-chevron-small {
    color: var(--text-muted);
    transition: transform 0.3s ease;
    font-size: 0.7rem;
}

.shared-chevron-small.expanded {
    transform: rotate(180deg);
}

/* Friend Detail */
.shared-friend-detail {
    border-top: 1px solid rgba(0,0,0,0.06);
    padding: 12px 16px;
    background: rgba(0,0,0,0.015);
    animation: sharedFadeIn 0.25s ease;
}

.shared-detail-table {
    width: 100%;
}

.shared-detail-header-row {
    display: flex;
    padding: 6px 0;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    margin-bottom: 4px;
}

.shared-detail-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    align-items: center;
}

.shared-detail-row:last-child {
    border-bottom: none;
}

/* Responsive tweaks */
@media (max-width: 480px) {
    .shared-friend-stats {
        font-size: 0.72rem;
    }
    .shared-friend-stats span:nth-child(2) {
        display: none; /* hide pipe separator */
    }
    .shared-friend-stats {
        display: flex;
        flex-direction: column;
        gap: 1px;
    }
    .shared-expense-main {
        flex-wrap: wrap;
        gap: 4px;
    }
}