:root {
    --primary: #4361ee;
    --secondary: #3a0ca3;
    --success: #4cc9f0;
    --danger: #f72585;
    --warning: #fca311;
    --light: #f8f9fa;
    --dark: #212529;
    --gray: #6c757d;
    --light-gray: #e9ecef;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--dark);
    min-height: 100vh;
    padding: 0;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 clamp(10px, 2vw, 15px);
    width: 100%;
}

/* Compact header */
header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: clamp(10px, 2vw, 15px);
    padding: clamp(8px, 1.5vw, 12px) clamp(15px, 3vw, 20px);
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    position: relative;
    width: 100%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.logo {
    max-width: clamp(25px, 5vw, 40px);
    height: auto;
    margin-right: clamp(10px, 1.5vw, 15px);
}

.header-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

h1 {
    color: white;
    margin-bottom: clamp(3px, 0.8vw, 5px);
    font-size: clamp(1rem, 4vw, 1.8rem);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    line-height: 1.2;
}

.subtitle {
    color: rgba(255, 255, 255, 0.85);
    font-size: clamp(0.65rem, 2vw, 0.9rem);
    line-height: 1.2;
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: clamp(8px, 1.5vw, 12px);
    margin-bottom: clamp(12px, 2.5vw, 20px);
    width: 100%;
}

.card {
    background: white;
    border-radius: 8px;
    padding: clamp(10px, 2vw, 15px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    width: 100%;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.card h2 {
    color: var(--primary);
    margin-bottom: clamp(6px, 1.2vw, 10px);
    padding-bottom: clamp(3px, 0.8vw, 5px);
    border-bottom: 1px solid var(--light-gray);
    font-size: clamp(1rem, 2.5vw, 1.3rem);
}

.summary-cards {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(6px, 1.2vw, 10px);
    margin-bottom: clamp(12px, 2.5vw, 20px);
    justify-content: space-between;
    width: 100%;
}

.summary-card {
    background: white;
    border-radius: 6px;
    padding: clamp(8px, 1.5vw, 12px);
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
    transition: transform 0.3s ease;
    flex: 1 1 calc(33.33% - 8px);
    min-width: 120px;
    max-width: 100%;
}

.summary-card:hover {
    transform: translateY(-2px);
}

.summary-card h3 {
    color: var(--gray);
    font-size: clamp(0.65rem, 1.8vw, 0.8rem);
    margin-bottom: clamp(3px, 0.8vw, 5px);
}

.summary-card .amount {
    font-size: clamp(1rem, 3.5vw, 1.5rem);
    font-weight: 600;
}

.balance .amount {
    color: var(--primary);
}

.total-expenses .amount {
    color: var(--danger);
}

.per-person .amount {
    color: var(--success);
}

.form-group {
    margin-bottom: clamp(6px, 1.2vw, 10px);
    width: 100%;
}

.form-group label {
    display: block;
    margin-bottom: clamp(2px, 0.6vw, 4px);
    font-weight: 500;
    color: var(--dark);
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
}

.form-control {
    width: 100%;
    padding: clamp(5px, 1.2vw, 7px) clamp(8px, 1.8vw, 10px);
    border: 1px solid var(--light-gray);
    border-radius: 5px;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    transition: border-color 0.3s, box-shadow 0.3s;
    max-width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.15);
}

.btn {
    display: inline-block;
    padding: clamp(8px, 1.5vw, 10px) clamp(12px, 2.5vw, 16px);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.3s, transform 0.3s;
    text-align: center;
}

.btn:hover {
    background: var(--secondary);
    transform: translateY(-1px);
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #c1121f;
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: #4895ef;
}

.btn-warning {
    background: var(--warning);
    color: var(--dark);
}

.btn-warning:hover {
    background: #f48c06;
}

/* People Section - Button Styles */
.add-person-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .add-person-form {
        grid-template-columns: 1fr;
    }
}

.add-person-btn {
    padding: clamp(8px, 1.5vw, 10px) clamp(12px, 2.5vw, 16px);
    white-space: nowrap;
    height: 100%;
}

