/* =========================================================
   MyFinance Web App — Light Blue Telegram Theme
   ========================================================= */

/* ===== CSS VARIABLES ===== */
:root {
    /* Brand palette */
    --blue-primary: #2B7EFA;
    --blue-dark: #1A5FCC;
    --blue-light: #5B9BFB;
    --blue-bg: #EEF4FF;
    --blue-card: #DDEAFF;

    --orange: #FF7D3B;
    --orange-light: #FFF0E8;
    --green: #2DC98E;
    --green-light: #E6FAF3;
    --red: #F25C5C;
    --red-light: #FFECEC;
    --yellow: #F5A623;
    --yellow-light: #FFF8E8;
    --purple: #7B61FF;
    --purple-light: #F0EDFF;

    /* Neutrals */
    --white: #FFFFFF;
    --bg: #F2F6FF;
    --surface: #FFFFFF;
    --border: #E0E9FF;
    --text-primary: #1A2340;
    --text-secondary: #6B7A99;
    --text-hint: #A3B0CC;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(43, 126, 250, 0.10);
    --shadow-md: 0 4px 20px rgba(43, 126, 250, 0.14);
    --shadow-lg: 0 8px 32px rgba(43, 126, 250, 0.18);

    /* Spacing */
    --nav-height: 68px;
    --nav-safe: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ===== LAYOUT ===== */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    /* Extra bottom padding = nav bar + safe area + buffer so last card is never hidden */
    padding: 0 0 calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px) 0;
}

/* ===== HEADER HERO ===== */
.hero {
    background: linear-gradient(135deg, var(--blue-primary) 0%, var(--blue-light) 100%);
    padding: 20px 20px 56px;
    position: relative;
    overflow: hidden;
}

.hero::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg);
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.hero-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.hero-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-weight: 700;
    font-size: 17px;
}

.hero-logo-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.hero-greeting {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    margin-bottom: 4px;
}

.hero-title {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
}

/* ===== METRIC CARDS ROW ===== */
.metric-row {
    display: flex;
    gap: 10px;
}

.metric-card {
    flex: 1;
    border-radius: var(--radius-md);
    padding: 14px 14px 12px;
    color: #fff;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
}

