/* Design tokens — refined modern editorial fintech system. Light is the brand default. */
:root, [data-theme="light"] {
    --paper: #f6f3ec;
    --surface: #fffdf9;
    --surface-translucent: rgba(255, 253, 249, 0.84);
    --sunken: #eee9df;
    --skeleton-base: #ece6db;
    --skeleton-shine: #f7f3ea;
    --ink: #0e1116;
    --ink-muted: #545049;
    --ink-subtle: #6a655d;
    --on-ink: #fffdf9;
    --line: #e4ddd2;
    --line-strong: #c6bdb0;
    --brand: #e08a1e;
    --brand-hover: #ec972b;
    --on-brand: #0e1116;
    --brand-soft: #fdf0db;
    --brand-border: rgba(224, 138, 30, 0.28);
    --brand-glow: rgba(224, 138, 30, 0.22);
    --brand-ink: #8a4b00;
    --positive: #157347;
    --positive-soft: rgba(21, 115, 71, 0.11);
    --negative: #b42318;
    --negative-soft: rgba(180, 35, 24, 0.10);
    --below-target: #2457a4;
    --below-soft: rgba(36, 87, 164, 0.10);
    --focus: #2457a4;
    --class-br-stock: #2563eb;
    --class-intl-stock: #0d9488;
    --class-fii: #7c3aed;
    --class-reit: #db2777;
    --class-crypto: #65a30d;
    --class-fixed-br: #0284c7;
    --class-fixed-intl: #c2410c;
    --shadow-card: 0 1px 2px rgba(14, 17, 22, 0.04), 0 4px 14px rgba(14, 17, 22, 0.035);
    --shadow-card-hover: 0 4px 10px rgba(14, 17, 22, 0.06), 0 14px 28px rgba(14, 17, 22, 0.06);
    --shadow-raised: 0 2px 6px rgba(138, 75, 0, 0.08), 0 14px 32px rgba(14, 17, 22, 0.08);
    --shadow-brand-btn: 0 2px 6px rgba(224, 138, 30, 0.28), 0 8px 18px rgba(224, 138, 30, 0.18);
    --tip-bg: #161921;
    --tip-ink: #f8f6f1;
    --tip-border: rgba(255, 255, 255, 0.12);
    --bg-ambient: radial-gradient(920px 460px at 88% -8%, rgba(224, 138, 30, 0.09), transparent 62%), radial-gradient(760px 420px at 8% 100%, rgba(31, 95, 166, 0.05), transparent 60%);
    color-scheme: light;
}

[data-theme="dark"] {
    --paper: #0e1015;
    --surface: #161921;
    --surface-translucent: rgba(22, 25, 33, 0.82);
    --sunken: #0b0d12;
    --skeleton-base: #1c2029;
    --skeleton-shine: #272d38;
    --ink: #f3f0e9;
    --ink-muted: #b2aca1;
    --ink-subtle: #969085;
    --on-ink: #0e1015;
    --line: #252a34;
    --line-strong: #3e4554;
    --brand: #f2a93b;
    --brand-hover: #f7b854;
    --on-brand: #1a1206;
    --brand-soft: #261e12;
    --brand-border: rgba(242, 169, 59, 0.26);
    --brand-glow: rgba(242, 169, 59, 0.24);
    --brand-ink: #f6bd63;
    --positive: #4ad08d;
    --positive-soft: rgba(74, 208, 141, 0.14);
    --negative: #f87171;
    --negative-soft: rgba(248, 113, 113, 0.14);
    --below-target: #7da9f4;
    --below-soft: rgba(125, 169, 244, 0.14);
    --focus: #7da9f4;
    --class-br-stock: #60a5fa;
    --class-intl-stock: #2dd4bf;
    --class-fii: #a78bfa;
    --class-reit: #f472b6;
    --class-crypto: #a3e635;
    --class-fixed-br: #38bdf8;
    --class-fixed-intl: #fb923c;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.36), 0 6px 18px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.45), 0 16px 32px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    --shadow-raised: 0 4px 14px rgba(0, 0, 0, 0.48), 0 18px 40px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(242, 169, 59, 0.12);
    --shadow-brand-btn: 0 2px 8px rgba(242, 169, 59, 0.28), 0 8px 20px rgba(242, 169, 59, 0.16);
    --tip-bg: #252b38;
    --tip-ink: #f5f2eb;
    --tip-border: rgba(255, 255, 255, 0.14);
    --bg-ambient: radial-gradient(900px 440px at 85% -10%, rgba(242, 169, 59, 0.09), transparent 62%), radial-gradient(720px 420px at 10% 100%, rgba(110, 159, 224, 0.07), transparent 60%);
    color-scheme: dark;
}

