/* ============================================================
   AccountEngine — iOS Design System
   Pure CSS, no Bootstrap dependency
   ============================================================ */

/* ── Design Tokens ── */
:root {
    color-scheme: light dark;
    /* ── iOS System Colors ── */
    --ios-expense:   var(--ui-danger);
    --ios-income:    var(--ui-success);
    --ios-bg:        var(--color-bg);
    --ios-card:      var(--color-surface);
    --ios-text:      var(--color-text);
    --ios-secondary: var(--color-text-secondary);
    --ios-muted:     var(--color-text-muted);
    --ios-separator: var(--color-separator);
    --ios-fill:      var(--color-fill);
    --ios-blue:      var(--color-primary);
    --ios-orange:    var(--color-warning);
    --ios-purple:    var(--color-accent);
    --ios-red:       var(--ui-danger);
    --ios-green:     var(--ui-success);
    --ios-teal:      var(--color-teal);
    --ios-indigo:    var(--color-indigo);

    /* ── Spacing Scale ── */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    /* ── Border Radius ── */
    --ios-radius:    16px;
    --ios-radius-sm: 12px;
    --ios-radius-xs: 8px;

    /* ── Shadows ── */
    --ios-shadow:    var(--shadow-xs);
    --ios-shadow-md: var(--shadow-md);
    --ios-shadow-lg: var(--shadow-lg);

    /* ── Glassmorphism ── */
    --glass-bg:      var(--nav-glass-bg);
    --glass-border:  var(--nav-glass-border);
    --glass-blur:    saturate(180%) blur(20px);

    /* ── Safe Area / Layout ── */
    --page-padding-x: var(--space-4);   /* 16px edge-to-edge on mobile */
    --page-max-width: 1200px;
    --ios-topbar-height: 0px; /* header 已移除，設為 0 */
    --ae-topbar-height: 56px;
    --ae-topbar-sticky-top: calc(var(--ios-topbar-height) + env(safe-area-inset-top));

    /* ── Typography ── */
    --font-body:    -apple-system, BlinkMacSystemFont, 'Noto Sans TC', 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-mono:    'SF Mono', SFMono-Regular, ui-monospace, Consolas, monospace;

    /* ── App semantic aliases ── */
    --ae-primary:      var(--ios-blue);
    --ae-primary-light: var(--color-primary);
    --ae-primary-dark: var(--color-primary);
    --ae-accent:       var(--ios-purple);
    --ae-success:      var(--ui-success);
    --ae-danger:       var(--ui-danger);
    --ae-warning:      var(--ios-orange);
    --ae-info:         var(--ios-blue);
    --ae-bg:           var(--ios-bg);
    --ae-card-bg:      var(--ios-card);
    --ae-border:       var(--ios-separator);
    --ae-text:         var(--ios-text);
    --ae-text-muted:   var(--ios-muted);
    --ae-radius:       var(--ios-radius);
    --ae-shadow:       var(--ios-shadow);
    --ae-shadow-md:    var(--ios-shadow-md);

    /* ── ios-design.css system aliases ── */
    --system-background:            var(--ios-card);
    --secondary-system-background:  var(--ios-bg);
    --system-gray-4:                var(--ios-separator);
    --system-gray-5:                var(--ios-fill);
    --system-gray-6:                var(--ios-bg);
    --label-color:                  var(--ios-text);
    --secondary-label-color:        var(--ios-muted);
    --ios-label:                    var(--ios-text);
    --ios-secondary-label:          var(--ios-muted);
    --system-blue:                  var(--ios-blue);
    --system-green:                 var(--ios-green);
    --system-red:                   var(--ios-red);
    --system-orange:                var(--ios-orange);
    --aey-muted:                   var(--ios-muted);

    /* ── MOZE Design System Tokens ── */
    --aey-system-bg:    var(--ios-bg);       /* 頁面底色 */
    --aey-card-bg:      var(--ios-card);     /* 卡片底色 */
    --aey-primary-green: var(--amount-income);  /* 金額收入色 */
    --aey-primary-red:  var(--amount-expense);  /* 金額支出色 */
    --aey-text-main:    var(--color-text-strong); /* 主要文字 */
    --aey-text-muted:   var(--ios-muted);    /* 輔助文字 */
    --aey-radius:       16px;                /* 統一圓角 */
    --aey-shadow:       var(--shadow-xs);    /* 極輕懸浮陰影 */
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; }

* {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: var(--font-body);
    background-color: var(--ios-bg);
    color: var(--ios-text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    /* 禁止長按選取與 iOS callout（含長按連結彈出選單） */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    /* 全域禁止原生下拉重新整理（PWA 由自訂 PTR 處理） */
    overscroll-behavior-y: none;
    max-width: 100%;
    overflow-x: hidden;
    /* Android: force single-finger vertical pan to remain available */
    touch-action: pan-y pinch-zoom;
}

html,
body,
#app {
    min-height: 100%;
}

body {
    min-height: 100dvh;
    overflow-y: auto;
}

button,
[role="button"],
a,
input,
textarea,
select {
    touch-action: manipulation;
}

.ae-standard-page-main,
.ae-page-main,
.pm-overview-content,
.pm-content,
.stats-main,
.accounts-main,
.ae-addtx-scroll {
    content-visibility: auto;
    contain-intrinsic-size: 900px;
}

.ae-modal-backdrop,
.ios-sheet-overlay,
.aey-fs-backdrop {
    contain: layout paint style;
}

.ae-modal-backdrop:has(.ae-color-picker-sheet) {
    --ae-modal-backdrop-z: 6200;
    contain: none !important;
}

