:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --surface-3: #f9fbfc;
  --border: #d7dfe5;
  --text: #202a33;
  --muted: #65717b;
  --green: #247b5b;
  --blue: #256c9a;
  --red: #a93d3d;
  --amber: #986c19;
  --shadow: 0 12px 28px rgba(32, 42, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input,
select {
  font: inherit;
}

button,
select,
input {
  min-height: 36px;
}

button {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9eb0bd;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

select,
input,
textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--text);
}

select,
input {
  padding: 0 10px;
}

.primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-weight: 800;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 850;
  font-size: 18px;
}

.subline,
.status,
label span,
.metric span,
td,
pre,
.detail p,
.news-group p {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  min-width: 92px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  font-size: 13px;
  text-align: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 64px);
}

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

.panel-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

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

h1,
h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.inputs {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.input-tools,
.config-grid {
  display: grid;
  gap: 8px;
  padding: 14px 16px 0;
}

.input-tools {
  grid-template-columns: 1fr 92px 1fr;
}

.input-tools button {
  grid-column: 1 / -1;
}

.config-grid {
  grid-template-columns: 1.2fr 0.8fr 0.8fr;
  padding-bottom: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

label span {
  font-size: 12px;
  font-weight: 800;
}

.field {
  padding: 14px 16px 0;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

#portfolioInput {
  min-height: 132px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 16px;
}

.error {
  margin: 0 16px 16px;
  padding: 12px;
  border: 1px solid #e0aaaa;
  border-radius: 6px;
  background: #fff5f5;
  color: var(--red);
  white-space: pre-wrap;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 16px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(112px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 80px;
  padding: 14px;
  box-shadow: none;
}

.metric.flat {
  min-height: 76px;
}

.metric span {
  display: block;
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 9px;
  font-size: 22px;
}

.results {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.results-head {
  align-items: flex-start;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.tab {
  border: 0;
  border-radius: 0;
  min-height: 34px;
  background: var(--surface);
}

.tab.active {
  background: var(--surface-2);
  color: var(--blue);
  font-weight: 850;
}

.tabview {
  display: none;
  min-height: 0;
  flex: 1;
}

.tabview.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(4, minmax(130px, 170px));
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-3);
}

.split {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(360px, 0.75fr);
  min-height: 650px;
}

.table-wrap {
  overflow: auto;
  border-right: 1px solid var(--border);
}

.table-wrap.simple {
  border: 1px solid var(--border);
  border-radius: 7px;
}

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

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 14px;
  vertical-align: top;
}

td span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

th {
  color: var(--text);
  background: var(--surface-3);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #edf5f1;
}

.pill,
.risk {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 850;
}

.pill {
  background: #e9f2f8;
  color: var(--blue);
}

.pill.high_priority {
  background: #e8f5e9;
  color: var(--green);
}

.pill.filtered {
  background: #f8eddc;
  color: var(--amber);
}

.risk.low,
.risk.positive {
  background: #e8f5e9;
  color: var(--green);
}

.risk.medium,
.risk.mixed,
.risk.unknown {
  background: #edf2fb;
  color: var(--blue);
}

.risk.high,
.risk.negative {
  background: #fff0f0;
  color: var(--red);
}

.detail {
  padding: 18px;
  overflow: auto;
}

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

.detail p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.price-chart {
  width: 100%;
  height: 220px;
  display: block;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-3);
}

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

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

.kv {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-3);
}

.kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.kv strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
}

.risk-list,
.news-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.risk-list {
  flex-direction: row;
  flex-wrap: wrap;
}

.risk-list li {
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--red);
  background: #fff0f0;
  font-size: 12px;
  font-weight: 850;
}

.news-list li {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-3);
}

.news-list.compact li {
  border: 0;
  padding: 0;
  background: transparent;
}

.news-list span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tab-pad {
  padding: 16px;
}

.news-group {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.news-group:first-child {
  padding-top: 0;
}

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

#jsonOutput,
#markdownOutput {
  margin: 0;
  min-height: 650px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  padding: 16px;
  background: var(--surface-3);
  color: #2f3d38;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

#htmlOutput {
  width: 100%;
  min-height: 650px;
  border: 0;
  background: var(--surface);
}

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

  .table-wrap {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

@media (max-width: 760px) {
  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    padding: 10px;
  }

  .input-tools,
  .config-grid,
  .toolbar,
  .metrics,
  .detail-grid,
  .section-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1 1 110px;
  }

  th,
  td {
    padding: 10px;
  }
}

.mock-banner {
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: 8px;
  background: #fff4e5;
  border: 1px solid #f0b66b;
  color: #8a4b08;
  font-size: 13px;
  font-weight: 800;
}

.detail h4 {
  margin: 14px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 4px 0 10px;
  padding: 0;
  list-style: none;
}

.chip-list li {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

.chip-list li span {
  display: inline;
  margin: 0;
  font-weight: 850;
  color: var(--text);
}