:root {
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --font-display: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
    --font-text: Inter, "Segoe UI", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

html, body {
    margin: 0;
    font-family: var(--font-text);
    font-size: 15px;
    line-height: 22px;
    background-color: var(--paper);
    background-image: var(--bg-ambient);
    background-attachment: fixed;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

a {
    color: var(--ink);
}

/* Type styles */
.display { font-family: var(--font-display); font-size: 40px; line-height: 44px; font-weight: 800; letter-spacing: -0.02em; }
.h1 { font-family: var(--font-display); font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.01em; }
.h2 { font-family: var(--font-display); font-size: 20px; line-height: 26px; font-weight: 700; }
.h3 { font-family: var(--font-display); font-size: 16px; line-height: 22px; font-weight: 600; }
.body { font-family: var(--font-text); font-size: 15px; line-height: 22px; font-weight: 400; }
.small { font-family: var(--font-text); font-size: 13px; line-height: 18px; font-weight: 400; }
.figure-xl { font-family: var(--font-text); font-size: 36px; line-height: 40px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.figure { font-family: var(--font-text); font-size: 15px; line-height: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }

@media (max-width: 599.98px) {
    .display { font-size: 30px; line-height: 34px; }
    .figure-xl { font-size: 30px; line-height: 34px; }
}

.ma-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.ma-muted { color: var(--ink-muted); }
.ma-subtle { color: var(--ink-subtle); }
.ma-label { font: 600 12px/16px var(--font-text); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.ma-ticker { font: 500 14px/20px var(--font-mono); letter-spacing: .01em; }
.ma-below { color: var(--below-target); font-weight: 600; }
.ma-aporte-value { color: var(--brand-ink); font-weight: 700; }

/* Card: crisp tactile elevation with subtle depth; contribution hero gets warm ambient sheen. */
.ma-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-card);
    transition: border-color .18s ease, box-shadow .22s ease, transform .22s cubic-bezier(0.22, 1, 0.36, 1);
}
.ma-card--aporte {
    background: linear-gradient(148deg, var(--brand-soft) 0%, color-mix(in srgb, var(--brand) 8%, var(--surface)) 100%);
    border: 1px solid var(--brand-border);
    box-shadow: var(--shadow-raised);
}

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

@media (max-width: 599.98px) {
    .ma-card { padding: var(--space-4); }
}

/* Buttons. Primary = ink. Aporte = brand, tactile glow and micro-lift. */
.ma-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 18px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font: 600 15px/22px var(--font-text);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform .15s cubic-bezier(0.22, 1, 0.36, 1), box-shadow .18s ease, border-color .15s ease, background-color .15s ease, filter .15s ease;
}
.ma-btn:hover:not(:disabled) { transform: translateY(-1px); }
.ma-btn:active:not(:disabled) { transform: translateY(0); }
.ma-btn:disabled { cursor: not-allowed; opacity: .45; }
.ma-btn--primary {
    background: var(--ink);
    color: var(--on-ink);
    box-shadow: 0 1px 2px rgba(14, 17, 22, 0.14);
}
.ma-btn--primary:hover:not(:disabled) {
    filter: brightness(1.16);
    box-shadow: 0 4px 12px rgba(14, 17, 22, 0.18);
}
.ma-btn--aporte {
    background: linear-gradient(180deg, var(--brand-hover) 0%, var(--brand) 100%);
    color: var(--on-brand);
    box-shadow: var(--shadow-brand-btn);
}
.ma-btn--aporte:hover:not(:disabled) {
    filter: brightness(1.04);
    box-shadow: 0 4px 12px rgba(224, 138, 30, 0.36), 0 10px 24px rgba(224, 138, 30, 0.22);
}
.ma-btn--secondary {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
    box-shadow: 0 1px 2px rgba(14, 17, 22, 0.04);
}
.ma-btn--secondary:hover:not(:disabled) {
    background: var(--sunken);
    border-color: var(--ink-muted);
}
.ma-btn--ghost { background: transparent; color: var(--ink); }
.ma-btn--ghost:hover:not(:disabled) { background: var(--sunken); transform: none; }
.ma-btn--danger { background: transparent; color: var(--negative); border-color: var(--line-strong); }
.ma-btn--danger:hover:not(:disabled) { background: var(--negative-soft); border-color: var(--negative); }
.ma-btn--sm { min-height: 36px; padding: 0 13px; font-size: 14px; }

/* Asset class: colored square + class name; the color never appears alone. */
.ma-class { display: inline-flex; align-items: center; gap: 7px; font: 500 13px/18px var(--font-text); color: var(--ink); white-space: nowrap; }
.ma-class::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--ink-muted)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c, var(--ink-muted)) 18%, transparent); flex: none; }
.ma-c-br-stock { --c: var(--class-br-stock); }
.ma-c-intl-stock { --c: var(--class-intl-stock); }
.ma-c-fii { --c: var(--class-fii); }
.ma-c-reit { --c: var(--class-reit); }
.ma-c-crypto { --c: var(--class-crypto); }
.ma-c-fixed-br { --c: var(--class-fixed-br); }
.ma-c-fixed-intl { --c: var(--class-fixed-intl); }

