/* ShishaBot Mini App — Clean Design */
:root {
    --bg: #f5f5f5;
    --text: #1a1a1a;
    --hint: #8e8e93;
    --link: #007aff;
    --btn: #007aff;
    --btn-text: #ffffff;
    --card-bg: #ffffff;
    --border: #e5e5ea;
    --green: #34c759;
    --orange: #ff9500;
    --red: #ff3b30;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1c1e;
        --text: #ffffff;
        --hint: #8e8e93;
        --card-bg: #2c2c2e;
        --border: #38383a;
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 80px;
    -webkit-overflow-scrolling: touch;
    line-height: 1.4;
}

/* ========== HEADER ========== */
.header {
    background: var(--card-bg);
    padding: 20px 16px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}
.header h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}
.header .total {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1px;
}
.header .subtitle {
    color: var(--hint);
    font-size: 14px;
    margin-top: 4px;
}

/* ========== PERIOD TABS ========== */
.periods {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.periods button {
    flex: 1;
    padding: 10px 0;
    border-radius: 10px;
    border: none;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.periods button.active {
    background: var(--btn);
    color: var(--btn-text);
    font-weight: 600;
}

/* ========== CHART ========== */
.chart-container {
    background: var(--card-bg);
    margin: 12px 16px;
    padding: 20px;
    border-radius: 16px;
    display: flex;
    justify-content: center;
}
.chart-container canvas {
    max-width: 120px;
    max-height: 120px;
}

/* Category progress bars */
.cat-bars { padding: 0 16px 8px; }
.cat-bar-item {
    display: flex;
    align-items: center;
    padding: 6px 0;
    gap: 10px;
}
.cat-bar-item .cat-icon { font-size: 16px; width: 24px; text-align: center; }
.cat-bar-item .cat-name { font-size: 13px; width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-bar-item .cat-progress { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.cat-bar-item .cat-progress .fill { height: 100%; border-radius: 4px; transition: width 0.5s; }
.cat-bar-item .cat-amount { font-size: 13px; font-weight: 600; width: 70px; text-align: right; }

/* ========== BUDGET BAR ========== */
.budget-bar {
    margin: 0 16px 8px;
    padding: 14px 16px;
    background: var(--card-bg);
    border-radius: 12px;
}
.budget-bar .label {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}
.budget-bar .bar {
    height: 10px;
    background: var(--bg);
    border-radius: 5px;
    overflow: hidden;
}
.budget-bar .bar .fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease;
}
.budget-bar .bar .fill.ok { background: var(--green); }
.budget-bar .bar .fill.warn { background: var(--orange); }
.budget-bar .bar .fill.danger { background: var(--red); }

/* ========== SECTION TITLE ========== */
.section-title {
    padding: 16px 16px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ========== EXPENSE LIST ========== */
.expense-list {
    background: var(--card-bg);
    margin: 0 16px;
    border-radius: 16px;
    overflow: hidden;
}
.expense-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.expense-item:last-child { border-bottom: none; }
.expense-item .icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 12px;
    background: var(--bg);
    flex-shrink: 0;
}
.expense-item .info { flex: 1; min-width: 0; }
.expense-item .info .desc {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.expense-item .info .cat {
    font-size: 13px;
    color: var(--hint);
    margin-top: 2px;
}
.expense-item .amount {
    font-size: 16px;
    font-weight: 700;
    margin-left: 8px;
    white-space: nowrap;
}

/* ========== TAB BAR ========== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 6px 0;
    padding-bottom: max(env(safe-area-inset-bottom), 6px);
    z-index: 100;
}
.tab-bar button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: none;
    background: none;
    color: var(--hint);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 4px;
    transition: color 0.2s;
}
.tab-bar button .icon { font-size: 22px; }
.tab-bar button.active { color: var(--btn); }

/* ========== SHOPPING LIST ========== */
.shop-list {
    padding: 0 16px;
}
.shop-type {
    font-size: 16px;
    font-weight: 700;
    padding: 16px 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.shop-section {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 12px;
}
.shop-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.shop-item:last-child { border-bottom: none; }
.shop-item:active { background: var(--bg); }
.shop-item .check {
    width: 26px;
    height: 26px;
    border: 2px solid var(--border);
    border-radius: 50%;
    margin-right: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    color: transparent;
    transition: all 0.2s;
}
.shop-item .check.done {
    background: var(--green);
    border-color: var(--green);
    color: white;
}
.shop-item.done .name {
    text-decoration: line-through;
    color: var(--hint);
}
.shop-item .name {
    font-size: 16px;
    flex: 1;
}
.shop-item .user {
    font-size: 12px;
    color: var(--hint);
    margin-left: 8px;
}

/* ========== PAGES ========== */
.page { display: none; }
.page.active { display: block; }

/* ========== LOADING / EMPTY ========== */
.loading {
    text-align: center;
    padding: 40px 16px;
    color: var(--hint);
    font-size: 15px;
}
.empty-state {
    text-align: center;
    padding: 60px 16px;
    color: var(--hint);
}
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state .text { font-size: 16px; }

/* ========== FAB BUTTON ========== */
.fab {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--btn);
    color: var(--btn-text);
    border: none;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 50;
    transition: transform 0.2s;
}
.fab:active { transform: scale(0.9); }

/* ========== SWIPE DELETE ========== */
.expense-item {
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}
.expense-item .delete-bg {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

/* ========== CATEGORY LEGEND ========== */
.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    padding: 8px 16px 0;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.legend-amount {
    color: var(--hint);
    font-weight: 500;
}

/* ========== ADD MODAL ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card-bg);
    border-radius: 20px 20px 0 0;
    width: 100%;
    padding: 20px 16px 40px;
    max-height: 80vh;
}
.modal h3 { font-size: 18px; text-align: center; margin-bottom: 16px; }
.modal input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    background: var(--bg);
    color: var(--text);
    margin-bottom: 12px;
    outline: none;
}
.modal input:focus { border-color: var(--btn); }
.modal .btn-row { display: flex; gap: 12px; }
.modal button {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.modal .btn-primary { background: var(--btn); color: var(--btn-text); }
.modal .btn-cancel { background: var(--bg); color: var(--text); }

/* Category selector */
.cat-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0 12px;
    -webkit-overflow-scrolling: touch;
}
.cat-chip {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.cat-chip.active {
    border-color: var(--btn);
    background: var(--btn);
    color: var(--btn-text);
}

/* Swipe to delete */
.expense-item-wrap {
    position: relative;
    overflow: hidden;
}
.expense-item-wrap .swipe-delete {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 80px;
    background: var(--red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.expense-item-wrap .swipe-edit {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 80px;
    background: var(--btn);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.expense-item-wrap .expense-item {
    position: relative;
    z-index: 1;
    background: var(--card-bg);
    transition: transform 0.2s;
}
