:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #18212b;
  --muted: #637083;
  --line: #d9e0e8;
  --accent: #0d766e;
  --accent-dark: #095c56;
  --soft: #edf6f4;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 48px;
}

.query-panel,
.status-band,
.strategy-panel,
.chart-panel,
.report {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.query-panel {
  padding: 24px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

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

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

.brand-row p,
.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.source-pill {
  flex: 0 0 auto;
  border: 1px solid #9fd0ca;
  background: var(--soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 0;
}

.page-nav a,
.page-nav button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  background: #fbfcfd;
  padding: 8px 12px;
  font-weight: 700;
  text-decoration: none;
  font-size: 14px;
  line-height: 1.4;
  height: auto;
}

.page-nav a:hover,
.page-nav button:hover {
  border-color: var(--accent);
  background: var(--soft);
}

.page-nav button:disabled {
  color: #6f8582;
  background: #edf3f2;
  cursor: wait;
}

.chart-panel {
  position: relative;
}

.chart-tooltip {
  position: fixed;
  z-index: 20;
  min-width: 178px;
  border: 1px solid rgba(24, 33, 43, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(24, 33, 43, 0.14);
  color: var(--text);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.55;
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.chart-tooltip span {
  display: block;
  color: var(--muted);
}

.query-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
}

input[type="text"],
input[name="question"],
select {
  width: 100%;
  height: 46px;
  border: 1px solid #b9c4d0;
  border-radius: 6px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  outline: none;
}

input[name="question"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 118, 110, 0.14);
}

select {
  width: auto;
  min-width: 156px;
  background: #ffffff;
}

button {
  height: 46px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

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

button:disabled {
  cursor: wait;
  background: #8aa6a2;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.options-grid label {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: #344254;
  font-size: 14px;
  background: #fbfcfd;
}

.status-band {
  margin-top: 14px;
  min-height: 50px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

#symbols {
  color: var(--accent-dark);
  font-weight: 700;
}

.report {
  margin-top: 14px;
  padding: 26px;
  min-height: 320px;
}

.chart-panel {
  margin-top: 14px;
  padding: 18px;
}

.strategy-panel {
  margin-top: 14px;
  padding: 18px;
}

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

.section-head h2 {
  font-size: 18px;
}

#chart-caption {
  color: var(--muted);
  font-size: 14px;
}

#kline-chart,
#sector-kline-chart,
#holding-kline-chart {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

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

.strategy-actions button {
  height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

#strategy-status {
  color: var(--muted);
  margin-bottom: 12px;
}

#validation-status {
  color: var(--muted);
  margin-bottom: 12px;
}

#holding-status,
#holding-list-caption,
#holding-detail-title {
  color: var(--muted);
  margin-bottom: 12px;
}

.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.filter-bar label {
  color: #344254;
  font-weight: 800;
}

.filter-bar select {
  height: 38px;
  padding: 0 10px;
  font-size: 14px;
}

.tracking-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.tracking-summary div {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 12px;
}

.tracking-summary strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.tracking-summary span {
  display: block;
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  height: 34px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  color: #344254;
  padding: 0 12px;
  font-size: 13px;
}

.tab-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.strategy-content {
  display: grid;
  gap: 16px;
}

.strategy-content > *,
.picks-grid > *,
.sector-rank-grid > * {
  min-width: 0;
}

.picks-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.sector-rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
}

.pick-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfd;
  color: var(--text);
  cursor: pointer;
  height: auto;
  text-align: left;
  text-decoration: none;
}

.pick-card:hover {
  border-color: var(--accent);
  background: var(--soft);
}

.pick-rank {
  color: var(--muted);
  font-size: 12px;
}

.pick-name {
  font-weight: 800;
  margin-top: 4px;
}

.pick-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 6px;
}

.strategy-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

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

.strategy-table th,
.strategy-table td {
  border: 1px solid var(--line);
  padding: 8px 9px;
  font-size: 13px;
  text-align: left;
}

.strategy-table th {
  background: #f0f4f7;
}

