:root {
  --ink: #162024;
  --muted: #5e6d75;
  --line: #d8e0e5;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --accent: #0f6651;
  --accent-soft: #e7f2ee;
  --down: #a43f34;
  --up: #0f6651;
  --blue: #315f9f;
  --gold: #a87311;
  --shadow: 0 10px 28px rgba(22, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

.app-header {
  border-bottom: 1px solid var(--line);
  padding: 28px clamp(18px, 4vw, 48px);
  background: #fff;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(30px, 4vw, 46px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.dek,
.data-note {
  max-width: 780px;
  color: var(--muted);
  line-height: 1.45;
}

.dek {
  margin-bottom: 6px;
}

.data-note {
  margin-bottom: 0;
  font-size: 13px;
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(480px, 1fr);
  grid-template-areas:
    "controls table"
    "controls chart";
  gap: 18px;
  align-items: start;
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  grid-area: controls;
}

.chart-panel {
  grid-area: chart;
  min-width: 0;
}

.table-panel {
  grid-area: table;
  min-width: 0;
}

label {
  display: block;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input {
  display: block;
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 22px;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.96);
}

.currency-heading,
.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.currency-heading h2,
.panel-title h2 {
  margin-bottom: 0;
}

#selectedCount {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.chart-mode {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #f6f8f5;
}

.chart-mode button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.chart-mode button.active {
  background: var(--accent);
  color: #fff;
}

.chart-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.currency-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.currency-option {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
  color: var(--ink);
}

.currency-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.currency-name {
  display: grid;
  gap: 2px;
  font-weight: 800;
}

.currency-code {
  color: var(--muted);
  font-size: 12px;
}

.currency-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.chart {
  min-height: 460px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  overflow: hidden;
}

.chart svg {
  display: block;
  width: 100%;
  height: 460px;
}

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

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

.series-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.series-point {
  stroke: #fff;
  stroke-width: 2;
}

.legend-item {
  cursor: pointer;
}

.legend-item .tick-label {
  pointer-events: none;
}

.legend-hidden {
  opacity: 0.35;
}

.legend-hidden .tick-label {
  text-decoration: line-through;
}

.empty-state {
  display: grid;
  min-height: 460px;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.summary-grid div {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  line-height: 1.3;
}

.table-panel .panel-title {
  align-items: center;
  margin-bottom: 16px;
}

#downloadCsv {
  width: auto;
  padding: 0 14px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3f6f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  line-height: 1.35;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 210px;
  background: #fff;
}

th:first-child {
  z-index: 3;
  background: #f3f6f3;
}

.week-cell {
  min-width: 132px;
}

.week-value {
  display: block;
  font-weight: 800;
}

.week-change {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.change-up {
  color: var(--up);
  font-weight: 800;
}

.change-down {
  color: var(--down);
  font-weight: 800;
}

.change-flat {
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "table"
      "chart";
  }
}

@media (max-width: 680px) {
  .app-header {
    padding: 24px 18px;
  }

  .layout {
    padding: 18px;
  }

  .date-grid,
  .button-row,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .currency-heading,
  .panel-title {
    flex-direction: column;
  }

  .chart {
    overflow-x: auto;
  }

  .chart svg {
    width: 760px;
  }
}
