:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #111827;
  --text: #1f2937;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warning: #b45309;
  --danger: #b42318;
  --good: #047857;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: stretch;
  padding: 28px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 8px;
  color: #0f766e;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-panel .eyebrow {
  color: #5eead4;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.lead {
  max-width: 720px;
  margin: 14px 0 0;
  color: #d1d5db;
  line-height: 1.7;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 96px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.status-card strong,
.status-card small {
  display: block;
}

.status-card small {
  margin-top: 4px;
  color: #cbd5e1;
}

.status-dot {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.18);
}

.mode-switch,
.toolbar,
.summary-grid,
.content-grid {
  margin-top: 18px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.mode-button {
  min-width: 150px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.mode-button:hover {
  background: #eef2f7;
  color: var(--text);
}

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

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px auto auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
button {
  min-height: 42px;
  border-radius: 8px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
}

button {
  border: 0;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

button.secondary:hover {
  background: #eef2f7;
}

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

.summary-grid article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-grid article {
  padding: 18px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
}

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

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

#lastUpdated {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

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

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

th {
  color: var(--muted);
  font-size: 13px;
  background: #f8fafc;
}

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

.stock-row {
  cursor: pointer;
}

.stock-row:hover,
.stock-row:focus {
  background: #f0fdfa;
  outline: none;
}

.stock-row:focus td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.badge.strong {
  background: #d1fae5;
  color: var(--good);
}

.badge.watch {
  background: #fef3c7;
  color: var(--warning);
}

.badge.risk {
  background: #fee4e2;
  color: var(--danger);
}

.side-panel ol {
  margin: 12px 0 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.8;
}

.mini-chart {
  display: flex;
  align-items: end;
  gap: 10px;
  height: 150px;
  margin-top: 24px;
  padding: 16px;
  border-radius: 8px;
  background: #f8fafc;
}

.mini-chart span {
  flex: 1;
  min-width: 24px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #14b8a6, #0f766e);
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.62);
}

.chart-modal.open {
  display: flex;
}

.chart-dialog {
  width: min(1080px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.chart-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.icon-button:hover {
  background: #eef2f7;
}

.chart-status {
  margin: 18px 24px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
}

.chart-canvas-wrap {
  position: relative;
  margin: 18px 24px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

#chartCanvas {
  display: block;
  width: 100%;
  height: 520px;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.92);
  color: #ffffff;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip span {
  margin-top: 4px;
  color: #d1d5db;
}

.chart-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 24px 24px;
}

.chart-stats span {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.chart-stats strong {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 860px) {
  .hero-panel,
  .toolbar,
  .summary-grid,
  .content-grid,
  .chart-stats {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    display: grid;
    grid-template-columns: 1fr;
  }

  .mode-button {
    min-width: 0;
  }

  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .hero-panel {
    padding: 22px;
  }

  h1 {
    font-size: 28px;
  }

  #lastUpdated {
    white-space: normal;
  }

  .chart-modal {
    padding: 10px;
  }

  .chart-header {
    padding: 18px;
  }

  .chart-canvas-wrap,
  .chart-status {
    margin-left: 14px;
    margin-right: 14px;
  }

  #chartCanvas {
    height: 430px;
  }

  .chart-stats {
    padding: 14px;
  }
}
