:root {
  color-scheme: light;
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-muted: #e9ede8;
  --ink: #18201d;
  --muted: #68736e;
  --line: #d8ded9;
  --green: #12735a;
  --green-soft: #dcefe8;
  --amber: #a05b08;
  --amber-soft: #f8ead6;
  --red: #a53c36;
  --red-soft: #f7dfdc;
  --blue: #2f6092;
  --blue-soft: #e1ebf5;
  --charcoal: #202a26;
  --sidebar-width: 218px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: 24px 16px 18px;
  color: #eef4f0;
  background: var(--charcoal);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 8px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #5f9d87;
  border-radius: 6px;
  color: #d9f6eb;
  font-weight: 750;
  font-size: 13px;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { margin-top: 2px; color: #9fb0a8; font-size: 11px; }

.primary-nav {
  display: grid;
  gap: 5px;
  margin-top: 36px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 6px;
  color: #b7c3bd;
  font-weight: 600;
}

.nav-link:hover { background: #2b3732; color: white; }
.nav-link.is-active { color: white; background: #33413b; }
.nav-indicator { width: 6px; height: 6px; border-radius: 50%; background: #697a72; }
.nav-link.is-active .nav-indicator { background: #53c598; box-shadow: 0 0 0 3px #315e4e; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 12px 9px 0;
  border-top: 1px solid #39453f;
  color: #9fb0a8;
  font-size: 11px;
}
.safety-dot { width: 7px; height: 7px; border-radius: 50%; background: #53c598; }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  min-height: 116px;
  padding: 30px clamp(24px, 4vw, 58px) 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(242, 244, 241, 0.94);
}

.eyebrow, .section-kicker {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.topbar h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 720; }
.updated-at, .data-asof { margin: 0; color: var(--muted); font-size: 12px; }
.topbar-account { display: grid; justify-items: end; gap: 8px; }
.logout-form { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.text-button { padding: 0; border: 0; color: var(--green); background: transparent; font: inherit; font-weight: 700; cursor: pointer; }
.text-button:hover { text-decoration: underline; }

.page-content {
  width: min(1420px, 100%);
  padding: 28px clamp(24px, 4vw, 58px) 70px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.metric-cell { min-width: 0; padding: 19px 22px; border-right: 1px solid var(--line); }
.metric-cell:last-child { border-right: 0; }
.metric-cell span, .metric-cell small { display: block; color: var(--muted); }
.metric-cell span { font-size: 12px; font-weight: 650; }
.metric-cell strong { display: block; margin: 8px 0 5px; font-size: 27px; line-height: 1; }
.metric-cell .metric-date { font-size: 20px; }
.metric-cell small { font-size: 11px; }

.trade-signal-panel {
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-left: 4px solid #98a39d;
  border-radius: 8px;
  background: var(--surface);
}
.trade-signal-panel.has-signals { border-left-color: var(--green); }
.trade-signal-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.trade-signal-heading h2 { margin: 0; font-size: 18px; }
.trade-signal-list { display: grid; gap: 8px; margin-top: 15px; }
.trade-signal-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbf9;
}
.signal-action { font-weight: 800; }
.signal-buy .signal-action { color: var(--red); }
.signal-sell .signal-action { color: var(--green); }
.signal-stock strong, .signal-stock small { display: block; }
.signal-stock small, .signal-session { color: var(--muted); font-size: 10px; }
.signal-stock small { margin-top: 3px; }
.signal-session { white-space: nowrap; }
.no-trade-signal { display: flex; align-items: baseline; gap: 12px; margin-top: 14px; }
.no-trade-signal span { color: var(--muted); font-size: 12px; }

.content-section { margin-top: 34px; }
.section-heading, .toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}
.section-heading h2, .dialog-heading h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.text-link { color: var(--green); font-size: 12px; font-weight: 700; }
.text-link:hover { text-decoration: underline; }

.job-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.job-panel {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-left: 4px solid #9aa49f;
  border-radius: 7px;
  background: var(--surface);
}
.job-panel.status-success { border-left-color: var(--green); }
.job-panel.status-failed { border-left-color: var(--red); }
.job-panel.status-running { border-left-color: var(--blue); }
.job-panel.status-degraded { border-left-color: var(--amber); }
.job-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.job-title-row h3 { margin: 0; font-size: 15px; }
.job-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 21px 0 13px; }
.job-meta div { min-width: 0; }
.job-meta dt { color: var(--muted); font-size: 11px; }
.job-meta dd { margin: 5px 0 0; font-weight: 650; }
.muted-line { margin: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }

.status-badge, .notification-session {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}
.status-success, .candidate-focus { color: var(--green); background: var(--green-soft); }
.status-failed, .candidate-filtered { color: var(--red); background: var(--red-soft); }
.status-running, .candidate-pass { color: var(--blue); background: var(--blue-soft); }
.candidate-pending { color: #68551f; background: #fff3c9; }
.candidate-failed, .analysis-failed { color: var(--red); background: var(--red-soft); }
.analysis-pending { color: #68551f; background: #fff3c9; }
.analysis-ready { color: var(--green); background: var(--green-soft); }
.status-degraded { color: var(--amber); background: var(--amber-soft); }
.status-unknown { color: #5f6864; background: var(--surface-muted); }

.table-wrap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 13px 15px; border-bottom: 1px solid #e8ece9; text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); background: #f7f8f6; font-size: 11px; font-weight: 700; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafbf9; }
.data-table td { font-variant-numeric: tabular-nums; }
.price-change { font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-change.is-rise { color: var(--red); }
.price-change.is-fall { color: var(--green); }
.price-change.is-flat, .price-change.is-missing { color: var(--muted); }
.data-table td strong, .data-table td small { display: block; }
.data-table td small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.stock-identity, .metric-reading { display: grid; justify-items: start; min-width: 0; }
.score-cell { color: var(--green); font-weight: 800; }
.compact-table { min-width: 840px; }
.candidate-table { min-width: 1680px; }
.issues-cell { max-width: 260px; color: var(--muted); font-size: 12px; }

.scored-metric strong { font-size: 14px; font-weight: 850; }
.scored-metric small { white-space: nowrap; }
.metric-excellent strong, .metric-excellent small { color: var(--green) !important; }
.metric-good strong, .metric-good small { color: var(--blue) !important; }
.metric-fair strong, .metric-fair small { color: var(--amber) !important; }
.metric-weak strong, .metric-weak small { color: var(--red) !important; }
.metric-missing strong, .metric-missing small { color: var(--muted) !important; }

.metric-guide { margin: 5px 0 20px; padding: 18px 0 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-guide-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.metric-guide-heading h2 { margin: 0; font-size: 18px; }
.metric-scale { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px 14px; color: var(--muted); font-size: 11px; }
.metric-scale span { white-space: nowrap; }
.metric-definition-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 19px 0 0; border-top: 1px solid #e1e6e2; }
.metric-definition-grid div { min-width: 0; padding: 12px 18px 10px 0; border-bottom: 1px solid #e1e6e2; }
.metric-definition-grid dt { color: var(--ink); font-size: 12px; font-weight: 800; }
.metric-definition-grid dd { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.metric-guide-note { margin: 13px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.empty-state {
  display: flex;
  min-height: 130px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 24px;
  border: 1px dashed #c4ccc7;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,.5);
}
.empty-state strong { color: var(--ink); }
.error-state { border-color: #e4b8b4; background: #fcf3f2; }
.is-hidden, [hidden] { display: none !important; }

.notification-list { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.notification-line {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 9px 15px;
  border-bottom: 1px solid #e8ece9;
}
.notification-line:last-child { border-bottom: 0; }
.notification-line:hover { background: #fafbf9; }
.notification-session { min-height: 22px; }
.session-preopen { color: var(--blue); background: var(--blue-soft); }
.session-close { color: var(--amber); background: var(--amber-soft); }
.notification-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.notification-line time { color: var(--muted); font-size: 11px; white-space: nowrap; }

.full-notifications { border: 0; border-radius: 0; background: transparent; }
.notification-record { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); overflow: hidden; }
.notification-record summary {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
}
.notification-record summary::-webkit-details-marker { display: none; }
.notification-summary-main strong, .notification-summary-main small { display: block; }
.notification-summary-main small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.disclosure-label { color: var(--green); font-size: 11px; font-weight: 700; }
.notification-content { padding: 17px 18px 20px; border-top: 1px solid var(--line); color: #34403b; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }

.segmented-control { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.segment { display: inline-flex; min-height: 32px; align-items: center; justify-content: center; padding: 0 12px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; }
.segment:hover { color: var(--ink); }
.segment.is-active { color: white; background: var(--charcoal); }

.watchlist-toolbar { margin-bottom: 16px; }
.watchlist-tools { display: flex; align-items: end; gap: 9px; }
.compact-select-label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.compact-select { height: 34px; padding: 0 28px 0 9px; border: 1px solid #c8d0cb; border-radius: 6px; color: var(--ink); background: white; }
.watchlist-table { min-width: 780px; }
.analysis-state-cell { max-width: 280px; }
.analysis-state-cell small { line-height: 1.45; }
.actions-heading { text-align: right !important; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.primary-button, .secondary-button, .danger-button {
  min-height: 34px;
  padding: 0 13px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}
.primary-button { border: 1px solid var(--green); color: white; background: var(--green); }
.primary-button:hover { background: #0e624d; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button { border: 1px solid #c8d0cb; color: var(--ink); background: white; }
.secondary-button:hover { border-color: #8d9993; }
.danger-button { border: 1px solid #e3bab7; color: var(--red); background: #fff8f7; }
.danger-button:hover { background: var(--red-soft); }

.alert-message { margin-bottom: 14px; padding: 11px 13px; border-radius: 6px; font-weight: 650; }
.alert-message.is-error { color: var(--red); background: var(--red-soft); }
.alert-message.is-success { color: var(--green); background: var(--green-soft); }

.editor-dialog {
  width: min(460px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(18, 30, 24, .2);
}
.editor-dialog::backdrop { background: rgba(24, 32, 29, .5); }
.editor-dialog form { padding: 22px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 21px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 5px; color: var(--muted); background: #f1f3f1; font-size: 22px; line-height: 1; cursor: pointer; }
.field-label { display: block; margin: 13px 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.text-input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #c8d0cb; border-radius: 6px; outline: none; color: var(--ink); background: white; }
.text-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.confirm-dialog-body { padding: 22px; }
.confirm-copy { margin: 0; color: var(--muted); line-height: 1.65; }
.confirm-copy strong { color: var(--ink); }

.recommendation-list { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.recommendation-row {
  display: grid;
  grid-template-columns: minmax(160px, .7fr) minmax(260px, 1.4fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  padding: 13px 15px;
  border-bottom: 1px solid #e8ece9;
}
.recommendation-row:last-child { border-bottom: 0; }
.recommendation-stock strong, .recommendation-stock small { display: block; }
.recommendation-stock small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.recommendation-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.auth-page { min-height: 100vh; background: var(--bg); }
.auth-shell { width: min(420px, calc(100% - 32px)); margin: 0 auto; padding: clamp(48px, 10vh, 100px) 0 40px; }
.auth-brand { display: flex; align-items: center; gap: 12px; width: max-content; margin: 0 auto 24px; }
.auth-brand .brand-mark { color: var(--green); border-color: #73a895; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand strong { font-size: 17px; }
.auth-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.auth-panel { padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.auth-panel h1 { margin: 0; font-size: 24px; }
.auth-form { display: grid; gap: 7px; margin-top: 23px; }
.auth-form label { margin-top: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.auth-form input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #c8d0cb; border-radius: 6px; outline: none; color: var(--ink); background: white; }
.auth-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.auth-submit { width: 100%; margin-top: 15px; }
.auth-error { margin-top: 16px; padding: 10px 12px; border-radius: 6px; color: var(--red); background: var(--red-soft); font-size: 12px; }
.auth-link { display: block; margin-top: 18px; color: var(--green); text-align: center; font-size: 12px; font-weight: 700; }
.auth-link:hover { text-decoration: underline; }

.mobile-nav { display: none; }

@media (max-width: 900px) {
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-cell:nth-child(2) { border-right: 0; }
  .metric-cell:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .job-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body { font-size: 13px; }
  .sidebar { display: none; }
  .workspace { margin-left: 0; }
  .topbar { min-height: 96px; padding: 22px 17px 16px; }
  .topbar h1 { font-size: 23px; }
  .updated-at { display: none; }
  .topbar-account { display: block; }
  .logout-form span { display: none; }
  .page-content { padding: 18px 14px 88px; }
  .metric-cell { padding: 15px; }
  .metric-cell strong { font-size: 23px; }
  .metric-cell .metric-date { font-size: 16px; }
  .trade-signal-panel { padding: 16px; }
  .trade-signal-row { grid-template-columns: 70px minmax(0, 1fr); }
  .signal-session { grid-column: 2; white-space: normal; }
  .no-trade-signal { align-items: flex-start; flex-direction: column; gap: 5px; }
  .content-section { margin-top: 27px; }
  .section-heading { margin-bottom: 11px; }
  .job-panel { padding: 16px; }
  .job-meta { margin-top: 17px; }
  .toolbar-row { align-items: flex-start; flex-direction: column-reverse; }
  .metric-guide-heading { align-items: flex-start; flex-direction: column; gap: 12px; }
  .metric-scale { justify-content: flex-start; }
  .metric-definition-grid { grid-template-columns: 1fr; }
  .metric-definition-grid div { padding-right: 0; }
  .watchlist-toolbar { align-items: stretch; flex-direction: column; }
  .watchlist-tools { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .watchlist-tools .primary-button { grid-column: 1 / -1; }
  .compact-select { width: 100%; }
  .segmented-control { width: 100%; overflow-x: auto; }
  .segment { flex: 1 0 auto; padding: 0 10px; }
  .candidate-table-wrap, .table-wrap { border: 0; background: transparent; overflow: visible; }
  .data-table { min-width: 0; }
  .data-table thead { display: none; }
  .data-table tbody { display: grid; gap: 10px; }
  .data-table tr { display: block; padding: 11px 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
  .data-table td {
    display: flex;
    min-height: 35px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 0;
    border-bottom: 1px solid #edf0ee;
    text-align: right;
  }
  .data-table td:last-child { border-bottom: 0; }
  .data-table td::before { content: attr(data-label); flex: 0 0 auto; color: var(--muted); font-size: 11px; font-weight: 650; }
  .data-table td strong, .data-table td small { text-align: right; }
  .stock-identity, .metric-reading { justify-items: end; margin-left: auto; text-align: right; }
  .data-table .row-actions { justify-content: flex-end; }
  .issues-cell { max-width: none; }
  .notification-line { grid-template-columns: 47px minmax(0, 1fr); gap: 9px; }
  .notification-line time { display: none; }
  .notification-record summary { grid-template-columns: 47px minmax(0, 1fr); gap: 10px; padding: 11px 13px; }
  .disclosure-label { display: none; }
  .notification-content { padding: 14px; font-size: 12px; }
  .recommendation-row { grid-template-columns: minmax(0, 1fr) auto; gap: 9px 14px; padding: 13px; }
  .recommendation-row p { grid-column: 1 / -1; grid-row: 2; }
  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.97);
  }
  .mobile-nav a { display: grid; place-items: center; color: var(--muted); font-size: 11px; font-weight: 700; }
  .mobile-nav a.is-active { color: var(--green); box-shadow: inset 0 3px 0 var(--green); }
}