.ae-color-picker-sheet {
    max-height: min(86dvh, 680px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

body:has(.ae-modal-backdrop),
body:has(.ios-sheet-overlay.show),
body:has(.pm-modal-mask),
body:has(.balance-sheet-backdrop),
body:has(.aey-fs-backdrop),
body:has(.ae-dialog-backdrop),
body:has(.fb-overlay),
body:has(.wj-overlay) {
    overflow: hidden;
    overscroll-behavior: none;
}

.ae-modal-backdrop,
.ios-sheet-overlay.show,
.pm-modal-mask,
.balance-sheet-backdrop,
.aey-fs-backdrop,
.ae-dialog-backdrop,
.fb-overlay,
.wj-overlay {
    position: fixed !important;
    inset: 0 !important;
    pointer-events: auto !important;
    touch-action: none;
    overscroll-behavior: contain;
    z-index: var(--ae-modal-backdrop-z, 3000) !important;
}

.ae-modal-backdrop > *,
.ios-sheet-overlay.show > *,
.pm-modal-mask > *,
.aey-fs-backdrop > *,
.fb-overlay > *,
.wj-overlay > * {
    touch-action: pan-y pinch-zoom;
}

.ae-modal,
.ae-modal-sheet,
.ios-sheet,
.ae-txd-sheet,
.cm-modal,
.pm-modal,
.pm-warn-modal,
.balance-sheet,
.stats-modal,
.fb-sheet {
    position: relative;
    z-index: calc(var(--ae-modal-backdrop-z, 3000) + 1) !important;
    pointer-events: auto;
}

.ae-txd-overlay.ios-sheet-overlay.show {
    z-index: var(--ae-transaction-sheet-z, 5000) !important;
}

.ae-txd-overlay.ios-sheet-overlay.show > .ae-txd-sheet {
    z-index: calc(var(--ae-transaction-sheet-z, 5000) + 1) !important;
}

/* ── Unified Fullscreen Charts ── */
.aey-fs-backdrop,
.ae-modal-backdrop:has(.aey-fullscreen-chart) {
    position: fixed;
    inset: 0;
    background: var(--modal-backdrop-bg);
    display: flex;
    align-items: stretch;
    justify-content: center;
    z-index: 1200;
}

.aey-fs-sheet,
.ae-modal-sheet.aey-fullscreen-chart {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
    background: var(--chart-fullscreen-bg);
    color: var(--chart-fs-tick-color);
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
    overflow: hidden;
}

.aey-fs-landscape {
    width: 100%;
    height: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.aey-fs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    padding: 12px 14px;
    border-bottom: var(--hairline-width) solid var(--chart-grid-fs-color);
}

.aey-fs-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.aey-fs-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 999px;
    background: color-mix(in oklab, var(--chart-fs-tick-color) 14%, transparent);
    color: var(--chart-fs-tick-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.aey-fs-canvas {
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px;
}

.aey-fs-canvas.aey-fs-canvas-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pinch-zoom;
}

.aey-fs-chart-wrapper {
    height: 100%;
    min-width: 100%;
}

.aey-fs-canvas canvas {
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 719px) and (orientation: portrait) {
    .aey-fs-canvas.aey-fs-canvas-scroll .aey-fs-chart-wrapper {
        min-width: max(860px, 100%);
    }

    .aey-fs-canvas:not(.aey-fs-canvas-scroll) {
        min-width: 100%;
    }
}

/* ── Shared Category/Manager Modal Shell ── */
.cm-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 24px));
    max-height: 82vh;
    overflow: auto;
    background: var(--color-surface);
    border-radius: 18px;
    border: var(--hairline-width) solid var(--color-separator);
    z-index: 1300;
}

.cm-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1299;
    background: var(--modal-backdrop-bg);
}

.ios-nav-container {
    display: contents;
}

.ios-sidebar-footer {
    margin-top: auto;
}

.ae-groups-page,
.ae-templates-page,
.theme-page {
    min-height: 100%;
}

.bme-topbar {
    z-index: 40;
}

.cm-main-list-card {
    min-width: 0;
}

.import-help {
    grid-column: 1 / -1;
}

.cm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: var(--hairline-width) solid var(--color-separator);
}

.cm-modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.cm-modal-body {
    padding: 12px 14px;
}

.cm-modal-footer {
    border-top: var(--hairline-width) solid var(--color-separator);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 14px;
}

.ios-shell,
.ios-content-wrapper,
.ios-main,
.ios-container {
    max-width: 100%;
}

.ios-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: row;
    overflow-x: hidden;
}

.ios-content-wrapper {
    min-height: 0;
    overflow: hidden;
}

.ae-tx-date-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0.5rem 0;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Glassmorphism helper ── */
.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

/* ── Page container (edge-to-edge) ── */
.ae-page {
    padding-left: var(--page-padding-x);
    padding-right: var(--page-padding-x);
    max-width: var(--page-max-width);
    margin: 0 auto;
    width: 100%;
}

