:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef2f4;
  --text: #17202a;
  --muted: #5d6975;
  --line: #d9e0e4;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warning: #9a5b13;
  --blue: #2563eb;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

button,
.button-link {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.button-link:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button-link:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
}

.secondary-button {
  background: #e6ecef;
  color: var(--text);
}

.secondary-button:hover {
  background: #d4dde2;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  background: #fff;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  background: #fff;
}

label {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 72px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding:
    max(12px, env(safe-area-inset-top))
    max(clamp(16px, 4vw, 44px), env(safe-area-inset-right))
    12px
    max(clamp(16px, 4vw, 44px), env(safe-area-inset-left));
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  font-size: 0.95rem;
}

.install-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent-dark);
}

.install-button:hover {
  background: var(--surface-strong);
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.freshness-card {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--success);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.freshness-card > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.freshness-card p {
  margin: 5px 0 0 20px;
  color: var(--muted);
  font-size: 0.88rem;
}

.freshness-card[data-status="stale"] {
  border-left-color: var(--warning);
}

.freshness-card[data-status="unavailable"] {
  border-left-color: var(--danger);
}

.freshness-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  flex: 0 0 auto;
}

.freshness-card[data-status="stale"] .freshness-indicator {
  background: var(--warning);
}

.freshness-card[data-status="unavailable"] .freshness-indicator {
  background: var(--danger);
}

.search-band {
  background: #12343b;
  color: #fff;
  border-radius: 8px;
  padding: clamp(18px, 3vw, 28px);
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  box-shadow: var(--shadow);
}

.search-copy h2 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.search-copy p {
  max-width: 620px;
  margin: 0;
  color: #d7e4e3;
}

.search-form label {
  color: inherit;
}

.filter-section {
  display: grid;
  grid-template-columns: minmax(230px, 0.8fr) minmax(280px, 1fr) minmax(320px, 1.25fr);
  gap: 14px;
}

.expense-filter-group {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 10px;
}

