/* ===== Theme Variables (default = minimal) ===== */
:root {
    --primary: #2563EB;
    --bg: #F8FAFC;
    --card: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #94A3B8;
    --income: #22D3A0;
    --expense: #EF4444;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --font: -apple-system, 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ===== App Shell ===== */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 500px;
    margin: 0 auto;
    background: var(--bg);
}

.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    padding-bottom: 4px;
}

.page-header {
    display: none; /* Mobile: title in each page */
}

.page-body {
    min-height: 100%;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 12px 0 env(safe-area-inset-bottom, 12px);
    background: var(--card);
    border-top: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 500px;
    margin: 0 auto;
    z-index: 100;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 18px;
    border-radius: 10px;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: var(--primary);
    font-weight: 600;
}

.nav-icon { font-size: 24px; line-height: 1; }
.nav-label { font-size: 11px; }

/* ===== Auth Page ===== */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 90vh;
    padding: 20px;
}

.auth-card {
    background: var(--card);
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    text-align: center;
}

.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-title { font-size: 22px; font-weight: 700; color: var(--text); }
.auth-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }

.auth-input {
    width: 100%;
    padding: 12px 14px;
    margin: 6px 0;
    border: 1.5px solid #E2E8F0;
    border-radius: 10px;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}

.auth-input:focus { border-color: var(--primary); }

.auth-btn {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.auth-btn:disabled { opacity: 0.6; }

.auth-link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 14px;
    margin-top: 12px;
    cursor: pointer;
}

/* ===== Sections ===== */
.section { margin-bottom: 16px; }
.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.3px;
}

/* ===== Task Items ===== */
.task-item {
    background: var(--card);
    margin: 4px 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    transition: all 0.15s;
}

.task-check {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2px solid #CBD5E1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    color: white;
    transition: all 0.15s;
}

.task-check.done {
    background: var(--income);
    border-color: var(--income);
}

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 500; }
.task-title.done { text-decoration: line-through; opacity: 0.5; }
.task-time { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.task-time.overdue { color: var(--expense); font-weight: 500; }

.task-priority { font-size: 12px; min-width: 18px; text-align: center; }

/* ===== Transaction Items ===== */
.txn-item {
    background: var(--card);
    margin: 4px 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
}

.txn-icon {
    width: 34px; height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.03);
}

.txn-info { flex: 1; min-width: 0; }
.txn-name { font-size: 13px; font-weight: 500; }
.txn-cat { font-size: 11px; color: var(--text-secondary); }

.txn-amount { font-size: 14px; font-weight: 600; white-space: nowrap; }
.txn-amount.income { color: var(--income); }
.txn-amount.expense { color: var(--expense); }

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid #E2E8F0;
    background: var(--card);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== Type Toggle Single ===== */
.type-toggle-single {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border: 1.5px solid #E2E8F0;
    border-radius: 10px;
    background: var(--card);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}
.type-toggle-single.expense {
    border-color: var(--expense);
    background: color-mix(in srgb, var(--expense) 12%, var(--card));
}
.type-toggle-single.income {
    border-color: var(--income);
    background: color-mix(in srgb, var(--income) 12%, var(--card));
}
.type-toggle-single .toggle-icon { font-size: 16px; line-height: 1; }
.type-toggle-single .toggle-label { font-size: 13px; font-weight: 600; color: var(--text); }
.type-toggle-single .toggle-arrow { font-size: 12px; color: var(--text-secondary); opacity: 0.5; }

/* ===== Add Bar ===== */
.add-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    align-items: center;
}

.add-input {
    flex: 1;
    padding: 10px 12px;
    border: 1.5px solid #E2E8F0;
    border-radius: 10px;
    font-size: 14px;
    background: var(--card);
    color: var(--text);
    outline: none;
    min-width: 0;
}

.add-input.date-input {
    max-width: 140px;
    font-size: 13px;
    flex: none;
}

.add-input:focus { border-color: var(--primary); }
.add-input.amount { max-width: 100px; text-align: right; }
/* Hide number spinners on amount field */
.add-input.amount::-webkit-outer-spin-button,
.add-input.amount::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.add-input.amount[type="number"] {
    -moz-appearance: textfield;
}

.add-select {
    padding: 10px 8px;
    border: 1.5px solid #E2E8F0;
    border-radius: 10px;
    font-size: 13px;
    background: var(--card);
    color: var(--text);
    outline: none;
}

.add-btn {
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
}

/* ===== Calendar ===== */
.cal-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 8px;
}

.cal-month-title {
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 12px;
}

.cal-day-header {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 6px 0;
}

.cal-day {
    text-align: center;
    padding: 8px 0;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}

.cal-day:hover { background: rgba(0,0,0,0.04); }
.cal-day.today { background: var(--primary); color: white; font-weight: 700; }
.cal-day.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-day.has-events { font-weight: 600; }

.cal-dot {
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--primary);
    margin: 2px auto 0;
}

