* { box-sizing: border-box; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
body { background: #f3f4f6; margin: 0; padding: 16px; transition: background 0.3s, color 0.3s; }
body.dark { background: #1e1e2f; color: #e2e2e2; }
body.dark .card { background: #2a2a3a; }
body.dark input, body.dark select, body.dark button { background: #3a3a4a; color: #e2e2e2; border-color: #555; }
.container { max-width: 1200px; margin: 0 auto; }
.card { background: white; border-radius: 24px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); transition: background 0.3s; }
h2 { font-size: 1.5rem; margin: 0 0 12px 0; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.flex-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-group { flex: 1; min-width: 120px; }
label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 4px; }
input, select, button { padding: 10px 12px; border-radius: 14px; border: 1px solid #cbd5e1; font-size: 1rem; background: white; }
button { width: 100%; background: #6366f1; color: white; border: none; font-weight: 600; cursor: pointer; transition: 0.2s; }
button:hover { background: #4f46e5; }
button:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-inline { width: auto; display: inline-block; padding: 4px 10px; font-size: 0.8rem; margin-left: 5px; }
.btn-secondary { background: #f1f5f9; color: #1e293b; border: 1px solid #cbd5e1; }
body.dark .btn-secondary { background: #4a4a5a; color: #e2e2e2; border-color: #666; }
.btn-danger { background: #ef4444; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; width: auto; }

/* Logout button - RED color */
#logoutBtn {
    background: #ef4444 !important;
    color: white !important;
    border: none !important;
}
#logoutBtn:hover {
    background: #dc2626 !important;
}

/* Avatar styling */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
}

.member-tag { background: #e2e8f0; border-radius: 40px; padding: 6px 14px; display: inline-flex; align-items: center; gap: 8px; margin: 0 8px 8px 0; flex-wrap: wrap; }
.member-tag input { width: 80px; padding: 4px; font-size: 0.8rem; }
.submission-item { background: #f8fafc; border-radius: 20px; padding: 8px 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
body.dark .submission-item { background: #3a3a4a; }
.submission-checkbox { margin-right: 8px; transform: scale(1.1); }
.submission-details { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; }
.submission-details strong { font-size: 0.9rem; min-width: 70px; }
.submission-details span { font-size: 0.75rem; color: #555; }
body.dark .submission-details span { color: #bbb; }
.edit-own-btn { background: #3b82f6; width: auto; padding: 4px 8px; font-size: 0.7rem; margin-left: 8px; }
.progress-bar { background: #e2e8f0; border-radius: 20px; height: 6px; overflow: hidden; margin: 6px 0; }
.progress-fill { background: #10b981; height: 100%; width: 0%; transition: width 0.3s; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 12px; }
@media (max-width: 480px) { .stats-grid { gap: 8px; } }
.stat-card { background: #f1f5f9; border-radius: 16px; text-align: center; font-size: 0.85rem; overflow: hidden; }
body.dark .stat-card { background: #3a3a4a; }
.stat-card-header { background: #cbd5e1; padding: 8px; font-weight: bold; display: flex; align-items: center; justify-content: center; gap: 6px; }
body.dark .stat-card-header { background: #4a4a5a; }
.stat-card-body { padding: 8px; }
.stat-card strong { display: block; margin-bottom: 4px; }
.dark-toggle { position: fixed; bottom: 20px; right: 20px; background: #6366f1; border-radius: 50%; width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 24px; z-index: 1000; }
.admin-recovery { position: fixed; bottom: 20px; left: 20px; background: #64748b; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 20px; opacity: 0.5; transition: opacity 0.2s; z-index: 1000; }
.admin-recovery:hover { opacity: 1; }
.group-code { font-family: monospace; font-size: 1.4rem; font-weight: bold; background: #e2e8f0; padding: 8px; border-radius: 16px; text-align: center; letter-spacing: 2px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; align-items: flex-end; }
.code-button { background: #10b981; padding: 8px 16px; border-radius: 40px; font-size: 0.9rem; width: auto; }
.positive { color: #10b981; font-weight: bold; }
.negative { color: #ef4444; font-weight: bold; }
.pending-badge { background: #f59e0b; color: white; border-radius: 20px; padding: 2px 8px; font-size: 0.7rem; display: inline-block; }
.approved-badge { background: #10b981; color: white; border-radius: 20px; padding: 2px 8px; font-size: 0.7rem; display: inline-block; }
.badge { background: #ef4444; color: white; border-radius: 20px; padding: 2px 8px; font-size: 0.7rem; margin-left: 8px; }
.submission-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 16px; gap: 12px; }
.total-approved { font-weight: bold; font-size: 1.1rem; background: #e2e8f0; padding: 6px 12px; border-radius: 40px; display: inline-block; }
body.dark .total-approved { background: #3a3a4a; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 0.7rem; margin-left: 8px; }
.role-admin { background: #6366f1; color: white; }
.role-supervisor { background: #10b981; color: white; }
.role-approver { background: #f59e0b; color: white; }
.audit-entry { padding: 8px; border-bottom: 1px solid #ddd; font-size: 0.85rem; }
.flag { background: #ef4444; color: white; border-radius: 20px; padding: 2px 6px; font-size: 0.7rem; margin-left: 6px; }
.sticky-top { position: sticky; top: 0; z-index: 100; background: inherit; }
.scrollable-container { max-height: 500px; overflow-y: auto; border-radius: 16px; }
.scrollable-audit { max-height: 300px; overflow-y: auto; }
.password-wrapper { display: flex; gap: 8px; align-items: center; }
.password-wrapper input { flex: 1; }
.toggle-pwd { width: auto; padding: 10px; background: #9ca3af; }
/* Popup styles */
.popup-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.popup-content { background: white; padding: 24px; border-radius: 30px; max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; }
body.dark .popup-content { background: #2a2a3a; }
.popup-content h3 { margin-top: 0; }
.popup-content .flex-row { margin-top: 12px; }
@media (max-width: 700px) { .flex-row { flex-direction: column; align-items: stretch; } .submission-header { flex-direction: column; align-items: stretch; } }
/* Fix sticky top area - no gap */
.sticky-top .card:first-child {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.sticky-top .card:last-child {
    margin-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.sticky-top {
    background: inherit;
    padding-bottom: 0;
}

/* ==================== PENDING APPROVAL CARDS ==================== */
.pending-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid #e2e8f0;
}

body.dark .pending-card {
    background: #2a2a3a;
    border-color: #4a4a5a;
}

.pending-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: nowrap;
    gap: 8px;
}

.pending-member {
    font-weight: bold;
    font-size: 1rem;
    color: #1e293b;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

body.dark .pending-member {
    color: #e2e2e2;
}

.pending-amount {
    font-weight: bold;
    color: #3b82f6;
    font-size: 1rem;
    flex-shrink: 0;
    text-align: right;
}

body.dark .pending-amount {
    color: #60a5fa;
}

/* Mobile fix - keep name and amount on same row */
@media (max-width: 480px) {
    .pending-card-header {
        flex-wrap: nowrap;
        gap: 6px;
    }
    
    .pending-member {
        white-space: normal;
        word-break: break-word;
        flex: 2;
        font-size: 0.9rem;
    }
    
    .pending-amount {
        font-size: 0.9rem;
        flex-shrink: 0;
    }
}

.pending-card-details-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 12px;
    font-size: 0.75rem;
    color: #64748b;
    line-height: 1.4;
}

body.dark .pending-card-details-row {
    color: #94a3b8;
}

.pending-card-details-row span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.detail-flag {
    color: #ef4444;
}

.pending-card-buttons-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

body.dark .pending-card-buttons-row {
    border-top-color: #4a4a5a;
}

.pending-card-buttons-row button {
    flex: 1;
    min-width: 70px;
    padding: 6px 8px;
    font-size: 0.7rem;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
}

.btn-approve {
    background: #10b981;
    color: white;
    border: none;
}

.btn-approve:hover {
    background: #059669;
}

.btn-reject {
    background: #ef4444;
    color: white;
    border: none;
}

.btn-reject:hover {
    background: #dc2626;
}

.btn-flag {
    background: #f59e0b;
    color: white;
    border: none;
}

.btn-flag:hover {
    background: #d97706;
}

.btn-note {
    background: #3b82f6;
    color: white;
    border: none;
}

.btn-note:hover {
    background: #2563eb;
}

/* For very small screens */
@media (max-width: 380px) {
    .pending-card-buttons-row button {
        font-size: 0.65rem;
        padding: 5px 4px;
        min-width: 55px;
    }
}

/* ==================== OTHER PWA FEATURES ==================== */

/* Total Pending Card */
#totalPendingAmount {
    transition: all 0.3s ease;
    font-weight: bold;
    font-size: 1.1rem;
}

/* Show Mine Button */
#showMineBtn {
    transition: all 0.2s ease;
}

#showMineBtn:hover {
    background: #7c3aed !important;
    transform: scale(1.02);
}

/* Mine Progress Popup - Large Card */
#mineProgressPopup .popup-content {
    max-width: 450px;
}

#mineProgressPopup .stat-card {
    background: #f8fafc;
    border-radius: 20px;
}

body.dark #mineProgressPopup .stat-card {
    background: #3a3a4a;
}

#mineProgressFill {
    background: #10b981;
    transition: width 0.5s ease;
}

#mineProgressMessage {
    font-weight: 500;
    line-height: 1.4;
}

/* Edit Member & Edit Category Popups */
#editMemberPopup .popup-content,
#editCategoryPopup .popup-content {
    max-width: 400px;
}

#editMemberPopup input,
#editCategoryPopup input,
#editMemberPopup button,
#editCategoryPopup button {
    margin: 8px 0;
    width: 100%;
    padding: 10px;
}

#editMemberPopup button,
#editCategoryPopup button {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 14px;
}

#editMemberPopup button:last-child,
#editCategoryPopup button:last-child {
    background: #ef4444;
    margin-top: 4px;
}

/* Edit buttons in members and categories list */
.edit-member-btn,
.edit-category-btn {
    background: #3b82f6 !important;
    color: white !important;
}

.edit-member-btn:hover,
.edit-category-btn:hover {
    background: #2563eb !important;
}

/* Device ID in audit log (small text) */
.device-id {
    font-size: 0.7rem;
    color: #64748b;
    display: inline-block;
    margin-top: 2px;
}

body.dark .device-id {
    color: #94a3b8;
}

/* Supervisor Clear All button */
#supervisorClearAuditLogBtn {
    font-size: 0.8rem;
    padding: 4px 12px;
}

/* Fix for submission item on mobile */
@media (max-width: 480px) {
    .submission-item {
        flex-wrap: wrap;
    }
    
    .submission-details {
        flex: 1 1 100%;
    }
    
    .edit-own-btn {
        margin-left: 0;
        margin-top: 6px;
    }
}

/* ==================== V5.5 FIXES - ROLE INDICATOR & TOP BUTTONS ==================== */

/* Fix for role indicator - button and name on same row, NO full width */
#roleIndicator {
    display: flex !important;
    align-items: center !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 12px !important;
}

#roleIndicator button.group-code-btn {
    width: auto !important;
    display: inline-block !important;
    flex-shrink: 0 !important;
    background: #3b82f6 !important;
    color: white !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 4px 10px !important;
    font-size: 0.7rem !important;
    cursor: pointer !important;
}

#roleIndicator button.group-code-btn:hover {
    background: #2563eb !important;
}

#roleIndicator .role-badge {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
}

/* Fix for top card buttons on mobile - keep all three in one row */
@media (max-width: 480px) {
    .sticky-top .card:last-child > div {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        justify-content: center !important;
    }
    
    .sticky-top .card:last-child button {
        flex: 1 !important;
        min-width: 0 !important;
        font-size: 0.7rem !important;
        padding: 8px 4px !important;
        white-space: nowrap !important;
    }
}