.strategy-table a {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.strategy-table a:hover {
  text-decoration: underline;
}

.pick-card a,
.sector-link,
.sector-chip {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.pick-card a:hover,
.sector-link:hover,
.sector-chip:hover {
  text-decoration: underline;
}

.sector-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sector-chip {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 7px 10px;
}

.tracking-table {
  min-width: 1180px;
}

.holdings-table {
  min-width: 1280px;
}

.holdings-table tbody tr {
  cursor: pointer;
}

.holdings-table tbody tr:hover,
.holdings-table tbody tr.selected-row {
  background: var(--soft);
}

.holding-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.holding-analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.holding-analysis-grid > div {
  min-width: 0;
}

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

.holding-profile > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 13px 14px;
}

.holding-profile span,
.holding-profile em {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.holding-profile strong {
  display: block;
  margin: 5px 0;
  font-size: 21px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.holding-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
}

.holding-detail-list div {
  min-width: 0;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.holding-detail-list div:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.holding-detail-list div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.holding-detail-list div:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  border-right: 0;
}

.holding-detail-list span {
  color: var(--muted);
  font-size: 13px;
}

.holding-detail-list strong {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.holding-detail-grid div,
.holding-feature-list div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 11px 12px;
}

.holding-detail-grid span,
.holding-feature-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.holding-detail-grid strong,
.holding-feature-list strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.holding-feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.holding-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.holding-chip-row span {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 7px 9px;
  color: #344254;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.track-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 300px;
}

.track-list span {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 3px 6px;
  white-space: nowrap;
}

.track-list em {
  font-style: normal;
}

.return-pos {
  color: var(--danger);
  font-weight: 800;
}

.return-neg {
  color: #0f7b3f;
  font-weight: 800;
}

.return-flat {
  color: var(--muted);
  font-weight: 800;
}

.empty-inline {
  color: var(--muted);
  padding: 12px 0;
}

.report.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.report h1 {
  font-size: 26px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.report h2 {
  font-size: 19px;
  margin: 24px 0 10px;
}

.report ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.report li {
  margin: 8px 0;
  line-height: 1.65;
}

.report p {
  line-height: 1.7;
  margin: 10px 0;
}

.report table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 22px;
  overflow: hidden;
}

.report th,
.report td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  font-size: 14px;
}

.report th {
  background: #f0f4f7;
}

.warning-box,
.error-box {
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.warning-box {
  background: #fff8e6;
  border: 1px solid #f3d58b;
  color: #6f4e00;
}

.error-box {
  background: #fff1f0;
  border: 1px solid #ffccc7;
  color: var(--danger);
}

@media (max-width: 760px) {
  .app {
    width: min(100% - 16px, 1120px);
    margin: 12px auto 28px;
  }

  .brand-row,
  .status-band {
    display: block;
  }

  .source-pill {
    display: inline-block;
    margin-top: 12px;
  }

  .query-panel,
  .strategy-panel,
  .chart-panel,
  .report {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

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

  .page-nav a,
  .page-nav button {
    width: 100%;
    min-height: 40px;
    padding: 8px 6px;
    text-align: center;
  }

  .page-nav button {
    grid-column: 1 / -1;
  }

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

  .strategy-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .strategy-actions select,
  .strategy-actions button {
    width: 100%;
  }

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

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

  .picks-grid {
    grid-template-columns: 1fr;
  }

  .sector-rank-grid {
    grid-template-columns: 1fr;
  }

  .strategy-content > div {
    width: 100%;
  }

  .pick-card {
    padding: 12px;
  }

  .pick-meta {
    display: grid;
    gap: 3px;
    line-height: 1.55;
  }

  .overview-mobile-table {
    min-width: 0;
  }

  .overview-mobile-table thead {
    display: none;
  }

  .overview-mobile-table,
  .overview-mobile-table tbody,
  .overview-mobile-table tr,
  .overview-mobile-table td {
    display: block;
    width: 100%;
  }

  .overview-mobile-table tbody {
    display: grid;
    gap: 10px;
  }

  .overview-mobile-table tr {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
    overflow: hidden;
  }

  .overview-mobile-table td {
    min-height: 34px;
    border: 0;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    overflow-wrap: anywhere;
  }

  .overview-mobile-table td:last-child {
    border-bottom: 0;
  }

  .overview-mobile-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

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

  .tracking-summary strong {
    font-size: 19px;
    overflow-wrap: anywhere;
  }

  #kline-chart,
  #sector-kline-chart,
  #holding-kline-chart {
    height: 300px;
  }

  .holding-analysis-grid,
  .holding-detail-grid,
  .holding-feature-list,
  .holding-profile,
  .holding-detail-list {
    grid-template-columns: 1fr;
  }

  .holding-profile strong {
    font-size: 20px;
  }

  .holding-detail-list {
    border: 0;
    gap: 8px;
    background: transparent;
  }

  .holding-detail-list div,
  .holding-detail-list div:nth-child(odd),
  .holding-detail-list div:nth-last-child(-n + 2),
  .holding-detail-list div:last-child:nth-child(odd) {
    border: 1px solid var(--line);
    border-radius: 6px;
  }

  .holding-detail-list div {
    grid-column: auto;
    grid-template-columns: 76px minmax(0, 1fr);
    padding: 9px 10px;
  }

  .holding-feature-list div {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
  }

  .holding-feature-list span {
    margin-bottom: 0;
  }

  .holdings-table {
    min-width: 0;
  }

  .holdings-table thead {
    display: none;
  }

  .holdings-table,
  .holdings-table tbody,
  .holdings-table tr,
  .holdings-table td {
    display: block;
    width: 100%;
  }

  .holdings-table tbody {
    display: grid;
    gap: 10px;
  }

  .holdings-table tr {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
    overflow: hidden;
  }

  .holdings-table td {
    min-height: 36px;
    border: 0;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    overflow-wrap: anywhere;
  }

  .holdings-table td:last-child {
    border-bottom: 0;
  }

  .holdings-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .holding-chip-row span {
    width: 100%;
  }

  .report {
    padding: 18px;
    overflow-x: auto;
  }
}