/* Action buttons section */
.action-buttons-section {
    border-top: 2px solid var(--light-gray);
    padding-top: 20px;
    margin-top: 20px;
}

.action-buttons {
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    padding: clamp(8px, 1.5vw, 10px);
    text-align: center;
    min-width: 0;
}

.export-btn {
    background: var(--success);
}

.export-btn:hover {
    background: #4895ef;
}

.import-btn {
    background: var(--warning);
    color: var(--dark);
}

.import-btn:hover {
    background: #f48c06;
}

.reset-btn {
    background: var(--danger);
}

.reset-btn:hover {
    background: #c1121f;
}

/* Responsive adjustments for action buttons */
@media (max-width: 768px) {
    .action-buttons {
        flex-direction: column;
    }
}

.transaction-list {
    max-height: clamp(180px, 25vw, 220px);
    overflow-y: auto;
    margin-top: clamp(6px, 1.2vw, 10px);
    border-radius: 5px;
    background: var(--light);
    width: 100%;
}

.transaction-item {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto auto;
    align-items: center;
    padding: clamp(6px, 1.2vw, 8px);
    border-bottom: 1px solid var(--light-gray);
    gap: clamp(3px, 0.8vw, 5px);
    transition: background 0.3s;
    font-size: clamp(0.7rem, 1.8vw, 0.8rem);
    width: 100%;
}

@media (max-width: 768px) {
    .transaction-item {
        grid-template-columns: 2fr 1fr 1fr auto;
        grid-template-areas: 
            "description description description description"
            "type amount paid-by actions";
        gap: clamp(2px, 0.6vw, 4px);
    }
    
    .transaction-description { grid-area: description; }
    .transaction-type { grid-area: type; }
    .transaction-amount { grid-area: amount; }
    .transaction-paid-by { grid-area: paid-by; }
    .transaction-actions { 
        grid-area: actions; 
        display: flex;
        gap: 4px;
    }
}

.transaction-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.transaction-item:last-child {
    border-bottom: none;
}

.transaction-description {
    font-weight: 500;
}

.transaction-type {
    background: var(--light-gray);
    padding: clamp(2px, 0.6vw, 3px) clamp(4px, 1.2vw, 6px);
    border-radius: 10px;
    text-align: center;
}

.transaction-amount {
    font-weight: 600;
    text-align: right;
}

.transaction-paid-by {
    background: var(--light-gray);
    padding: clamp(2px, 0.6vw, 3px) clamp(4px, 1.2vw, 6px);
    border-radius: 10px;
    text-align: center;
}

.delete-btn, .edit-btn {
    color: white;
    border: none;
    border-radius: 3px;
    padding: clamp(2px, 0.5vw, 3px) clamp(4px, 0.8vw, 6px);
    cursor: pointer;
    transition: background 0.3s, transform 0.3s;
    font-size: clamp(0.55rem, 1.2vw, 0.65rem);
    width: 28px;
    height: 22px;
    display: inline-flex; /* Changed to inline-flex */
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 0 2px; /* Added horizontal margin */
}

.delete-btn {
    background: var(--danger);
}

.delete-btn:hover {
    background: #cd0f35;
    transform: translateY(-1px);
}

.edit-btn {
    background: var(--warning);
}

.edit-btn:hover {
    background: #f48c06;
    transform: translateY(-1px);
}

/* Ensure buttons stay horizontal in all views */
.transaction-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

/* For mobile devices */
@media (max-width: 768px) {
    .delete-btn, .edit-btn {
        padding: clamp(1px, 0.4vw, 2px) clamp(3px, 0.6vw, 4px);
        font-size: clamp(0.5rem, 1.1vw, 0.6rem);
        width: 26px;
        height: 20px;
        margin: 0 1px;
    }
}

/* For very small screens */
@media (max-width: 480px) {
    .delete-btn, .edit-btn {
        padding: 1px 2px;
        font-size: 0.5rem;
        width: 24px;
        height: 18px;
    }
    
    .transaction-actions {
        gap: 3px;
    }
}

.people-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: clamp(6px, 1.2vw, 8px);
    margin-top: clamp(6px, 1.2vw, 10px);
    width: 100%;
}

