:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #18211f;
  --muted: #60706a;
  --line: #d9dfd8;
  --panel: #ffffff;
  --accent: #176b5b;
  --accent-strong: #0f4f44;
  --blue: #2f6fad;
  --rose: #b2445d;
  --amber: #b87815;
  --danger: #9f283f;
  --shadow: 0 18px 45px rgba(24, 33, 31, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(246, 247, 244, 0) 270px),
    var(--bg);
  color: var(--ink);
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.workspace,
.chart-head,
.maintenance-panel dl {
  display: flex;
  gap: 20px;
}

.topbar {
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.18rem;
  line-height: 1.25;
}

.data-status {
  flex: 0 0 auto;
  max-width: 360px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.workspace {
  align-items: stretch;
  margin-bottom: 18px;
}

.control-panel,
.result-panel,
.chart-panel,
.maintenance-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-panel {
  flex: 0 0 320px;
  display: grid;
  align-content: start;
  gap: 15px;
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fbfcfa;
  font: inherit;
}

input:focus {
  outline: 3px solid rgba(23, 107, 91, 0.18);
  border-color: var(--accent);
}

.primary-action {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.primary-action:hover,
.primary-action:focus {
  background: var(--accent-strong);
}

.result-panel {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px;
}

.result-head,
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
  margin-top: 22px;
}

.result-section {
  min-width: 0;
  border-top: 3px solid var(--line);
  padding-top: 12px;
}

.result-section-brl {
  border-color: var(--accent);
}

.result-section-exchange {
  border-color: var(--rose);
}

.result-section-usd {
  border-color: var(--blue);
}

.result-section h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.25;
}

.result-table {
  margin: 0;
}

.result-table div {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(92px, 0.75fr);
  gap: 12px;
  align-items: baseline;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.result-table dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
}

.result-table dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: right;
}

.notice {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.notice.error {
  color: var(--danger);
  font-weight: 800;
}

.chart-panel {
  padding: 18px;
}

.chart-head {
  margin-bottom: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-cdi {
  background: var(--accent);
}

.swatch-usd {
  background: var(--rose);
}

.swatch-real {
  background: var(--blue);
}

.chart-wrap {
  position: relative;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  overflow: hidden;
}

#comparison-chart {
  display: block;
  width: 100%;
  height: 360px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.chart-empty.hidden {
  display: none;
}

.axis-line {
  stroke: #c8d0ca;
  stroke-width: 1;
}

.grid-line {
  stroke: #e8ece7;
  stroke-width: 1;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.series-line {
  fill: none;
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.series-cdi {
  stroke: var(--accent);
}

.series-usd {
  stroke: var(--rose);
}

.series-real {
  stroke: var(--blue);
}

.maintenance-panel {
  margin-top: 18px;
  padding: 14px 16px;
}

.maintenance-panel dl {
  margin: 0;
  justify-content: space-between;
  flex-wrap: wrap;
}

.maintenance-panel dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.maintenance-panel dd {
  margin: 4px 0 0;
  font-weight: 800;
}

@media (max-width: 840px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .workspace,
  .result-head,
  .chart-head {
    flex-direction: column;
    align-items: stretch;
  }

  .data-status,
  .result-head {
    max-width: none;
    text-align: left;
  }

  .control-panel {
    flex-basis: auto;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 520px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .result-table div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .result-table dd {
    text-align: left;
  }

  .chart-wrap,
  #comparison-chart {
    min-height: 310px;
    height: 310px;
  }
}
