:root {
  --bg-a: #07101c;
  --bg-b: #081628;
  --surface: #111f31;
  --surface-soft: #16263b;
  --line: #2e435d;
  --text: #eef4ff;
  --muted: #98abc2;
  --blue: #59acff;
  --green: #4ce38d;
  --yellow: #f3dd61;
  --orange: #ff9842;
  --danger: #ff6b6b;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #123152 0%, transparent 40%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
  color: var(--text);
  font-family: "SF Pro Display", "Noto Sans TC", "Segoe UI", sans-serif;
}

.dashboard {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 40px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 10px;
  color: #8ac6ff;
  font-size: 13px;
  font-weight: 620;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3.3vw, 46px);
  line-height: 1.12;
  letter-spacing: 0.01em;
}

.source-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(89, 172, 255, 0.42);
  border-radius: 999px;
  background: rgba(89, 172, 255, 0.1);
  color: #cfe8ff;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.source-link:hover {
  border-color: #8fd0ff;
  background: rgba(89, 172, 255, 0.18);
  transform: translateY(-1px);
}

.date-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: linear-gradient(160deg, #15283d, #122134);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.date-button {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.date-button::after {
  content: "▾";
  margin-left: 7px;
  color: var(--muted);
  font-size: 11px;
}

.calendar-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: 286px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #111b28;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}

.calendar-popover[hidden] {
  display: none;
}

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.calendar-head strong {
  color: var(--text);
  font-size: 15px;
}

.calendar-nav {
  width: 32px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.calendar-nav:hover {
  border-color: var(--line);
  color: var(--text);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.calendar-weekdays {
  margin-bottom: 6px;
  color: #c8d8eb;
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.calendar-day {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  line-height: 1;
}

.calendar-day[data-has-data="false"],
.calendar-day.outside {
  color: #5f6b79;
}

.calendar-day:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.calendar-day[data-has-data="true"]:hover {
  border-color: rgba(89, 172, 255, 0.56);
  background: rgba(89, 172, 255, 0.12);
}

.calendar-day[data-today="true"] {
  border-color: rgba(76, 227, 141, 0.55);
}

.calendar-day[data-selected="true"] {
  border-color: #8dc8ff;
  background: #8dc8ff;
  color: #07101c;
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(160deg, #1a2e45, #122338);
  color: var(--blue);
  cursor: pointer;
  font-size: 23px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  transition: border-color 160ms ease, transform 160ms ease;
}

.icon-button:hover {
  border-color: #83c6ff;
  transform: translateY(-1px);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: linear-gradient(160deg, #15283d, #122134);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.status-pill::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #6f86a1;
}

.status-pill[data-tone="ok"] {
  color: #d4ffe8;
}

.status-pill[data-tone="ok"]::before {
  background: var(--green);
}

.status-pill[data-tone="error"] {
  color: #ffdada;
}

.status-pill[data-tone="error"]::before {
  background: var(--danger);
}

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

.summary-card {
  min-width: 0;
  min-height: 104px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(155deg, #16273c, #111f32);
  box-shadow: var(--shadow);
}

.summary-card.primary {
  border-color: #1f6f8d;
  background: linear-gradient(155deg, #104351, #156075);
}

.summary-card .title {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 580;
}

.summary-card strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: clamp(26px, 2.5vw, 36px);
  line-height: 1.04;
  letter-spacing: 0;
}

.summary-card strong small {
  font-size: 26px;
  color: var(--muted);
  margin-left: 4px;
}

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

.meta-card {
  min-width: 0;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, #15263b, #111f31);
}

.meta-card .label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 560;
}

.meta-card strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 19px;
  line-height: 1.1;
}

.chart-shell {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, #13243a, #102035);
  box-shadow: var(--shadow);
  padding: 16px;
}

.chart-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.legend {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #cde1ff;
  font-size: 15px;
  font-weight: 540;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.blue {
  background: var(--blue);
}

.dot.green {
  background: var(--green);
}

.dot.yellow {
  background: var(--yellow);
}

.chart-status {
  grid-column: 3;
  justify-self: end;
  color: var(--muted);
  font-size: 14px;
}

.canvas-wrap {
  position: relative;
  min-height: 500px;
}

#reserve-chart {
  display: block;
  width: 100%;
  height: 500px;
  border-radius: 12px;
}

.chart-tooltip {
  position: absolute;
  min-width: 172px;
  padding: 10px 12px;
  border: 1px solid rgba(130, 177, 224, 0.35);
  border-radius: 10px;
  background: rgba(5, 16, 30, 0.92);
  color: #e6f1ff;
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

.empty-state {
  position: absolute;
  inset: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-radius: 12px;
  background: rgba(4, 11, 21, 0.48);
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .summary-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meta-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .dashboard {
    width: min(100% - 20px, 1120px);
    padding-top: 18px;
  }

  h1 {
    font-size: clamp(28px, 9vw, 38px);
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .status-pill {
    font-size: 14px;
  }

  .chart-head {
    grid-template-columns: 1fr;
  }

  .legend,
  .chart-status {
    grid-column: 1;
    justify-self: center;
    text-align: center;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }

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

  .canvas-wrap {
    min-height: 380px;
  }

  #reserve-chart {
    height: 380px;
  }
}
