/* ============================== Reset & Base ============================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0a14;
    --surface: #13131c;
    --surface-2: #1c1c28;
    --surface-3: #252533;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.14);
    --text: #ffffff;
    --text-2: #8e8e9a;
    --text-3: #5a5a6e;
    --primary: #ffffff;
    --primary-text: #0a0a14;
    --income: #06ffa5;
    --expense: #ff5a5f;
    --radius: 16px;
    --radius-lg: 20px;
    --nav-height: 76px;
}

html, body {
    height: 100%;
    background: #000;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    overscroll-behavior: none;
}

button {
    font-family: inherit;
}

input, select, textarea {
    font-family: inherit;
}

/* ============================== App Container ============================== */
body {
    display: flex;
    justify-content: center;
    background: #000;
}

.app {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    position: relative;
    overflow: hidden;
}

/* ============================== Views ============================== */
.view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: var(--nav-height);
    display: none;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 20px;
}

.view.active {
    display: flex;
    animation: viewIn 0.3s ease;
}

.view-add {
    bottom: 0;
    padding: 0;
}

@keyframes viewIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================== Top Bar ============================== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 12px;
    flex-shrink: 0;
}

.user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff006e 0%, #3a86ff 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 14px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.welcome {
    font-size: 12px;
    color: var(--text-2);
    margin-bottom: 2px;
}

.username {
    font-size: 15px;
    font-weight: 600;
}

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.icon-btn:active {
    transform: scale(0.92);
    background: var(--surface-2);
}

/* ============================== Iridescent Card ============================== */
.iridescent {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    isolation: isolate;
}

