:root {
    --primary: #8C7851;
    --primary-light: #AD9D80;
    --bg: #F0EDE6;
    --card-bg: rgba(255, 255, 255, 0.7);
    --text: #1a1a1a;
    --text-light: #555;
    --accent: #B4975A;
    --success: #637042;
    --danger: #964242;
    --glass-border: rgba(255, 255, 255, 0.8);
    --shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    --z-login: 2000;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    background: url('bg.jpg') no-repeat center center fixed;
    background-size: cover;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(240, 237, 230, 0.3);
    z-index: -1;
}

h1, h2, h3 { font-family: 'Playfair Display', serif; color: #111; }

.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
}

.glass {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

/* ===== Header ===== */
.main-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo h1 { font-size: 1.2rem; font-weight: 600; color: var(--primary); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.balance-badge { background: var(--primary); color: white; padding: 6px 14px; border-radius: 50px; font-size: 0.85rem; }

/* ===== Hero Card / Budget ===== */
.hero-card { padding: 30px; margin-bottom: 25px; border-radius: 24px; }
.section-title { font-size: 1.8rem; font-weight: 500; margin-bottom: 5px; color: #111; }
.progress-info-row { display: flex; justify-content: space-between; margin-bottom: 12px; }
.progress-bar-container { height: 14px; background: rgba(255,255,255,0.8); border-radius: 20px; position: relative; margin: 20px 0; }
.progress-bar { height: 100%; background: #998C7A; border-radius: 20px; transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
.progress-marker { position: absolute; font-size: 10px; color: #888; transform: translateX(-50%); }
.progress-marker.top { top: -15px; }
.progress-marker.bottom { bottom: -15px; }
.progress-labels { display: flex; justify-content: space-between; font-size: 0.85rem; color: #666; }

/* ===== Category Cards ===== */
.category-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 15px;
    margin: 20px -20px;
    padding: 0 20px 15px 20px;
    scrollbar-width: none;
}
.category-grid::-webkit-scrollbar { display: none; }
.cat-card {
    flex: 0 0 130px;
    padding: 20px 10px;
    text-align: center;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    scroll-snap-align: start;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}
.cat-card:active { transform: scale(0.95); background: rgba(255,255,255,0.6); }
.cat-card.active { background: var(--primary); color: white; }
.cat-card.active .icon-box { background: rgba(255,255,255,0.2); }
.cat-card.active .bar-wrap { background: rgba(255,255,255,0.3); }
.cat-card.active .bar-fill { background: white; }
.cat-card .icon-box { width: 48px; height: 48px; background: rgba(255,255,255,0.6); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.cat-card h4 { font-size: 0.9rem; margin: 0; }
.cat-card .bar-wrap { width: 60px; height: 6px; background: rgba(255,255,255,0.8); border-radius: 10px; }
.cat-card .bar-fill { height: 100%; background: #998C7A; border-radius: 10px; }

/* ===== Stats Grid ===== */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 25px; }
.stat-card { padding: 25px; border-radius: 20px; }
.stat-card.highlight { background: white; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab-btn {
    flex: 1;
    padding: 12px 6px;
    border: none;
    background: none;
    font-size: 0.88rem;
    color: var(--text-light);
    border-bottom: 2.5px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    font-family: inherit;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-btn:active { transform: scale(0.97); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== List / Items ===== */
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.add-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: transform 0.15s;
}
.add-btn:active { transform: scale(0.95); }
.add-btn.secondary { background: var(--primary-light); }

.transaction-list { display: flex; flex-direction: column; gap: 12px; }
.item {
    display: flex;
    align-items: center;
    padding: 15px;
    gap: 15px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}
.item:active { transform: scale(0.98); background: rgba(255,255,255,0.5); }
.item.purchased { opacity: 0.55; }
.item-icon { width: 45px; height: 45px; background: var(--bg); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.item-info { flex: 1; min-width: 0; }
.item-info .title { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-info .subtitle { font-size: 0.75rem; color: var(--text-light); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-amount {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    flex-shrink: 0;
}
.item-amount .val { font-weight: 600; display: block; white-space: nowrap; }
.item-amount .who { font-size: 0.7rem; background: #E8E4DB; padding: 2px 8px; border-radius: 5px; }

.img-thumbs { display: flex; gap: 5px; margin-top: 5px; }
.img-thumbs img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; cursor: pointer; border: 1px solid rgba(0,0,0,0.1); }

/* ===== Priority Tags ===== */
.priority-tag { font-size: 0.65rem; padding: 2px 8px; border-radius: 5px; font-weight: 500; }
.priority-tag.must { background: #FFE5E5; color: #C0392B; }
.priority-tag.want { background: #FFF8E1; color: #E67E22; }
.priority-tag.maybe { background: #E8F5E9; color: #27AE60; }

/* ===== Wishlist Summary ===== */
.wishlist-summary {
    display: flex;
    justify-content: space-around;
    padding: 16px;
    margin-bottom: 15px;
    border-radius: 16px;
}
.ws-stat { text-align: center; }
.ws-label { display: block; font-size: 0.8rem; color: var(--text-light); }
.ws-value { display: block; font-size: 1.1rem; font-weight: 600; color: var(--primary); margin-top: 4px; }

/* ===== Filter Badge ===== */
.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.85rem;
    margin-bottom: 15px;
}
.filter-badge .close { cursor: pointer; font-size: 1.1rem; line-height: 1; }

/* ===== Image Viewer ===== */
.viewer-content { max-width: 90%; max-height: 90%; }
.viewer-content img { width: 100%; height: auto; border-radius: 12px; }

/* ===== Modals (Bottom Sheet Style) ===== */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0);
    display: none;
    align-items: flex-end; justify-content: center;
    z-index: 1000;
    transition: background 0.35s;
    pointer-events: none;
}
.modal.active { 
    display: flex; 
    background: rgba(0,0,0,0.6);
    pointer-events: all;
}
.modal-content {
    width: 100%;
    max-width: 600px;
    padding: 0 24px 24px 24px;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
}
.modal.active .modal-content {
    transform: translateY(0);
}
/* Login Overlay stays centered */
.login-overlay { 
    z-index: var(--z-login); 
    background: var(--bg); 
    align-items: center;
}
.login-overlay.active {
    background: var(--bg);
}
.login-overlay .modal-content {
    border-radius: 20px;
    transform: none;
    padding: 30px;
    max-width: 450px;
}
.login-overlay .bottom-sheet-handle { display: none; }

/* ===== Form Styling Improvements ===== */
.modal-content h3 {
    text-align: center;
    font-size: 1.3rem;
    margin: 10px 0 20px;
    color: var(--primary);
}
.form-group { margin-bottom: 20px; }
.form-group label { 
    display: block; 
    font-size: 0.8rem; 
    margin-bottom: 6px; 
    font-weight: 600;
    color: var(--text-light);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select, textarea {
    width: 100%; padding: 12px 14px;
    border: 1.2px solid #EEE; 
    border-radius: 12px;
    font-size: 0.95rem; 
    background: #F9F9F9;
    font-family: inherit;
    transition: all 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(140, 120, 81, 0.1);
}

.radio-group { 
    display: flex; 
    gap: 8px; 
    background: #F0F0F0;
    padding: 4px;
    border-radius: 12px;
}
.radio-label { 
    flex: 1;
    display: flex; 
    align-items: center; 
    justify-content: center;
    gap: 4px; 
    cursor: pointer; 
    padding: 8px;
    border-radius: 9px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}
.radio-label input { display: none; }
.radio-label:has(input:checked) {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    color: var(--primary);
}

.modal-actions { display: flex; gap: 12px; margin-top: 25px; }
.btn-submit {
    flex: 2; 
    background: var(--primary);
    color: white; border: none;
    padding: 14px; border-radius: 14px; font-weight: 600;
    cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-submit:active { transform: scale(0.97); }

.btn-cancel {
    flex: 1; background: #EEE; border: none;
    padding: 14px; border-radius: 14px;
    cursor: pointer; transition: all 0.2s; font-family: inherit;
    color: #666;
}

.category-edit-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ===== Settings ===== */
.settings-list {
    margin-top: 15px;
    display: flex; flex-direction: column; gap: 8px;
    max-height: 40vh; overflow-y: auto;
    padding-right: 5px;
}
.settings-item { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 12px 16px; 
    background: white; 
    border: 1px solid #EEE;
    border-radius: 14px;
}
.settings-item .cat-icon {
    font-size: 1.2rem;
    margin-right: 12px;
}
.settings-item .del-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.85rem; }
.settings-trigger { background: none; border: none; font-size: 1.2rem; cursor: pointer; opacity: 0.6; }


/* ===== Export Modal ===== */
.export-options { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.export-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    text-align: left;
    font-family: inherit;
}
.export-btn:active { transform: scale(0.97); background: rgba(0,0,0,0.06); }
.export-btn .export-icon { font-size: 1.6rem; }
.export-btn span { font-size: 0.95rem; font-weight: 500; display: block; }
.export-btn small { display: block; font-size: 0.75rem; color: var(--text-light); font-weight: 400; margin-top: 2px; }

/* ===== Bottom Sheet ===== */
.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 1500;
    pointer-events: none;
    transition: background 0.35s;
}
.bottom-sheet-overlay.active {
    background: rgba(0,0,0,0.5);
    pointer-events: all;
}
.bottom-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-width: 600px;
    margin: 0 auto;
    background: #fff;
    border-radius: 24px 24px 0 0;
    max-height: 85vh;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 1501;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15);
}
.bottom-sheet-overlay.active .bottom-sheet {
    transform: translateY(0);
}
.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin: 12px auto 16px;
    position: sticky;
    top: 0;
}

/* ===== Bottom Sheet Detail Content ===== */
.bs-detail { padding-bottom: 10px; }
.bs-detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.bs-icon-box {
    width: 52px; height: 52px;
    background: var(--bg);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
}
.bs-detail-header h3 { font-size: 1.1rem; }
.bs-cat-badge { background: #E8E4DB; padding: 4px 12px; border-radius: 8px; font-size: 0.8rem; }
.bs-detail-title { font-size: 1.3rem; margin: 8px 0 5px; }
.bs-detail-amount { font-size: 1.8rem; font-weight: 600; color: var(--primary); margin: 5px 0 15px; }

.ring-chart {
    width: 110px; height: 110px;
    border-radius: 50%;
    background: conic-gradient(var(--primary) calc(var(--ring-percent) * 1%), #eee 0);
    display: flex; align-items: center; justify-content: center;
    margin: 15px auto;
}
.ring-inner {
    width: 78px; height: 78px;
    border-radius: 50%; background: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 1.2rem; color: var(--primary);
}

.bs-stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 15px 0; }
.bs-stat { text-align: center; padding: 10px; background: #f9f8f5; border-radius: 10px; }
.bs-stat-label { display: block; font-size: 0.75rem; color: var(--text-light); }
.bs-stat-value { display: block; font-weight: 600; font-size: 0.95rem; margin-top: 4px; }
.bs-stat-value.danger { color: var(--danger); }

.bs-list-header { display: flex; justify-content: space-between; align-items: center; margin: 15px 0 8px; }
.bs-section-title { font-size: 0.9rem; color: var(--text-light); font-family: inherit; margin: 0; }
.bs-text-btn { background: none; border: none; color: var(--primary); font-size: 0.85rem; cursor: pointer; font-family: inherit; font-weight: 500; }
.bs-mini-list { display: flex; flex-direction: column; gap: 6px; }
.bs-mini-item {
    display: flex; justify-content: space-between;
    padding: 10px 12px; background: #f9f8f5;
    border-radius: 10px; font-size: 0.9rem;
    cursor: pointer; transition: background 0.15s;
}
.bs-mini-item:active { background: #f0efe9; }
.bs-empty { text-align: center; color: var(--text-light); font-size: 0.9rem; padding: 20px; }

.bs-meta { display: flex; flex-direction: column; gap: 8px; margin: 15px 0; }
.bs-meta-item { font-size: 0.9rem; color: var(--text-light); }

.bs-images { display: flex; gap: 12px; margin: 15px 0; overflow-x: auto; }
.bs-img-wrap { flex: 0 0 auto; }
.bs-img-wrap p { font-size: 0.75rem; color: var(--text-light); margin-bottom: 5px; }
.bs-img-wrap img { width: 120px; height: 120px; border-radius: 12px; object-fit: cover; cursor: pointer; }

.bs-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.bs-action-btn {
    flex: 1;
    min-width: 70px;
    padding: 12px 14px;
    border: none;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.15s;
    background: #f0efe9;
    color: var(--text);
    font-family: inherit;
}
.bs-action-btn:active { transform: scale(0.95); }
.bs-action-btn.primary { background: var(--primary); color: white; }
.bs-action-btn.danger { background: var(--danger); color: white; }
.bs-action-btn.convert {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    flex: 0 0 100%;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 14px;
}

.priority-badge { padding: 4px 12px; border-radius: 8px; font-size: 0.8rem; font-weight: 500; }
.priority-badge.must { background: #FFE5E5; color: #C0392B; }
.priority-badge.want { background: #FFF8E1; color: #E67E22; }
.priority-badge.maybe { background: #E8F5E9; color: #27AE60; }

.status-badge { padding: 4px 12px; border-radius: 8px; font-size: 0.8rem; font-weight: 500; }
.status-badge.purchased { background: #E8F5E9; color: #27AE60; }
.status-badge.pending { background: #FFF8E1; color: #E67E22; }

/* ===== FAB ===== */
.fab-container {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 24px;
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}
.fab-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(140, 120, 81, 0.4);
    transition: transform 0.25s;
    display: flex; align-items: center; justify-content: center;
}
.fab-btn:active { transform: scale(0.9); }
.fab-icon {
    display: block; line-height: 1;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.fab-btn.open .fab-icon { transform: rotate(45deg); }

.fab-menu {
    display: flex; flex-direction: column;
    gap: 8px; align-items: flex-end;
    opacity: 0; pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.25s, transform 0.25s;
}
.fab-menu.open {
    opacity: 1; pointer-events: all;
    transform: translateY(0);
}
.fab-item {
    background: white;
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    cursor: pointer;
    font-size: 0.88rem;
    font-family: inherit;
    white-space: nowrap;
    transition: transform 0.15s;
}
.fab-item:active { transform: scale(0.95); }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: all;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .bs-stats-grid { grid-template-columns: 1fr 1fr; }
}
