:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-soft: #fbfaf7;
  --text: #1f211d;
  --muted: #74786e;
  --line: #deded6;
  --gold: #b9851d;
  --green: #17775c;
  --amber: #986b10;
  --red: #a04c3f;
  --blue: #315b77;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 245, 241, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #d6be82;
  border-radius: var(--radius);
  background: #f3dfa7;
  color: #4b3407;
  font-family: Georgia, serif;
  font-weight: 700;
}

.nav-list {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.nav-list a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.nav-list a:hover,
.nav-list a.active {
  background: var(--text);
  color: var(--text);
  color: #fffdf7;
}

main {
  padding: 24px 0 40px;
}

.summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}

.summary-note {
  max-width: 680px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

.trend-top-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(0, 1.05fr);
  gap: 12px;
  align-items: stretch;
  margin-bottom: 12px;
}

.buyback-widgets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.buyback-widget {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.widget-top {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.widget-brand {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.widget-badge {
  flex: 0 0 auto;
  padding: 4px 7px;
  border: 1px solid #d8d0bd;
  border-radius: 999px;
  background: #fffaf0;
  color: var(--amber);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.buyback-widget strong {
  font-size: 22px;
  line-height: 1.1;
  white-space: nowrap;
}

.widget-change {
  display: block;
  margin-top: -3px;
  font-size: 12px;
  font-weight: 850;
}

.buyback-widget small {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.widget-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.widget-meta span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.buyback-widget em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 650;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.benchmark {
  min-width: 260px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.benchmark span,
.benchmark small,
.freshness,
td small,
.delta {
  color: var(--muted);
}

.benchmark span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.benchmark strong {
  display: block;
  margin: 4px 0;
  font-size: 28px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
.refresh-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0 11px;
}

.refresh-button {
  cursor: pointer;
  font-weight: 700;
}

.refresh-button:hover {
  border-color: #c9c5b9;
  background: #fdfcf8;
}

.refresh-button.subtle {
  background: var(--panel-soft);
  color: var(--muted);
}

.freshness {
  margin-left: auto;
  padding-bottom: 9px;
  font-size: 13px;
}

.rate-grid,
.two-column,
.full-row {
  display: grid;
  gap: 12px;
}

.rate-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.rate-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.rate-card {
  min-height: 138px;
  padding: 14px;
}

.card-top,
.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.jeweller-name {
  display: block;
  margin-bottom: 3px;
  font-size: 15px;
  font-weight: 750;
}

.rate-card small {
  display: block;
  line-height: 1.45;
}

.rate-card strong {
  display: block;
  margin-top: 18px;
  font-size: 24px;
}

.delta {
  margin: 3px 0 12px;
  font-size: 12px;
}

.badge,
.panel-title span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.badge.high,
.status-live {
  background: #e8f4ef;
  color: var(--green);
}

.badge.medium,
.status-review {
  background: #f6edda;
  color: var(--amber);
}

.badge.low,
.status-unavailable {
  background: #f6e8e5;
  color: var(--red);
}

.two-column {
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.8fr);
  margin-top: 12px;
}

.full-row {
  grid-template-columns: 1fr;
  margin-top: 12px;
}

.history-chart-panel {
  margin-top: 0;
}

.history-chart-panel .panel {
  height: 100%;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-large {
  min-height: 360px;
}

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

.panel-title span {
  background: #edf2f5;
  color: var(--blue);
}

.chart-title {
  align-items: center;
}

.chart-title small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  font-weight: 500;
}

.chart-actions,
.chart-range,
.chart-brand-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chart-actions {
  justify-content: flex-end;
}

.chart-range button,
.chart-brand-toggles button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.chart-range button {
  padding: 0 11px;
}

.chart-brand-toggles {
  margin-top: 12px;
}

.chart-brand-toggles button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 0 10px;
}

.chart-range button.active,
.chart-brand-toggles button.active {
  border-color: #c9c5b9;
  background: #ebe8df;
  color: var(--text);
}

.chart-brand-toggles i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.history-chart-wrap {
  position: relative;
  margin-top: 12px;
  min-height: 240px;
}

#historyChart {
  display: block;
  width: 100%;
  height: 240px;
}

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

.movement-layout {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(260px, 3fr);
  gap: 18px;
  align-items: start;
}

.movement-summary {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding-top: 2px;
}

.movement-summary-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.movement-stat {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.movement-stat.primary {
  border-color: #d8d0bd;
  background: #fffdf8;
}

.movement-stat span,
.movement-stat small,
.movement-empty {
  color: var(--muted);
}

.movement-stat span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.movement-stat strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  line-height: 1.15;
}

.movement-stat small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  font-style: italic;
  font-weight: 550;
}

.movement-empty {
  font-size: 13px;
  font-style: italic;
}

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

.trend-table {
  width: auto;
  min-width: 760px;
  table-layout: fixed;
}

.trend-table th,
.trend-table td {
  padding: 14px 20px;
}

.trend-table th:nth-child(1),
.trend-table td:nth-child(1) {
  width: 280px;
}

.trend-table th:nth-child(2),
.trend-table td:nth-child(2) {
  width: 210px;
}

.trend-table th:nth-child(3),
.trend-table td:nth-child(3) {
  width: 270px;
}

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

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  font-weight: 650;
}

td small {
  display: block;
  margin-top: 3px;
  font-weight: 500;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.legend span {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(0, 1.28fr);
  gap: 14px;
  align-items: start;
}

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

.calc-form label:first-child {
  grid-column: 1 / -1;
}

.result-grid {
  display: grid;
  grid-template-columns: 1.15fr repeat(2, minmax(0, 0.9fr));
  gap: 10px;
}

.result-card {
  min-height: 94px;
  padding: 14px;
  border: 1px solid #d8d3c5;
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.result-card.primary {
  border-color: #ceb47a;
  background: #fffcf3;
}

.result-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.result-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.05;
}

.calc-steps {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.calc-step {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.calc-step span {
  color: var(--muted);
  font-weight: 750;
}

.calc-step strong {
  color: var(--text);
  font-weight: 700;
}

.profit {
  color: var(--green);
  font-weight: 750;
}

.loss {
  color: var(--red);
  font-weight: 750;
}

.trend-value {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-weight: 800;
}

.rate-summary {
  display: grid;
  gap: 3px;
}

.rate-summary strong {
  font-size: 18px;
}

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

.change-line {
  display: block;
  font-size: 13px;
  font-weight: 750;
}

.trend-up {
  color: var(--green);
}

.trend-down {
  color: var(--red);
}

.trend-flat {
  color: var(--muted);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.admin-row {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.admin-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.admin-card-head strong {
  display: block;
  font-size: 17px;
}

.admin-card-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  font-weight: 550;
}

.admin-card-head > span {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.admin-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

.admin-panel {
  padding: 18px;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.admin-toolbar h2 {
  font-size: 20px;
}

.admin-toolbar small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  font-weight: 550;
}

.admin-status {
  min-height: 30px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.primary-action {
  border-color: #746144;
  background: var(--text);
  color: #fffdf7;
}

.last-updated {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  font-weight: 500;
}

.revision-list {
  display: grid;
  gap: 4px;
  max-width: 250px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.revision-list > span,
.revision-admin > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.revision-row {
  display: grid;
  grid-template-columns: 58px minmax(80px, 1fr) 70px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.revision-row strong {
  color: var(--text);
}

.revision-row em {
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.revision-admin {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.revision-admin-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.45fr) minmax(180px, 0.55fr);
  gap: 8px;
}

.is-hidden {
  display: none;
}

@media (max-width: 980px) {
  .topbar,
  .summary {
    align-items: flex-start;
  }

  .topbar,
  .summary,
  .trend-top-grid,
  .two-column,
  .calculator-layout,
  .movement-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 16px 0;
  }

  .admin-toolbar,
  .admin-card-head {
    display: grid;
  }

  .admin-status {
    text-align: left;
  }

  .admin-grid,
  .admin-fields {
    grid-template-columns: 1fr;
  }

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

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

  .chart-title {
    display: grid;
  }

  .chart-actions {
    justify-content: stretch;
  }

  .benchmark {
    width: 100%;
  }
}

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

  main {
    padding-top: 16px;
  }

  .nav-list {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .topbar {
    gap: 12px;
  }

  .nav-list a {
    padding: 8px 12px;
  }

  .rate-grid,
  .calc-form {
    grid-template-columns: 1fr;
  }

  .buyback-widgets {
    gap: 8px;
    margin-bottom: 12px;
  }

  .buyback-widget {
    padding: 10px;
  }

  .buyback-widget strong {
    font-size: 18px;
  }

  .buyback-widget small {
    font-size: 12px;
  }

  .widget-meta span:first-child {
    display: none;
  }

  .chart-range {
    width: 100%;
  }

  .chart-range button {
    flex: 1;
  }

  .history-chart-wrap {
    min-height: 210px;
  }

  #historyChart {
    height: 210px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow: visible;
  }

  .movement-summary {
    order: -1;
  }

  .trend-table,
  .trend-table thead,
  .trend-table tbody,
  .trend-table tr,
  .trend-table th,
  .trend-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .trend-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .trend-table tr {
    margin-bottom: 12px;
    padding: 14px 14px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
  }

  .trend-table td,
  .trend-table th:nth-child(1),
  .trend-table td:nth-child(1),
  .trend-table th:nth-child(2),
  .trend-table td:nth-child(2),
  .trend-table th:nth-child(3),
  .trend-table td:nth-child(3) {
    width: 100%;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .trend-table td:first-child {
    padding-top: 0;
  }

  .trend-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .trend-table td::before {
    content: none;
  }

  .jeweller-cell {
    font-size: 20px;
    font-weight: 850;
  }

  .today-cell {
    background: #fbfaf7;
    margin: 0 -4px;
    padding: 12px !important;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  .trend-value {
    font-size: 22px;
  }

  .change-line {
    font-size: 14px;
  }

  .last-updated {
    font-size: 12px;
  }

  .yesterday-cell {
    color: var(--text);
  }

  .revision-list {
    max-width: none;
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-row strong {
    padding-bottom: 0;
  }

  .calc-step {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .freshness {
    width: 100%;
    margin-left: 0;
    padding-bottom: 0;
  }
}