.iridescent-bg {
    position: absolute;
    inset: -20px;
    background:
        radial-gradient(ellipse 60% 80% at 15% 10%, #ff006e 0%, transparent 55%),
        radial-gradient(ellipse 60% 80% at 85% 20%, #ffbe0b 0%, transparent 55%),
        radial-gradient(ellipse 60% 80% at 50% 90%, #3a86ff 0%, transparent 60%),
        radial-gradient(ellipse 60% 80% at 100% 60%, #06ffa5 0%, transparent 55%),
        radial-gradient(ellipse 60% 80% at 0% 70%, #8338ec 0%, transparent 55%);
    filter: blur(28px) saturate(1.2);
    z-index: -1;
    animation: iridescentShift 12s ease-in-out infinite alternate;
}

@keyframes iridescentShift {
    0% { transform: scale(1) rotate(0deg); }
    100% { transform: scale(1.08) rotate(3deg); }
}

/* ============================== Balance Card ============================== */
.balance-card {
    margin: 4px 0 20px;
    height: 180px;
    flex-shrink: 0;
}

.balance-content {
    position: relative;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: rgba(10, 10, 20, 0.35);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-lg);
}

.card-row, .balance-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.card-toggle, .balance-toggle {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: all 0.15s;
}

.card-toggle:active, .balance-toggle:active {
    transform: scale(0.9);
}

.balance-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 4px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.balance-amount {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.8px;
    background: linear-gradient(135deg, #fff 0%, rgba(255, 255, 255, 0.75) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.balance-amount.hidden {
    letter-spacing: 2px;
}

/* ============================== Quick Actions ============================== */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 28px;
    flex-shrink: 0;
}

.action-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 8px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.action-btn:active {
    transform: scale(0.96);
    background: var(--surface-2);
}

.action-btn.primary {
    background: var(--primary);
    color: var(--primary-text);
    border-color: var(--primary);
    font-weight: 600;
}

.action-btn.primary:active {
    background: rgba(255, 255, 255, 0.85);
}

.action-icon {
    font-size: 20px;
    line-height: 1;
}

/* ============================== Recent Section ============================== */
.recent-section {
    flex: 1;
    min-height: 0;
    padding-bottom: 20px;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 14px;
}

.section-title h2 {
    font-size: 17px;
    font-weight: 600;
}

.view-all {
    background: none;
    border: none;
    color: var(--text-2);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

.transaction-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.transaction-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.15s;
}

.transaction-item:active {
    background: var(--surface-2);
    transform: scale(0.99);
}

.transaction-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

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

.transaction-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-meta {
    font-size: 12px;
    color: var(--text-2);
}

.transaction-amount {
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.transaction-amount.income { color: var(--income); }
.transaction-amount.expense { color: var(--expense); }

.empty-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-2);
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-hint {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 4px;
}

/* ============================== Add View ============================== */
.add-amount-card {
    height: 300px;
    flex-shrink: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    margin-bottom: 24px;
}

.add-amount-content {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(10, 10, 20, 0.35);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    padding: 60px 20px 40px;
}

.amount-display {
    font-size: 60px;
    font-weight: 700;
    letter-spacing: -1.5px;
    background: linear-gradient(135deg, #fff 0%, rgba(255, 255, 255, 0.75) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-align: center;
    line-height: 1;
}

.change-amount-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 18px;
    border-radius: 20px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.15s;
}

.change-amount-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.25);
}

.add-form {
    padding: 0 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field-grow {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.field-grow .field-control {
    flex: 1;
    align-items: stretch;
}

.type-toggle {
    display: flex;
    gap: 6px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    border: 1px solid var(--border);
}

.type-btn {
    flex: 1;
    padding: 11px;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-2);
    transition: all 0.15s;
}

.type-btn.active {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
}

.type-btn.active[data-type="expense"] {
    color: var(--expense);
}

.type-btn.active[data-type="income"] {
    color: var(--income);
}

.field label {
    display: block;
    font-size: 12px;
    color: var(--text-2);
    margin-bottom: 6px;
    font-weight: 500;
}

.field-control {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    min-height: 48px;
    transition: border-color 0.15s;
}

.field-control:focus-within {
    border-color: rgba(255, 255, 255, 0.3);
}

.field-control select,
.field-control input,
.field-control textarea {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    width: 100%;
    color-scheme: dark;
}

.field-control select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    cursor: pointer;
}

.field-control textarea {
    resize: none;
    min-height: 80px;
    padding: 12px 16px;
    line-height: 1.5;
}

.field-chevron, .field-icon {
    position: absolute;
    right: 14px;
    color: var(--text-2);
    font-size: 14px;
    pointer-events: none;
}

.add-actions {
    display: flex;
    gap: 10px;
    padding: 16px 20px 20px;
    flex-shrink: 0;
}

.add-action-btn {
    flex: 1;
    height: 56px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.add-action-btn:active {
    transform: scale(0.95);
    background: var(--surface-2);
}

.add-action-btn.confirm {
    background: var(--primary);
    color: var(--primary-text);
    border-color: var(--primary);
    font-weight: 700;
    font-size: 26px;
}

.add-action-btn.confirm:active {
    background: rgba(255, 255, 255, 0.85);
}

/* ============================== Number Pad ============================== */
.number-pad {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding: 16px 20px 24px;
    max-width: 480px;
    margin: 0 auto;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    pointer-events: none;
}

.number-pad.open {
    transform: translateY(0);
    pointer-events: auto;
}

.number-pad-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    height: 44px;
}

.number-pad-title {
    font-size: 15px;
    font-weight: 600;
}

.number-pad-spacer {
    width: 44px;
}

.number-pad-close {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-pad-close:active {
    transform: scale(0.92);
}

.number-pad-display {
    text-align: center;
    font-size: 64px;
    font-weight: 700;
    padding: 40px 0 32px;
    letter-spacing: -1.5px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.number-pad-keys {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 380px;
    margin: 0 auto;
    width: 100%;
    align-content: center;
}

.num-key {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 28px;
    font-weight: 500;
    cursor: pointer;
    height: 64px;
    transition: all 0.08s;
}

.num-key:active {
    background: var(--surface-2);
    transform: scale(0.96);
}

.number-pad-done {
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    flex-shrink: 0;
    transition: all 0.15s;
}

.number-pad-done:active {
    background: rgba(255, 255, 255, 0.85);
    transform: scale(0.99);
}

/* ============================== Analytics ============================== */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 12px;
    flex-shrink: 0;
}

.analytics-header h1 {
    font-size: 17px;
    font-weight: 600;
}

.analytics-tabs {
    display: flex;
    gap: 6px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    border: 1px solid var(--border);
    margin-bottom: 24px;
    flex-shrink: 0;
}

.tab {
    flex: 1;
    padding: 11px;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-2);
    transition: all 0.15s;
}

.tab.active {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
}

.tab.active[data-tab="expense"] {
    color: var(--expense);
}

.tab.active[data-tab="income"] {
    color: var(--income);
}

.analytics-summary {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.analytics-amount {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.8px;
}

.period-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
}

.period-btn:active {
    transform: scale(0.95);
    background: var(--surface-2);
}

.period-chevron {
    font-size: 9px;
    opacity: 0.7;
    transition: transform 0.2s;
}

.period-btn[aria-expanded="true"] .period-chevron {
    transform: rotate(180deg);
}

.period-wrapper {
    position: relative;
}

.period-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface-2);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 6px;
    z-index: 60;
    display: none;
    min-width: 150px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.period-popover.open {
    display: block;
    animation: popIn 0.15s ease;
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.period-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-2);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.1s;
}

