:root {
    /* 🔥 ФОН СТАВ СВІТЛІШИМ (був #000000) */
    --bg-color: #121214;
    --bg-card: #1c1c1e;
    --text-main: #ffffff;
    --text-sec: #8e8e93;
    --accent: #ffd60a;
    --danger: #ff453a;
    --green: #32d74b;
    --blue: #0a84ff;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    max-width: 100vw;
    user-select: none;
}

.view {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    width: 100%;
    padding-bottom: 0;
}

.view.active {
    display: flex;
}

/* TABS */
.tabs {
    display: flex;
    justify-content: center;
    padding: 15px 0;
    background-color: var(--bg-color);
    width: 100%;
}
.tab {
    margin: 0 15px;
    color: var(--text-sec);
    font-weight: 600;
    padding-bottom: 5px;
    cursor: pointer;
}
.tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}

/* GRID (Categories) */
.grid-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px 10px;
    padding: 10px 15px;
    align-content: start;
    width: 100%;
}
.category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}
.icon-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 8px;
    border: 2px solid transparent;
    transition: 0.2s;
}
.category-item.selected .icon-circle {
    border-color: var(--accent);
    background-color: #333;
    transform: scale(1.05);
}
.cat-name {
    font-size: 11px;
    color: var(--text-sec);
    text-align: center;
    max-width: 70px;
    line-height: 1.1;
}
.category-item.selected .cat-name {
    color: #fff;
}

/* INPUT */
.amount-area {
    background-color: var(--bg-card);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 20px 20px 0 0;
    position: relative;
    width: 100%;
}
.date-btn {
    background: #2c2c2e;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text-sec);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
#dateInput {
    position: absolute;
    opacity: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}
.input-display {
    display: flex;
    align-items: baseline;
}
.val {
    font-size: 32px;
    font-weight: 700;
}
.cur {
    font-size: 18px;
    color: var(--text-sec);
    margin-left: 5px;
}

/* KEYPAD */
.keypad {
    background-color: var(--bg-card);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 5px 10px 10px;
    gap: 8px;
    width: 100%;
}
.key {
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background-color: #2c2c2e;
    border-radius: 12px;
    cursor: pointer;
}
.key:active {
    background-color: #3a3a3c;
}
.key-yellow {
    background-color: var(--accent);
    color: #000;
    font-weight: 600;
}

/* BALANCE */
.balance-container {
    padding: 20px;
    padding-bottom: 0;
    width: 100%;
}
.cards-scroll {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 15px;
    scrollbar-width: none;
    width: 100%;
}
.cards-scroll::-webkit-scrollbar {
    display: none;
}

.balance-card {
    min-width: 210px;
    flex: 0 0 auto;

    background: var(--bg-card);
    border-radius: 22px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid #333;
}

