:root {
  --bg: #f4efe6;
  --bg-strong: #efe5d6;
  --panel: rgba(255, 251, 245, 0.84);
  --panel-strong: #fffaf1;
  --border: rgba(114, 84, 42, 0.14);
  --text: #1f1c18;
  --muted: #6d6458;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --danger: #b42318;
  --shadow: 0 20px 50px rgba(77, 53, 21, 0.08);
  --radius: 22px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 36%),
    linear-gradient(135deg, #f7f2e9 0%, #efe4d4 50%, #f2efe7 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(121, 93, 45, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(121, 93, 45, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent 88%);
}

.page-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.hero,
.panel,
.rules-card {
  backdrop-filter: blur(12px);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  gap: 24px;
  grid-template-columns: 1.6fr 1fr;
  border-radius: 32px;
  padding: 28px;
}

.eyebrow,
.panel-label,
.pill,
.status-chip {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}

.eyebrow,
.panel-label {
  margin: 0 0 10px;
  color: var(--muted);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(38px, 4vw, 64px);
  line-height: 0.98;
}

.hero-text {
  margin-top: 14px;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.65;
  font-size: 16px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  justify-content: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  border: 1px solid var(--border);
}

.primary-button {
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 700;
  color: #fffdf7;
  background: linear-gradient(135deg, #1e8e85, #0f766e);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
  box-shadow: 0 16px 32px rgba(15, 118, 110, 0.24);
}

.primary-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.rules-card {
  margin-top: 18px;
  border-radius: 24px;
  padding: 18px 22px;
}

.section-nav {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  padding: 6px;
  border-radius: 22px;
  background: rgba(255, 251, 245, 0.78);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.nav-tab {
  border: 0;
  border-radius: 18px;
  padding: 14px 20px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-tab:hover {
  transform: translateY(-1px);
}

.nav-tab.active {
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(114, 84, 42, 0.08);
}

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

.rule-item {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 250, 241, 0.75);
  border: 1px solid rgba(114, 84, 42, 0.1);
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.page-stack {
  margin-top: 18px;
}

.panel {
  border-radius: 28px;
  padding: 22px;
}

.page-view {
  display: none;
}

.page-view.active {
  display: block;
}

.main-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.main-panel.page-view {
  display: none;
}

.main-panel.page-view.active {
  display: flex;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.panel-head.compact {
  align-items: center;
}

.panel-head h2 {
  font-size: 28px;
}

.status-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.status-chip.failed {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.08);
  border-color: rgba(180, 35, 24, 0.18);
}

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

.stat-card {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: 30px;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stream-card,
.history-list,
.events-log {
  border-radius: 22px;
}

.stream-card {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  overflow: hidden;
}

.stream-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 10px;
}

.stream-head h3 {
  font-size: 20px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  border-top: 1px solid rgba(114, 84, 42, 0.08);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tbody tr:hover {
  background: rgba(15, 118, 110, 0.04);
}

.ticker {
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 13px;
}

.stock-cell {
  min-width: 0;
}

.stock-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.stock-code {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.metric-main,
.metric-sub {
  display: block;
}

.metric-main {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.metric-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.results-table-wrap {
  overflow: visible;
}

.results-table {
  table-layout: fixed;
}

.results-table th,
.results-table td {
  padding: 13px 10px;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) {
  width: 18%;
}

.results-table th:nth-child(2),
.results-table td:nth-child(2),
.results-table th:nth-child(3),
.results-table td:nth-child(3),
.results-table th:nth-child(5),
.results-table td:nth-child(5) {
  width: 10%;
}

.results-table th:nth-child(4),
.results-table td:nth-child(4),
.results-table th:nth-child(6),
.results-table td:nth-child(6),
.results-table th:nth-child(7),
.results-table td:nth-child(7),
.results-table th:nth-child(8),
.results-table td:nth-child(8) {
  width: 13%;
}

.results-table td {
  font-size: 13px;
  word-break: break-word;
}

.results-table th {
  white-space: normal;
}

.results-table .link-button {
  margin-top: 8px;
}

.data-table {
  table-layout: fixed;
}

.data-table th,
.data-table td {
  white-space: normal;
  word-break: break-word;
}

.history-table th:nth-child(1) {
  width: 12%;
}

.history-table th:nth-child(2) {
  width: 10%;
}

.history-table th:nth-child(3),
.history-table th:nth-child(4),
.history-table th:nth-child(5),
.history-table th:nth-child(6) {
  width: 9%;
}

.history-table th:nth-child(7) {
  width: 10%;
}

.history-table th:nth-child(8) {
  width: 16%;
}

.history-table th:nth-child(9) {
  width: 10%;
}

.logs-table th:nth-child(1) {
  width: 18%;
}

.logs-table th:nth-child(2) {
  width: 12%;
}

.logs-table th:nth-child(3) {
  width: auto;
}

.view-hint {
  color: var(--muted);
  font-size: 13px;
}

.table-action {
  border: 0;
  border-radius: 999px;
  padding: 9px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.table-row-active {
  background: rgba(15, 118, 110, 0.07);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.status-badge.failed {
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.status-badge.skipped {
  background: rgba(181, 71, 8, 0.08);
  color: #b54708;
}

.positive {
  color: #b54708;
  font-weight: 700;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

a.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .hero {
    grid-template-columns: 1fr;
  }

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

  .results-table-wrap,
  .history-table-wrap,
  .logs-table-wrap {
    overflow-x: auto;
  }

  .results-table,
  .data-table {
    min-width: 980px;
  }
}

@media (max-width: 768px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding: 14px 0 24px;
  }

  .hero,
  .panel,
  .rules-card {
    padding: 18px;
    border-radius: 22px;
  }

  .section-nav {
    gap: 8px;
    overflow-x: auto;
    padding: 5px;
    scrollbar-width: none;
  }

  .section-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 12px 16px;
  }

  .hero-actions {
    width: 100%;
  }

  .hero-actions .primary-button {
    width: 100%;
  }

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

  .stat-card {
    padding: 15px;
  }

  .stat-card strong {
    margin-top: 10px;
    font-size: 24px;
  }

  .panel-head,
  .stream-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-head h2 {
    font-size: 24px;
  }

  .view-hint {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .stats-grid,
  .rule-grid {
    grid-template-columns: 1fr;
  }
}