.period-option:active { background: var(--surface-3); }

.period-option.active {
    color: var(--text);
    background: var(--surface-3);
    font-weight: 600;
}

.bar-chart {
    display: flex;
    gap: 6px;
    height: 200px;
    align-items: end;
    margin-bottom: 24px;
    flex-shrink: 0;
    padding: 4px 4px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
    -webkit-overflow-scrolling: touch;
    justify-content: safe center;
}

.bar-chart::-webkit-scrollbar { height: 4px; }
.bar-chart::-webkit-scrollbar-track { background: transparent; }
.bar-chart::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

.bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
    justify-content: end;
    flex: 0 0 var(--bar-width, 36px);
    min-width: var(--bar-width, 36px);
}

.bar-value {
    font-size: 9px;
    color: var(--text-2);
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 100%;
    text-align: center;
}

.bar {
    width: 100%;
    max-width: 32px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-height: 4px;
    transition: height 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

.bar.today {
    background: linear-gradient(180deg, #ff006e 0%, #8338ec 50%, #3a86ff 100%);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 16px rgba(255, 0, 110, 0.4);
}

.bar-label {
    font-size: 11px;
    color: var(--text-2);
    font-weight: 500;
}

.bar-label.today {
    color: var(--text);
    font-weight: 700;
}

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-bottom: 20px;
    flex-shrink: 0;
}

.category-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: all 0.15s;
}

.category-card:active {
    transform: scale(0.98);
    background: var(--surface-2);
}

.category-name {
    font-size: 12px;
    color: var(--text-2);
    margin-bottom: 6px;
    font-weight: 500;
}

.category-amount {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.category-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px 20px;
    color: var(--text-2);
    font-size: 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ============================== Bottom Nav ============================== */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(19, 19, 28, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 50;
}

.nav-item {
    background: none;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: var(--text-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

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

.nav-item.active {
    color: var(--text);
    background: var(--surface-2);
}

.nav-item.nav-add {
    background: var(--primary);
    color: var(--primary-text);
    width: 56px;
    height: 56px;
    box-shadow: 0 4px 16px rgba(255, 255, 255, 0.15);
}

.nav-item.nav-add.active {
    background: var(--primary);
    color: var(--primary-text);
}

.nav-item.nav-add:active {
    transform: scale(0.92);
}

/* ============================== Toast ============================== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface-2);
    color: var(--text);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    z-index: 300;
    opacity: 0;
    transition: all 0.25s ease;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================== Responsive tweaks ============================== */
@media (min-width: 481px) {
    .app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

@media (max-height: 700px) {
    .balance-card { height: 160px; }
    .add-amount-card { height: 240px; }
    .amount-display { font-size: 52px; }
    .bar-chart { height: 160px; }
}
