:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #657282;
  --line: #d9e0e7;
  --primary: #176b87;
  --primary-dark: #10556c;
  --danger: #a33c3c;
  --shadow: 0 10px 24px rgba(31, 45, 61, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(23, 107, 135, 0.28);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.skip-link:focus {
  top: 12px;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
}

.topbar nav {
  align-items: center;
  display: flex;
  gap: 18px;
  color: var(--muted);
}

.auth-menu {
  position: relative;
  flex: 0 0 auto;
  margin-left: 4px;
  color: var(--text);
  white-space: nowrap;
}

.auth-menu[open] {
  z-index: 20;
}

.auth-trigger {
  align-items: center;
  display: inline-flex;
  gap: 7px;
  min-width: 0;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.auth-trigger::-webkit-details-marker {
  display: none;
}

.auth-trigger:hover,
.auth-menu[open] .auth-trigger {
  border-color: #cbd5e1;
  background: #ffffff;
}

.auth-trigger:focus-visible {
  outline: 3px solid rgba(23, 107, 135, 0.28);
  outline-offset: 2px;
}

.auth-avatar {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  line-height: 1;
}

.auth-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-chevron {
  width: 7px;
  height: 7px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: rotate(45deg) translateY(-2px);
}

.auth-menu[open] .auth-chevron {
  transform: rotate(225deg) translateY(-1px);
}

.auth-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 132px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.logout-form {
  margin: 0;
}

.auth-logout {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #334155;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.auth-logout:hover {
  background: #f8fafc;
  color: #0f172a;
}

.auth-logout:focus-visible {
  outline: 3px solid rgba(23, 107, 135, 0.28);
  outline-offset: 2px;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 56px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

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

.button:hover,
.filter-pill:hover,
.support-panel a:hover,
.strategy-row:hover,
.strategy-type-card:hover {
  border-color: #b8c6d4;
  box-shadow: 0 8px 20px rgba(31, 45, 61, 0.10);
}

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

.login-panel {
  width: min(420px, 100%);
  margin: 72px auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 20px;
  font-size: 24px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.login-form input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

.alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 6px;
}

.alert.error {
  border: 1px solid #e6c6c6;
  background: #fff5f5;
  color: var(--danger);
}

.button.accent {
  border-color: #f59e0b;
  background: #f59e0b;
  color: #17202a;
}

.button.accent:hover {
  background: #d97706;
}

.button.danger {
  border-color: #e6c6c6;
  color: var(--danger);
}

.button.danger.subtle {
  background: #fff;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
}

.rule-card,
.panel,
.form-panel,
.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.rule-card {
  display: grid;
  gap: 18px;
  padding: 18px;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metrics div {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics.compact {
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
}

.metrics.compact div {
  padding: 10px;
  box-shadow: none;
}

.latest-price-section {
  margin-bottom: 18px;
}

.latest-price-section h2 {
  margin-bottom: 10px;
}

.metric-note {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.5;
}

dt {
  color: var(--muted);
  font-size: 13px;
}

dd {
  margin: 4px 0 0;
  font-weight: 700;
}

.form-panel {
  padding: 0;
}

.form-section {
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.compact-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  background: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
}

.check-row input {
  width: auto;
}

.check-row span {
  display: grid;
  gap: 3px;
}

.check-row small {
  color: var(--muted);
  font-weight: 500;
}

input.is-disabled {
  background: #eef2f6;
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 12px;
  padding: 18px 22px;
}

.inline-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.watchlist-form {
  margin-bottom: 18px;
}

.watchlist-input-row {
  display: grid;
  grid-template-columns: minmax(220px, 360px) auto;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

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

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.chart-grid h3 {
  margin: 0;
  font-size: 14px;
}

.chart-card {
  min-width: 0;
}

.chart-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 6px;
}

.chart-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.result-chart-stat {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #e5edf3;
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.result-chart-shell {
  min-width: 0;
  padding: 8px 8px 2px;
  border: 1px solid #e3e9ef;
  border-radius: 6px;
  background: #ffffff;
}

.result-chart-echarts {
  display: block;
  width: 100%;
  height: clamp(190px, 26vw, 260px);
  min-height: 190px;
  background: transparent;
}

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

  .chart-card-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .chart-stats {
    justify-content: flex-start;
  }

  .result-chart-stat {
    white-space: normal;
  }

  .result-chart-echarts {
    height: 220px;
  }
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-grid div,
.support-panel,
.strategy-row,
.strategy-type-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-grid div {
  padding: 14px 16px;
}

.strategy-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.strategy-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.strategy-filter-bar {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.filter-pill.active {
  border-color: var(--primary);
  background: #eaf2ff;
  color: var(--primary);
}

.strategy-list {
  display: grid;
  gap: 10px;
}

.strategy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
}

.strategy-main h3 {
  margin: 8px 0 0;
  font-size: 18px;
}

.strategy-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 10px 0 0;
}

.strategy-meta div {
  min-width: 120px;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.type-pill.type-rotation {
  background: #dbeafe;
  color: #1e40af;
}

.type-pill.type-smh_soxl_rotation {
  background: #e0f2fe;
  color: #075985;
}

.type-pill.type-buy_hold {
  background: #ccfbf1;
  color: #0f766e;
}

.type-pill.type-a_share_margin {
  background: #fef3c7;
  color: #92400e;
}

.strategy-type-rotation {
  border-left: 4px solid #60a5fa;
}

.strategy-type-smh_soxl_rotation {
  border-left: 4px solid #38bdf8;
}

.strategy-type-buy_hold {
  border-left: 4px solid #2dd4bf;
}

.strategy-type-a_share_margin {
  border-left: 4px solid #f59e0b;
}

.strategy-row.highlighted {
  border-color: #f59e0b;
  background: #fffbeb;
}

.strategy-actions {
  justify-content: flex-end;
  align-items: center;
}

.favorite-form {
  margin: 0;
}

.favorite-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d7dee7;
  border-radius: 6px;
  background: #ffffff;
  color: #94a3b8;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.favorite-button:hover {
  border-color: #f59e0b;
  color: #d97706;
  box-shadow: 0 8px 20px rgba(31, 45, 61, 0.10);
}

.favorite-button.active {
  border-color: #f5c451;
  background: #fffbeb;
  color: #d97706;
}

.support-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.support-panel a {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.support-panel span {
  color: var(--muted);
  font-size: 13px;
}

.strategy-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.strategy-type-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.result-head.compact {
  margin-top: 18px;
}

.result-head h1,
.result-head h2 {
  margin-top: 8px;
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.segmented button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--primary);
  color: #fff;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 14px;
}

.table-wrap.tall {
  max-height: 460px;
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
}

.sticky-first {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
}

.delete-confirm {
  margin: 0;
}

td input {
  max-width: 120px;
}

.event-table {
  min-width: 720px;
}

.watchlist-table {
  min-width: 1120px;
}

.watchlist-table td,
.watchlist-table th {
  white-space: nowrap;
}

.watchlist-live {
  margin-left: 8px;
}

.event-date {
  width: 128px;
  font-weight: 700;
  white-space: nowrap;
}

.event-log-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-operation {
  display: grid;
  gap: 6px;
}

.event-operation + .event-operation {
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.event-line {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
}

.event-followup {
  color: #33404d;
}

.event-type {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.event-note {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-right: 8px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.prediction {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: #eef7f5;
  border: 1px solid #c9e4df;
  border-radius: 8px;
}

.order-plan {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.order-plan div {
  min-height: 72px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #c9e4df;
  border-radius: 6px;
}

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

.notice {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.notice.success {
  border-color: #b9dccf;
  background: #eef7f3;
  color: #245d48;
}

.notice.error {
  border-color: #e6c6c6;
  background: #fff4f4;
  color: var(--danger);
}

.plain-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.risk-summary {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.risk-summary h2 {
  margin-top: 4px;
  font-size: 34px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.risk-score {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.risk-score div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.risk-score dd {
  overflow-wrap: anywhere;
}

.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.signal-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.signal-card strong {
  font-size: 24px;
}

.status-green {
  border-color: #b9dccf;
}

.status-yellow {
  border-color: #e5d38a;
}

.status-red {
  border-color: #e6b1ad;
}

.status-gray {
  border-color: var(--line);
}

.status-opp-low,
.status-opp-medium,
.status-opp-high {
  border-color: #b8d1eb;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.status-green {
  background: #eef7f3;
  color: #245d48;
}

.status-pill.status-yellow {
  background: #fff8df;
  color: #6d5710;
}

.status-pill.status-red {
  background: #fff0ef;
  color: #8f2e28;
}

.status-pill.status-gray {
  background: #f3f5f7;
  color: var(--muted);
}

.status-pill.status-opp-low {
  background: #eef5fb;
  color: #315f85;
}

.status-pill.status-opp-medium {
  background: #e7f1ff;
  color: #1f5f9f;
}

.status-pill.status-opp-high {
  background: #dfeeff;
  color: #174f88;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.source-list a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  font-weight: 700;
}

.tight {
  margin-top: 0;
}

.empty,
.error-panel {
  padding: 28px;
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }

  .topbar nav {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 8px;
    padding-bottom: 4px;
  }

  .page-head,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .watchlist-input-row {
    grid-template-columns: 1fr;
  }

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

  .strategy-layout,
  .strategy-row {
    grid-template-columns: 1fr;
  }

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

  .strategy-filter-bar {
    justify-items: start;
  }

  .strategy-actions {
    justify-content: flex-start;
  }

  .result-head {
    flex-direction: column;
  }

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

  .risk-score {
    grid-template-columns: 1fr;
  }

  .metrics.compact {
    grid-template-columns: 1fr;
  }
}