/* ── Standard page shell for settings/manager pages ── */
.ae-standard-page {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.ae-standard-page-main {
    padding: 12px 12px 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (max-width: 768px) {
    .ae-standard-page-main {
        padding-left: 0;
        padding-right: 0;
    }
}

/* ── Settings subpage topbar (match CategoryManager style) ── */
.ae-settings-page {
    min-height: 100vh;
    width: 100%;
}

.ae-settings-main {
    padding: 12px 12px 0;
}

.ae-settings-topbar {
    position: sticky;
    top: var(--ae-topbar-sticky-top);
    z-index: 20;
    height: var(--ae-topbar-height);
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    padding: 0 14px;
    background: var(--nav-glass-bg);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: var(--hairline-width) solid var(--color-separator);
}

.ae-settings-topbar-title {
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.ae-settings-icon-btn,
.ae-settings-icon-spacer {
    width: 34px;
    height: 34px;
}

.ae-settings-icon-btn {
    border-radius: 999px;
    border: none;
    background: transparent;
    font-size: 1.05rem;
    color: var(--color-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ae-settings-icon-btn:active {
    background: var(--accent-soft-12);
}

.ae-topbar-action-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 768px) {
    .ae-settings-main {
        padding-left: 0;
        padding-right: 0;
    }
}

@media (min-width: 769px) {
    .ae-page { padding-left: 0; padding-right: 0; }
}

/* 輸入欄位恢復文字選取，避免影響輸入體驗 */
input, textarea, [contenteditable] {
    -webkit-touch-callout: default;
    -webkit-user-select: text;
    user-select: text;
}

h1, h2, h3, h4, h5, h6 { margin: 0; }
a { color: var(--ios-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1:focus { outline: none; }

/* Iconify baseline */
iconify-icon {
    display: inline-block;
    line-height: 1;
    vertical-align: middle;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ios-separator); border-radius: 2px; }


/* ══════════════════════════════════════════════
   BOOTSTRAP-COMPATIBLE UTILITY CLASSES
   ══════════════════════════════════════════════ */

/* ── Display ── */
.d-none         { display: none !important; }
.d-block        { display: block !important; }
.d-flex         { display: flex !important; }
.d-inline-flex  { display: inline-flex !important; }
.d-inline-block { display: inline-block !important; }

/* ── Flex ── */
.flex-column    { flex-direction: column !important; }
.flex-row       { flex-direction: row !important; }
.flex-wrap      { flex-wrap: wrap !important; }
.flex-nowrap    { flex-wrap: nowrap !important; }
.flex-grow-1    { flex-grow: 1 !important; }
.flex-shrink-0  { flex-shrink: 0 !important; }

.align-items-center  { align-items: center !important; }
.align-items-start   { align-items: flex-start !important; }
.align-items-end     { align-items: flex-end !important; }
.align-items-stretch { align-items: stretch !important; }

.justify-content-between { justify-content: space-between !important; }
.justify-content-center  { justify-content: center !important; }
.justify-content-end     { justify-content: flex-end !important; }
.justify-content-start   { justify-content: flex-start !important; }

/* ── Gap ── */
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 0.75rem !important; }
.gap-4 { gap: 1rem !important; }

/* ── Spacing — Margin ── */
.m-0  { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 0.75rem !important; }
.mb-4 { margin-bottom: 1rem !important; }
.mb-5 { margin-bottom: 1.5rem !important; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 0.75rem !important; }
.mt-4 { margin-top: 1rem !important; }
.ms-1 { margin-left: 0.25rem !important; }
.ms-2 { margin-left: 0.5rem !important; }
.ms-3 { margin-left: 0.75rem !important; }
.ms-auto { margin-left: auto !important; }
.me-1 { margin-right: 0.25rem !important; }
.me-2 { margin-right: 0.5rem !important; }
.me-3 { margin-right: 0.75rem !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

/* ── Spacing — Padding ── */
.p-0  { padding: 0 !important; }
.p-2  { padding: 0.5rem !important; }
.p-3  { padding: 0.75rem !important; }
.py-0 { padding-top: 0 !important; padding-bottom: 0 !important; }
.py-1 { padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
.py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.px-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-3 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
.px-4 { padding-left: 1rem !important; padding-right: 1rem !important; }
.pt-2 { padding-top: 0.5rem !important; }
.pt-3 { padding-top: 0.75rem !important; }
.pb-2 { padding-bottom: 0.5rem !important; }
.pb-3 { padding-bottom: 0.75rem !important; }

/* ── Text ── */
.text-center  { text-align: center !important; }
.text-end     { text-align: right !important; }
.text-start   { text-align: left !important; }
.text-danger  { color: var(--ui-danger) !important; }
.text-success { color: var(--ui-success) !important; }
.text-muted   { color: var(--ios-muted) !important; }
.text-primary { color: var(--ios-blue) !important; }
.fw-bold      { font-weight: 700 !important; }
.small        { font-size: 0.85rem !important; }

/* ── Width / Overflow ── */
.w-100 { width: 100% !important; }
.w-auto { width: auto !important; }
.overflow-auto   { overflow: auto; }
.overflow-hidden { overflow: hidden; }

/* ── Border ── */
.border-top { border-top: 1px solid var(--ios-separator) !important; }

/* ── Position ── */
.position-relative { position: relative; }

/* ── Transition ── */
.ae-transition { transition: all 0.2s ease; }
.ae-transition-fast { transition: all 0.15s ease; }


/* ── Grid System (Bootstrap-compatible) ── */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -0.375rem;
    margin-right: -0.375rem;
}

.row > * {
    padding-left: 0.375rem;
    padding-right: 0.375rem;
    min-width: 0;
    width: 100%;
}

.row.g-2 { margin-left: -0.25rem; margin-right: -0.25rem; }
.row.g-2 > * { padding-left: 0.25rem; padding-right: 0.25rem; padding-bottom: 0.5rem; }
.row.g-3 { margin-left: -0.375rem; margin-right: -0.375rem; }
.row.g-3 > * { padding-left: 0.375rem; padding-right: 0.375rem; padding-bottom: 0.75rem; }

/* Column widths (mobile-first: default full width) */
.col-4  { width: 33.333% !important; }
.col-5  { width: 41.667% !important; }
.col-6  { width: 50% !important; }
.col-7  { width: 58.333% !important; }
.col-8  { width: 66.667% !important; }
.col-12 { width: 100% !important; }

@media (min-width: 576px) {
    .col-sm-6 { width: 50% !important; }
    .col-sm-4 { width: 33.333% !important; }
}

@media (min-width: 768px) {
    .col-md-3 { width: 25% !important; }
    .col-md-4 { width: 33.333% !important; }
    .col-md-6 { width: 50% !important; }
}

@media (min-width: 992px) {
    .col-lg-4 { width: 33.333% !important; }
    .col-lg-8 { width: 66.667% !important; }
}

@media (min-width: 1200px) {
    .col-xl-3 { width: 25% !important; }
}


/* ══════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════ */

.ae-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.55rem 1.25rem;
    border-radius: 100px;
    font-size: 0.88rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
}

.ae-btn:active { transform: scale(0.97); }
.ae-btn:focus  { outline: none; }

.ae-btn-primary           { background: var(--ios-blue); color: var(--color-surface); }
.ae-btn-primary:hover     { filter: brightness(1.08); }
.ae-btn-secondary         { background: var(--ios-fill); color: var(--ios-secondary); }
.ae-btn-secondary:hover   { background: var(--surface-2); }
.ae-btn-success           { background: var(--ui-success); color: var(--color-surface); }
.ae-btn-danger            { background: var(--ui-danger); color: var(--color-surface); }

.ae-btn-outline-secondary {
    background: transparent;
    color: var(--ios-muted);
    border: var(--hairline-width) solid var(--ios-separator);
}
.ae-btn-outline-secondary:hover { background: var(--ios-fill); color: var(--ios-secondary); }

.ae-btn-outline-danger {
    background: transparent;
    color: var(--ui-danger);
    border: 1px solid var(--ui-danger);
}

.ae-btn-link {
    background: none;
    border: none;
    color: var(--ios-blue);
    padding: 0;
    border-radius: 0;
    font-weight: 400;
    cursor: pointer;
    text-decoration: none;
}

.ae-btn-sm { padding: 0.35rem 0.9rem; font-size: 0.8rem; }

.ae-btn-icon {
    flex-shrink: 0;
}

/* ══════════════════════════════════════════════
   FORM CONTROLS
   ══════════════════════════════════════════════ */

/* Validation */
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--ui-success); }
.invalid { outline: 1px solid var(--ui-danger); }
.validation-message { color: var(--ui-danger); font-size: 0.8rem; }


/* ══════════════════════════════════════════════
   ALERTS
   ══════════════════════════════════════════════ */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--ios-radius-sm);
    font-size: 0.88rem;
    margin-bottom: 1rem;
    display: block;
}

