/* Shared mobile-first layout for every dashboard screen. */

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  min-width: 0;
}

.page {
  width: 100%;
  max-width: 26.5rem;
  min-width: 0;
  overflow-x: hidden;
  padding: 3.15rem 1rem 2.4rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(2.4rem, env(safe-area-inset-bottom));
}

body:has(.topbar) .page {
  max-width: 26.5rem;
  padding-top: 1.25rem;
}

body.has-app .page {
  padding-top: 1.35rem;
}

body.terminal-page.has-app .terminal {
  padding-top: 1rem;
  min-height: calc(100vh - 3.5rem);
}

.card,
.call {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.checkpoint,
.title {
  overflow-wrap: anywhere;
  white-space: normal;
}

.checkpoint {
  font-size: clamp(1.4rem, 7vw, 2.15rem);
}

.title {
  font-size: clamp(1.35rem, 6.2vw, 2.15rem);
  line-height: 1.15;
}

.card-nav {
  gap: 0.6rem;
}

.card-nav .caption {
  text-align: center;
  min-width: 0;
  flex: 1;
}

.nav-btn {
  min-width: 2.75rem;
  min-height: 2.75rem;
  flex-shrink: 0;
  touch-action: manipulation;
}

.dash-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.15rem;
  line-height: 1.65;
}

.num,
.level-num,
.expectancy-stat,
.preview-num,
.size-line {
  overflow-wrap: anywhere;
}

.closed-body,
.chart-note,
.infra-note,
.caption,
.action-note {
  overflow-wrap: anywhere;
  white-space: normal;
}

.risk-row,
.row-top,
.expectancy {
  flex-wrap: wrap;
}

.row-top > * {
  min-width: 0;
}

.date {
  overflow-wrap: anywhere;
}

.chart-wrap {
  width: 100%;
  max-width: 100%;
  min-height: clamp(12.5rem, 58vw, 20rem);
  overflow: hidden;
}

.chart-wrap canvas,
.call-chart,
#chart {
  width: 100% !important;
  max-width: 100%;
  height: clamp(12.5rem, 58vw, 20rem) !important;
}

.tf-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.75rem;
  margin: 0 0 0.7rem;
}

