/* Shared responsive shell for the existing Mini App. */
:root {
  color-scheme: dark;
  --nav-width: 250px;
}

html,
body {
  min-width: 0;
  width: 100%;
  overflow-x: clip;
}

button,
input,
select,
textarea {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #57b9ff;
  outline-offset: 2px;
}

.card,
.section-title,
.muted,
.detail-row,
.report-cell,
.settings-row {
  overflow-wrap: anywhere;
}

.bottom-nav button {
  min-width: 0;
}

@media (max-width: 600px) {
  .app-shell {
    width: 100%;
    max-width: 100%;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: calc(132px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    left: 0;
    width: 100%;
    max-width: none;
    transform: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    padding: 7px max(8px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    border-radius: 16px 16px 0 0;
  }

  .bottom-nav button {
    min-height: 53px;
    padding: 5px 2px;
    gap: 3px;
    white-space: normal;
  }

  .bottom-nav button span {
    font-size: clamp(9px, 2.75vw, 12px);
    line-height: 1.15;
    white-space: nowrap;
    letter-spacing: 0;
  }

  .section-title {
    line-height: 1.15;
  }

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

  .market-chart,
  .chart {
    max-width: 100%;
  }

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

  .risk-form-grid label,
  .risk-form-grid input,
  .risk-form-grid select {
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 359px) {
  .app-shell {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .bottom-nav button span {
    font-size: 9px;
  }

  .risk-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (min-width: 601px) and (max-width: 899px) {
  .app-shell {
    width: min(100%, 760px);
    max-width: 760px;
  }

  .bottom-nav {
    width: min(100%, 760px);
  }

  .bottom-nav button span {
    font-size: clamp(10px, 1.7vw, 13px);
    white-space: nowrap;
    letter-spacing: 0;
  }
}

@media (min-width: 900px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--nav-width) minmax(0, 1fr);
    grid-template-rows: 76px auto 1fr;
    width: 100%;
    max-width: none;
    min-height: 100vh;
    margin: 0;
    padding: 0 30px 42px 0;
  }

  .topbar {
    position: sticky;
    z-index: 8;
    top: 0;
    grid-column: 1 / -1;
    grid-row: 1;
    height: 76px;
    padding: 0 30px;
    background: #0d1828f5;
    border-bottom: 1px solid #24394e;
    backdrop-filter: blur(14px);
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .brand-copy strong {
    font-size: 16px;
    letter-spacing: 0.4px;
  }

  .brand-copy span {
    font-size: 10px;
  }

  #connection-banner {
    grid-column: 2;
    grid-row: 2;
    width: min(100%, 1600px);
    margin: 18px auto 0;
  }

  #view {
    grid-column: 2;
    grid-row: 3;
    width: min(100%, 1600px);
    max-width: 1600px;
    min-width: 0;
    margin: 24px auto 0;
    padding-bottom: 20px;
  }

  .bottom-nav {
    position: fixed;
    z-index: 10;
    top: 76px;
    bottom: 0;
    left: 0;
    width: var(--nav-width);
    max-width: var(--nav-width);
    height: calc(100vh - 76px);
    height: calc(100dvh - 76px);
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 7px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
    background: #0b1624f5;
    border-top: 0;
    border-right: 1px solid #24394e;
    backdrop-filter: blur(16px);
  }

  .bottom-nav button {
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 13px;
    width: 100%;
    min-height: 48px;
    padding: 10px 13px;
    border-radius: 12px;
    font-size: 14px;
    text-align: left;
    white-space: nowrap;
  }

  .bottom-nav button svg {
    width: 21px;
    height: 21px;
    flex: 0 0 21px;
  }

  .bottom-nav button span {
    min-width: 0;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
    letter-spacing: 0;
  }

  .bottom-nav button.active {
    color: #68beff;
    background: #19334b;
  }

  .section-title {
    margin-top: 0;
    font-size: clamp(28px, 3vw, 40px);
  }

  .card {
    padding: 22px;
    margin-bottom: 18px;
  }

  .card h2,
  .card h3 {
    font-size: 18px;
  }

  .chart {
    height: 300px;
  }

  .signal-card .chart {
    height: 240px;
  }

  .home-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .home-summary > .card {
    min-width: 0;
  }

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

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

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

  .bottom-nav button:focus-visible {
    outline-offset: 1px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

html[data-app-theme="light"] {
  color-scheme: light;
  --bg: #f2f6fb;
  --card: #ffffff;
  --panel: #e8eff7;
  --blue: #087bd2;
  --green: #087e5a;
  --red: #c83250;
  --text: #18283a;
  --muted: #526a82;
  --line: #c5d3e1;
  --shadow: 0 8px 22px #213b541c;
}

html[data-app-theme="light"] body {
  color: var(--text);
  background: radial-gradient(ellipse at 50% -25%, #e1effc 0, transparent 55%), var(--bg);
}

html[data-app-theme="light"] .card,
html[data-app-theme="light"] .notifications-panel,
html[data-app-theme="light"] .risk-calculator,
html[data-app-theme="light"] .settings-pane {
  color: var(--text);
  background: linear-gradient(145deg, #ffffff, #edf3f9);
  border-color: var(--line);
}

html[data-app-theme="light"] .bottom-nav {
  background: #f7faffed;
  border-color: var(--line);
}

html[data-app-theme="light"] .metric,
html[data-app-theme="light"] .provider-line,
html[data-app-theme="light"] .report-cell,
html[data-app-theme="light"] .price-cell,
html[data-app-theme="light"] .quick-button,
html[data-app-theme="light"] .feature-nav button,
html[data-app-theme="light"] .filter-chip,
html[data-app-theme="light"] .tab-chip,
html[data-app-theme="light"] .settings-row select,
html[data-app-theme="light"] .settings-row input,
html[data-app-theme="light"] .risk-form-grid input,
html[data-app-theme="light"] .search,
html[data-app-theme="light"] .market-search-result,
html[data-app-theme="light"] .notification-item,
html[data-app-theme="light"] .monitor-event,
html[data-app-theme="light"] .forex-watch-row,
html[data-app-theme="light"] .compare-panel {
  color: var(--text);
  background: #eaf1f8;
  border-color: var(--line);
}

html[data-app-theme="light"] .state-pill,
html[data-app-theme="light"] .direction,
html[data-app-theme="light"] .tag {
  background: #e5edf5;
  color: #435b73;
}

html[data-app-theme="light"] .state-pill.online,
html[data-app-theme="light"] .direction.long {
  background: #d9f3e9;
  color: #087e5a;
}

html[data-app-theme="light"] .state-pill.error,
html[data-app-theme="light"] .direction.short {
  background: #f9e1e7;
  color: #b72d49;
}

html[data-app-theme="light"] .chart-host,
html[data-app-theme="light"] .chart {
  background: #f7faff;
  border-color: var(--line);
}

html[data-app-theme="light"] .bottom-nav button {
  color: #526a82;
}

html[data-app-theme="light"] .bottom-nav button.active {
  color: var(--blue);
}