.alert-info    { background: var(--accent-soft-08); color: var(--color-primary); border-left: 3px solid var(--ios-blue); }
.alert-warning { background: var(--warning-soft-12); color: var(--color-warning); border-left: 3px solid var(--ios-orange); }
.alert-danger  { background: var(--danger-soft-10);  color: var(--ui-danger); border-left: 3px solid var(--ui-danger); }
.alert-success { background: var(--success-soft-10);  color: var(--ui-success); border-left: 3px solid var(--ui-success); }

.ae-inline-error {
    display: flex;
    align-items: center;
    gap: 0.42rem;
    margin-bottom: 1rem;
    padding: 0.68rem 0.82rem;
    border-radius: var(--ios-radius-sm);
    border: var(--hairline-width) solid var(--danger-soft-20);
    background: var(--danger-soft-10);
    color: var(--ui-danger);
    font-size: 0.85rem;
    font-weight: 750;
    line-height: 1.35;
}

.ae-inline-error iconify-icon {
    flex: 0 0 auto;
}

.ae-inline-error-compact {
    margin-bottom: 0.5rem;
    padding: 0.52rem 0.68rem;
}

.ae-inline-error-spaced {
    margin-bottom: 1rem;
}

.ae-app-error {
    margin: 1rem;
    padding: 1rem;
    border-radius: var(--ios-radius-md);
    border: var(--hairline-width) solid var(--danger-soft-20);
    background: var(--danger-soft-10);
    color: var(--color-text);
}

.ae-app-error h4 {
    margin: 0 0 0.45rem;
    color: var(--ui-danger);
    font-size: 1rem;
    font-weight: 850;
}

.ae-app-error p {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: 0.88rem;
    line-height: 1.45;
}

.ae-app-error-divider {
    height: 1px;
    margin: 0.72rem 0;
    background: var(--color-separator);
}

.ae-app-error-footnote {
    color: var(--color-text-muted) !important;
}

.ae-auth-loading-surface {
    min-height: 100dvh;
    background: var(--color-bg);
}


/* ══════════════════════════════════════════════
   SPINNER
   ══════════════════════════════════════════════ */

.spinner-border {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 0.2rem solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ae-spin 0.65s linear infinite;
    flex-shrink: 0;
}

.spinner-border-sm { width: 1rem; height: 1rem; border-width: 0.15rem; }

@keyframes ae-spin { to { transform: rotate(360deg); } }


/* ══════════════════════════════════════════════
   AE COMPONENTS (MOZE styled)
   ══════════════════════════════════════════════ */

/* ── Page Header ── */
.ae-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

@media (max-width: 768px) {
    .ae-page-header {
        padding-left: 0;
        padding-right: 0;
    }
}

@media (min-width: 769px) {
    .ae-page-header {
        padding-left: 0;
        padding-right: 0;
    }
}

.ae-page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ios-text);
    margin: 0;
    letter-spacing: -0.3px;
}

.ae-page-subtitle {
    font-size: 0.8rem;
    color: var(--ios-muted);
    margin: 0.15rem 0 0;
}

/* ── Cards ── */
.ae-card {
    padding: 0 0.25rem 0.75rem 0.25rem;
    margin-bottom: 1rem;
}

.ae-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    background: var(--surface-2);
    margin: -1.25rem -1.25rem 1rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--ios-radius) var(--ios-radius) 0 0;
}

.ae-card-title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ios-text);
    margin: 0;
}

.ae-card-title-icon {
    flex-shrink: 0;
}

.ae-card-header-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Stat Cards ── */
.ae-stat-card {
    background: var(--ios-card);
    border-radius: var(--ios-radius);
    box-shadow: var(--ios-shadow);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.ae-stat-label {
    font-size: 0.72rem;
    color: var(--ios-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ae-stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--ios-text);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.ae-stat-sub { font-size: 0.76rem; color: var(--ios-muted); }

.ae-stat-positive { color: var(--amount-income) !important; }
.ae-stat-negative { color: var(--amount-expense) !important; }
.ae-stat-warning  { color: var(--ios-orange) !important; }

/* ── Badges ── */
.ae-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
}

.ae-badge-income   { background: var(--income-soft-15);  color: var(--amount-income); }
.ae-badge-expense  { background: var(--expense-soft-12);  color: var(--amount-expense); }
.ae-badge-transfer { background: var(--accent-soft-12); color: var(--color-primary); }
.ae-badge-active   { background: var(--success-soft-12);  color: var(--ui-success); }
.ae-badge-inactive { background: var(--ios-fill); color: var(--ios-muted); }
.ae-badge-success  { background: var(--success-soft-12); color: var(--ui-success); }
.ae-badge-danger   { background: var(--danger-soft-12); color: var(--ui-danger); }
.ae-badge-info     { background: var(--accent-soft-12); color: var(--color-primary); }
.ae-badge-muted    { background: var(--ios-fill); color: var(--ios-muted); }
.ae-badge-credit   { background: var(--warning-soft-12); color: var(--color-warning); }
.ae-badge-crypto   { background: var(--accent-soft-12); color: var(--color-accent); }

.ae-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.ae-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ae-switch .slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 999px;
    background: var(--ios-fill);
    transition: background 0.16s ease;
}

.ae-switch .slider::before {
    content: "";
    position: absolute;
    width: 24px;
    height: 24px;
    left: 2px;
    top: 2px;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.16s ease;
}

.ae-switch input:checked + .slider {
    background: var(--color-primary);
}

.ae-switch input:checked + .slider::before {
    transform: translateX(20px);
}

.transaction-list-skeleton {
    display: grid;
    gap: 10px;
    padding: 12px 0;
}

.skeleton-loader {
    position: relative;
    overflow: hidden;
    background: var(--surface-2);
    border-radius: 10px;
}

.skeleton-loader::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--accent-soft-12), transparent);
    animation: aeSkeletonShimmer 1.2s infinite;
}

.skeleton-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    flex: 0 0 38px;
}

.skeleton-text {
    height: 12px;
    width: 72%;
}

.skeleton-text-short {
    height: 10px;
    width: 44%;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--accent-soft-08);
    color: var(--color-primary);
    font-size: 0.72rem;
    font-weight: 700;
}

.receipt-preview-container {
    position: relative;
    display: inline-block;
}

.receipt-preview-img {
    max-width: min(220px, 72vw);
    max-height: 180px;
    border-radius: 16px;
    object-fit: cover;
    box-shadow: var(--shadow-sm);
}