.balance-card.primary {
    background: linear-gradient(135deg, #333, #1c1c1e);
    border-color: #555;
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.bc-title {
    font-size: 13px;
    color: var(--text-sec);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bc-amount {
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
    line-height: normal;
    margin-top: 2px;
}
.bc-amount.accent {
    color: var(--accent);
}
.bc-amount.danger {
    color: var(--danger);
}
.btn-card-add {
    width: 32px;
    height: 32px;
    background: rgba(255, 214, 10, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    transition: 0.2s;
}
.btn-card-add:active {
    background: var(--accent);
    color: #000;
    transform: scale(0.9);
}

.section-block {
    background-color: var(--bg-card);
    border-radius: 20px;
    padding: 15px;
    margin-bottom: 25px;
}
.section-header {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.switcher {
    display: flex;
    background: #2c2c2e;
    border-radius: 10px;
    padding: 2px;
}
.sw-btn {
    flex: 1;
    text-align: center;
    font-size: 12px;
    padding: 6px;
    border-radius: 8px;
    color: var(--text-sec);
    cursor: pointer;
    transition: 0.2s;
}
.sw-btn.active {
    background: #636366;
    color: #fff;
    font-weight: 600;
}

/* LIST ITEM (HISTORY) */
.list-item {
    padding: 12px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #2c2c2e;
    cursor: pointer;
}
.list-item:last-child {
    border-bottom: none;
}
.li-name {
    font-size: 15px;
    font-weight: 500;
}
.li-sub {
    font-size: 12px;
    color: var(--text-sec);
}

.li-right {
    font-size: 15px;
    font-weight: 600;

    padding: 8px 12px;
    border-radius: 10px;
    min-width: 85px;
    text-align: center;

    display: flex;
    justify-content: center;
    align-items: center;
    line-height: normal;
    font-variant-numeric: tabular-nums;
}

/* STICKER COLORS */
.val-inc { color: var(--green); background: rgba(50, 215, 75, 0.15); }
.val-cash { color: var(--accent); background: rgba(255, 214, 10, 0.15); }
.val-bank { color: var(--danger); background: rgba(255, 69, 58, 0.15); }
.val-plain { color: #fff; background: transparent; padding: 0; text-align: right; }

/* DATE HEADER */
.date-header {
    text-align: center;
    font-size: 12px;
    color: var(--text-sec);
    font-weight: 600;
    margin: 15px 0 5px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ANALYTICS */
.analytics-header {
    text-align: center;
    margin-bottom: 10px;
}
.chart-container {
    position: relative;
    height: 260px;
    width: 100%;
    margin: 10px 0;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

canvas {
    max-width: 100% !important;
    height: auto !important;
}

.analytics-list {
    margin-top: 20px;
    padding: 10px !important;
}
.analytics-legend-item {
    margin-bottom: 16px;
    padding: 4px 0;
}

/* NAV */
.bottom-nav {
    background-color: #121212;
    padding: 10px 0 20px;
    display: flex;
    justify-content: space-around;
    border-top: 1px solid #333;
    width: 100%;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-sec);
    font-size: 10px;
    cursor: pointer;
    width: 33%;
}
.nav-item.active {
    color: var(--accent);
}
.nav-icon {
    font-size: 24px;
}

/* MODALS */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}
.modal {
    background: #2c2c2e;
    width: 85%;
    max-width: 320px;
    border-radius: 25px;
    padding: 25px;
    text-align: center;
}
.modal-input {
    width: 100%;
    background: #1c1c1e;
    border: 1px solid #444;
    color: #fff;
    padding: 12px;
    border-radius: 12px;
    font-size: 18px;
    margin-bottom: 20px;
    box-sizing: border-box;
    text-align: center;
}
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}
.btn-primary { background: var(--accent); color: #000; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-cancel { background: #444; color: #fff; }
.piggy-menu-btn {
    display: block;
    width: 100%;
    padding: 15px;
    margin-bottom: 10px;
    background: #3a3a3c;
    color: #fff;
    border-radius: 12px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

/* CAT SELECT GRID */
.cat-select-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
    max-height: 300px;
    overflow-y: auto;
}
.cat-select-btn {
    background: #3a3a3c;
    color: #fff;
    padding: 10px 5px;
    border-radius: 12px;
    font-size: 12px;
    text-align: center;
    cursor: pointer;
    border: 1px solid #444;
    transition: 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}
.cat-select-btn .cat-icon {
    font-size: 24px;
    margin-bottom: 5px;
}
.cat-select-btn:active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    transform: scale(0.95);
}

/* CREDITS */
.total-debt-block {
    background: linear-gradient(135deg, #ff3b30 0%, #ff9500 100%);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    color: white;
    margin-bottom: 24px;
    box-shadow: 0 8px 20px rgba(255, 59, 48, 0.25);
}
.credit-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 40px;
}
.credit-row {
    background-color: #1c1c1e;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
    cursor: pointer;
}
.credit-row:active {
    background-color: #2c2c2e;
}
.cr-left {
    display: flex;
    align-items: center;
    gap: 14px;
}
.cr-icon {
    width: 44px;
    height: 44px;
    background-color: #2c2c2e;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}
.cr-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cr-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}
.credit-payment-info {
    font-size: 13px;
    color: #32d74b;
    font-weight: 500;
}
.credit-val {
    font-size: 16px;
    font-weight: 700;
    color: #ff453a;
}
.credit-val.positive {
    color: #32d74b;
}

/* 🔥 PIGGY REDESIGN (СУМА СПРАВА) */
.piggy-block {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 12px;
    margin-bottom: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.piggy-header-text {
    text-align: left;
    padding-left: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #ff9f0a;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* Сама картка */
.piggy-card {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(255, 159, 10, 0.2) 100%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 14px;
    padding: 10px 12px;
    margin-bottom: 6px;

    display: flex;
    align-items: center;
    justify-content: space-between; /* Розносить ліву і праву частину */
    cursor: pointer;
    transition: 0.2s;
}
.piggy-card:active {
    transform: scale(0.98);
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.3) 0%, rgba(255, 159, 10, 0.3) 100%);
}

/* Ліва частина: Іконка + Назва */
.piggy-left-part {
    display: flex;
    align-items: center;
    overflow: hidden; /* Щоб довга назва не ламала верстку */
}

.piggy-icon-box {
    font-size: 18px;
    margin-right: 10px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.piggy-name-text {
    font-family: -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    font-size: 15px;
    font-weight: 800;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.3px;
}

/* 🔥 ПРАВА ЧАСТИНА: СУМА В ПЛАШЦІ (ЯК В ІСТОРІЇ) */
.piggy-amount-box {
    background: rgba(50, 215, 75, 0.15); /* Зелений фон */
    color: #32d74b; /* Зелений текст */
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    margin-left: 10px;
}

/* Кнопка */
.btn-create-piggy {
    width: 100%;
    margin-top: 8px;
    padding: 10px 0;
    background: var(--accent);
    color: #000000;
    border: none;
    box-shadow: 0 2px 10px rgba(255, 214, 10, 0.2);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: 0.2s;
}
.btn-create-piggy:active {
    transform: scale(0.98);
    opacity: 0.9;
}