/* Price change / performance badge: semantic emerald & crimson tinted pills. */
.ma-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    font: 600 12px/16px var(--font-text);
    font-variant-numeric: tabular-nums;
    background: var(--sunken);
    color: var(--ink-muted);
    white-space: nowrap;
}
.ma-delta--up {
    background: var(--positive-soft);
    color: var(--positive);
}
.ma-delta--down {
    background: var(--negative-soft);
    color: var(--negative);
}

/* Filter chip (toggle). Pressed = ink fill with crisp depth. */
.ma-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    font: 500 14px/18px var(--font-text);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .12s ease, box-shadow .15s ease;
}
.ma-chip:hover { background: var(--sunken); border-color: var(--ink-muted); }
.ma-chip[aria-pressed="true"] {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--on-ink);
    box-shadow: 0 2px 8px rgba(14, 17, 22, 0.16);
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Native form controls (text, number, date, select) with soft focus halo. */
.ma-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ma-input {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font: 400 15px/22px var(--font-text);
    font-variant-numeric: tabular-nums;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ma-input:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px var(--below-soft);
}
select.ma-input { padding-right: 32px; }

/* Money input */
.ma-money {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    padding: 0 var(--space-4);
    min-height: 56px;
    box-shadow: inset 0 1px 2px rgba(14, 17, 22, 0.04);
    transition: border-color .16s ease, box-shadow .18s ease;
}
.ma-money:focus-within {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-glow);
}
.ma-money span { font: 600 18px/1 var(--font-text); color: var(--ink-muted); }
.ma-money input { border: 0; background: transparent; color: var(--ink); font: 700 24px/1 var(--font-text); font-variant-numeric: tabular-nums; width: 100%; min-width: 0; outline: none; }

/* Data table */
.ma-table-wrap { overflow-x: auto; }
.ma-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ma-table th { text-align: left; font: 600 11px/16px var(--font-text); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-subtle); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.ma-table td { padding: var(--space-3); border-bottom: 1px solid var(--line); vertical-align: middle; transition: background-color .14s ease; }
.ma-table tbody tr:hover td { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
.ma-table tr:last-child td { border-bottom: 0; }
.ma-table .num { text-align: right; white-space: nowrap; }
.ma-table tr.is-suggested td { background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.ma-table tr.is-suggested:hover td { background: color-mix(in srgb, var(--brand) 15%, var(--surface)); }
.ma-table tr.is-muted td { color: var(--ink-subtle); }

/* Allocation bar: smooth fill with luminous target tick. */
.ma-bar { position: relative; height: 10px; background: var(--sunken); border-radius: var(--radius-pill); }
.ma-bar__fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, var(--c, var(--ink-muted)) 0%, color-mix(in srgb, var(--c, var(--ink-muted)) 82%, #ffffff) 100%);
    transition: width .55s cubic-bezier(0.22, 1, 0.36, 1);
}
.ma-bar__target {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 2px;
    margin-left: -1px;
    background: var(--ink);
    border-radius: 2px;
    box-shadow: 0 0 0 2px var(--surface);
}

/* Skeleton placeholder for loading states. Own tokens per theme: --sunken is darker than the page in dark mode, which made it invisible. */
.ma-skeleton {
    background: linear-gradient(90deg, var(--skeleton-base) 0%, var(--skeleton-shine) 50%, var(--skeleton-base) 100%);
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: ma-skeleton-shimmer 1.6s ease-in-out infinite;
}
@keyframes ma-skeleton-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Inline status message inside a card (errors, empty states) */
.ma-notice { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--sunken); border: 1px solid var(--line); color: var(--ink); }
.ma-notice--error { background: var(--negative-soft); border-color: color-mix(in srgb, var(--negative) 28%, transparent); color: var(--negative); }

/* MudBlazor surface overrides with frosted translucent glass chrome. */
.mud-appbar.app-bar {
    background: var(--surface-translucent) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--ink) !important;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 8px rgba(14, 17, 22, 0.04) !important;
}