.tf-label {
  font-size: 0.75rem;
  color: var(--data-slate, #5b6472);
}

.tf-select {
  min-height: 2.75rem;
  min-width: 7.25rem;
  max-width: 100%;
  flex: 1 1 8rem;
  font-family: var(--mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.92rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line, #d8d3c8);
  background: var(--paper, #fafafa);
  color: var(--ink, #12181f);
  touch-action: manipulation;
}

.actions .btn,
.run-engine,
.login-btn,
.autonomy-switch,
.tf-select {
  touch-action: manipulation;
}

.logout-btn {
  top: max(0.55rem, env(safe-area-inset-top));
  right: max(0.7rem, env(safe-area-inset-right));
  min-height: 2.2rem;
  padding: 0.35rem 0.7rem;
}

.strip-list li {
  min-width: 0;
}

.autonomy {
  border: 1px solid var(--line, #d8d3c8);
  padding: 0.9rem 1rem;
  margin: 0 0 1.15rem;
}

.autonomy-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
}

.autonomy-row > div {
  min-width: 0;
}

.autonomy .caption {
  margin: 0.2rem 0 0;
}

.autonomy-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  padding: 0.2rem 0.5rem 0.2rem 0.28rem;
  border: 1px solid var(--line, #d8d3c8);
  background: var(--paper, #fafafa);
  color: var(--ink, #12181f);
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

.autonomy-switch:disabled {
  opacity: 0.72;
  cursor: wait;
}

.autonomy-knob {
  position: relative;
  width: 2.4rem;
  height: 1.35rem;
  border: 1px solid var(--ink, #12181f);
  border-radius: 999px;
  background: var(--paper, #fafafa);
  flex-shrink: 0;
}

.autonomy-knob::after {
  content: "";
  position: absolute;
  top: 0.1rem;
  left: 0.1rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: var(--ink, #12181f);
}

.autonomy-switch.is-on .autonomy-knob {
  background: var(--ink, #12181f);
}

.autonomy-switch.is-on .autonomy-knob::after {
  left: auto;
  right: 0.1rem;
  background: var(--paper, #fafafa);
}

.autonomy-state {
  font-family: var(--mono, "IBM Plex Mono", ui-monospace, monospace);
  font-size: 0.82rem;
  min-width: 1.7rem;
  text-align: left;
}

body.terminal-page {
  overflow-x: hidden;
}

body.terminal-page .terminal {
  max-width: none;
  width: 100%;
  padding: 3.15rem 0.85rem 1.1rem;
  padding-left: max(0.85rem, env(safe-area-inset-left));
  padding-right: max(0.85rem, env(safe-area-inset-right));
}

body.terminal-page .checkpoint {
  font-size: clamp(1.05rem, 4.4vw, 1.45rem);
}

body.terminal-page .chart-wrap {
  width: 100%;
  max-width: 100%;
  min-height: clamp(16rem, 48vh, 28rem);
  overflow: hidden;
}

body.terminal-page .chart-wrap canvas,
body.terminal-page #chart {
  width: 100% !important;
  max-width: 100%;
  height: clamp(16rem, 48vh, 28rem) !important;
}

body.terminal-page .watchlist {
  width: 100%;
}

@media (max-width: 767px) {
  body.terminal-page .term-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  body.terminal-page .tf-bar,
  body.terminal-page .tf-quick {
    width: 100%;
  }

  body.terminal-page .tf-quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  body.terminal-page .tf-btn {
    flex-shrink: 0;
  }

  body.terminal-page .tf-btn,
  body.terminal-page .tf-more-btn {
    min-height: 2.75rem;
  }
}

@media (min-width: 768px) {
  body.terminal-page .terminal {
    padding: 3.3rem 1.15rem 1.2rem;
  }

  body.terminal-page .term-body {
    grid-template-columns: minmax(0, 1fr) 16.5rem;
    align-items: start;
  }

  body.terminal-page .chart-wrap,
  body.terminal-page .chart-wrap canvas,
  body.terminal-page #chart {
    min-height: clamp(22rem, 58vh, 36rem);
    height: clamp(22rem, 58vh, 36rem) !important;
  }
}

@media (min-width: 1200px) {
  body.terminal-page .terminal {
    padding: 3.4rem 1.5rem 1.3rem;
  }

  body.terminal-page .term-body {
    grid-template-columns: minmax(0, 1fr) 18rem;
    gap: 1rem;
  }

  body.terminal-page .chart-wrap,
  body.terminal-page .chart-wrap canvas,
  body.terminal-page #chart {
    min-height: calc(100vh - 17rem);
    height: calc(100vh - 17rem) !important;
  }
}

@media (max-width: 400px) {
  .page {
    padding-left: max(0.8rem, env(safe-area-inset-left));
    padding-right: max(0.8rem, env(safe-area-inset-right));
  }

  body.terminal-page .term-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  body.terminal-page .tf-bar,
  body.terminal-page .tf-quick {
    width: 100%;
  }

  body.terminal-page .tf-btn,
  body.terminal-page .tf-more-btn {
    min-height: 2.75rem;
  }

  .row-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }

  .card,
  .call {
    padding: 0.95rem 0.85rem 1.1rem;
  }

  .strip-list li {
    grid-template-columns: 5.4rem 1fr;
    gap: 0.4rem;
  }

  .run-engine {
    font-size: 1.15rem;
    padding: 0.95rem 0.7rem;
  }

  .level-num {
    font-size: 1.5rem;
  }

  .actions {
    gap: 0.45rem;
  }

  .topbar {
    height: 56px;
    padding: 0 1rem;
  }

  .code-layer {
    font-size: 0.52rem;
    line-height: 1.26;
  }

  .autonomy-row {
    flex-direction: column;
    align-items: stretch;
  }

  .autonomy-switch {
    align-self: flex-start;
  }
}

@media (min-width: 768px) {
  .page {
    max-width: 36rem;
    padding-top: 3.4rem;
  }

  body:has(.topbar) .page {
    max-width: 28rem;
    padding-top: 1.5rem;
  }
}

@media (min-width: 1200px) {
  .page {
    max-width: 42rem;
  }

  body:has(.topbar) .page {
    max-width: 28rem;
  }
}
