:root {
  --ink: #16221f;
  --muted: #6e7975;
  --line: #dfe5e1;
  --paper: #f7f8f4;
  --white: #ffffff;
  --green: #176b4d;
  --green-dark: #0f5039;
  --green-soft: #dceee6;
  --mint: #9bcfb5;
  --gold: #d9ae63;
  --red: #b35a4d;
  --shadow: 0 18px 50px rgba(23, 45, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 6%, rgba(155, 207, 181, 0.2), transparent 24rem),
    var(--paper);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 0 44px;
}

.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(22, 34, 31, 0.09);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--green);
  border-radius: 50% 50% 50% 12px;
  font-family: Georgia, serif;
  font-size: 19px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.source-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(217, 174, 99, 0.13);
}

.status-dot.online {
  background: #36a06f;
  box-shadow: 0 0 0 5px rgba(54, 160, 111, 0.13);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(179, 90, 77, 0.13);
}

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: 160ms ease;
}

.button-secondary {
  background: rgba(255, 255, 255, 0.7);
}

.button:hover,
.page-button:hover {
  border-color: var(--green);
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.refresh-icon {
  display: inline-block;
  margin-right: 4px;
  font-size: 18px;
}

.is-spinning .refresh-icon {
  animation: spin 0.9s linear infinite;
}

.hero {
  min-height: 470px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: center;
  gap: 90px;
  padding: 66px 5% 64px;
  overflow: hidden;
  position: relative;
}

.hero::before {
  content: "";
  position: absolute;
  right: -60px;
  bottom: -160px;
  width: 430px;
  height: 430px;
  border: 1px solid rgba(23, 107, 77, 0.11);
  border-radius: 50%;
}

.eyebrow,
.section-kicker {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.19em;
}

.hero h1 {
  max-width: 720px;
  margin: 0;
  font-family: Georgia, "Noto Serif TC", "Microsoft JhengHei", serif;
  font-size: clamp(48px, 6vw, 82px);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 1.06;
}

.hero h1 span {
  color: var(--green);
  font-style: italic;
}

.hero-description {
  max-width: 650px;
  margin: 28px 0 25px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.9;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  color: var(--muted);
  font-size: 12px;
}

.hero-meta strong {
  color: var(--ink);
  font-weight: 700;
}

.hero-calendar {
  width: 290px;
  padding: 0 24px 24px;
  justify-self: center;
  position: relative;
  z-index: 1;
  color: var(--white);
  background: var(--green);
  border-radius: 22px;
  box-shadow: 26px 30px 0 var(--green-soft), var(--shadow);
  transform: rotate(2deg);
}

.calendar-top {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  font-family: Georgia, serif;
  letter-spacing: 0.16em;
}

.calendar-rings {
  color: var(--mint);
  letter-spacing: 0.4em;
}

.calendar-date {
  margin-top: 15px;
  font-family: Georgia, serif;
  font-size: 112px;
  line-height: 1;
  text-align: center;
}

.calendar-label {
  color: var(--mint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
}

.calendar-next {
  min-height: 40px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-bottom: 28px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 145px;
  padding: 24px 28px;
  background: var(--white);
}

.stat-card-primary {
  color: var(--white);
  background: var(--green);
}

.stat-label,
.stat-foot {
  display: block;
  color: var(--muted);
}

.stat-card-primary .stat-label,
.stat-card-primary .stat-foot {
  color: rgba(255, 255, 255, 0.68);
}

.stat-label {
  font-size: 12px;
  font-weight: 700;
}

.stat-value {
  display: block;
  margin: 9px 0 5px;
  font-family: Georgia, serif;
  font-size: 42px;
  font-weight: 500;
  line-height: 1;
}

.stat-money {
  font-size: 36px;
}

.stat-foot {
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: start;
}

.workspace-main,
.side-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
}

.workspace-main {
  min-width: 0;
  padding: 30px;
}

.section-heading,
.side-card-heading,
.table-tools,
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.section-heading h2,
.side-card h3 {
  margin: 0;
  font-family: Georgia, "Noto Serif TC", serif;
  font-weight: 500;
}

.section-heading h2 {
  font-size: 30px;
}

.side-card h3 {
  font-size: 21px;
}

.view-tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  background: var(--paper);
  border-radius: 10px;
}

.view-tab {
  padding: 8px 11px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
}

.view-tab.active {
  color: var(--green);
  background: var(--white);
  box-shadow: 0 3px 12px rgba(23, 45, 36, 0.08);
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: minmax(230px, 1.6fr) repeat(3, minmax(125px, 0.7fr));
  gap: 10px;
  margin: 26px 0 12px;
}

.filters select,
.filters input,
.sort-control select,
.custom-range input {
  width: 100%;
  height: 44px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid transparent;
  border-radius: 9px;
  outline: 0;
}

.filters select,
.sort-control select {
  padding: 0 33px 0 12px;
  cursor: pointer;
}

.filters input {
  padding: 0 12px 0 38px;
}

.filters select:focus,
.filters input:focus,
.sort-control select:focus,
.custom-range input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.1);
}

.search-field {
  position: relative;
}

.search-field > span {
  position: absolute;
  left: 13px;
  top: 8px;
  z-index: 1;
  color: var(--muted);
  font-size: 23px;
}

.custom-range {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 38px;
  color: var(--muted);
  font-size: 12px;
}

.custom-range label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.custom-range input {
  width: 145px;
  height: 34px;
  padding: 0 8px;
}

