:root {
  --bg: #d9d5cf;
  --shell: rgba(255, 251, 245, 0.82);
  --panel: rgba(255, 252, 248, 0.88);
  --panel-soft: rgba(255, 255, 255, 0.72);
  --ink: #171b22;
  --muted: #6b6d73;
  --line: rgba(23, 27, 34, 0.1);
  --line-strong: rgba(23, 27, 34, 0.16);
  --accent: #191d24;
  --gold: #e2c16b;
  --green: #169667;
  --red: #c6573f;
  --shadow: 0 10px 30px rgba(42, 37, 29, 0.07);
  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  color: var(--ink);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% 0%, rgba(255, 255, 255, 0.42), transparent 28%),
    radial-gradient(circle at 85% 12%, rgba(226, 193, 107, 0.3), transparent 18%),
    linear-gradient(180deg, #dfdbd4 0%, var(--bg) 100%);
}

.hidden {
  display: none !important;
}

.viewport {
  height: 100dvh;
  padding: 10px;
  overflow: hidden;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.soft {
  background: var(--panel-soft);
}

.eyebrow,
.metric-label,
.progress-head strong,
.signal-box strong,
.field span {
  margin: 0;
  font-size: 10px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.status {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.support-copy {
  margin: 0;
  font-size: 11px;
  line-height: 1.38;
  color: var(--muted);
}

.auth-screen {
  min-height: calc(100vh - 24px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
  padding: 20px;
  display: grid;
  gap: 12px;
}

.auth-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
}

.auth-card h1 {
  margin: 2px 0 0;
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.07em;
}

.field {
  display: grid;
  gap: 6px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 58px;
}

.auth-actions,
.actions,
.chart-metrics,
.stat-row,
.signal-grid,
.panel-head,
.progress-head,
.brand-block {
  display: flex;
}

.auth-actions {
  gap: 8px;
}

.app-shell {
  height: calc(100dvh - 20px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}

.masthead {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-block {
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: block;
  object-fit: contain;
  border-radius: 8px;
}

.brand-copy h1,
h2,
.market-title,
.chart-value,
.metric-value,
.metric-inline {
  font-family: "Space Grotesk", "Avenir Next", "IBM Plex Sans", sans-serif;
}

.brand-copy h1 {
  margin: 2px 0 0;
  font-size: 18px;
  letter-spacing: -0.06em;
  line-height: 1;
}

.session-box {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.session-box p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.controls-card {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr;
  gap: 8px;
}

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

.toggle-row {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.toggle-row small {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  grid-template-rows: minmax(0, 0.95fr) minmax(0, 0.86fr) minmax(0, 0.82fr);
  grid-template-areas:
    "overview chart"
    "signal signal"
    "sync sync";
  gap: 10px;
  overflow: hidden;
}

.overview-card,
.chart-card,
.signal-card,
.sync-card {
  padding: 10px;
}

.overview-card {
  grid-area: overview;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.chart-card {
  grid-area: chart;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.signal-card {
  grid-area: signal;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.sync-card {
  grid-area: sync;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;
}

.sync-card .panel-head,
.sync-card .support-copy {
  grid-column: 1 / -1;
}

.panel-head {
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

h2 {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1;
  letter-spacing: -0.05em;
}

.title-stack {
  display: grid;
  gap: 6px;
}

.market-title {
  margin: 0;
  font-size: 21px;
  line-height: 1.02;
  letter-spacing: -0.08em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.stat-row {
  gap: 8px;
  min-width: 0;
}

.metric-card {
  flex: 1 1 0;
  min-width: 0;
  border-radius: var(--radius-lg);
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
}

.metric-card-accent {
  background: linear-gradient(180deg, rgba(226, 193, 107, 0.24), rgba(255, 255, 255, 0.86));
}

.metric-value {
  margin-top: 8px;
  display: block;
  font-size: 16px;
  line-height: 1;
  letter-spacing: -0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-inline {
  margin-top: 4px;
  display: block;
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: -0.04em;
}

.badge,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  font-size: 9px;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.sync-head-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sync-dot {
  font-size: 11px;
  line-height: 1;
  color: #b09f78;
}

.actions {
  gap: 6px;
  flex-wrap: wrap;
}

button {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(31, 28, 24, 0.08);
}

button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, #151a21, #363d46);
  color: #f9f3e8;
}

button.ghost {
  min-height: 28px;
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
}

.chart-stage {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.chart-copy {
  display: grid;
  gap: 4px;
}

.chart-value {
  margin: 0;
  font-size: 29px;
  line-height: 0.94;
  letter-spacing: -0.09em;
}

.chart-caption {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
}

.signal-chart {
  width: 100%;
  height: 100%;
  min-height: 82px;
  display: block;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(243, 239, 233, 0.72)),
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(25% - 1px),
      rgba(23, 27, 34, 0.06) calc(25% - 1px),
      rgba(23, 27, 34, 0.06) 25%
    );
  border: 1px solid var(--line);
}

.chart-area {
  fill: rgba(23, 27, 34, 0.08);
}

.chart-path-glow {
  fill: none;
  stroke: rgba(226, 193, 107, 0.36);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-path {
  fill: none;
  stroke: url(#signalLineGradient);
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-metrics {
  justify-content: space-between;
  gap: 8px;
}

.chart-metrics > div {
  flex: 1 1 0;
  min-width: 0;
}

.signal-summary-line {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(23, 27, 34, 0.05), rgba(255, 255, 255, 0.74));
  font-size: 10px;
  line-height: 1.35;
  font-weight: 600;
  color: #232831;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signal-grid {
  min-height: 0;
  gap: 8px;
}

.signal-grid > * {
  flex: 1 1 0;
  min-width: 0;
}

.signal-box {
  min-height: 0;
  padding: 10px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
}

.thesis-box {
  background: linear-gradient(180deg, rgba(226, 193, 107, 0.16), rgba(255, 255, 255, 0.78));
}

.signal-box p {
  margin: 0;
  font-size: 10px;
  line-height: 1.35;
  color: var(--ink);
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.progress-wrap {
  display: grid;
  gap: 4px;
  padding: 9px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
}

.sync-progress {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(244, 242, 237, 0.86));
}

.cycle-progress {
  background: linear-gradient(180deg, rgba(226, 193, 107, 0.14), rgba(255, 255, 255, 0.84));
}

.progress-head {
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.progress-head span {
  font-size: 10px;
  color: var(--muted);
}

.progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(23, 27, 34, 0.06);
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  transition: width 0.35s ease;
}

.sync-fill {
  position: relative;
  background: linear-gradient(90deg, #1a1f28 0%, #49505b 100%);
}

.sync-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.3) 0 8px,
    rgba(255, 255, 255, 0) 8px 16px
  );
  animation: sync-stripes 1.15s linear infinite;
}

.cycle-fill {
  background: linear-gradient(90deg, #cda54b 0%, #f0d592 100%);
}

.chip[data-direction="LONG"],
#signalCard[data-direction="LONG"] .signal-summary-line {
  border-color: rgba(22, 150, 103, 0.24);
}

.chip[data-direction="LONG"] {
  background: rgba(22, 150, 103, 0.12);
  color: #0f7e57;
}

.chip[data-direction="SHORT"],
#signalCard[data-direction="SHORT"] .signal-summary-line {
  border-color: rgba(198, 87, 63, 0.24);
}

.chip[data-direction="SHORT"] {
  background: rgba(198, 87, 63, 0.12);
  color: #a94735;
}

.chip[data-direction="NEUTRAL"] {
  background: rgba(23, 27, 34, 0.06);
  color: var(--muted);
}

.controls-card .support-copy,
.sync-card .support-copy {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.sync-dot[data-state="online"] {
  color: var(--green);
}

.sync-dot[data-state="error"] {
  color: var(--red);
}

.sync-dot[data-state="pending"] {
  color: #b09f78;
}

@keyframes sync-stripes {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 24px 0;
  }
}

@media (max-height: 860px) and (min-width: 981px) {
  .dashboard-grid {
    grid-template-rows: minmax(0, 0.88fr) minmax(0, 0.8fr) minmax(0, 0.76fr);
  }

  .market-title {
    font-size: 19px;
  }

  .chart-value {
    font-size: 26px;
  }

  .signal-chart {
    min-height: 72px;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .viewport {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .app-shell {
    height: auto;
    overflow: visible;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "overview"
      "chart"
      "signal"
      "sync";
  }

  .sync-card {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 540px) {
  .viewport {
    padding: 10px;
  }

  .app-shell {
    gap: 10px;
  }

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

  .brand-copy h1 {
    font-size: 18px;
  }

  .market-title {
    font-size: 20px;
  }

  .chart-value {
    font-size: 27px;
  }

  .signal-grid,
  .stat-row,
  .sync-card {
    gap: 8px;
  }

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

  .auth-logo {
    height: 34px;
  }
}