.metric-card.income {
    background: linear-gradient(135deg, #2DC98E, #22A876);
}

.metric-card.expense {
    background: linear-gradient(135deg, #FF7D3B, #E8612A);
}

.metric-card.savings {
    background: linear-gradient(135deg, #7B61FF, #5B3FE0);
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.85;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.metric-value {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}

.metric-bar {
    margin-top: 8px;
    height: 4px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 99px;
    overflow: hidden;
}

.metric-bar-fill {
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 99px;
}

/* ===== CONTENT AREA ===== */
.content {
    padding: 0 16px;
    margin-top: -16px;
    position: relative;
    z-index: 2;
    /* Always leave room for fixed nav + safe area */
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 32px);
}

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.card-link {
    font-size: 13px;
    color: var(--blue-primary);
    font-weight: 500;
    text-decoration: none;
}

/* ===== TIP CARD ===== */
.tip-card {
    background: var(--yellow-light);
    border: 1px solid #FAEA9A;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.tip-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.tip-title {
    font-size: 13px;
    font-weight: 700;
    color: #8B6200;
    margin-bottom: 4px;
}

.tip-text {
    font-size: 13px;
    color: #7A5500;
    line-height: 1.4;
}

/* ===== SECTION TITLE ===== */
.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ===== TRANSACTION LIST ===== */
.tx-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tx-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.tx-item:last-child {
    border-bottom: none;
}

.tx-icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.tx-icon.food {
    background: var(--orange-light);
}

.tx-icon.transport {
    background: var(--blue-card);
}

.tx-icon.health {
    background: var(--green-light);
}

.tx-icon.fun {
    background: var(--purple-light);
}

.tx-icon.income {
    background: var(--green-light);
}

.tx-icon.other {
    background: #F5F5F5;
}

.tx-info {
    flex: 1;
    min-width: 0;
}

.tx-cat {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.tx-desc {
    font-size: 12px;
    color: var(--text-hint);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-right-col {
    text-align: right;
    flex-shrink: 0;
}

.tx-amount {
    font-size: 14px;
    font-weight: 700;
}

.tx-date {
    font-size: 11px;
    color: var(--text-hint);
    margin-top: 1px;
}

.tx-amount.expense {
    color: var(--red);
}

.tx-amount.income {
    color: var(--green);
}

.tx-loading {
    text-align: center;
    color: var(--text-hint);
    font-size: 14px;
    padding: 24px 0;
}

/* ===== GOAL CARD ===== */
.goal-item {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.goal-item:last-child {
    border-bottom: none;
}

.goal-emoji {
    font-size: 32px;
    width: 52px;
    height: 52px;
    background: var(--blue-bg);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.goal-info {
    flex: 1;
    min-width: 0;
}

.goal-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 6px;
}

.goal-amounts {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.goal-amounts b {
    color: var(--blue-primary);
}

.goal-bar-track {
    height: 6px;
    background: var(--blue-bg);
    border-radius: 99px;
    overflow: hidden;
}

.goal-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue-primary), var(--blue-light));
    border-radius: 99px;
    transition: width 0.7s cubic-bezier(.4, 0, .2, 1);
}

.goal-bar-fill.done {
    background: linear-gradient(90deg, var(--green), #22A876);
}

.goal-pct {
    font-size: 13px;
    font-weight: 700;
    color: var(--blue-primary);
    flex-shrink: 0;
}

.goal-pct.done {
    color: var(--green);
}

/* ===== BUDGET BARS ===== */
.budget-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.budget-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.budget-item:last-child {
    border-bottom: none;
}

.budget-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.budget-cat {
    font-size: 14px;
    font-weight: 600;
}

.budget-amounts {
    font-size: 12px;
    color: var(--text-secondary);
}

.budget-amounts b {
    color: var(--text-primary);
    font-weight: 700;
}

.budget-bar-track {
    height: 8px;
    background: var(--blue-bg);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 4px;
}

.budget-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s cubic-bezier(.4, 0, .2, 1);
    background: linear-gradient(90deg, var(--blue-primary), var(--blue-light));
}

.budget-bar-fill.warn {
    background: linear-gradient(90deg, var(--yellow), #F5C842);
}

.budget-bar-fill.over {
    background: linear-gradient(90deg, var(--red), #F04040);
}

.budget-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.budget-pct {
    font-size: 12px;
    font-weight: 600;
}

.budget-pct.ok {
    color: var(--blue-primary);
}

.budget-pct.warn {
    color: var(--yellow);
}

.budget-pct.over {
    color: var(--red);
}

.budget-remaining {
    font-size: 12px;
    color: var(--text-hint);
}

/* ===== SUMMARY ROW ===== */
.summary-row {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}

.summary-pill {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 12px 14px;
    text-align: center;
}

.summary-pill-label {
    font-size: 11px;
    color: var(--text-hint);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.summary-pill-val {
    font-size: 16px;
    font-weight: 700;
}

.summary-pill-val.income {
    color: var(--green);
}

.summary-pill-val.expense {
    color: var(--red);
}

.summary-pill-val.balance {
    color: var(--blue-primary);
}

/* ===== FORM ELEMENTS ===== */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: block;
}

.form-select,
.form-input {
    width: 100%;
    background: var(--blue-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.form-select:focus,
.form-input:focus {
    border-color: var(--blue-primary);
    background: #fff;
}

.form-row-2 {
    display: flex;
    gap: 10px;
}

.form-row-2>* {
    flex: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue-primary), var(--blue-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    padding: 14px 20px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    width: 100%;
    box-shadow: 0 4px 14px rgba(43, 126, 250, 0.35);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(43, 126, 250, 0.45);
}

.btn-primary:active {
    transform: scale(0.98);
}

.form-status {
    font-size: 13px;
    text-align: center;
    min-height: 18px;
    margin-top: 8px;
    color: var(--green);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--text-hint);
    font-size: 14px;
    line-height: 1.6;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Height + iOS safe area */
    height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    /* items sit at top of padded bar */
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(43, 126, 250, 0.08);
}

.nav-item {
    flex: 1;
    height: var(--nav-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text-hint);
    font-size: 11px;
    font-weight: 500;
    transition: color 0.18s;
    cursor: pointer;
    padding-bottom: 4px;
}

.nav-item:hover {
    color: var(--blue-light);
}

.nav-item.active {
    color: var(--blue-primary);
}

.nav-icon {
    font-size: 24px;
    line-height: 1;
    transition: transform 0.15s;
}

.nav-item.active .nav-icon {
    transform: scale(1.12);
}

.nav-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--blue-primary);
    margin-top: -2px;
    opacity: 0;
    transition: opacity 0.18s;
}

.nav-item.active .nav-dot {
    opacity: 1;
}

/* ===== PAGE HEADER (non-hero pages) ===== */
.page-header {
    background: linear-gradient(135deg, var(--blue-primary), var(--blue-light));
    padding: 20px 20px 52px;
    position: relative;
}

.page-header::after {
    content: '';
    position: absolute;
    bottom: -28px;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg);
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.page-header-title {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
}

.page-header-sub {
    color: rgba(255, 255, 255, 0.75);
    font-size: 13px;
    margin-top: 4px;
}

/* ===== CHART CONTAINER ===== */
.chart-wrap {
    position: relative;
    max-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MISC UTILS ===== */
.mt-1 {
    margin-top: 8px;
}

.mt-2 {
    margin-top: 14px;
}

.text-center {
    text-align: center;
}