:root {
  color-scheme: light;
  --navy: #102a43;
  --blue: #1677ff;
  --green-dark: #17613c;
  --green: #238653;
  --yellow: #e4b531;
  --orange: #e58328;
  --red: #c83c3c;
  --ink: #243b53;
  --muted: #6b7c93;
  --line: #dde6ef;
  --surface: #ffffff;
  --background: #f3f7fb;
  --soft: #edf3f8;
  --shadow: 0 10px 30px rgba(16, 42, 67, 0.06);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --navy: #d7e8f7;
  --blue: #62a5ff;
  --green-dark: #64bd88;
  --green: #52b579;
  --yellow: #ecc95c;
  --orange: #f2a24c;
  --red: #ff7777;
  --ink: #d7e2ee;
  --muted: #9cacc0;
  --line: #34475b;
  --surface: #1b2b3c;
  --background: #111d2a;
  --soft: #24384b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--background);
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 35%, transparent);
  outline-offset: 2px;
}

.app-shell { max-width: 1240px; margin: 0 auto; padding: 22px 28px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 38px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 13px; background: #102a43; color: #fff; font: 27px Georgia, serif; }
.brand-title { display: block; color: var(--navy); font-size: 17px; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1.25px; }
.main-nav { display: flex; align-items: center; gap: 8px; }
.main-nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 650; text-decoration: none; }
.main-nav a:hover { color: var(--blue); background: var(--soft); }
.theme-toggle, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; }
.theme-toggle:hover, .secondary-button:hover { border-color: var(--blue); }

