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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    overflow-x: hidden;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8em;
    line-height: 1.3;
    padding: 0 10px;
}

.friends {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.friend-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.friend {
    background: white;
    padding: 10px 18px;
    border-radius: 50px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-weight: 600;
    color: #333;
    font-size: 14px;
    white-space: nowrap;
}

.balance-section {
    margin: 25px 0;
}

.balance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.balance-card {
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s;
}

.balance-card:hover {
    transform: translateY(-3px);
}

.balance-card.positive {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.balance-card.negative {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.balance-card h3 {
    font-size: 1.3em;
    margin-bottom: 8px;
    color: #333;
    word-wrap: break-word;
}

.amount {
    font-size: 1.6em;
    font-weight: bold;
    margin: 8px 0;
    line-height: 1.2;
}

.status {
    font-style: italic;
    color: #555;
    font-size: 14px;
}

.form-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.form-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.form-card h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.2em;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #555;
    font-size: 14px;
}

.form-group select,
.form-group input {
    width: 100%;
    padding: 14px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.3s;
    -webkit-appearance: none;
    appearance: none;
}

.form-group select:focus,
.form-group input:focus {
    border-color: #667eea;
    outline: none;
}

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

.checkbox-label {
    position: relative;
    cursor: pointer;
    font-size: 16px;
    color: #333;
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkbox-label span {
    position: relative;
    padding-left: 30px;
    cursor: pointer;
    display: block;
}

.checkbox-label span::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background: white;
    transition: all 0.3s;
}

.checkbox-label input[type="checkbox"]:checked + span::before {
    background: #667eea;
    border-color: #667eea;
}

.checkbox-label input[type="checkbox"]:checked + span::after {
    content: "✓";
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    width: 100%;
    transition: transform 0.3s, opacity 0.3s;
    min-height: 48px;
}

.btn:hover {
    transform: translateY(-2px);
    opacity: 0.95;
}

.history-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.history-column h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.2em;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 6px;
    overflow: hidden;
    font-size: 14px;
}

th {
    background: #667eea;
    color: white;
    padding: 12px 10px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
}

td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    line-height: 1.4;
}

tr:hover {
    background: #f5f5f5;
}

.summary-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-top: 30px;
}

.summary-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.2em;
}

#paymentSummary {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.payment-item {
    background: white;
    padding: 14px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    animation: slideIn 0.5s ease-out;
    font-size: 14px;
    line-height: 1.4;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Large Mobile Phones (481px - 767px) */
@media (min-width: 481px) and (max-width: 767px) {
    .container {
        padding: 25px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .friend-list {
        gap: 12px;
    }
    
    .friend {
        padding: 12px 22px;
        font-size: 15px;
    }
    
    .balance-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    
    .form-section {
        grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
    }
    
    .form-card {
        padding: 25px;
    }
    
    .history-section {
        grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
    }
}

/* Tablets (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        padding: 30px;
    }
    
    h1 {
        font-size: 2.2em;
    }
    
    .friend-list {
        flex-wrap: wrap;
        gap: 15px;
    }
    
    .friend {
        padding: 14px 26px;
        font-size: 16px;
    }
    
    .balance-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 20px;
    }
    
    .form-section {
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
        gap: 25px;
    }
    
    .history-section {
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
        gap: 25px;
    }
    
    table {
        font-size: 15px;
    }
    
    th, td {
        padding: 14px 12px;
    }
}

/* Desktop (1024px and above) */
@media (min-width: 1024px) {
    .container {
        padding: 30px;
    }
    
    h1 {
        font-size: 2.5em;
    }
    
    .friend-list {
        gap: 20px;
    }
    
    .friend {
        padding: 15px 30px;
        font-size: 16px;
    }
    
    .balance-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 20px;
    }
    
    .form-section {
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
        gap: 30px;
    }
    
    .history-section {
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
        gap: 30px;
    }
    
    table {
        font-size: 16px;
    }
    
    th, td {
        padding: 15px;
    }
}

/* Very Small Devices (up to 360px) */
@media (max-width: 360px) {
    body {
        padding: 8px;
    }
    
    .container {
        padding: 15px;
        border-radius: 8px;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 15px;
        padding: 0 5px;
    }
    
    .friends {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .friend {
        padding: 8px 14px;
        font-size: 12px;
        font-weight: 500;
    }
    
    .balance-card {
        padding: 15px;
    }
    
    .balance-card h3 {
        font-size: 1.1em;
    }
    
    .amount {
        font-size: 1.3em;
    }
    
    .form-card {
        padding: 15px;
    }
    
    .form-group label {
        font-size: 13px;
    }
    
    .form-group select,
    .form-group input {
        padding: 12px;
        font-size: 15px;
    }
    
    .btn {
        padding: 14px 20px;
        font-size: 15px;
        min-height: 44px;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .payment-item {
        padding: 12px;
        font-size: 13px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    .balance-card:active {
        transform: scale(0.99);
    }
    
    select, input, button {
        min-height: 44px; /* Minimum touch target size */
    }
    
    .form-group select,
    .form-group input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .checkbox-label span {
        padding-left: 34px;
    }

    .checkbox-label span::before {
        width: 24px;
        height: 24px;
    }

    .checkbox-label input[type="checkbox"]:checked + span::after {
        left: 6px;
    }
}

/* Landscape Mode Optimizations */
@media (max-height: 600px) and (orientation: landscape) {
    .container {
        padding: 15px;
    }

    .form-section {
        grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
    }

    .balance-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* Install Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    max-width: 300px;
    width: 90%;
}

.modal-content p {
    margin-bottom: 20px;
    font-size: 18px;
    color: #333;
}

.modal-content .btn {
    width: auto;
    margin: 0 10px;
    padding: 12px 20px;
    font-size: 16px;
}

/* Checkbox group styles */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 10px 14px;
    border-radius: 6px;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: border-color 0.3s, background-color 0.3s;
    font-size: 14px;
    font-weight: 500;
}

.checkbox-label:hover {
    border-color: #667eea;
    background-color: #f8f9ff;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
    accent-color: #667eea;
}

.checkbox-label input[type="checkbox"]:checked + span {
    color: #667eea;
    font-weight: 600;
}