body {
  background-color: #141414;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#page-wrapper {
  width: 90vw;
  max-width: 1000px;
  padding: 3rem 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#stats-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  background-color: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 0.85rem 1.2rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.stat-card {
  display: flex;
  flex-direction: column;
  min-width: 130px;
}

.stat-label {
  font-size: 0.68rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.stat-value {
  font-size: 1.05rem;
  font-weight: bold;
  color: #e6e6e6;
}

.stat-delta {
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

.stat-delta.up {
  color: #90ee90;
}
.stat-delta.down {
  color: #f45b5b;
}
.stat-delta.flat {
  color: #888;
}

.stat-date {
  font-size: 0.68rem;
  color: #555;
  margin-top: 0.1rem;
}

#controls-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}

/* Month nav */
#month-wrapper {
  position: relative;
}

#month-nav {
  display: flex;
  align-items: stretch;
  border: 1px solid #444;
  border-radius: 4px;
  overflow: hidden;
}

#month-prev,
#month-next {
  background: #2a2a2a;
  color: #cccccc;
  border: none;
  padding: 0 0.7rem;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  min-height: 36px;
  transition: background-color 0.15s;
}

#month-label {
  background: #2a2a2a;
  color: #cccccc;
  border: none;
  border-left: 1px solid #444;
  border-right: 1px solid #444;
  padding: 0.32rem 0.85rem;
  font-size: 0.88rem;
  cursor: pointer;
  min-height: 36px;
  width: 160px;
  white-space: nowrap;
  transition: background-color 0.15s;
}

#month-prev:hover:not(:disabled),
#month-next:hover:not(:disabled),
#month-label:hover {
  background-color: #383838;
}

#month-prev:disabled,
#month-next:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Month picker dropdown */
#month-picker {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 210px;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 0.55rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  z-index: 200;
}

#month-picker.open {
  display: block;
}

#picker-all-time {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: #2a2a2a;
  color: #cccccc;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 0.28rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: center;
  margin-bottom: 0.4rem;
}

#picker-all-time:hover,
#picker-all-time.selected {
  background: #383838;
}
#picker-all-time.selected {
  border-color: #666;
  color: #fff;
}

.picker-year-label {
  font-size: 0.68rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.3rem 0 0.2rem;
  border-top: 1px solid #2a2a2a;
  margin-top: 0.2rem;
}

.picker-months-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.22rem;
}

.picker-month-btn {
  background: #2a2a2a;
  color: #cccccc;
  border: 1px solid #2e2e2e;
  border-radius: 3px;
  padding: 0.27rem 0.2rem;
  font-size: 0.78rem;
  /* always bold so selection can't shift layout */
  font-weight: bold;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.1s;
  /* fixed height so border-color change doesn't reflow */
  height: 28px;
  box-sizing: border-box;
}

.picker-month-btn:not(:disabled):hover {
  background: #383838;
}
.picker-month-btn.selected {
  background: #3a3a3a;
  border-color: #777;
  color: #fff;
}
.picker-month-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

#refresh-btn {
  background-color: #2a2a2a;
  color: #cccccc;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 0.32rem 0.65rem;
  font-size: 0.88rem;
  cursor: pointer;
  min-height: 36px;
}

#refresh-btn {
  transition: background-color 0.15s;
}

#refresh-btn:hover:not(:disabled) {
  background-color: #383838;
}
#refresh-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

#auto-refresh-label {
  color: #888;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  user-select: none;
}

#last-updated {
  color: #555;
  font-size: 0.78rem;
  margin-left: auto;
}

#container {
  width: 100%;
  height: 60vh;
  min-height: 300px;
  padding: 1rem;
  box-sizing: border-box;
  margin-bottom: 2rem;
  /* Let Highcharts own all touch events for pan/pinch */
  touch-action: none;
}

.highcharts-data-table table {
  border-collapse: collapse;
  width: auto;
  background-color: #1e1e1e;
  margin: 1rem auto;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.highcharts-data-table td,
.highcharts-data-table th {
  border: 1px solid #333;
  padding: 0.75rem 0.6rem;
  text-align: center;
  color: #cccccc;
}

.highcharts-data-table thead tr {
  background-color: #2a2a2a;
  font-weight: bold;
}

.highcharts-data-table tbody tr:nth-child(even) {
  background-color: #252525;
}

.highcharts-data-table tbody tr:hover {
  background-color: #333333;
  cursor: pointer;
}

.highcharts-data-table caption {
  font-size: 1.1em;
  font-weight: bold;
  padding: 0.5rem;
  color: #e6e6e6;
  background-color: #1e1e1e;
}

@media (max-width: 600px) {
  body {
    min-height: 0;
    height: 100svh;
    overflow: hidden;
    overscroll-behavior: none;
    align-items: stretch;
  }

  #page-wrapper {
    width: 100vw;
    height: 100svh;
    padding: 0;
    overflow: hidden;
  }

  #stats-header {
    flex-shrink: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    gap: 0.25rem 0.75rem;
    padding: 0.35rem 1rem;
    margin-bottom: 0;
  }

  /* Horizontal compact card: label left, value+delta right */
  .stat-card {
    flex: 1 1 calc(50% - 0.75rem);
    min-width: 0;
    flex-direction: row;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 0.35rem;
  }

  .stat-label {
    font-size: 0.62rem;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-delta {
    font-size: 0.68rem;
    margin-top: 0;
    flex-basis: 100%;
  }

  .stat-date {
    display: none;
  }

  /* Swap Today max (3rd) and Central Bank (4th) */
  #stats-header .stat-card:nth-child(3) {
    order: 4;
  }
  #stats-header .stat-card:nth-child(4) {
    order: 3;
  }

  #controls-bar {
    flex-shrink: 0;
    padding: 0.35rem 1rem;
    gap: 0.5rem;
    margin-bottom: 0;
  }

  #month-wrapper {
    flex: 0 0 auto;
  }
  #month-label {
    width: 105px;
    font-size: 0.88rem;
  }
  #month-prev,
  #month-next {
    min-height: 38px;
  }

  #refresh-btn {
    flex: 1;
    min-height: 38px;
    font-size: 0.95rem;
    text-align: center;
  }

  #month-picker {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }

  #auto-refresh-label {
    font-size: 0.9rem;
    min-height: 38px;
  }

  #last-updated {
    width: 100%;
    margin-left: 0;
    text-align: right;
    font-size: 0.72rem;
  }

  /* chart-wrapper fills all remaining space */
  #chart-wrapper {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  #container {
    width: 100%;
    height: 100%;
    padding: 0.25rem;
    margin-bottom: 0;
    min-height: 0;
  }

  /* data table hidden on mobile — can't scroll to it anyway */
  #table-container {
    display: none;
  }
}