@media (max-width: 480px) {
    .people-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

.person-card {
    background: var(--light);
    border-radius: 6px;
    padding: clamp(6px, 1.2vw, 8px);
    text-align: center;
    transition: transform 0.3s ease;
    width: 100%;
}

.person-card:hover {
    transform: translateY(-2px);
}

.person-card h4 {
    margin-bottom: clamp(3px, 0.8vw, 5px);
    color: var(--dark);
    font-size: clamp(0.8rem, 2vw, 0.95rem);
}

.person-card .balance {
    font-weight: 600;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

.settlement-list {
    margin-top: clamp(6px, 1.2vw, 10px);
    width: 100%;
}

.settlement-item {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: clamp(6px, 1.2vw, 8px);
    border-bottom: 1px solid var(--light-gray);
    text-align: center;
    transition: background 0.3s;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    width: 100%;
}

@media (max-width: 480px) {
    .settlement-item {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

.settlement-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.settlement-amount {
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Tabs - Always horizontal layout */
.tabs {
    display: flex;
    margin-bottom: clamp(12px, 2.5vw, 18px);
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
    width: 100%;
    flex-direction: row; /* Ensure horizontal layout */
}

/* Remove the mobile vertical layout */
.tab {
    flex: 1;
    padding: clamp(8px, 1.5vw, 10px);
    text-align: center;
    background: var(--light);
    cursor: pointer;
    transition: background 0.3s, color 0.3s;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    white-space: nowrap; /* Prevent text wrapping */
}

.tab.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.tab-content {
    display: none;
    width: 100%;
}

.tab-content.active {
    display: block;
}

/* Ensure tabs remain horizontal on very small screens */
@media (max-width: 480px) {
    .tabs {
        flex-direction: row; /* Force horizontal layout */
        overflow-x: auto; /* Allow horizontal scrolling if needed */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    .tab {
        flex: 1;
        min-width: max-content; /* Ensure tabs don't shrink too much */
        padding: clamp(6px, 1.2vw, 8px) clamp(8px, 1.5vw, 10px);
        font-size: clamp(0.7rem, 1.6vw, 0.8rem);
    }
}

/* For very small screens, make text smaller but keep horizontal */
@media (max-width: 320px) {
    .tab {
        font-size: 0.65rem;
        padding: 5px 8px;
    }
}

.chart-container {
    position: relative;
    height: clamp(140px, 22vw, 180px);
    margin-top: clamp(6px, 1.2vw, 10px);
    border-radius: 5px;
    overflow: hidden;
    width: 100%;
}

.empty-state {
    text-align: center;
    padding: clamp(12px, 2.5vw, 18px);
    color: var(--gray);
    width: 100%;
}

.empty-state i {
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-bottom: clamp(4px, 1vw, 6px);
    color: var(--light-gray);
}

footer {
    text-align: center;
    margin-top: clamp(12px, 2.5vw, 18px);
    padding: clamp(8px, 1.5vw, 10px);
    color: var(--gray);
    font-size: clamp(0.65rem, 1.8vw, 0.8rem);
    width: 100%;
}

.notification {
    position: fixed;
    top: clamp(5px, 1.5vw, 10px);
    right: clamp(5px, 1.5vw, 10px);
    padding: clamp(6px, 1.2vw, 8px) clamp(10px, 1.8vw, 12px);
    background: var(--success);
    color: white;
    border-radius: 5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    font-size: clamp(0.65rem, 1.8vw, 0.8rem);
    max-width: 90%;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.import-export {
    display: flex;
    gap: clamp(6px, 1.2vw, 8px);
    margin-top: clamp(6px, 1.2vw, 10px);
    width: 100%;
}

@media (max-width: 480px) {
    .import-export {
        flex-direction: column;
    }
}

/* Ensure no horizontal scrolling */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Responsive adjustments for very small screens */
@media (max-width: 320px) {
    .summary-card {
        flex: 1 1 100%;
        min-width: unset;
    }
    
    .transaction-item {
        font-size: 0.7rem;
    }
}