.text-button {
  padding: 3px;
  color: var(--green);
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.text-button:hover {
  text-decoration: underline;
}

.table-tools {
  min-height: 62px;
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.table-tools p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.table-tools > div {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.sort-control select {
  width: auto;
  height: 34px;
  background: transparent;
  border-color: var(--line);
}

.export-button {
  white-space: nowrap;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 12px 14px;
  color: var(--muted);
  background: var(--paper);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-align: left;
  white-space: nowrap;
}

th:first-child {
  border-radius: 9px 0 0 9px;
}

th:last-child {
  border-radius: 0 9px 9px 0;
}

td {
  padding: 17px 14px;
  border-bottom: 1px solid #edf0ed;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fbfcfa;
}

.date-cell {
  white-space: nowrap;
}

.date-cell strong,
.stock-cell strong {
  display: block;
  font-size: 14px;
}

.date-cell small,
.stock-cell small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.number-cell {
  text-align: right;
  white-space: nowrap;
}

.dividend-value {
  color: var(--green);
  font-family: Georgia, serif;
  font-size: 16px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-market {
  color: #4f625b;
  background: #edf1ee;
}

.badge-event {
  color: var(--green);
  background: var(--green-soft);
}

.badge-rights {
  color: #8a642a;
  background: #f5ead6;
}

.loading-state,
.empty-state {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  color: var(--muted);
  text-align: center;
}

.loader {
  width: 27px;
  height: 27px;
  border: 3px solid var(--green-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.pagination {
  justify-content: center;
  margin-top: 20px;
}

.pagination span {
  color: var(--muted);
  font-size: 12px;
}

.page-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.page-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.workspace-side {
  display: grid;
  gap: 20px;
}

.side-card {
  padding: 24px;
}

.legend-dot {
  color: var(--muted);
  font-size: 10px;
}

.legend-dot::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  background: var(--green);
  border-radius: 50%;
}

.bar-chart {
  height: 190px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  margin-top: 25px;
  padding-top: 10px;
  border-bottom: 1px solid var(--line);
}

.bar-item {
  min-width: 0;
  height: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  position: relative;
}

.bar {
  width: 100%;
  min-height: 3px;
  background: var(--green-soft);
  border-radius: 4px 4px 0 0;
  transition: height 280ms ease;
}

.bar.active {
  background: var(--green);
}

.bar-item small {
  height: 20px;
  color: var(--muted);
  font-size: 9px;
  writing-mode: vertical-rl;
}

.bar-item:hover::before {
  content: attr(data-count) " 筆";
  position: absolute;
  top: -15px;
  z-index: 2;
  padding: 4px 6px;
  color: var(--white);
  background: var(--ink);
  border-radius: 5px;
  font-size: 10px;
  white-space: nowrap;
}

.date-card {
  color: var(--white);
  background: var(--green);
  border-color: var(--green);
}

.date-card .section-kicker {
  color: var(--mint);
}

.busy-date {
  margin: 19px 0 8px;
  font-family: Georgia, serif;
  font-size: 45px;
}

.date-card > p:last-child {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.source-card h3 {
  margin-bottom: 16px;
}

.source-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.source-row b {
  color: var(--green);
}

.source-row b.failed {
  color: var(--red);
}

.source-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

footer {
  min-height: 170px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  margin-top: 55px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

footer strong {
  color: var(--ink);
  font-size: 15px;
}

footer p {
  margin: 7px 0 0;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(380px, calc(100vw - 48px));
  padding: 13px 17px;
  color: var(--white);
  background: var(--ink);
  border-radius: 9px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: 180ms ease;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.sr-only {
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1120px) {
  .page-shell {
    padding: 0 25px;
  }

  .hero {
    gap: 35px;
    padding-inline: 2%;
  }

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

  .workspace-side {
    grid-template-columns: repeat(3, 1fr);
  }

  .filters {
    grid-template-columns: 1.5fr repeat(3, 1fr);
  }
}

@media (max-width: 800px) {
  .page-shell {
    padding: 0 16px;
  }

  .topbar {
    height: 75px;
  }

  .source-pill {
    display: none;
  }

  .hero {
    min-height: 0;
    grid-template-columns: 1fr;
    padding: 55px 0 75px;
  }

  .hero h1 {
    font-size: clamp(46px, 13vw, 68px);
  }

  .hero-calendar {
    display: none;
  }

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

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

  .view-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .view-tab {
    flex: 1;
    white-space: nowrap;
  }

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

  .search-field {
    grid-column: 1 / -1;
  }

  .workspace-side {
    grid-template-columns: 1fr;
  }

  .table-tools {
    align-items: flex-start;
    flex-direction: column;
    padding: 15px 0;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
  }
}

@media (max-width: 520px) {
  .brand small {
    display: none;
  }

  .button {
    padding: 0 11px;
    font-size: 12px;
  }

  .stats-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .search-field {
    grid-column: auto;
  }

  .stat-card {
    min-height: 115px;
  }

  .workspace-main {
    padding: 22px 16px;
  }

  .custom-range {
    align-items: stretch;
    flex-direction: column;
  }

  .custom-range > span {
    display: none;
  }

  .custom-range label {
    justify-content: space-between;
  }

  .custom-range input {
    width: min(210px, 70%);
  }

  .table-tools > div {
    width: 100%;
    justify-content: space-between;
  }

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

  th,
  td {
    padding-inline: 10px;
  }
}
