:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #1f2933;
  --muted: #64707d;
  --line: #d8d4ca;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #b45309;
  --red: #b42318;
  --green: #15803d;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.status-row,
.button-row,
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.status-pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(15, 118, 110, 0.09);
  color: var(--teal-dark);
  font-size: 0.84rem;
  font-weight: 700;
}

.status-pill.muted {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.assistant-panel,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 18px;
  padding: 16px;
}

.control-section {
  display: grid;
  gap: 9px;
  padding: 0 0 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.control-section:last-of-type {
  margin-bottom: 18px;
}

label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--surface-soft);
  color: var(--ink);
}

input:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

select:focus {
  border-color: var(--teal);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

input[type="file"] {
  min-height: auto;
  padding: 8px;
}

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

.primary-button,
.secondary-button,
.segment {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 9px 12px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover,
.primary-button:focus {
  background: var(--teal-dark);
}

.secondary-button {
  width: 100%;
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.secondary-button:hover,
.secondary-button:focus {
  border-color: rgba(15, 118, 110, 0.5);
}

.compact {
  width: auto;
  min-height: 36px;
  padding: 7px 10px;
  font-size: 0.84rem;
}

.dashboard {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.assistant-panel {
  background: #ffffff;
}

.assistant-badge {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(180, 83, 9, 0.1);
  color: var(--amber);
  font-size: 0.8rem;
  font-weight: 850;
}

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

.assistant-card {
  min-height: 86px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.assistant-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.assistant-value {
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.25;
}

.assistant-value.good {
  color: var(--green);
}

.assistant-value.bad {
  color: var(--red);
}

.assistant-value.warn {
  color: var(--amber);
}

.scan-panel table {
  min-width: 680px;
}

.scan-panel .metric-value {
  font-size: 0.92rem;
}

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

.autopilot-panel table {
  min-width: 760px;
}

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

.metric-card {
  min-height: 92px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--surface);
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-value {
  color: var(--ink);
  font-size: 1.28rem;
  font-weight: 850;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.metric-value.good {
  color: var(--green);
}

.metric-value.bad {
  color: var(--red);
}

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

.panel-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--surface-soft);
}

.segment {
  min-width: 82px;
  min-height: 36px;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
}

.segment.active {
  background: var(--ink);
  color: #ffffff;
}

.canvas-shell {
  width: 100%;
  min-height: 360px;
  aspect-ratio: 16 / 7;
  padding: 8px 10px 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.legend {
  min-height: 48px;
  padding: 0 16px 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.legend-swatch {
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--teal);
}

.table-wrap {
  max-height: 340px;
  overflow: auto;
}

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

th,
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

td {
  font-size: 0.92rem;
}

.side {
  display: inline-flex;
  justify-content: center;
  min-width: 48px;
  border-radius: 999px;
  padding: 4px 8px;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 850;
}

.side.buy {
  background: var(--green);
}

.side.sell {
  background: var(--red);
}

.side.wait {
  background: var(--muted);
}

.side.error {
  background: var(--amber);
}

.empty-row {
  color: var(--muted);
}

.error-bar {
  margin-top: 18px;
  border: 1px solid rgba(180, 35, 24, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(180, 35, 24, 0.08);
  color: var(--red);
  font-weight: 750;
}

footer {
  padding: 18px 0 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

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

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

@media (max-width: 860px) {
  .app {
    padding: 14px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .control-panel {
    position: static;
  }

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

  .canvas-shell {
    min-height: 300px;
    aspect-ratio: 4 / 3;
  }
}

@media (max-width: 540px) {
  h1 {
    font-size: 1.65rem;
  }

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

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

  .compact {
    width: 100%;
  }
}