.page-section { scroll-margin-top: 20px; }
.section-heading { margin: 0 0 18px; }
.section-heading h1, .section-heading h2 { margin: 0 0 7px; color: var(--navy); }
.section-heading h1 { font-size: clamp(26px, 4vw, 35px); letter-spacing: -0.7px; }
.section-heading h2 { font-size: 25px; }
.section-subtitle { max-width: 670px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.search-card { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.search-card label { display: block; margin-bottom: 8px; color: var(--ink); font-size: 13px; font-weight: 750; }
.search-row { display: grid; grid-template-columns: minmax(180px, 1fr) 155px 190px; align-items: end; gap: 12px; }
.search-row > input, .rate-input input, .section-actions select, #periodo {
  width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px;
  background: var(--surface); color: var(--ink);
}
.rate-input { margin: 0 !important; color: var(--muted) !important; font-size: 11px !important; }
.rate-input input { display: block; margin-top: 5px; color: var(--ink); font-size: 15px; }
.search-row button { min-height: 46px; border: 0; border-radius: 8px; padding: 0 17px; background: #102a43; color: #fff; font-weight: 750; cursor: pointer; }
.search-row button:hover { background: #194866; }
.search-row button:disabled, .secondary-button:disabled { opacity: 0.65; cursor: wait; }
.rate-label { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.rate-suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.rate-suggestion { border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; background: var(--soft); color: var(--ink); font-size: 12px; cursor: pointer; }
.rate-suggestion:hover { border-color: var(--blue); }
.rate-suggestion:disabled { opacity: 0.65; cursor: wait; }
.period-label { margin-top: 16px; }
#periodo { max-width: 360px; }
.methodology-notice { margin: 14px 0 0; padding: 12px 15px; border-left: 3px solid var(--blue); border-radius: 6px; background: var(--soft); color: var(--ink); font-size: 13px; line-height: 1.5; }
.interpretation { margin-top: 20px; }
.interpretation-list { display: grid; gap: 10px; margin: 0; }
.interpretation-list div { display: flex; align-items: center; gap: 12px; }
.interpretation-list dt { min-width: 100px; }
.interpretation-list dd { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }

.message { min-height: 18px; margin: 10px 2px; color: var(--red); font-size: 13px; font-weight: 650; }
.results { animation: appear 0.25s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } }
.asset-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 20px 0 16px; }
.asset-heading h2 { margin: 0 0 8px; color: var(--navy); font-size: 23px; }
.ticker-badge { display: inline-block; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 800; }
.status-badge { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; padding: 8px 12px; color: #fff; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-badge.muito-barata { background: var(--green-dark); }
.status-badge.barata { background: var(--green); }
.status-badge.justa { background: #b48b0d; color: #fff; }
.status-badge.cara { background: var(--orange); color: #fff; }
.status-badge.muito-cara { background: var(--red); }

.warning-list { margin: 14px 0; padding: 13px 16px; border: 1px solid #e8c66b; border-radius: 10px; background: color-mix(in srgb, #f8d77a 18%, var(--surface)); color: var(--ink); font-size: 13px; }
.warning-list ul { margin: 7px 0 0; padding-left: 19px; line-height: 1.55; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card, .panel, .table-wrap { min-width: 0; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.metric-card { padding: 17px; }
.metric-card p { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.metric-card p > span:first-child { color: var(--blue); font-size: 15px; }
.metric-card strong { display: block; overflow-wrap: anywhere; color: var(--navy); font-size: clamp(19px, 2.4vw, 24px); }
.metric-card.highlight { border-top: 3px solid var(--blue); }
.info { display: inline-grid; width: 15px; height: 15px; place-items: center; border: 1px solid var(--muted); border-radius: 50%; color: var(--muted); font-size: 10px; cursor: help; }

.details-grid, .charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.panel { padding: 18px; }
.panel h3, .history-section h2 { margin: 0 0 14px; color: var(--navy); font-size: 16px; }
.profile-prices summary { color: var(--navy); font-size: 16px; font-weight: 700; cursor: pointer; }
.profile-prices .data-list { margin-top: 9px; }
.calculation p { margin: 0; padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--ink); font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.calculation p:last-child { border-bottom: 0; color: var(--navy); font-weight: 800; }
.data-list { margin: 0; }
.data-list div { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.data-list dt { color: var(--muted); }
.data-list dd { margin: 0; color: var(--ink); font-weight: 750; text-align: right; }
.subheading { margin: 16px 0 9px; color: var(--ink); font-size: 12px; }
.dividend-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(85px, 1fr)); gap: 7px; }
.dividend-item { min-width: 0; padding: 10px 5px; border-radius: 8px; background: var(--soft); text-align: center; }
.dividend-item span { display: block; color: var(--muted); font-size: 11px; }
.dividend-item strong { display: block; margin-top: 4px; color: var(--navy); font-size: 12px; overflow-wrap: anywhere; }
.dividend-item .dividend-state { margin-top: 4px; }
.chart-panel { min-height: 290px; }
.chart-caption { margin: -7px 0 12px; color: var(--muted); font-size: 12px; }
.chart-wrap { position: relative; height: 210px; }

.dashboard-section { margin-top: 46px; }
.section-heading-row { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.section-actions { display: flex; align-items: center; gap: 8px; }
.section-actions select { min-width: 175px; height: 40px; }
.secondary-button { min-height: 40px; font-size: 13px; }
.table-wrap { overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; text-align: left; }
thead { background: var(--soft); }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--ink); font-size: 13px; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: 0.25px; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--soft) 55%, var(--surface)); }
.ticker-cell { color: var(--navy); font-weight: 800; }
.comparison-ticker { border: 0; padding: 2px 0; background: transparent; color: var(--blue); font-weight: 800; text-decoration: underline; cursor: pointer; }
.comparison-ticker:disabled { opacity: 0.6; cursor: wait; }
.table-badge { padding: 6px 9px; font-size: 10px; }
.empty-state { padding: 20px; color: var(--muted); text-align: center; white-space: normal; }
.comparison-form { margin-bottom: 7px; box-shadow: none; }
.comparison-row { grid-template-columns: minmax(180px, 1fr) 190px; }
.comparison-row label { display: none; }
.history-section { margin-top: 44px; }
.disclaimer { margin-top: 30px; color: var(--muted); font-size: 11px; line-height: 1.5; text-align: center; }

.skeleton-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.skeleton { position: relative; overflow: hidden; border-radius: 10px; background: var(--soft); }
.skeleton::after { position: absolute; inset: 0; content: ""; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 72%, transparent), transparent); animation: shimmer 1.35s infinite; }
.skeleton-card { height: 90px; }
.skeleton-panel { grid-column: span 2; height: 190px; }
.skeleton-table { height: 230px; margin: 10px 0; }
@keyframes shimmer { 100% { transform: translateX(100%); } }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 850px) {
  .app-shell { padding-right: 20px; padding-left: 20px; }
  .topbar { flex-wrap: wrap; margin-bottom: 30px; }
  .main-nav { order: 3; width: 100%; justify-content: center; border-top: 1px solid var(--line); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading-row { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 620px) {
  .app-shell { padding: 16px 13px 36px; }
  .topbar { gap: 10px; margin-bottom: 25px; }
  .main-nav { justify-content: flex-start; gap: 0; overflow-x: auto; }
  .main-nav a { padding: 10px 9px; font-size: 12px; white-space: nowrap; }
  .theme-toggle { min-height: 36px; padding: 6px 9px; }
  .theme-label { display: none; }
  .search-row, .comparison-row { grid-template-columns: 1fr 1fr; }
  .search-row > input { grid-column: 1 / -1; }
  .search-row button { grid-column: 1 / -1; }
  .comparison-row input { grid-column: 1 / -1; }
  .comparison-row button { grid-column: 1 / -1; }
  .details-grid, .charts-grid { grid-template-columns: 1fr; }
  .section-actions { width: 100%; }
  .section-actions select, .section-actions button { flex: 1; min-width: 0; }
  .dividend-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .skeleton-grid { grid-template-columns: repeat(2, 1fr); }
  .skeleton-panel { grid-column: span 2; }
  th, td { padding: 10px 11px; }
}

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