/* ===== View Switcher ===== */
.view-switcher {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}
.view-btn {
    flex: 1;
    padding: 6px;
    border: 1.5px solid #E2E8F0;
    border-radius: 8px;
    background: var(--card);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.view-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== Day / Agenda View ===== */
.day-view { padding: 0 0 12px 0; }
.day-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.day-view-date { font-size: 16px; font-weight: 600; }
.day-section { margin-bottom: 12px; }
.day-section-title { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }

.timeline { position: relative; padding-left: 60px; }
.timeline-item {
    display: flex;
    margin-bottom: 12px;
    cursor: pointer;
    position: relative;
}
.timeline-time {
    position: absolute;
    left: -60px;
    width: 52px;
    text-align: right;
    padding-top: 2px;
}
.timeline-hour { font-size: 13px; font-weight: 600; color: var(--text); }
.timeline-end { font-size: 10px; color: var(--text-secondary); }
.timeline-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 16px;
    flex-shrink: 0;
    margin-right: 8px;
}
.timeline-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    z-index: 1;
    flex-shrink: 0;
}
.timeline-bar {
    width: 2px;
    flex: 1;
    min-height: 30px;
    border-radius: 1px;
}
.timeline-card {
    flex: 1;
    background: var(--card);
    padding: 8px 10px;
    border-radius: 8px;
    border-left: 3px solid;
    box-shadow: var(--shadow);
}
.timeline-card-title { font-size: 13px; font-weight: 500; }

/* ===== Year View ===== */
.year-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.year-month {
    padding: 12px 8px;
    border-radius: 10px;
    background: var(--card);
    text-align: center;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all 0.15s;
    box-shadow: var(--shadow);
}
.year-month:hover { border-color: var(--primary); }
.year-month.current { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--card)); }
.year-month-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal-card {
    background: var(--card);
    border-radius: 16px 16px 0 0;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}
.modal-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 12px;
}

/* ===== Color Picker ===== */
.color-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}
.color-swatch.active {
    border-color: var(--text);
    transform: scale(1.2);
}

/* ===== Toggle Label ===== */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

/* ===== Theme Selector ===== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.theme-card {
    padding: 16px;
    border-radius: 14px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}

.theme-card.active {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px var(--primary);
}

/* ===== Summary Row ===== */
.summary-row {
    display: flex;
    gap: 8px;
}

.summary-card {
    flex: 1;
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.summary-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
.summary-value { font-size: 16px; font-weight: 700; }
.summary-value.income { color: var(--income); }
.summary-value.expense { color: var(--expense); }

/* ===== Common ===== */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

.center-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: white;
    text-decoration: none;
    display: inline-block;
}

.btn-danger {
    background: var(--expense);
    margin-top: 12px;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
}

.btn-icon:hover { opacity: 1; }

.toggle-chip {
    padding: 3px 10px;
    border-radius: 12px;
    border: 1.5px solid #E2E8F0;
    background: var(--card);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.toggle-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 8px;
}

.alert-error {
    background: rgba(239,68,68,0.1);
    color: var(--expense);
    border: 1px solid rgba(239,68,68,0.2);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 4px; }

/* ===== Blazor Error UI ===== */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ===== Loading Spinner ===== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 隱藏 Blazor 內建 loading 動畫 */
.loading-progress,
.loading-progress-text {
    display: none;
}

#app {
    min-height: 100dvh;
    background: var(--bg, #F8FAFC);
}

/* ===== Reports / Charts ===== */
.trend-chart {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.trend-bar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.trend-label {
    font-size: 10px;
    color: var(--text-secondary);
    width: 48px;
    flex-shrink: 0;
}

.trend-bars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.trend-row {
    height: 16px;
    position: relative;
}

.trend-bar {
    height: 100%;
    border-radius: 3px;
    min-width: 2px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 4px;
    transition: width 0.3s ease;
}

.trend-bar.inc { background: var(--income); }
.trend-bar.exp { background: var(--expense); }

.trend-bar span {
    font-size: 9px;
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.trend-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

.trend-legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.trend-legend .dot.inc { background: var(--income); }
.trend-legend .dot.exp { background: var(--expense); }

/* Category chart */
.cat-chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.cat-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cat-label {
    width: 80px;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.cat-amount {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 600;
}

.cat-bar-bg {
    flex: 1;
    height: 20px;
    background: var(--card);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);
}

.cat-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--income));
    border-radius: 10px;
    transition: width 0.3s ease;
    min-width: 4px;
}

.cat-pct {
    width: 40px;
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
}

/* Toggle chip */
.toggle-chip {
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}

.toggle-chip.active {
    background: var(--primary);
    color: #fff;
}

/* ===== Add Section (card-style input area) ===== */
.add-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 8px 10px;
    box-shadow: var(--shadow);
    margin-bottom: 8px;
}

/* ===== Pie Charts ===== */
.pie-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}

.pie-svg {
    width: 160px;
    height: 160px;
    flex-shrink: 0;
}

.pie-legend {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text);
    line-height: 1.3;
}

.legend-item span:last-child {
    word-break: break-all;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
