:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-strong: #eef2f5;
  --line: #d8dee6;
  --text: #17202a;
  --muted: #657080;
  --accent: #0b6bcb;
  --accent-strong: #084f97;
  --good: #137a4b;
  --bad: #b42318;
  --warn: #a15c00;
  --neutral: #56616f;
  --shadow: 0 12px 24px rgba(37, 50, 66, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Arial,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 24px;
}

.topbar h1,
.panel h2,
.safety-band h2 {
  margin: 0;
  line-height: 1.05;
}

.topbar h1 {
  font-size: clamp(32px, 5vw, 56px);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subtle-line {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions,
.inline-control {
  display: flex;
  gap: 10px;
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 1;
  background: #b8c6d4;
  color: #526174;
}

.button.primary {
  background: var(--accent);
  color: white;
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.button.secondary:hover {
  border-color: var(--accent);
}

.button.ghost {
  background: transparent;
  color: var(--muted);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.status-strip article,
.panel,
.control-band,
.safety-band,
.assistant-window {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-strip article {
  min-height: 112px;
  padding: 18px;
}

.status-strip span,
.status-strip small,
dt,
.timestamp {
  color: var(--muted);
}

.status-strip strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 26px;
}

.control-band {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.1fr;
  gap: 16px;
  margin-bottom: 14px;
  padding: 16px;
}

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

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 12px;
}

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.two-column {
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel h2,
.safety-band h2 {
  font-size: 22px;
}

.graph-controls {
  display: grid;
  gap: 8px;
  justify-items: end;
  min-width: min(260px, 100%);
}

.live-data-panel {
  margin-bottom: 14px;
}

.live-data-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr auto repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.live-data-grid > div {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-strong);
}

.live-data-grid span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.live-data-grid strong {
  font-size: 14px;
}

.live-events {
  min-height: 28px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.range-buttons {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 170px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.range-button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

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

#stockGraphCanvas {
  display: block;
  width: 100%;
}

.graph-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.graph-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-strong);
}

.graph-stats span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.graph-stats strong {
  font-size: 16px;
}

.contribution-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.wide-field {
  grid-column: 1 / -1;
}

.contribution-form .button {
  grid-column: 1 / -1;
}

.contribution-table {
  max-height: 210px;
  margin-top: 14px;
  overflow: auto;
}

.contribution-table table {
  min-width: 480px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.good {
  background: #dff3e9;
  color: var(--good);
}

.badge.bad {
  background: #fde7e5;
  color: var(--bad);
}

.badge.wait,
.badge.neutral {
  background: #edf0f3;
  color: var(--neutral);
}

.badge.warn {
  background: #fff0d8;
  color: var(--warn);
}

.recommendation p {
  max-width: 68ch;
  margin: 0 0 16px;
  color: var(--text);
  line-height: 1.55;
}

.recommendation dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}

.recommendation dl div,
.forecast-stats div,
.allocation-rows div {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

dt {
  margin-bottom: 6px;
  font-size: 12px;
}

dd {
  margin: 0;
  font-weight: 800;
}

.order-note {
  min-height: 24px;
  margin-top: 12px;
  color: var(--accent-strong);
  font-size: 14px;
}

.allocation-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.allocation-rows {
  display: grid;
  gap: 10px;
}

.allocation-rows div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

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

.market-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-strong);
}

.market-card strong {
  display: block;
  margin-bottom: 8px;
}

.market-card .change,
.watch-change {
  font-weight: 800;
}

.up {
  color: var(--good);
}

.down {
  color: var(--bad);
}

.flat {
  color: var(--neutral);
}

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

.news-item {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 138px;
  border-left: 4px solid var(--line);
  padding: 12px;
  background: var(--surface-strong);
  border-radius: 6px;
}

.news-item.positive {
  border-left-color: var(--good);
}

.news-item.negative {
  border-left-color: var(--bad);
}

.news-item.neutral {
  border-left-color: var(--neutral);
}

.news-item a {
  color: inherit;
  text-decoration: none;
}

.news-item a:hover {
  color: var(--accent);
}

.news-summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.news-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.forecast-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.forecast-stats span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.safety-band {
  margin-top: 14px;
  padding: 18px;
  border-left: 5px solid var(--accent);
}

.safety-band p {
  max-width: 90ch;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.page-assistant {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
}

.assistant-toggle {
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 800;
}

.assistant-window {
  position: absolute;
  right: 0;
  bottom: 62px;
  display: grid;
  grid-template-rows: auto minmax(220px, 360px) auto;
  width: min(420px, calc(100vw - 28px));
  overflow: hidden;
}

.assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.assistant-header strong,
.assistant-header span {
  display: block;
}

.assistant-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.assistant-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
}

.message {
  max-width: 88%;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.message.bot {
  background: white;
  border: 1px solid var(--line);
}

.message.user {
  justify-self: end;
  background: var(--accent);
  color: white;
}

.assistant-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

@media (max-width: 1050px) {
  .status-strip,
  .control-band,
  .two-column {
    grid-template-columns: 1fr 1fr;
  }

  .live-data-grid {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 12px;
  }

  .topbar,
  .topbar-actions,
  .inline-control,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .status-strip,
  .control-band,
  .live-data-grid,
  .two-column,
  .recommendation dl,
  .allocation-layout,
  .forecast-stats,
  .graph-stats,
  .market-grid,
  .news-list {
    grid-template-columns: 1fr;
  }

  .graph-controls {
    justify-items: stretch;
  }

  .range-buttons {
    width: 100%;
  }

  .contribution-form {
    grid-template-columns: 1fr;
  }

  .allocation-layout canvas {
    justify-self: center;
  }

  .page-assistant {
    right: 10px;
    bottom: 10px;
  }
}