.filter-group {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.advanced-filters {
  grid-column: 1 / -1;
  min-width: 0;
}

.advanced-filters summary {
  width: fit-content;
  min-height: 42px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-weight: 700;
}

.advanced-filters summary:hover {
  background: rgba(255, 255, 255, 0.18);
}

.advanced-filters summary::marker {
  color: #d7e4e3;
}

.group-title {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #d7e4e3;
}

.search-actions {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.search-actions p {
  margin: 0;
  color: #d7e4e3;
  font-size: 0.9rem;
}

.search-actions button {
  min-width: 180px;
}

.progress-wrap {
  margin-top: 14px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #d7e4e3;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: #38bdf8;
  transition: width 220ms ease;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.workspace {
  margin-top: 18px;
  display: block;
}

.panel,
.profile-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-heading {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-heading > div h2 {
  margin-top: 2px;
}

.section-kicker {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#results-count {
  min-width: 30px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--surface-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

.count-badge {
  min-width: 30px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.represent-list {
  display: grid;
  gap: 8px;
}

.represent-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 12px;
  text-align: left;
}

.represent-item strong {
  display: block;
  margin-bottom: 4px;
}

.represent-item span {
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-area {
  display: grid;
  gap: 18px;
}

.selector-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 0.9fr);
  gap: 14px;
  align-items: end;
}

.selected-card {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: var(--surface-strong);
}

.selected-card img,
#selected-photo-fallback {
  width: 48px;
  height: 56px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.selected-card img {
  object-fit: cover;
  background: #fff;
}

.selected-card img[hidden],
#selected-photo-fallback[hidden] {
  display: none;
}

#selected-photo-fallback {
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.7rem;
  background: #fff;
}

.selected-card strong {
  display: block;
  margin-bottom: 3px;
}

.selected-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.status {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8ec;
  color: var(--warning);
  display: flex;
  align-items: center;
  padding: 12px 14px;
}

.status:empty {
  display: none;
}

.status[data-kind="success"] {
  background: #edfdf4;
  border-color: #a6f4c5;
  color: var(--success);
}

.status[data-kind="error"] {
  background: #fff1f0;
  border-color: #fda29b;
  color: var(--danger);
}

.status[data-kind="warning"] {
  background: #fff8ec;
}

.profile-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 0;
}

.profile-photo {
  padding: 18px;
  border-right: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.profile-photo img {
  width: 112px;
  height: 140px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.profile-photo img[hidden],
#profile-photo-fallback[hidden] {
  display: none;
}

#profile-photo-fallback {
  width: 112px;
  height: 140px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.86rem;
}

.profile-main {
  padding: 18px;
}

.profile-main h2 {
  margin: 0 0 16px;
  font-size: clamp(1.5rem, 3vw, 2rem);
}

.favorite-button {
  margin: -6px 0 18px;
  min-height: 36px;
}

.share-button {
  margin: -6px 0 18px 8px;
  min-height: 36px;
}

.favorite-button.is-favorite {
  background: #fff3cd;
  color: #785900;
}

.alert-form {
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.alert-form label {
  font-size: 0.78rem;
}

.alert-form button {
  min-height: 42px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
}

dd {
  margin: 4px 0 0;
  font-weight: 700;
}

.metric-strip {
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr;
}

.metric-strip div {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.metric-strip div:last-child {
  border-bottom: 0;
}

.metric-strip span {
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.metric-strip strong {
  font-size: 1.35rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.compare-panel {
  grid-column: 1 / -1;
}

.alerts-panel {
  grid-column: 1 / -1;
}

.alert-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.alert-rule {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.8rem;
}

.alert-rule button {
  min-height: auto;
  padding: 0 0 0 8px;
  background: transparent;
  color: var(--danger);
}

.alert-notification.unread {
  border-left: 4px solid var(--warning);
}

.mark-read-button {
  margin-top: 12px;
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-item {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
}

.compact-item:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.compact-item strong,
.compact-item small {
  display: block;
}

.compact-item small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 400;
}

.ranking-item {
  grid-template-columns: 34px minmax(0, 1fr) auto;
}

.ranking-item b {
  color: var(--accent-dark);
  white-space: nowrap;
}

.rank-position {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 14px;
}

.compare-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 8px 14px;
  align-items: end;
}

.compare-form label,
.compare-form select,
.compare-form .field-help {
  grid-column: 1;
}

.compare-form button {
  grid-column: 2;
  grid-row: 2;
}

.compare-form select {
  min-height: 132px;
  padding: 6px;
}

.field-help,
.analysis-notice {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.comparison-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.comparison-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.comparison-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.analysis-notice:not(:empty) {
  margin-top: 12px;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.update-toast {
  position: fixed;
  z-index: 20;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  width: min(520px, calc(100% - 32px));
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.update-toast[hidden] {
  display: none;
}

.site-footer {
  width: min(1240px, calc(100% - 32px));
  margin: -24px auto 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
  font-size: 0.84rem;
}

.legal-page {
  width: min(760px, calc(100% - 32px));
  margin: 32px auto;
  padding: clamp(20px, 4vw, 40px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.legal-page h1 {
  margin-top: 24px;
}

.legal-page h2 {
  margin-top: 28px;
  font-size: 1.1rem;
}

.legal-page p {
  color: var(--muted);
}

.api-reference li {
  margin: 10px 0;
}

.api-reference code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-strong);
  color: var(--text);
}

.represent-panel {
  grid-column: 1 / -1;
}

.variation-panel {
  grid-column: 1 / -1;
}

.variation-card {
  border-left: 5px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  padding: 16px;
}

.variation-card[data-trend="alta"] {
  border-left-color: var(--warning);
}

.variation-card[data-trend="queda"] {
  border-left-color: var(--success);
}

.variation-card[data-trend="estavel"] {
  border-left-color: var(--blue);
}

.variation-card strong,
.variation-card span {
  display: block;
}

.variation-card strong {
  font-size: 1.35rem;
  margin-bottom: 5px;
}

.variation-card span {
  color: var(--muted);
}

.represent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.represent-item strong {
  margin-bottom: 2px;
}

.represent-item .percent {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent-dark);
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.92rem;
}

.bar-progress {
  appearance: none;
  width: 100%;
  height: 10px;
  border: 0;
  background: var(--surface-strong);
  border-radius: 999px;
  overflow: hidden;
}

.bar-progress::-webkit-progress-bar {
  background: var(--surface-strong);
  border-radius: 999px;
}

.bar-progress::-webkit-progress-value {
  background: var(--blue);
  border-radius: 999px;
}

.bar-progress::-moz-progress-bar {
  background: var(--blue);
  border-radius: 999px;
}

.table-wrap {
  overflow-x: auto;
}

.export-actions {
  display: flex;
  gap: 8px;
}

.pagination {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.ranking-pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ranking-pagination button {
  min-height: 36px;
  padding: 0 12px;
}

.ranking-pagination span {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.pagination span {
  color: var(--muted);
  font-size: 0.88rem;
}

.secondary-link {
  background: #e6ecef;
  color: var(--text);
}

.secondary-link:hover {
  background: #d4dde2;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
}

td:last-child,
th:last-child {
  text-align: right;
}

.compare-form {
  margin-bottom: 14px;
}

@media (max-width: 920px) {
  .topbar,
  .search-band,
  .profile-grid,
  .dashboard-grid,
  .insights-grid,
  .filter-section,
  .selector-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .topnav {
    justify-content: flex-start;
  }

  .metric-strip {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .profile-photo {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    justify-content: flex-start;
  }

  .metric-strip div {
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .metric-strip div:last-child {
    border-right: 0;
  }

  .compare-panel {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 20px, 1240px);
    margin-top: 10px;
  }

  .topbar {
    position: static;
  }

  .search-row,
  .meta-grid,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .filter-group {
    grid-template-columns: 1fr;
  }

  .expense-filter-group {
    grid-template-columns: 1fr;
  }

  .search-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-actions button {
    width: 100%;
  }

  .compare-form {
    grid-template-columns: 1fr;
  }

  .alert-form {
    grid-template-columns: 1fr;
  }

  .favorite-button,
  .share-button {
    width: 100%;
    margin: 0 0 8px;
  }

  .compare-form button {
    grid-column: 1;
    grid-row: auto;
  }

  .ranking-item {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .ranking-item b {
    grid-column: 2;
  }

  .panel-heading {
    align-items: flex-start;
  }

  #expenses-panel .panel-heading {
    flex-direction: column;
  }

  .export-actions {
    width: 100%;
  }

  .export-actions .button-link {
    flex: 1;
  }

  .pagination {
    justify-content: space-between;
  }

  .pagination button {
    padding: 0 12px;
  }

  .metric-strip div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