.receipt-preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--ui-danger);
    color: var(--color-surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

@keyframes aeSkeletonShimmer {
    100% { transform: translateX(100%); }
}

/* ── Amount Colors ── */
.amount-income   { color: var(--amount-income);  font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-expense  { color: var(--amount-expense); font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-transfer { color: var(--ios-blue);    font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Progress Bar ── */
.ae-progress {
    height: 6px;
    border-radius: 3px;
    background: var(--ios-fill);
    overflow: hidden;
}

.ae-progress-bar { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.ae-progress-safe    { background: var(--ui-success); }
.ae-progress-caution { background: var(--ios-orange); }
.ae-progress-danger  { background: var(--ui-danger); }

/* ── Table ── */
.ae-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.ae-table th {
    background: var(--ios-bg);
    color: var(--ios-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.6rem 1rem;
    border-bottom: 2px solid var(--ios-fill);
    white-space: nowrap;
}

.ae-table td {
    padding: 0.75rem 1rem;
    border-bottom: var(--hairline-width) solid var(--color-separator);
    vertical-align: middle;
}

.ae-table tbody tr:last-child td { border-bottom: none; }
.ae-table tbody tr:hover { background: var(--surface-2); }

/* ── Category / Account icon ── */
.acct-icon, .cat-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

/* ── Global Responsive Widget Grid ── */
.ios-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ios-widget { min-width: 0; }
@media (min-width: 768px) {
    .ios-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 6px;
        align-items: start;
    }
}
@media (min-width: 1024px) {
    .ios-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Global Banners ── */
.ae-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.ae-banner-info    { background: var(--accent-soft-12); color: var(--color-primary); }
.ae-banner-warn    { background: var(--warning-soft-12);  color: var(--color-warning); }
.ae-banner-success { background: var(--success-soft-10);   color: var(--ui-success); }
.ae-banner-danger  { background: var(--danger-soft-10);   color: var(--ui-danger); }

/* ── Page section padding helper ── */
.ae-section { margin-bottom: 1.5rem; }
.ae-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--ios-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.ae-edit-card-title {
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.ae-meta-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ios-text);
}

.ae-meta-sub {
    margin-top: 2px;
    font-size: 0.72rem;
    color: var(--ios-muted);
}

.ae-form-label-compact {
    color: var(--ios-muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.ae-edit-panel {
    width: 100%;
    border: none;
    text-align: left;
    background: var(--color-surface);
    border-radius: 14px;
    padding: 12px;
    box-shadow: inset 0 0 0 var(--hairline-width) var(--color-separator);
}

.ae-sheet-form-body {
    padding: 16px;
}

.ae-sheet-form-footer {
    padding: 0 16px 16px;
}


/* ══════════════════════════════════════════════
   MODAL (global — shared across pages)
   ══════════════════════════════════════════════ */

.ae-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--ios-card);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    z-index: 101;
    width: min(560px, 95vw);
    max-height: 88vh;
    overflow-y: auto;
}

.ae-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: var(--hairline-width) solid var(--color-separator);
    position: sticky;
    top: 0;
    background: var(--ios-card);
    border-radius: 20px 20px 0 0;
    z-index: 1;
}

.ae-modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    color: var(--ios-text);
}

.ae-modal-body { padding: 1.5rem; }

.ae-modal-footer { display:flex; justify-content:flex-end; gap:0.5rem; padding:1rem 1.5rem; border-top:var(--hairline-width) solid var(--color-separator); }

.ae-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-toast-bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ae-modal-sheet {
    background: var(--color-surface);
    border-radius: 20px;
    width: 92vw;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    box-sizing: border-box;
}

.ae-modal-sheet *,
.ae-modal-sheet *::before,
.ae-modal-sheet *::after {
    box-sizing: border-box;
}

.ae-modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.ae-modal-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ae-modal-close:hover { background: var(--surface-2); }

/* Shared AeDialog. Keep this global because AeDialog renders in its own component scope. */
.ae-dialog {
    width: min(420px, calc(100vw - 28px));
    max-height: min(86vh, 680px);
    overflow: auto;
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: 20px;
    border: var(--hairline-width) solid var(--color-separator);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.ae-dialog-title {
    padding: 1.05rem 1.15rem 0.85rem;
    border-bottom: var(--hairline-width) solid var(--color-separator);
    color: var(--color-text);
    font-size: 1.02rem;
    font-weight: 900;
    letter-spacing: -0.01em;
    text-align: center;
}

.ae-dialog-body {
    padding: 1rem 1.15rem;
    color: var(--color-text);
    font-size: 0.92rem;
    line-height: 1.45;
}

.ae-dialog-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    padding: 0.85rem 1.15rem 1.05rem;
    border-top: var(--hairline-width) solid var(--color-separator);
}

.ae-dialog-btn {
    min-height: 42px;
    border: none;
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 850;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}

.ae-dialog-btn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.ae-dialog-btn:active:not(:disabled) {
    transform: scale(0.98);
    background: var(--neutral-soft-08);
}

.ae-dialog-btn-primary {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
}

.ae-dialog-btn-primary:active:not(:disabled) {
    background: color-mix(in srgb, var(--color-primary) 88%, #000);
}

.ae-dialog-btn-danger {
    background: var(--danger-soft-12);
    color: var(--ui-danger);
}

.ae-dialog-btn-danger:active:not(:disabled) {
    background: var(--danger-soft-20);
}

.ae-credit-payment-dialog {
    width: min(440px, calc(100vw - 24px));
}

.ae-credit-payment-dialog .ae-dialog-body {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.cc-pay-summary {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.9rem;
    border-radius: 16px;
    background: var(--surface-2);
    border: var(--hairline-width) solid var(--color-separator);
}

.cc-pay-summary-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: var(--danger-soft-12);
    color: var(--ui-danger);
}

.cc-pay-summary-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
}

.cc-pay-summary-text span {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.cc-pay-summary-text strong {
    color: var(--color-text);
    font-size: 1.12rem;
    font-weight: 950;
    font-variant-numeric: tabular-nums;
}

.cc-pay-field {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
}

.cc-pay-label {
    margin: 0;
    color: var(--color-text);
    font-size: 0.86rem;
    font-weight: 850;
}

.cc-pay-picker,
.cc-pay-input {
    min-height: 44px;
    border-radius: 14px;
}

.cc-pay-error {
    margin: 0;
}

/* Classes passed into child components through SheetClass/TriggerClass must be global. */
.ae-picker-sheet {
    width: min(96vw, 420px);
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.ae-cal-picker-sheet {
    max-height: 88vh;
}

.ae-time-picker-sheet {
    max-height: 75vh;
}

.ae-quick-add-sheet {
    width: min(94vw, 460px);
    padding: 0 16px 16px;
}

.ae-select-picker-sheet {
    width: min(92vw, 520px);
    max-height: min(72vh, 560px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ae-more-modal {
    max-width: 340px;
    width: 92vw;
}

.ae-nw-modal,
.curr-edit-sheet {
    max-width: 420px;
    width: 92vw;
}

.curr-picker-sheet {
    max-height: 72vh;
    display: flex;
    flex-direction: column;
}

.ae-info-picker-fit,
.tmpl-currency-picker {
    flex: 0 1 auto;
    width: auto;
    min-width: 72px;
}

.ae-account-picker-trigger-sm {
    min-height: 31px;
    font-size: 0.82rem;
    border-radius: 8px;
    padding: 6px 8px;
}

.qa-picker-trigger {
    min-height: 44px;
    border-radius: 14px;
    background: var(--color-surface);
    font-weight: 800;
}

.pref-palette-more {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 26px;
    height: 26px;
    background: color-mix(in srgb, var(--color-surface) 82%, transparent);
    border-color: color-mix(in srgb, var(--color-text) 18%, transparent);
    box-shadow: var(--shadow-xs);
}

.fl-select,
.wj-select {
    flex: 1;
    min-width: 120px;
    border-radius: 10px;
    border: var(--hairline-width) solid var(--color-separator);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.88rem;
    outline: none;
}

.fl-select {
    padding: 8px 12px;
}

.wj-select {
    padding: 0.4rem 0.65rem;
}

.srch-bm-select,
.srch-bm-date-input,
.stats-row-input {
    width: 100%;
    min-width: 0;
    margin: 0;
    background: var(--surface-2);
    border: var(--hairline-width) solid var(--color-separator);
    border-radius: 10px;
    color: var(--color-text);
}

.srch-bm-select,
.srch-bm-date-input {
    flex: 1;
    padding: 0.45rem 0.62rem;
}

.stats-row-input {
    padding: 6px 10px;
    font-size: 0.78rem;
}

.stats-modal-body {
    padding: 10px;
    overflow: auto;
}

.stats-modal-header {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: var(--hairline-width) solid var(--color-separator);
}

.stats-modal-header-wide {
    grid-template-columns: 40px 1fr 40px;
}

.stats-wheel-list {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
}


/* ══════════════════════════════════════════════
   CONTENT COMPAT
   ══════════════════════════════════════════════ */

.content { padding-top: 1rem; padding-bottom: 1rem; }


/* ══════════════════════════════════════════════
   BLAZOR SYSTEM UI
   ══════════════════════════════════════════════ */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: var(--shadow-sm);
    box-sizing: border-box;
    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;
}

.blazor-error-boundary {
    background: var(--ui-danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: var(--color-surface);
}

.blazor-error-boundary::after { content: "發生未處理的錯誤。"; }

/* ── Loading Progress (splash screen) ── */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--ios-fill);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--ios-blue);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text::after { content: var(--blazor-load-percentage-text, "載入中"); }

code { color: var(--color-accent); }

/* ── Privacy Mode: replace financial amounts with a readable mask ── */
.privacy-mode .ae-privacy,
.privacy-mode .ios-pill-val,
.privacy-mode .ae-stat-value,
.privacy-mode .ae-acct-balance,
.privacy-mode .amount-income,
.privacy-mode .amount-expense,
.privacy-mode .amount-transfer,
.privacy-mode .ae-debt-owed,
.privacy-mode .ae-debt-total,
.privacy-mode .ios-tx-amount,
.privacy-mode .ae-inst-amount,
.privacy-mode .ae-inst-remaining,
.privacy-mode .ae-inst-total,
.privacy-mode .ae-payment-amount,
.privacy-mode .ae-rec-amount,
.privacy-mode .ae-budget-spent,
.privacy-mode .ae-budget-total,
.privacy-mode .ae-detail-balance,
.privacy-mode .ae-detail-tx-amount,
.privacy-mode .ae-detail-running-bal,
.privacy-mode .ae-goal-current,
.privacy-mode .ae-goal-target,
.privacy-mode .ios-sp-val,
.privacy-mode .ios-date-total,
.privacy-mode .ios-hero-asset-val,
.privacy-mode .ios-budget-amounts,
.privacy-mode .ios-balance-val,
.privacy-mode .aey-group-total,
.privacy-mode .aey-alloc-val,
.privacy-mode .aey-alloc-center-val,
.privacy-mode .aey-trend-stat-total,
.privacy-mode .ae-alloc-val,
.privacy-mode .ios-pie-center-val,
.privacy-mode .ae-autotopup-info strong,
.privacy-mode .ae-tmpl-card-meta span:nth-child(2),
.privacy-mode .privacy-blur {
    position: relative;
    color: transparent !important;
    text-shadow: none !important;
    filter: none;
    user-select: none;
    background-color: transparent;
}

.privacy-mode .ae-privacy,
.privacy-mode .ios-pill-val,
.privacy-mode .ae-stat-value,
.privacy-mode .ae-acct-balance,
.privacy-mode .amount-income,
.privacy-mode .amount-expense,
.privacy-mode .amount-transfer,
.privacy-mode .ae-debt-owed,
.privacy-mode .ae-debt-total,
.privacy-mode .ios-tx-amount,
.privacy-mode .ae-inst-amount,
.privacy-mode .ae-inst-remaining,
.privacy-mode .ae-inst-total,
.privacy-mode .ae-payment-amount,
.privacy-mode .ae-rec-amount,
.privacy-mode .ae-budget-spent,
.privacy-mode .ae-budget-total,
.privacy-mode .ae-detail-balance,
.privacy-mode .ae-detail-tx-amount,
.privacy-mode .ae-detail-running-bal,
.privacy-mode .ae-goal-current,
.privacy-mode .ae-goal-target,
.privacy-mode .ios-sp-val,
.privacy-mode .ios-date-total,
.privacy-mode .ios-hero-asset-val,
.privacy-mode .ios-budget-amounts,
.privacy-mode .ios-balance-val,
.privacy-mode .aey-group-total,
.privacy-mode .aey-alloc-val,
.privacy-mode .aey-alloc-center-val,
.privacy-mode .aey-trend-stat-total,
.privacy-mode .ae-alloc-val,
.privacy-mode .ios-pie-center-val,
.privacy-mode .ae-autotopup-info strong,
.privacy-mode .ae-tmpl-card-meta span:nth-child(2),
.privacy-mode .privacy-blur {
    min-width: 4.4em;
}

.privacy-mode .ae-privacy::after,
.privacy-mode .ios-pill-val::after,
.privacy-mode .ae-stat-value::after,
.privacy-mode .ae-acct-balance::after,
.privacy-mode .amount-income::after,
.privacy-mode .amount-expense::after,
.privacy-mode .amount-transfer::after,
.privacy-mode .ae-debt-owed::after,
.privacy-mode .ae-debt-total::after,
.privacy-mode .ios-tx-amount::after,
.privacy-mode .ae-inst-amount::after,
.privacy-mode .ae-inst-remaining::after,
.privacy-mode .ae-inst-total::after,
.privacy-mode .ae-payment-amount::after,
.privacy-mode .ae-rec-amount::after,
.privacy-mode .ae-budget-spent::after,
.privacy-mode .ae-budget-total::after,
.privacy-mode .ae-detail-balance::after,
.privacy-mode .ae-detail-tx-amount::after,
.privacy-mode .ae-detail-running-bal::after,
.privacy-mode .ae-goal-current::after,
.privacy-mode .ae-goal-target::after,
.privacy-mode .ios-sp-val::after,
.privacy-mode .ios-date-total::after,
.privacy-mode .ios-hero-asset-val::after,
.privacy-mode .ios-budget-amounts::after,
.privacy-mode .ios-balance-val::after,
.privacy-mode .aey-group-total::after,
.privacy-mode .aey-alloc-val::after,
.privacy-mode .aey-alloc-center-val::after,
.privacy-mode .aey-trend-stat-total::after,
.privacy-mode .ae-alloc-val::after,
.privacy-mode .ios-pie-center-val::after,
.privacy-mode .ae-autotopup-info strong::after,
.privacy-mode .ae-tmpl-card-meta span:nth-child(2)::after,
.privacy-mode .privacy-blur::after {
    content: "億萬富翁";
    position: absolute;
    inset: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--color-text);
    white-space: nowrap;
}

/* ── Pull-to-Refresh indicator（薄型進度條） ─────────────────────────── */
.ptr-indicator {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(54px + env(safe-area-inset-top));
    height: 3px;
    z-index: 500;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ptr-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 0 2px 2px 0;
    width: 0%;
}

/* 下拉中：bar 寬度由 JS 直接控制 */
/* 刷新中：indeterminate 動畫 */
.ptr-indicator.ptr-refreshing {
    opacity: 1;
}

.ptr-indicator.ptr-refreshing .ptr-bar {
    width: 30%;
    animation: ptr-slide 1.2s ease-in-out infinite;
}

@keyframes ptr-slide {
    0%   { transform: translateX(-100%); }
    50%  { transform: translateX(250%); }
    100% { transform: translateX(-100%); }
}

/* Prevent native browser pull-to-refresh while our PTR is active */
.ios-main {
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y pinch-zoom;
    flex: 1 1 auto;
    min-height: 0;
}

/* ── Global Block De-carding (transparent + no border) ─────────────────── */
.ae-card,
.ae-stat-card,
.cm-card,
.stats-card,
.mf-card,
.dm-card,
.ae-tmpl-card,
.curr-list-card,
.ae-hero-card,
.ae-cat-card,
.ae-attr-card,
.ae-entry-card,
.ae-receipt-card,
.ae-goal-card,
.si-card,
.aey-trend-card,
.aey-alloc-card,
.aey-group-card,
.ios-filter-card,
.ae-autotopup-card,
.balance-card,
.balance-notes-card {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.ae-card-header,
.cm-card-header,
.dm-card-header,
.si-card-top {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.ae-tabs {
    display: flex;
    gap: 0;
    padding: 0 var(--space-4);
    border-bottom: var(--hairline-width) solid var(--hairline-color);
    background: var(--surface-2);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    min-height: 44px;
}

.ae-tab {
    flex: 1;
    border: none;
    background: transparent;
    min-height: 44px;
    color: var(--ios-muted);
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
}

.ae-tab.active {
    color: var(--ios-blue);
    border-bottom-color: var(--ios-blue);
}


/* ── Trend Card ── */
.aey-trend-card { padding: 1rem 1.1rem 1.05rem; }

.aey-trend-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 0.6rem;
}

.aey-trend-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.aey-trend-canvas {
    height: 190px;
    border-radius: 14px;
    background: var(--surface-2);
    padding: 0.4rem 0.5rem;
}

.aey-trend-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    margin-top: 0.45rem;
    padding: 0 0.1rem;
    font-size: 0.78rem;
}

.aey-trend-stat-date {
    color: var(--ios-muted);
    font-weight: 700;
}

.aey-trend-stat-total {
    color: var(--color-text-strong);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.aey-trend-stat-item {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25rem;
    white-space: nowrap;
}

/* ── Segmented Control ── */
.aey-seg {
    display: inline-flex;
    padding: 2px;
    border-radius: 999px;
    border: var(--hairline-width) solid var(--color-separator);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

.aey-seg.aey-seg-sm { transform: scale(0.92); transform-origin: right center; }

.aey-seg-btn {
    border: none;
    background: transparent;
    padding: 0.28rem 0.62rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ios-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.aey-seg-btn.active {
    background: var(--accent-soft-08);
    color: var(--aey-text-main);
}

.aey-icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    color: var(--aey-text-main);
    font-size: 1.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    background-color: transparent;
}

.aey-icon-btn:active { transform: scale(0.94); }

.aey-icon-btn-ghost {
    background: transparent;
    box-shadow: none;
}

/* ── Cross-component trigger classes ────────────────────────
   TriggerClass values are rendered inside shared picker components,
   so they must live in global CSS rather than parent .razor.css files. */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

.ae-date-range-btn {
    background: var(--accent-soft-08);
    border: none;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ios-blue);
    padding: 0.3rem 0.42rem;
    cursor: pointer;
    min-height: 32px;
    gap: 0;
    justify-content: center;
    white-space: nowrap;
    line-height: 1;
}

.ae-info-input {
    flex: 1;
    text-align: right;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--ios-muted);
    outline: none;
    min-width: 0;
    padding: 0;
}

.ae-info-input:focus {
    color: var(--ios-text);
}

.ae-recurring-frequency-picker {
    flex: 2;
}

.pm-input {
    width: 100%;
    border: var(--hairline-width) solid var(--color-separator);
    border-radius: 12px;
    padding: 10px;
    outline: none;
    background: var(--color-surface);
    color: var(--color-text);
}

.balance-inline-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-text);
    text-align: right;
    font-size: 0.95rem;
}

.budget-period-picker {
    width: auto;
    min-height: 32px;
    padding: 0 8px;
    font-size: 13px;
}

.sched-currency-picker {
    max-width: 90px;
    flex: 0 0 90px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.tmpl-picker-trigger {
    width: 100%;
    min-height: 42px;
    border: var(--hairline-width) solid var(--color-separator);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: inherit;
    padding: 0 12px;
}

.ae-dt-mini {
    background: var(--accent-soft-08);
    border: none;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 0.85rem;
    color: var(--color-primary);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.adv-input {
    flex: 1;
    background: var(--surface-2);
    border: var(--hairline-width) solid var(--color-separator);
    border-radius: 6px;
    padding: 6px 8px;
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
}

.ae-dt-btn {
    background: var(--color-surface);
    border: var(--hairline-width) solid var(--color-separator);
    border-radius: 8px;
    padding: 8px 14px;
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ae-dt-btn-sm {
    font-size: 0.82rem;
    padding: 5px 10px;
}

.import-source-select {
    padding: 6px 10px;
    border-radius: 10px;
    background: var(--surface-2);
    border: var(--hairline-width) solid var(--color-separator);
    color: var(--ios-label);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.import-source-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Shared settings list primitives. Used by Preferences, ReminderSettings, and settings-style pages. */
.pref-section-header {
    padding: 0.9rem var(--page-padding-x, 16px) 0.3rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ios-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pref-page-bottom-spacer {
    height: calc(env(safe-area-inset-bottom) + 2rem);
}

.pref-group {
    background: var(--ios-card);
    border-radius: var(--ios-radius-sm);
    margin: 0 var(--page-padding-x, 16px);
    overflow: hidden;
    box-shadow: var(--ios-shadow);
}

.pref-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-bottom: 0.5px solid var(--ios-separator);
    min-height: 52px;
}

.pref-row.pref-row-last,
.pref-row-last {
    border-bottom: none;
}

.pref-row-toggle {
    gap: 1rem;
}

.pref-row-stacked {
    align-items: stretch;
    flex-direction: column;
}

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

.pref-row-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ios-text);
}

.pref-row-sub {
    font-size: 0.78rem;
    color: var(--ios-muted);
    margin-top: 1px;
    line-height: 1.4;
}

.pref-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.pref-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.pref-toggle-track {
    width: 50px;
    height: 30px;
    border-radius: 15px;
    background: var(--ios-separator);
    transition: background 0.2s ease;
    position: relative;
}

.pref-toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease;
}

.pref-toggle input:checked + .pref-toggle-track {
    background: var(--ios-green);
}

.pref-toggle input:checked + .pref-toggle-track::after {
    transform: translateX(20px);
}

.pref-chip-inline {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 0;
}

.pref-chip-grid {
    justify-content: flex-start;
    width: 100%;
}

.pref-chip {
    padding: 4px 12px;
    border-radius: 20px;
    border: var(--hairline-width) solid var(--ios-separator);
    background: var(--ios-fill);
    color: var(--ios-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.12s;
    white-space: nowrap;
}

.pref-chip:active {
    transform: scale(0.95);
}

.pref-chip.active {
    background: var(--accent-soft-12);
    border-color: var(--ios-blue);
    color: var(--ios-blue);
}

.pref-font-chip {
    min-width: 86px;
    text-align: center;
}

.pref-danger-btn {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--ui-danger);
    background: transparent;
    color: #FF3B30;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.12s;
    white-space: nowrap;
    flex-shrink: 0;
}

.pref-danger-btn:active {
    transform: scale(0.95);
    background: rgba(255, 59, 48, 0.08);
}

.pref-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    border: var(--hairline-width) solid var(--ios-separator);
    background: var(--ios-fill);
    color: var(--ios-text);
    font-size: 0.9rem;
    outline: none;
}

.pref-secondary-btn {
    padding: 10px;
    border-radius: 12px;
    background: var(--ios-blue);
    color: #fff;
    font-weight: 700;
    border: none;
    font-size: 0.85rem;
}

.pref-secondary-btn:disabled {
    opacity: 0.6;
}

.pref-reminder-row {
    min-height: 54px;
    padding: 0.55rem 1rem;
    gap: 0.55rem;
}

.pref-time-trigger {
    border: none;
    border-radius: 10px;
    background: var(--ios-fill);
    color: var(--ios-label);
    font-size: 0.96rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 0.35rem 0.62rem;
    cursor: pointer;
    margin-left: auto;
}

.pref-delete-btn,
.pref-add-btn {
    border: none;
    border-radius: 10px;
    background: var(--danger-soft-12);
    color: var(--ui-danger);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.32rem 0.66rem;
    cursor: pointer;
}

.pref-add-row {
    justify-content: center;
}

.pref-add-btn {
    background: var(--accent-soft-12);
    color: var(--ios-blue);
    align-self: center;
}

.pref-saved-toast,
.pref-status-toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 70px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--overlay-toast-bg);
    color: var(--color-surface);
    padding: 7px 18px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 3000;
    white-space: nowrap;
    animation: prefToastFade 1.8s ease forwards;
    pointer-events: none;
}

.pref-status-toast {
    bottom: calc(env(safe-area-inset-bottom) + 106px);
}

@keyframes prefToastFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    65% { opacity: 1; }
    100% { opacity: 0; }
}

.ae-inline-icon-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ae-image-preview-frame {
    max-width: 90vw;
    max-height: 85vh;
    overflow: auto;
}

.ae-image-preview-img {
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.ae-action-row {
    display: flex;
    gap: 8px;
}

.ae-action-row-spaced,
.ae-action-top-gap {
    margin-top: 8px;
}

.ae-button-fill,
.ae-dialog-btn-fill {
    flex: 1;
}

.ae-button-block {
    width: 100%;
}

.ae-dialog-actions-padded {
    padding: 12px 16px 16px;
}

.ae-stack-top-xs {
    margin-top: 0.3rem;
}

.ae-stack-top-sm {
    margin-top: 0.4rem;
}

.ae-stack-top-md {
    margin-top: 0.5rem;
}

.ae-filter-separator {
    align-self: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.ios-filter-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.ios-date-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
