:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --ink: #14201d;
  --muted: #65736f;
  --line: #dbe4e0;
  --accent: #13795b;
  --accent-strong: #0f5e49;
  --amber: #b7791f;
  --red: #b42318;
  --green: #15803d;
  --blue: #1d4ed8;
  --shadow: 0 18px 45px rgba(28, 43, 38, 0.08);
  font-family: "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #10231e;
  color: #f6fbf8;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #2fb889;
  color: #082019;
  font-weight: 800;
  font-size: 1.4rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.18rem;
}

.brand p,
.source-box small,
.source-box span {
  margin: 3px 0 0;
  color: #b8cbc4;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  color: #dcebe5;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

.nav a:hover,
.nav a.active {
  background: rgba(255, 255, 255, 0.1);
}

.source-box {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 6px;
}

.workspace {
  padding: 28px;
  display: grid;
  gap: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 2.4vw, 2.15rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.ghost-button {
  background: transparent;
  color: var(--accent-strong);
}

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

.signal-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.signal-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 15px;
  display: grid;
  gap: 9px;
  box-shadow: var(--shadow);
}

.signal-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.signal-card strong {
  font-size: 1.05rem;
}

.signal-card small {
  color: var(--muted);
  line-height: 1.45;
}

.signal-bar {
  height: 8px;
  border-radius: 999px;
  background: #e3ebe7;
  overflow: hidden;
}

.signal-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

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

.metric {
  padding: 18px;
  display: grid;
  gap: 8px;
  min-height: 128px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  font-size: 1.7rem;
}

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

.panel {
  padding: 20px;
  min-width: 0;
  overflow: hidden;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.panel h3 {
  margin: 4px 0 0;
  font-size: 1.08rem;
}

.badge {
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  padding: 6px 10px;
  font-size: 0.78rem;
  white-space: nowrap;
}

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

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

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 260px;
}

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

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

td {
  font-size: 0.92rem;
}

.positive {
  color: var(--green);
  font-weight: 700;
}

.negative {
  color: var(--red);
  font-weight: 700;
}

.neutral {
  color: var(--muted);
}

.score-pill {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f5ef;
  color: var(--accent-strong);
  font-weight: 800;
}

.quote-time {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.snapshot-list {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.trend-list {
  display: grid;
  gap: 12px;
}

.trend-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfdfc;
}

.trend-rank {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.trend-main {
  min-width: 0;
}

.trend-main strong {
  display: block;
  font-size: 1rem;
}

.trend-main span,
.trend-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.trend-meta {
  text-align: right;
}

.mini-trend {
  display: flex;
  gap: 5px;
  align-items: end;
  height: 24px;
  margin-top: 8px;
}

.mini-trend i {
  width: 18px;
  border-radius: 4px 4px 0 0;
  background: #2f7f60;
}

.empty-state {
  color: var(--muted);
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 14px;
  line-height: 1.6;
}

.empty-state.compact {
  padding: 10px 12px;
  font-size: 0.9rem;
}

.snapshot-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.snapshot-item strong {
  color: var(--ink);
}

.note {
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 20px;
  }

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

  .source-box {
    margin-top: 0;
  }

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

@media (max-width: 720px) {
  body {
    background: #eef2f0;
  }

  .app-shell {
    display: block;
    width: 100%;
  }

  .sidebar {
    padding: 14px;
    gap: 12px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .brand p,
  .source-box,
  .nav a:nth-child(n + 3) {
    display: none;
  }

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

  .nav a {
    text-align: center;
    padding: 9px 8px;
    font-size: 0.86rem;
  }

  .workspace {
    padding: 14px 10px calc(110px + env(safe-area-inset-bottom));
    gap: 12px;
    width: 100%;
  }

  .topbar,
  .panel-heading {
    display: grid;
    gap: 10px;
  }

  .topbar h2 {
    font-size: 1.22rem;
    line-height: 1.25;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
    min-width: 0;
  }

  .status-grid,
  .signal-board,
  .panel-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric,
  .panel {
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(28, 43, 38, 0.06);
  }

  .metric {
    min-height: auto;
    padding: 14px;
  }

  .metric strong {
    font-size: 1.35rem;
  }

  .panel {
    padding: 14px;
  }

  .empty-state {
    font-size: 1rem;
    line-height: 1.5;
  }

  .empty-state.compact {
    font-size: 0.82rem;
  }

  .badge {
    justify-self: start;
    white-space: normal;
  }

  .table-wrap {
    overflow: visible;
  }

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

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    background: #fbfdfc;
  }

  td {
    border-bottom: 0;
    padding: 4px 0;
  }

  td:nth-child(1),
  td:nth-child(2),
  td:nth-child(3),
  td:nth-child(4),
  td:nth-child(5) {
    display: inline-block;
    width: auto;
    margin-right: 8px;
  }

  td:nth-child(1)::before {
    content: "#";
  }

  td:nth-child(6)::before {
    content: "收盤 ";
    color: var(--muted);
  }

  td:nth-child(7)::before {
    content: "漲跌 ";
    color: var(--muted);
  }

  td:nth-child(8) {
    color: var(--muted);
    line-height: 1.45;
  }

  canvas {
    height: 220px;
  }

  .chart-panel {
    min-height: 320px;
  }

  .snapshot-item {
    display: grid;
  }

  .trend-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .trend-meta {
    grid-column: 2;
    text-align: left;
  }
}
