:root {
  --ink: #111820;
  --muted: #5f6872;
  --paper: #f5f3ee;
  --surface: rgba(255, 255, 250, 0.9);
  --surface-strong: #fffdfa;
  --line: rgba(17, 24, 32, 0.14);
  --line-strong: rgba(17, 24, 32, 0.28);
  --blue: #2e5d86;
  --green: #2f7159;
  --amber: #96691d;
  --red: #a44444;
  --violet: #62508a;
  --shadow: 0 20px 60px rgba(17, 24, 32, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(47, 113, 89, 0.08), transparent 34%),
    linear-gradient(180deg, rgba(46, 93, 134, 0.07), transparent 48%),
    var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p,
td,
th,
span,
strong {
  overflow-wrap: anywhere;
}

.portfolio-shell {
  display: grid;
  gap: 18px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3.5vw, 42px);
}

.portfolio-header,
.input-panel,
.summary-panel,
.alert-panel,
.position-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.portfolio-header {
  display: grid;
  gap: 18px;
  padding: clamp(16px, 3vw, 28px);
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.top-nav a,
.panel-head button,
.action-row button,
.upload-button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue);
  background: rgba(255, 255, 250, 0.72);
  font-size: 0.84rem;
  font-weight: 760;
  text-decoration: none;
}

.top-nav a {
  padding: 0 12px;
}

.top-nav a:hover,
.panel-head button:hover,
.action-row button:hover,
.upload-button:hover {
  border-color: rgba(46, 93, 134, 0.34);
  background: var(--surface-strong);
}

.title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 340px);
  gap: clamp(16px, 4vw, 34px);
  align-items: end;
}

.kicker,
.panel-kicker {
  margin: 0 0 8px;
  color: var(--amber);
  font-size: 0.75rem;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  line-height: 1.1;
  letter-spacing: 0;
}

h3,
p {
  margin: 0;
}

.statement {
  max-width: 780px;
  margin-top: 12px;
  color: var(--muted);
  font-size: clamp(0.98rem, 1.35vw, 1.12rem);
  font-weight: 650;
  line-height: 1.65;
  min-width: 0;
  word-break: break-word;
}

.live-status {
  display: grid;
  gap: 7px;
  min-height: 118px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 250, 0.68);
}

.live-status span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 760;
}

.live-status strong {
  color: var(--blue);
  font-size: 1.25rem;
  line-height: 1.15;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: stretch;
}

.input-panel,
.summary-panel,
.alert-panel,
.position-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: clamp(16px, 2.2vw, 22px);
}

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

#portfolio-input {
  width: 100%;
  min-height: 176px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  color: var(--ink);
  background: rgba(255, 255, 250, 0.78);
  line-height: 1.55;
}

#portfolio-input:focus,
.threshold-grid input:focus {
  border-color: rgba(46, 93, 134, 0.5);
  outline: 2px solid rgba(46, 93, 134, 0.12);
}

.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

#image-input {
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
}

.upload-button {
  padding: 0 14px;
}

.image-preview {
  min-height: 120px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 250, 0.58);
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 6px;
}

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

.threshold-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 250, 0.62);
}

.threshold-grid span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 780;
}

.threshold-grid input {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 7px;
  color: var(--ink);
  background: var(--surface-strong);
  font-weight: 780;
}

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

.action-row button {
  padding: 0 16px;
}

#analyze-button {
  color: #fff;
  border-color: rgba(47, 113, 89, 0.18);
  background: var(--green);
}

#analyze-button:disabled,
#clear-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.extraction-panel {
  display: flex;
  min-height: 34px;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.source-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  background: rgba(255, 255, 250, 0.68);
  font-size: 0.76rem;
  font-weight: 780;
  line-height: 1.15;
}

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

.metric-strip div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 12px;
  background: rgba(255, 255, 250, 0.6);
}

.metric-strip div + div {
  border-left: 1px solid var(--line);
}

.metric-strip span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.metric-strip strong {
  font-size: clamp(1rem, 1.5vw, 1.4rem);
  line-height: 1.1;
}

.curve-chart {
  min-height: 338px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 250, 0.86), rgba(255, 255, 250, 0.62));
  overflow: hidden;
}

.curve-chart svg {
  display: block;
  width: 100%;
  height: 338px;
}

.chart-line {
  stroke: var(--blue);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: rgba(46, 93, 134, 0.12);
}

.chart-grid {
  stroke: rgba(17, 24, 32, 0.09);
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.empty-state {
  display: grid;
  min-height: 338px;
  place-items: center;
  color: var(--muted);
  font-weight: 760;
}

.alert-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 10px;
}

.alert-item {
  display: grid;
  gap: 7px;
  min-height: 100px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 250, 0.68);
}

.alert-item[data-level="risk"] {
  border-left-color: var(--red);
}

.alert-item[data-level="watch"] {
  border-left-color: var(--amber);
}

.alert-item[data-level="strong"],
.alert-item[data-level="ok"] {
  border-left-color: var(--green);
}

.alert-item[data-level="info"] {
  border-left-color: var(--violet);
}

.alert-item strong {
  font-size: 0.98rem;
}

.alert-item p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.position-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 250, 0.68);
}

.position-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.position-table th,
.position-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.position-table th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 820;
  text-transform: uppercase;
}

.position-table td {
  font-size: 0.92rem;
  font-weight: 650;
}

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

.tone-up {
  color: var(--green);
}

.tone-down {
  color: var(--red);
}

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

@media (max-width: 980px) {
  .title-row,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

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

  .metric-strip div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .metric-strip div:nth-child(4) {
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 620px) {
  .portfolio-shell {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 14px;
  }

  .portfolio-shell > * + * {
    margin-top: 14px;
  }

  .portfolio-header,
  .input-panel,
  .summary-panel,
  .alert-panel,
  .position-panel {
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
  }

  .top-nav {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-nav a {
    width: 100%;
    min-width: 0;
    padding: 0 8px;
  }

  h1 {
    font-size: clamp(2rem, 13vw, 3rem);
  }

  .statement {
    font-size: 0.95rem;
    line-height: 1.55;
    max-width: calc(100vw - 56px);
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .threshold-grid,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .metric-strip div + div,
  .metric-strip div:nth-child(3),
  .metric-strip div:nth-child(4) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

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

  .curve-chart,
  .curve-chart svg,
  .empty-state {
    min-height: 280px;
    height: 280px;
  }
}