.mud-drawer {
    background: var(--surface) !important;
    border-right: 1px solid var(--line);
}

/*
 * Space between the app bar and the page title, for every screen. Grows with the viewport
 * (24px on phones up to 48px on wide screens) so the title never sits against the bar.
 */
.mud-container.page-container {
    padding-top: clamp(var(--space-6), 1.5vw + 16px, var(--space-12));
    padding-bottom: var(--space-12);
}

/* A title followed by its one-line description or counter: a little air between them. */
.page-container h1.h1 + p {
    margin-top: var(--space-1);
}

.mud-table, .mud-paper {
    font-variant-numeric: tabular-nums;
}

/* Extra bottom padding on mobile so content is never hidden behind the fixed bottom nav. */
@media (max-width: 959.98px) {
    .pb-mobile {
        padding-bottom: 88px !important;
    }
}

.user-menu__name {
    font-weight: 600;
}

.user-menu__logout,
.user-menu__logout .mud-icon-root {
    color: var(--negative) !important;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--positive);
}

.invalid {
    outline: 1px solid var(--negative);
}

.validation-message {
    color: var(--negative);
}

#blazor-error-ui {
    color-scheme: normal;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    bottom: 16px;
    right: 16px;
    left: auto;
    width: auto;
    max-width: min(460px, calc(100vw - 32px));
    box-shadow: var(--shadow-raised);
    box-sizing: border-box;
    display: none;
    padding: 0.75rem 2.4rem 0.75rem 0.95rem;
    position: fixed;
    z-index: 2000;
    font-size: 0.9rem;
    line-height: 1.3;
}

#blazor-error-ui .reload {
    margin-left: 0.5rem;
    font-weight: 600;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.7rem;
    top: 0.5rem;
    opacity: 0.75;
}

#blazor-error-ui .dismiss:hover {
    opacity: 1;
}

.blazor-error-boundary {
    padding: 1rem;
    border-radius: var(--radius-md);
    background: var(--sunken);
    color: var(--negative);
}

.blazor-error-boundary::after {
    content: "Ocorreu um erro ao exibir esta parte da tela.";
}

/* Brand lockup: mark + "meu" (500) "Aporte" (800), with subtle tactile mark polish. */
.ma-lockup { display: inline-flex; align-items: center; gap: .32em; font-family: var(--font-display); color: var(--ink); line-height: 1; letter-spacing: -0.02em; text-decoration: none; }
.ma-lockup svg { width: 1.15em; height: 1.15em; flex: none; filter: drop-shadow(0 2px 4px var(--brand-glow)); transition: transform .2s cubic-bezier(0.22, 1, 0.36, 1); }
.ma-lockup:hover svg { transform: scale(1.05); }
.ma-lockup__meu { font-weight: 500; }
.ma-lockup__aporte { font-weight: 800; }
.ma-mark__badge { fill: var(--brand); }
.ma-mark__bar { fill: var(--on-brand); }

/* Boot / auth loading screen */
.app-loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: var(--paper);
}

.app-loading__bars {
    width: 4rem;
    height: 4rem;
}

.app-loading__label {
    font-family: var(--font-display);
    font-size: 1.5rem;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0;
}

.app-loading__meu { font-weight: 500; }
.app-loading__aporte { font-weight: 800; }

/* Each bar has its own rhythm so the mark reads like a live chart ticking. */
.loading-bar {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: 1.8s ease-in-out infinite;
}

.loading-bar--1 { animation-name: bar-tick-1; }
.loading-bar--2 { animation-name: bar-tick-2; }
.loading-bar--3 { animation-name: bar-tick-3; }

@keyframes bar-tick-1 {
    0%, 100% { transform: scaleY(1); }
    30% { transform: scaleY(0.6); }
    65% { transform: scaleY(1.2); }
}

@keyframes bar-tick-2 {
    0%, 100% { transform: scaleY(1); }
    35% { transform: scaleY(1.7); }
    70% { transform: scaleY(0.8); }
}

@keyframes bar-tick-3 {
    0%, 100% { transform: scaleY(1); }
    40% { transform: scaleY(0.7); }
    75% { transform: scaleY(1.05); }
}

.badge-pro {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    background: var(--brand);
    color: var(--on-brand);
    font-size: 0.75em;
    font-weight: 600;
    border-radius: 4px;
    vertical-align: super;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .loading-bar {
        animation: none;
    }

    /* No sweeping shimmer, but keep a slow fade so a loading placeholder never looks frozen. */
    .ma-skeleton {
        background: var(--skeleton-base);
        animation: ma-skeleton-fade 2s ease-in-out infinite !important;
    }
}
@keyframes ma-skeleton-fade { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
