/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* Matches .ocean-bg__base so overscroll / edges never flash wrong color */
  background: #0a1628;
  color: #e3f2fd;
  height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  /* Scroll lives in #content; avoids body + inner scroll fighting */
  overflow-y: hidden;
}
input, button, select, textarea { font-family: inherit; font-size: inherit; }

/* Marine UI tokens — muted blues / teals / oxides (same roles, less “bootstrap bright”) */
:root {
  --m-primary: #3f6283;
  --m-primary-mid: #4d7390;
  --m-success: #346b5f;
  --m-success-deep: #2d5a52;
  --m-danger: #6b4245;
  --m-danger-deep: #5a383b;
  --m-warning: #6e5a38;
  --m-on-accent: #e9f1f7;
  --m-accent-text: #9bb4c8;
  --m-accent-text-dim: #89a7bd;
  --m-focus: #567d96;
  --m-ok: #6bb39e;
  --m-err: #c9a0a3;
  --m-err-soft: #b89396;
  --m-border-primary: rgba(110, 160, 195, 0.32);
  --m-border-success: rgba(95, 165, 145, 0.32);
  --m-border-danger: rgba(185, 120, 125, 0.38);
  --m-border-warning: rgba(190, 160, 105, 0.35);
  --m-glow-primary: rgba(80, 130, 170, 0.22);
}

/* App root stacks above fixed ocean (body > .ocean-bg + .app-root) */
.app-root {
  position: relative;
  z-index: 1;
  /* dvh: stable flex height for #content scroll (avoids % height collapse on mobile) */
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Ocean backdrop (viewport-fixed; never scrolls with #content) ===== */
.ocean-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  /* Keep animated backdrop off the scrolling content’s layer work where possible */
  isolation: isolate;
}

/* Deep water base — teal / navy / abyss (static anchor) */
.ocean-bg__base {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      168deg,
      #071018 0%,
      #0a1c2e 18%,
      #0c2838 36%,
      #0a3642 52%,
      #083a3a 68%,
      #062830 84%,
      #051218 100%
    ),
    radial-gradient(ellipse 95% 55% at 50% -5%, rgba(55, 140, 195, 0.28) 0%, transparent 48%),
    radial-gradient(ellipse 70% 45% at 95% 75%, rgba(25, 110, 95, 0.22) 0%, transparent 46%),
    radial-gradient(ellipse 60% 40% at 5% 60%, rgba(30, 80, 120, 0.2) 0%, transparent 44%);
}

/*
 * Conic orbits: full 360° rotation = seamless loop (no tile seam).
 * Counter-rotating layer is larger, softer, slower — reads as depth.
 * Radial mask + light blur softens the hub so bands don’t read as one hard pivot.
 */
.ocean-bg__orbit {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 200vmax;
  height: 200vmax;
  margin-left: -100vmax;
  margin-top: -100vmax;
  pointer-events: none;
  opacity: 0.4;
  /* Slight blur smears the conic meet; mask feathers the center so base shows through */
  filter: blur(1.25px);
  -webkit-mask-image: radial-gradient(
    ellipse 82% 78% at 50% 46%,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0.65) 24%,
    rgba(0, 0, 0, 0.95) 52%,
    #000 100%
  );
  mask-image: radial-gradient(
    ellipse 82% 78% at 50% 46%,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0.65) 24%,
    rgba(0, 0, 0, 0.95) 52%,
    #000 100%
  );
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  background: conic-gradient(
    from 0deg at 50% 48%,
    transparent 0deg,
    rgba(45, 110, 150, 0.35) 55deg,
    transparent 95deg,
    rgba(40, 95, 105, 0.28) 155deg,
    transparent 195deg,
    rgba(55, 145, 165, 0.3) 260deg,
    transparent 310deg,
    transparent 360deg
  );
  animation: ocean-orbit-spin 100s linear infinite;
}
.ocean-bg__orbit--counter {
  top: 52%;
  width: 265vmax;
  height: 265vmax;
  margin-left: -132.5vmax;
  margin-top: -132.5vmax;
  opacity: 0.26;
  filter: blur(1.75px);
  -webkit-mask-image: radial-gradient(
    ellipse 88% 84% at 48% 52%,
    rgba(0, 0, 0, 0.15) 0%,
    rgba(0, 0, 0, 0.55) 30%,
    rgba(0, 0, 0, 0.92) 58%,
    #000 100%
  );
  mask-image: radial-gradient(
    ellipse 88% 84% at 48% 52%,
    rgba(0, 0, 0, 0.15) 0%,
    rgba(0, 0, 0, 0.55) 30%,
    rgba(0, 0, 0, 0.92) 58%,
    #000 100%
  );
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  background: conic-gradient(
    from 140deg at 52% 50%,
    transparent 0deg,
    rgba(65, 125, 140, 0.32) 70deg,
    transparent 120deg,
    rgba(35, 80, 110, 0.28) 200deg,
    transparent 250deg,
    rgba(50, 120, 95, 0.26) 320deg,
    transparent 360deg
  );
  animation: ocean-orbit-spin 148s linear infinite reverse;
}
@keyframes ocean-orbit-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Slow shifting color sheets — only transform + opacity (compositor-friendly) */
.ocean-bg__swell {
  position: absolute;
  width: 140%;
  height: 140%;
  left: -20%;
  top: -20%;
  pointer-events: none;
}
.ocean-bg__swell--1 {
  background: radial-gradient(ellipse 50% 42% at 28% 32%, rgba(100, 200, 255, 0.55) 0%, rgba(40, 140, 200, 0.15) 38%, transparent 65%);
  /* linear + looping keyframes: ease-in-out on 20s+ spends most time barely moving */
  /* ease-in-out: velocity ~0 at loop join (0% = 100%) → no subtle hitch */
  animation: ocean-swell-1 11s ease-in-out infinite;
}
.ocean-bg__swell--2 {
  background: radial-gradient(ellipse 48% 40% at 72% 48%, rgba(45, 212, 191, 0.45) 0%, rgba(20, 120, 110, 0.12) 40%, transparent 62%);
  animation: ocean-swell-2 14s ease-in-out infinite;
  animation-delay: -3.5s;
}
.ocean-bg__swell--3 {
  background:
    radial-gradient(ellipse 55% 38% at 50% 88%, rgba(56, 189, 248, 0.4) 0%, rgba(15, 80, 130, 0.1) 42%, transparent 68%),
    radial-gradient(ellipse 40% 50% at 12% 78%, rgba(34, 197, 158, 0.32) 0%, transparent 64%);
  animation: ocean-swell-3 9s ease-in-out infinite;
  animation-delay: -2s;
}

@keyframes ocean-swell-1 {
  0%, 100% { transform: translate(0%, 0%) scale(1);     opacity: 0.28; }
  50%      { transform: translate(14%, -11%) scale(1.14); opacity: 0.92; }
}
@keyframes ocean-swell-2 {
  0%, 100% { transform: translate(0%, 0%) scale(1.06);   opacity: 0.22; }
  50%      { transform: translate(-16%, 9%) scale(1);    opacity: 0.88; }
}
@keyframes ocean-swell-3 {
  0%, 100% { transform: translate(0%, 0%) scale(1.1);    opacity: 0.24; }
  50%      { transform: translate(11%, 14%) scale(1);    opacity: 0.9; }
}

/* Soft caustic shimmer on top of swells */
.ocean-bg__wash {
  position: absolute;
  inset: -40%;
  width: 180%;
  height: 180%;
  left: -40%;
  top: -40%;
  background:
    radial-gradient(ellipse 80% 60% at 20% 85%, rgba(74, 144, 226, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 70%, rgba(46, 196, 182, 0.09) 0%, transparent 50%),
    radial-gradient(ellipse 60% 45% at 50% 100%, rgba(30, 58, 95, 0.35) 0%, transparent 60%);
  animation: ocean-wash-drift 8s ease-in-out infinite;
}
.ocean-bg__bubbles {
  position: absolute;
  inset: 0;
}
/* Soft glass bubbles — visible but blended with deep-water gradient */
.ocean-bubble {
  position: absolute;
  bottom: -5vh;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.35) 0%, rgba(200, 230, 245, 0.08) 14%, transparent 40%),
    radial-gradient(circle at 70% 72%, rgba(60, 130, 175, 0.28) 0%, transparent 54%),
    linear-gradient(155deg, rgba(140, 190, 220, 0.18) 0%, rgba(50, 100, 140, 0.14) 50%, rgba(25, 70, 100, 0.22) 100%);
  border: 1px solid rgba(120, 175, 205, 0.28);
  box-shadow:
    inset -1px -3px 4px rgba(8, 35, 55, 0.35),
    inset 2px 2px 3px rgba(255, 255, 255, 0.08),
    0 0 4px rgba(80, 140, 180, 0.18);
  animation: ocean-bubble-rise var(--t) linear infinite;
  animation-delay: var(--d);
}
.ocean-bubble::after {
  content: '';
  position: absolute;
  top: 18%;
  right: 20%;
  width: 28%;
  height: 20%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 255, 255, 0.45) 0%, transparent 78%);
  opacity: 0.5;
  pointer-events: none;
}
@keyframes ocean-wash-drift {
  0%, 100% { transform: translate(0, 0) rotate(0deg);   opacity: 0.42; }
  50%      { transform: translate(6%, -4%) rotate(3deg); opacity: 0.95; }
}
@keyframes ocean-bubble-rise {
  0% {
    transform: translateY(0) translateX(0) scale(1);
    opacity: 0;
  }
  12% { opacity: 0.48; }
  88% { opacity: 0.36; }
  100% {
    transform: translateY(-115vh) translateX(14px) scale(0.32);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .ocean-bg__orbit,
  .ocean-bg__wash,
  .ocean-bg__swell--1,
  .ocean-bg__swell--2,
  .ocean-bg__swell--3 {
    animation: none !important;
    transform: none;
    opacity: 0.5;
  }
  .ocean-bg__orbit,
  .ocean-bg__orbit--counter {
    opacity: 0;
  }
  .ocean-bg__bubbles {
    display: none;
  }
}

/* ===== Screens ===== */
.screen {
  display: none;
  position: relative;
  z-index: 1;
}
.screen.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* ===== Login ===== */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.login-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-box h1 {
  font-size: 2rem;
  color: var(--m-accent-text);
  margin-bottom: 8px;
}
.login-box p {
  color: #8899aa;
  margin-bottom: 20px;
}
.login-box input {
  width: 100%;
  padding: 14px;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  background: #112233;
  color: #e3f2fd;
  margin-bottom: 14px;
  outline: none;
}
.login-box input:focus { border-color: var(--m-focus); }
.login-box button {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--m-border-success);
  border-radius: 10px;
  background: linear-gradient(145deg, var(--m-success) 0%, var(--m-success-deep) 100%);
  color: var(--m-on-accent);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.login-box button:active { opacity: .85; }
.error-msg { color: var(--m-err); margin-top: 12px; font-size: .85rem; min-height: 1.2em; }

/* ===== App Shell ===== */
#main-shell {
  /* Height comes from .app-root flex chain (100dvh); clip so #content is the scroller */
  min-height: 0;
  overflow: hidden;
}
#main-shell.screen.active {
  flex: 1 1 auto;
  min-height: 0;
}
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  /* Opaque bar — avoid backdrop-filter (heavy repaint while #content scrolls) */
  background: #0d1b2a;
  border-bottom: 1px solid #1e3a5f;
}
.header-title { font-weight: 700; font-size: 1.15rem; color: var(--m-accent-text); }
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.connected { background: var(--m-success); }
.dot.disconnected { background: var(--m-danger); }

#content {
  flex: 1 1 auto;
  /* Critical: flex default min-height:auto prevents shrinking → janky nested scroll */
  min-height: 0;
  /* Clear fixed #bottom-tabs — icon wrapper 62px + label ~9px + 3px bottom pad ≈ 78px */
  padding: 12px 14px 80px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ===== Bottom Tabs ===== */
#bottom-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  background: #0a1628;
  border-top: 1px solid #1e3a5f;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#bottom-tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  flex: 0 0 74px;
  min-width: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 2px 3px;
  border: none;
  background: transparent;
  color: #5a7a9a;
  font-size: .7rem;
  cursor: pointer;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  scroll-snap-align: center;
}
.tab.active { color: var(--m-accent-text-dim); }
.tab-icon { font-size: 1.2rem; }
.tab-icon--png {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 62px;
  line-height: 0;
  overflow: visible;
}
.tab-icon-img {
  display: block;
  width: 62px;
  height: 62px;
  object-fit: contain;
  flex-shrink: 0;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}
/* Trending art reads smaller — render at ~115% but within the same-height wrapper so labels align */
.tab-icon-img--trending {
  width: 71px;
  height: 71px;
}
.tab:not(.active) .tab-icon-img {
  opacity: 0.58;
}
.tab-label {
  font-weight: 600;
  font-size: .65rem;
  line-height: 1;
}

.mini-field {
  flex: 1;
  min-width: 86px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #6b8aaa;
  font-size: .72rem;
}

.optuna-setting-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  color: #d6e8ff;
  font-size: .82rem;
}
.optuna-setting-check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--m-primary);
}
.optuna-setting-check span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.optuna-setting-check small {
  color: #6b8aaa;
  font-size: .72rem;
}

.optuna-log-window {
  min-height: 260px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #07111f;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: 10px;
  color: #b8d7ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
  line-height: 1.35;
}

.optuna-status-panel {
  margin-top: 10px;
  padding: 10px;
  background: #07111f;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  color: #b8d7ff;
  font-size: .82rem;
  line-height: 1.5;
}

.optuna-param-picker,
.optuna-results-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  /* Let wide children (the trial table, action bars) shrink/scroll internally
     instead of stretching this grid past the viewport. */
  min-width: 0;
}

.optuna-param-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  background: #07111f;
  border: 1px solid #1e3a5f;
  border-radius: 9px;
}

.optuna-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.optuna-group-btn {
  border-color: rgba(126, 211, 255, .45);
}

.optuna-param-check strong em {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  color: #d6e8ff;
  font-size: .62rem;
  font-style: normal;
  font-weight: 700;
  vertical-align: middle;
}

.optuna-param-group-blue { border-left: 4px solid #4aa3ff; }
.optuna-param-group-purple { border-left: 4px solid #a78bfa; }
.optuna-param-group-green { border-left: 4px solid #4ade80; }
.optuna-param-group-orange { border-left: 4px solid #fb923c; }
.optuna-param-group-red { border-left: 4px solid #f87171; }
.optuna-param-group-teal { border-left: 4px solid #2dd4bf; }
.optuna-param-group-neutral { border-left: 4px solid #6b8aaa; }

.optuna-param-check input {
  margin-top: 3px;
}

.optuna-param-check span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: #b8d7ff;
  font-size: .8rem;
}

.optuna-param-check small {
  color: #6b8aaa;
  font-size: .72rem;
}

/* Uses the doubled .token-actions.token-actions-bar class to outweigh the base
   token-card rule (same-specificity, later in file) that pins these bars to
   flex-wrap:nowrap. Many actions (Use Seed, Apply, Promote, Save, Skip, Delete)
   must wrap onto multiple rows on narrow/vertical screens instead of forcing a
   wide row that runs off the viewport edge. */
.optuna-trial-card .token-actions.token-actions-bar {
  margin-top: 8px;
  flex-wrap: wrap;
}

.optuna-trial-card .token-actions-bar .btn {
  flex: 1 1 90px;
  min-width: 90px;
}

.optuna-trial-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0;
}

.optuna-trial-metrics span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 8px;
  border-radius: 8px;
  background: #07111f;
  border: 1px solid #1e3a5f;
}

.optuna-trial-metrics label {
  color: #6b8aaa;
  font-size: .68rem;
}

.optuna-trial-metrics strong {
  color: #e3f2fd;
  font-size: .8rem;
}

.optuna-trial-risk {
  margin: 8px 0;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  background: rgba(7, 17, 31, .65);
  overflow: hidden;
}

.optuna-trial-risk > summary {
  cursor: pointer;
  padding: 9px 10px;
  color: #e3f2fd;
  font-size: .82rem;
  font-weight: 700;
}

.optuna-param-group {
  padding: 8px 10px 10px;
  border-top: 1px solid rgba(30, 58, 95, .7);
}

.optuna-param-group-title {
  margin-bottom: 6px;
  color: #7ed3ff;
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.optuna-trial-param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.optuna-trial-param-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: #07111f;
  border: 1px solid rgba(30, 58, 95, .8);
}

.optuna-trial-param-row label {
  min-width: 0;
  color: #8eaed0;
  font-size: .72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.optuna-trial-param-row strong {
  color: #e3f2fd;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .74rem;
  white-space: nowrap;
}

@media (max-width: 560px) {
  .optuna-trial-param-grid {
    grid-template-columns: 1fr;
  }
}

.optuna-trial-browser {
  display: grid;
  gap: 10px;
  min-width: 0;
}

/* Grid items default to min-width:auto, which lets a wide table or button row
   expand the whole browser. Forcing 0 keeps every section within the viewport
   and lets the table scroll inside its own wrapper. */
.optuna-trial-browser > * {
  min-width: 0;
}

.optuna-trial-browser-tools {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(130px, 170px) minmax(180px, 1.6fr);
  gap: 8px;
  align-items: center;
}

.optuna-trial-browser-tools > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: #e3f2fd;
}

.optuna-trial-browser-tools small,
.optuna-trial-detail-head small,
.optuna-trial-table td small {
  color: #6b8aaa;
  font-size: .72rem;
}

.optuna-trial-table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  background: #07111f;
}

.optuna-trial-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  color: #b8d7ff;
  font-size: .78rem;
}

.optuna-trial-table th,
.optuna-trial-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(30, 58, 95, .72);
  text-align: left;
  white-space: nowrap;
}

.optuna-trial-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #081827;
}

.optuna-trial-table th button {
  border: 0;
  padding: 0;
  background: transparent;
  color: #8fbdf2;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.optuna-trial-table th button.active {
  color: #e3f2fd;
}

.optuna-trial-table-row {
  cursor: pointer;
}

.optuna-trial-table-row:hover,
.optuna-trial-table-row.selected {
  background: rgba(126, 189, 255, .10);
}

.optuna-trial-table td:first-child {
  white-space: normal;
  min-width: 140px;
}

.optuna-trial-table td:first-child strong,
.optuna-trial-table td:first-child small {
  display: block;
}

.optuna-trial-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 0;
  color: #e3f2fd;
}

.optuna-trial-detail .optuna-trial-card {
  margin-top: 0;
}

@media (max-width: 720px) {
  .optuna-trial-browser-tools {
    grid-template-columns: 1fr;
  }
}

/* ===== Optuna submenu navigation ===== */
.optuna-submenu-tabs {
  display: flex;
  gap: 4px;
  margin: -16px -16px 14px;
  padding: 10px 16px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(8, 24, 39, .96);
  border-bottom: 1px solid rgba(61, 119, 166, .38);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .18);
}

.optuna-submenu-tabs::-webkit-scrollbar {
  display: none;
}

.optuna-submenu-tab {
  position: relative;
  flex: 1 0 auto;
  min-width: max-content;
  border: 0;
  border-radius: 9px;
  padding: 10px 13px;
  background: transparent;
  color: #7898b9;
  font: inherit;
  font-size: .78rem;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}

.optuna-submenu-tab:hover {
  color: #c7e8ff;
  background: rgba(72, 137, 190, .10);
}

.optuna-submenu-tab.active {
  color: #d9f2ff;
  background: rgba(42, 126, 181, .20);
}

.optuna-submenu-tab.active::after {
  content: '';
  position: absolute;
  right: 12px;
  bottom: 3px;
  left: 12px;
  height: 2px;
  border-radius: 999px;
  background: #5fc3f3;
  box-shadow: 0 0 10px rgba(95, 195, 243, .55);
}

.optuna-submenu-tab:focus-visible {
  outline: 2px solid var(--m-focus);
  outline-offset: -2px;
}

.optuna-submenu-panel[hidden] {
  display: none !important;
}

.optuna-submenu-panel {
  min-width: 0;
}

.optuna-empty-submenu {
  min-height: 220px;
}

.optuna-section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.optuna-section-heading .section-title {
  margin-bottom: 0;
}

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

.optuna-setup-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(41, 86, 128, .72);
  border-radius: 11px;
  background: rgba(7, 17, 31, .66);
}

.optuna-setup-card-wide {
  grid-column: 1 / -1;
}

.optuna-setup-card-title {
  margin-bottom: 9px;
  color: #c8e6ff;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.optuna-setup-card .input-row:first-of-type {
  margin-top: 0;
}

.optuna-baseline-label {
  margin-top: 0;
}

.optuna-setup-card .optuna-actions {
  margin-top: 12px;
}

@media (max-width: 700px) {
  .optuna-setup-grid {
    grid-template-columns: 1fr;
  }

  .optuna-setup-card-wide {
    grid-column: auto;
  }
}

/* ===== Iterative follow-up contests ===== */
.optuna-followup-slot-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 16px;
}

.optuna-followup-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid rgba(51, 104, 149, .72);
  border-radius: 9px;
  background: rgba(7, 18, 31, .78);
  color: #bcd7eb;
  text-align: left;
}

button.optuna-followup-slot {
  width: 100%;
  border-style: dashed;
  color: #7898b9;
  cursor: pointer;
}

button.optuna-followup-slot:hover {
  border-color: #54b6ec;
  background: rgba(31, 100, 145, .13);
  color: #d4efff;
}

.optuna-followup-slot-body {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.optuna-followup-slot-body strong,
.optuna-followup-slot-body small,
.optuna-followup-slot-body span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.optuna-followup-slot-body strong {
  flex: 0 1 auto;
  color: #e1f4ff;
}

.optuna-followup-slot-body small {
  flex: 1 1 auto;
  color: #7898b9;
}

.optuna-followup-slot-body span {
  flex: 0 0 auto;
  color: #b8d7ef;
}

.optuna-followup-launch-row,
.optuna-followup-navigator,
.optuna-followup-result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.optuna-followup-slot-number {
  flex: 0 0 58px;
  color: #65c7f5;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.optuna-followup-slot-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.optuna-followup-slot-actions .btn {
  min-height: 0;
  padding: 4px 7px;
  font-size: .67rem;
}

.optuna-followup-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid rgba(41, 86, 128, .62);
  border-radius: 12px;
  background: rgba(7, 17, 31, .56);
}

.optuna-followup-settings .mini-field {
  min-width: 0;
}

.optuna-followup-settings .input {
  padding: 8px 10px;
}

.optuna-followup-carry {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
}

.optuna-followup-carry .optuna-switch-label {
  color: #6b8aaa;
  font-size: .72rem;
  font-weight: 400;
}

.optuna-followup-carry .optuna-mode-switch {
  min-height: 38px;
}

.optuna-followup-launch-row {
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 12px;
}

.optuna-followup-launch-row > span {
  margin-right: auto;
  color: #7898b9;
  font-size: .78rem;
}

.optuna-followup-navigator {
  margin: 10px 0 12px;
}

.optuna-followup-navigator .input {
  min-width: 0;
  flex: 1;
}

.optuna-followup-result-meta {
  flex-wrap: wrap;
  margin-bottom: 10px;
  color: #7898b9;
}

.optuna-followup-result-meta strong {
  color: #d7efff;
}

/* Contest results: two trial tables (slot averages, individual runs), each with
   its own detail card, reusing the shared .optuna-trial-table theme. */
.optuna-followup-table-block {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.optuna-followup-trial-table {
  min-width: 560px;
}

.optuna-followup-run-group td {
  background: rgba(31, 67, 96, .38);
  color: #8fbdf2;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.optuna-followup-detail-card {
  margin: 0;
}

.optuna-followup-detail-card h4 {
  margin: 10px 0 6px;
  color: #7898b9;
  font-size: .7rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.optuna-followup-detail-card .muted {
  color: #6b8aaa;
  font-size: .75rem;
}

.optuna-followup-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 7px;
  padding: 8px 12px 12px;
}

.optuna-followup-metric-grid > span {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  background: rgba(31, 67, 96, .27);
}

.optuna-followup-metric-grid label,
.optuna-followup-metric-grid strong {
  display: block;
}

.optuna-followup-metric-grid label {
  overflow: hidden;
  color: #6f91ad;
  font-size: .65rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.optuna-followup-metric-grid strong {
  margin-top: 3px;
  color: #d6edfa;
  font-size: .78rem;
}

.optuna-followup-metric-grid small {
  display: block;
  margin-top: 2px;
  color: #6f91ad;
  font-size: .62rem;
}

.optuna-followup-detail-card .optuna-followup-metric-grid {
  padding: 4px 0 0;
}

@media (min-width: 720px) {
  .optuna-followup-settings {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .optuna-followup-slot,
  .optuna-followup-slot-body {
    flex-wrap: wrap;
  }

  .optuna-followup-navigator {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .optuna-followup-navigator .input {
    flex-basis: 100%;
  }
}

/* ===== Optuna compact summary bar ===== */
.optuna-summary {
  margin-bottom: 14px;
}

.optuna-summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.optuna-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 22px;
  background: #07111f;
  border: 1px solid #1e3a5f;
  color: #b8d7ff;
  font-size: .86rem;
  line-height: 1.2;
}

.optuna-pill label {
  color: #6b8aaa;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.optuna-pill strong {
  color: #e3f2fd;
  font-weight: 700;
}

.optuna-pill-state {
  font-weight: 700;
  text-transform: uppercase;
  font-size: .78rem;
  letter-spacing: .04em;
  background: #1a3048;
  color: #8ecae6;
}

.optuna-pill-state.optuna-pill-on {
  background: rgba(46, 160, 102, 0.18);
  border-color: rgba(46, 160, 102, 0.45);
  color: var(--m-ok);
}

.optuna-summary-meta {
  font-size: .72rem;
  color: #6b8aaa;
  word-break: break-word;
}

.optuna-trial-highlight {
  border-color: var(--m-focus);
  box-shadow: 0 0 0 2px rgba(126, 189, 255, .24);
}

/* ===== Optuna collapsible sections ===== */
.optuna-details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.02rem;
  color: #8ecae6;
  padding: 4px 0;
  user-select: none;
}

.optuna-details > summary::-webkit-details-marker { display: none; }
.optuna-details > summary::marker { content: ''; }

.optuna-details > summary .optuna-summary-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.optuna-details > summary .optuna-summary-label::before {
  content: '\25B8';
  color: #6b8aaa;
  font-size: .9rem;
  transition: transform .15s ease;
  display: inline-block;
}

.optuna-details[open] > summary .optuna-summary-label::before {
  transform: rotate(90deg);
}

.optuna-details > *:not(summary) {
  margin-top: 10px;
}

.optuna-counter {
  color: #6b8aaa;
  font-size: .72rem;
  font-weight: 500;
  text-transform: lowercase;
}

/* ===== Parameter Insights (Tier 2) ===== */
.optuna-insights-intro {
  font-size: .78rem;
  line-height: 1.45;
  color: var(--m-accent-text);
  background: rgba(80, 130, 170, 0.08);
  border: 1px solid var(--m-border-primary);
  border-radius: 8px;
  padding: 8px 10px;
}
.optuna-insights-intro .btn { margin-top: 6px; }
.optuna-insights-block { margin-top: 12px; }
.optuna-insights-subtitle {
  font-size: .82rem;
  font-weight: 700;
  color: var(--m-accent-text);
  margin-bottom: 8px;
}
.optuna-insights-subtitle small { color: #6b8aaa; font-weight: 500; }

.optuna-importance-list { display: flex; flex-direction: column; gap: 5px; }
.optuna-importance-row {
  display: grid;
  grid-template-columns: minmax(110px, 38%) 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: .76rem;
}
.optuna-importance-label {
  color: #cfe0ef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.optuna-importance-track {
  position: relative;
  height: 9px;
  background: rgba(110, 160, 195, 0.14);
  border-radius: 5px;
  overflow: hidden;
}
.optuna-importance-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #4d7390, #6bb39e);
  border-radius: 5px;
}
.optuna-importance-val {
  color: var(--m-ok);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

.optuna-slice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.optuna-slice-card {
  background: rgba(10, 22, 40, 0.55);
  border: 1px solid var(--m-border-primary);
  border-radius: 8px;
  padding: 8px;
}
.optuna-slice-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.optuna-slice-head strong {
  font-size: .76rem;
  color: #cfe0ef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.optuna-slice-imp { font-size: .72rem; color: var(--m-ok); font-variant-numeric: tabular-nums; }
.optuna-slice-svg {
  display: block;
  width: 100%;
  height: auto;
  background: rgba(110, 160, 195, 0.06);
  border-radius: 6px;
}
.optuna-slice-band { fill: rgba(107, 179, 158, 0.16); }
.optuna-slice-zero { stroke: rgba(155, 180, 200, 0.35); stroke-width: 1; stroke-dasharray: 3 3; }
.optuna-slice-dot { fill: rgba(155, 180, 200, 0.45); }
.optuna-slice-dot.good { fill: var(--m-ok); }
.optuna-slice-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  font-size: .68rem;
  color: #6b8aaa;
  font-variant-numeric: tabular-nums;
}
.optuna-slice-best { color: var(--m-ok); font-weight: 600; text-align: center; }

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

.optuna-grid-3,
.optuna-grid-2 {
  gap: 6px;
  flex-wrap: wrap;
}

.optuna-grid-3 .mini-field {
  flex: 1 1 86px;
}

.optuna-grid-2 .mini-field {
  flex: 1 1 120px;
}

/* Full-width toggle rows: label on the left, switch on the right, so the
   Explore/Exploit and Off/On switches never run off a narrow mobile screen. */
.optuna-switch-row {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.optuna-switch-label {
  color: #a9c6e8;
  font-size: .8rem;
  font-weight: 700;
}

.optuna-mode-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #a9c6e8;
  font-size: .78rem;
  font-weight: 700;
}

.optuna-mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.optuna-mode-slider {
  position: relative;
  width: 46px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #123456;
  border: 1px solid rgba(126, 211, 255, .35);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2);
}

.optuna-mode-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #7ed3ff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  transition: transform .16s ease, background .16s ease;
}

.optuna-mode-switch input:checked + .optuna-mode-slider {
  background: #401a72;
  border-color: rgba(244, 114, 182, .55);
}

.optuna-mode-switch input:checked + .optuna-mode-slider::after {
  transform: translateX(22px);
  background: #f472b6;
}

.optuna-inline-msg:empty {
  display: none;
}

.optuna-inline-msg {
  margin-top: 8px;
}

.optuna-actions .btn {
  flex: 1;
}

.optuna-seed-row {
  align-items: center;
  flex-wrap: wrap;
}

.optuna-seed-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid #245c8f;
  border-radius: 999px;
  background: rgba(20, 78, 122, .35);
  color: #bfe7ff;
  font-size: .82rem;
  font-weight: 700;
}

.optuna-study-navigator {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  background: #07111f;
}

.optuna-study-selector-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.optuna-study-selector-row .input {
  flex: 1;
  min-width: 140px;
}

.optuna-followup-btn {
  flex-shrink: 0;
}

.optuna-create-study-row .btn {
  flex-shrink: 0;
}

.optuna-study-navigator-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.optuna-study-navigator-head span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.optuna-study-navigator-head strong {
  color: #e3f2fd;
}

.optuna-study-navigator-head small {
  color: #6b8aaa;
  font-size: .72rem;
  line-height: 1.35;
}

.optuna-study-navigator-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ===== Cards & Sections ===== */
.card {
  background: #112233;
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.card-title { font-weight: 700; font-size: .95rem; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 10px;
  color: #8ecae6;
}
.rw-section-toggle {
  background: none;
  border: 1px solid rgba(142, 202, 230, 0.3);
  border-radius: 4px;
  color: #8ecae6;
  font-size: 0.7rem;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.rw-section-toggle:hover,
.rw-section-toggle:active {
  opacity: 1;
}
.section-hint {
  font-size: .72rem;
  color: #6b8aaa;
  margin: -6px 0 6px;
}

.trading-hub-wallet-form {
  display: grid;
  gap: 12px;
  margin: 10px 0 12px;
}

.trading-hub-field {
  display: grid;
  gap: 6px;
  color: #8fb0d0;
  font-size: .76rem;
  line-height: 1.25;
}

.trading-hub-field .input {
  min-height: 42px;
}

.trading-hub-section-hint {
  margin: 0 0 12px;
  line-height: 1.45;
}

.swap-send-token-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
}

.swap-send-token-select-row .input {
  width: 100%;
  min-width: 0;
}

.swap-send-selected-token {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(143, 176, 208, 0.28);
  border-radius: 12px;
  background: rgba(8, 16, 26, 0.48);
}

.swap-send-selected-token .swap-send-token-thumb,
.swap-send-selected-token .swap-send-token-thumb-ph {
  width: 42px;
  height: 42px;
}

.swap-send-offer-balance {
  color: #8fb0d0;
  font-size: .8rem;
  line-height: 1.3;
}

.swap-send-offer-balance strong {
  color: #eaf3fb;
}

.swap-send-flip-row {
  display: flex;
  justify-content: center;
  margin: -2px 0 2px;
}

.swap-send-flip {
  min-width: 44px;
}

.swap-send-percent-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 2px 0 8px;
}

.swap-send-pct {
  min-width: 0;
  padding-inline: 4px;
}

.swap-send-pct.is-active {
  border-color: #4bd07f;
  background: rgba(75, 208, 127, 0.14);
  color: #eafff2;
}

.swap-send-amount-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.swap-send-amount-row .input {
  flex: 1 1 auto;
  min-width: 0;
}

.swap-send-swap-msg {
  margin-top: 8px;
}

.btn-not-ready {
  opacity: 0.55;
  filter: grayscale(0.4);
}

.trading-hub-jupiter-raw-output {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid rgba(143, 176, 208, 0.22);
  border-radius: 10px;
  background: rgba(8, 16, 26, 0.6);
  color: #bcd2e6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.trading-hub-backup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.trading-hub-backup-actions .btn {
  min-width: 0;
  justify-content: center;
}

.trading-hub-history-window {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow-y: auto;
  padding: 2px 3px 8px 0;
  overscroll-behavior: contain;
}

/* Trade-history table (styled after the Optuna trial table, which supplies the
   shared .optuna-trial-table / .optuna-trial-table-wrap base). */
.trading-hub-trade-wrap {
  max-height: 420px;
}

.trading-hub-trade-table {
  /* Fixed layout so the persisted <col> widths are authoritative and columns
     can be dragged to resize. The table's total width is set inline. */
  table-layout: fixed;
}

.trading-hub-trade-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.trading-hub-trade-table th.th-resizable {
  overflow: hidden;
}

.trading-hub-trade-table th .th-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 2;
}

.trading-hub-trade-table th .th-resize:hover {
  background: rgba(126, 189, 255, .4);
}

body.th-col-resizing,
body.th-col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.trading-hub-trade-table-row:hover {
  background: rgba(126, 189, 255, .08);
}

.trading-hub-trade-table .th-trade-time {
  color: #8aa7c3;
  font-size: .72rem;
}

.trading-hub-trade-table .th-trade-token strong {
  color: #e3f2fd;
}

.trading-hub-trade-table .th-trade-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(244, 114, 182, .18);
  color: #f9a8d4;
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  vertical-align: middle;
}

.trading-hub-trade-table .th-trade-sig a {
  color: #7fd0ff;
  text-decoration: none;
}

.trading-hub-trade-table .th-trade-sig a:hover {
  text-decoration: underline;
}

.trading-hub-gate-line {
  margin-top: 8px;
  color: #d7eaff;
  text-align: center;
  font-size: .82rem;
}

.trading-hub-gate-line.warning {
  color: #ffd6a3;
}

.trading-hub-exec-switch-card {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(30, 58, 95, .75);
  border-radius: 12px;
  background: rgba(7, 17, 31, .72);
  width: fit-content;
  max-width: 100%;
}

.trading-hub-exec-switch-card strong {
  color: #e3f2fd;
  font-size: .8rem;
  white-space: nowrap;
}

.trading-hub-exec-switch-card.armed {
  border-color: rgba(244, 114, 182, .45);
  background: rgba(64, 26, 114, .28);
}

.trading-hub-exec-switch {
  flex: 0 0 auto;
}

/* Gym — learning lock (same behavior as desktop: POST /mlbot/lock) */
.gym-dashboard {
  display: grid;
  gap: 12px;
}

.gym-dashboard-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
  align-items: center;
  gap: 12px;
}

.gym-primary-action {
  width: auto;
  min-height: 42px;
  align-self: stretch;
}

.gym-status-grid {
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
}

.gym-train-msg:empty {
  display: none;
}

.gym-train-msg {
  margin-top: 2px;
}

.gym-control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.gym-setting-card {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  background: #07111f;
}

.gym-setting-card-wide {
  grid-column: 1 / -1;
}

.gym-buy-floors-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.gym-buy-floors-grid label {
  display: flex;
  flex-direction: column;
  font-size: .72rem;
  color: #6b8aaa;
  gap: 3px;
}
.gym-buy-floors-grid .input {
  width: 100%;
}

.gym-setting-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.gym-setting-head strong {
  color: #e3f2fd;
  font-size: .9rem;
}

.gym-setting-head span,
.gym-subcontrol > span,
.gym-split-control > span,
.gym-inline-field > span,
.gym-inline-note {
  color: #6b8aaa;
  font-size: .72rem;
}

.gym-inline-note.positive {
  color: #7fb069;
}

.gym-setting-hint {
  margin: 0;
  color: #5a7a9a;
  font-size: .72rem;
  line-height: 1.35;
}

.gym-toggle-row {
  flex-wrap: wrap;
  margin-bottom: 0;
}

.gym-subcontrol {
  display: grid;
  gap: 6px;
}

.gym-split-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.gym-inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.gym-inline-field .input {
  width: 86px;
}

.gym-backup-actions {
  margin-top: 8px;
}

.gym-backup-actions .btn {
  flex: 1 1 130px;
}

.gym-learning-lock-block .btn {
  width: auto;
  min-width: 160px;
}

.gym-learning-lock-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(30, 58, 95, 0.45);
}
.gym-learning-lock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.gym-learning-lock-labelwrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.gym-learning-lock-title {
  font-weight: 700;
  font-size: 0.92rem;
  color: #8ecae6;
}
.gym-learning-lock-frozen {
  font-size: 0.72rem;
  color: var(--m-err-soft);
  font-weight: 600;
}
.gym-lock-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.gym-lock-badge-off {
  background: #1e3a5f;
  color: var(--m-accent-text);
}
.gym-lock-badge-on {
  background: rgba(107, 66, 69, 0.28);
  color: var(--m-err);
  border: 1px solid var(--m-border-danger);
}
.gym-learning-lock-hint {
  margin: 6px 0 10px !important;
  line-height: 1.35;
}

@media (max-width: 760px) {
  .gym-dashboard-head,
  .gym-control-grid {
    grid-template-columns: 1fr;
  }

  .gym-buy-floors-grid {
    grid-template-columns: 1fr;
  }

  .gym-primary-action {
    width: 100%;
  }

  .gym-split-control {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .optuna-study-navigator-head {
    align-items: stretch;
    flex-direction: column;
  }

  .optuna-study-navigator-head small {
    max-width: none;
  }

  .optuna-study-navigator-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .optuna-study-navigator-actions .btn,
  .optuna-followup-btn {
    width: 100%;
  }

  .optuna-study-selector-row {
    align-items: stretch;
    flex-direction: column;
  }

  .optuna-study-selector-row .input {
    min-width: 0;
    width: 100%;
  }

  .gym-backup-actions .btn,
  .gym-learning-lock-block .btn {
    width: 100%;
  }
}

/* ===== Stat Grids ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.stat-box {
  background: #0a1628;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.stat-val {
  font-weight: 700;
  font-size: 1.05rem;
  display: block;
}
.stat-lbl {
  font-size: .72rem;
  color: #6b8aaa;
  margin-top: 2px;
  display: block;
}
.positive { color: var(--m-ok); }
.negative { color: var(--m-err); }

/* ===== Disk usage ===== */
.disk-bar {
  margin-top: 10px;
  height: 10px;
  border-radius: 6px;
  background: #0a1628;
  overflow: hidden;
}
.disk-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--m-primary-mid);
  transition: width .3s ease;
}
.disk-bar-fill.warn { background: #b8934e; }
.disk-bar-fill.danger { background: var(--m-danger); }
.disk-cat-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.disk-cat-row { display: flex; flex-direction: column; gap: 3px; }
.disk-cat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .8rem;
}
.disk-cat-label { color: var(--m-accent-text); }
.disk-cat-size { color: var(--m-accent-text-dim); font-variant-numeric: tabular-nums; }
.disk-cat-bar {
  height: 6px;
  border-radius: 4px;
  background: #0a1628;
  overflow: hidden;
}
.disk-cat-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--m-primary);
}

/* ===== Data Cleaner (corrupt files) ===== */
.cleaner-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.cleaner-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #0a1628;
  font-size: .78rem;
}
.cleaner-file { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cleaner-name { color: var(--m-accent-text); font-variant-numeric: tabular-nums; }
.cleaner-token {
  color: var(--m-accent-text-dim);
  font-size: .7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.cleaner-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.cleaner-size { color: #f0b429; font-variant-numeric: tabular-nums; }
.cleaner-err {
  color: var(--m-accent-text-dim);
  font-size: .68rem;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  transition: opacity .15s, filter .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .82; filter: brightness(1.06); }
a.btn { text-decoration: none; }
.btn-primary {
  background: var(--m-primary);
  color: var(--m-on-accent);
  border-color: var(--m-border-primary);
}
.btn-success {
  background: var(--m-success);
  color: var(--m-on-accent);
  border-color: var(--m-border-success);
}
.btn-danger {
  background: var(--m-danger);
  color: var(--m-on-accent);
  border-color: var(--m-border-danger);
}
.btn-warning {
  background: var(--m-warning);
  color: var(--m-on-accent);
  border-color: var(--m-border-warning);
}
.btn-secondary {
  background: #1a3048;
  color: var(--m-accent-text);
  border-color: #2a4663;
}
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Generic choice modal ===== */
.m-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 12, 24, .72);
  animation: mModalFade .12s ease-out;
}
@keyframes mModalFade { from { opacity: 0; } to { opacity: 1; } }
.m-modal {
  width: min(460px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: #112233;
  border: 1px solid #1e3a5f;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}
.m-modal-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #e3f2fd;
  margin-bottom: 6px;
}
.m-modal-body {
  font-size: .82rem;
  color: var(--m-accent-text);
  margin-bottom: 14px;
}
.m-modal-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.m-modal-choice {
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  padding: 12px 14px;
  white-space: normal;
}
.m-modal-choice-label {
  font-weight: 700;
  font-size: .9rem;
}
.m-modal-choice-detail {
  font-weight: 500;
  font-size: .74rem;
  opacity: .85;
  line-height: 1.35;
}
.m-modal-choice-disabled {
  opacity: .5;
  cursor: not-allowed;
  filter: grayscale(.4);
}
.m-modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ===== Profile image cropper (pan + zoom) ===== */
.th-crop-modal { width: min(340px, 100%); }
/* Exact width/height are set from JS (responsive) so the mask and canvas align. */
.th-crop-stage {
  position: relative;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  background: #0a1628;
}
/* touch-action:none so dragging pans the crop instead of scrolling the page */
.th-crop-canvas { display: block; touch-action: none; cursor: grab; }
.th-crop-canvas:active { cursor: grabbing; }
/* Dims everything outside the circular guide via an outsized spread shadow */
.th-crop-mask {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(4, 12, 24, .62);
  border: 2px solid rgba(226, 232, 240, .55);
  box-sizing: border-box;
  pointer-events: none;
}
.th-crop-zoom { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.th-crop-zoom-label { font-size: .78rem; color: #94a3b8; flex: 0 0 auto; }
.th-crop-range { flex: 1 1 auto; min-width: 0; accent-color: #3b82f6; touch-action: none; }
.th-crop-zoom-val { font-size: .78rem; color: #cbd5e1; flex: 0 0 auto; min-width: 38px; text-align: right; }
.th-crop-actions { justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ===== Inputs ===== */
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #1e3a5f;
  border-radius: 8px;
  background: #0a1628;
  color: #e3f2fd;
  outline: none;
}
.input:focus { border-color: var(--m-focus); }
/* Text the field could not parse, so the value was not committed. */
.input.input-invalid, .input.input-invalid:focus { border-color: #dc2626; background: #2a1215; }
.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.input-row .input { flex: 1; }

/* ===== Status Chips ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  background: #1e3a5f;
  color: #8ecae6;
}
.report-index {
  display: inline-block;
  min-width: 2.4em;
  margin-right: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: .82rem;
  font-weight: 700;
  text-align: center;
  background: #243b57;
  color: #b8d4ec;
}
.chip .chip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.chip-ok .chip-dot { background: var(--m-success); }
.chip-warn .chip-dot { background: #a88a3a; }
.chip-err .chip-dot { background: var(--m-danger); }
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

/* Trending: sort approved list (persists via localStorage trendingApprovedSort) */
.trending-sort-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 14px 0;
}

/* ===== Token Cards ===== */
.token-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 14px;
  position: relative;
}
.token-card-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  min-width: 0;
}
.token-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-width: 0;
}
.token-actions.token-actions-bar {
  display: flex;
  flex-direction: row;
  width: 100%;
  gap: 8px;
  flex-wrap: nowrap;
}
.token-actions-bar .btn {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
  padding: 9px 6px;
  font-size: 0.7rem;
  white-space: nowrap;
}
.token-meta-line {
  display: block;
  word-break: break-all;
}
.token-meta-mcap {
  margin-top: 3px;
  font-weight: 600;
  color: var(--m-accent-text-dim);
}
.token-meta-vol {
  margin-top: 2px;
  font-weight: 600;
  color: #6d9e90;
  font-size: 0.72rem;
}
.token-meta-liq {
  margin-top: 2px;
  font-weight: 600;
  color: #e8c07a;
  font-size: 0.72rem;
}
.token-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}
.token-card-thumb-box {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.token-card-thumb {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--m-primary-mid);
  box-shadow: 0 2px 8px var(--m-glow-primary);
  background: #112233;
}
.token-card-thumb-ph {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  background: linear-gradient(145deg, #1e3a5f 0%, var(--m-primary-mid) 100%);
  border: 2px solid var(--m-primary-mid);
  box-shadow: 0 2px 8px var(--m-glow-primary);
}
.token-rank.token-rank-avatar {
  position: absolute;
  bottom: -3px;
  left: -3px;
  z-index: 2;
  min-width: 1.55rem;
  height: 1.55rem;
  padding: 0 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #0d1b2a;
  background: linear-gradient(145deg, #ffd54f 0%, #ffb300 45%, #ff8f00 100%);
  border: 2px solid rgba(255, 213, 79, 0.95);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(255, 152, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  letter-spacing: -0.02em;
}
.token-info {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}
.token-symbol {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.token-meta {
  font-size: .75rem;
  color: #6b8aaa;
  margin-top: 2px;
}
.token-tag {
  display: inline-block;
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}
.token-tag-manual {
  background: rgba(63, 98, 131, 0.35);
  color: var(--m-accent-text);
  border: 1px solid var(--m-border-primary);
}
.token-tag-scheduled {
  background: rgba(196, 96, 40, 0.28);
  color: #ffb37a;
  border: 1px solid rgba(196, 96, 40, 0.6);
}
.token-tag-read-only {
  background: rgba(127, 29, 29, 0.3);
  color: #fca5a5;
  border: 1px solid rgba(185, 28, 28, 0.65);
}
.token-tag-warming {
  background: rgba(180, 83, 9, 0.25);
  color: #fbbf24;
  border: 1px solid rgba(217, 119, 6, 0.65);
}
.token-tag-tradable {
  background: rgba(6, 95, 70, 0.3);
  color: #6ee7b7;
  border: 1px solid rgba(5, 150, 105, 0.6);
}
.token-price {
  text-align: right;
  font-size: .85rem;
  font-weight: 600;
}
.token-actions {
  display: flex;
  gap: 6px;
}
/* full-width bar replaces cramped side stack */
.token-card .token-actions:not(.token-actions-bar) {
  flex-wrap: wrap;
}

/* ===== Sections ===== */
.section { margin-bottom: 18px; }

/* ===== Loading & Status ===== */
.loading-text {
  text-align: center;
  color: #5a7a9a;
  padding: 32px 0;
}
.status-msg {
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: .85rem;
}
.status-msg.info { background: #1e3a5f33; color: #8ecae6; }
.status-msg.success { background: rgba(52, 107, 95, 0.28); color: var(--m-ok); }
.status-msg.error { background: rgba(107, 66, 69, 0.28); color: var(--m-err); }
.status-msg.warning { background: rgba(120, 95, 40, 0.30); color: #f0c674; }

/* ===== Chart ===== */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 280px;
  margin-bottom: 10px;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ===== Chart Tooltip ===== */
#m-chart-tooltip {
  position: absolute;
  background: rgba(10, 25, 47, .92);
  border: 1px solid var(--m-primary-mid);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: .75rem;
  color: #e0e0e0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
  z-index: 10;
  max-width: 180px;
  line-height: 1.4;
}

/* ===== Report List ===== */
.report-scroll-list {
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.report-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.report-card .report-card-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 58%;
}
.report-card .report-card-actions .btn-sm {
  font-size: 0.72rem;
  padding: 6px 8px;
}
#m-report-viewer {
  background: #0f2a40;
  border-top: 2px solid var(--m-primary-mid);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}

/* ===== Progress Bar ===== */
.progress-bar-wrap {
  height: 8px;
  background: #1e3a5f;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--m-primary) 0%, var(--m-primary-mid) 100%);
  border-radius: 4px;
  transition: width .4s ease;
}
.progress-details {
  display: flex;
  justify-content: space-between;
  font-size: .72rem;
  color: #6b8aaa;
  margin-bottom: 4px;
}

/* ===== Toggle Buttons ===== */
.toggle-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.toggle-btn {
  padding: 6px 14px;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  background: transparent;
  color: #6b8aaa;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
}
.toggle-btn.active {
  background: var(--m-primary);
  color: var(--m-on-accent);
  border-color: var(--m-primary-mid);
}

/* ===== Reward Config Form ===== */
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.config-field label {
  display: block;
  font-size: .72rem;
  color: #6b8aaa;
  margin-bottom: 3px;
}
.config-field input {
  width: 100%;
  padding: 8px;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  background: #0a1628;
  color: #e3f2fd;
  font-size: .85rem;
  outline: none;
}
.config-field input:focus { border-color: var(--m-focus); }

/* ===== Collapsible Sections ===== */
.collapse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 10px 0;
  -webkit-tap-highlight-color: transparent;
}
.collapse-header .arrow {
  transition: transform .2s;
  font-size: .8rem;
  color: #5a7a9a;
}
.collapse-header.open .arrow { transform: rotate(90deg); }
.collapse-body {
  display: none;
  padding-bottom: 8px;
}
.collapse-body.open { display: block; }

/* ===== Reward Row ===== */
.rw-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #1e3a5f22;
}
.rw-label {
  font-size: .82rem;
  color: #8ecae6;
  flex: 1;
  min-width: 0;
}
.rw-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.rw-controls-bool {
  min-width: 76px;
  justify-content: flex-end;
  gap: 6px;
}
/* Unlocked: cool neutral — reads clearly as “open / editable” */
.rw-lock-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 1px solid #3d5a80;
  border-radius: 6px;
  background: #0f1a2e;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  color: var(--m-accent-text);
}
.rw-lock-btn:active {
  background: #1a2f4a;
  transform: scale(0.96);
}
/* Locked: strong red so it’s obvious at a glance */
.rw-row-locked {
  background: rgba(107, 66, 69, 0.12);
  border-radius: 8px;
  margin: 2px -6px;
  padding: 6px 6px 6px 8px;
  border-left: 3px solid var(--m-danger);
  box-shadow: inset 0 0 0 1px rgba(107, 66, 69, 0.2);
}
.rw-row-locked .rw-lock-btn {
  border-color: var(--m-danger-deep);
  background: linear-gradient(180deg, #4a3034 0%, #352428 100%);
  color: #dcc8c9;
  box-shadow: 0 0 0 1px var(--m-border-danger), 0 1px 4px rgba(0, 0, 0, 0.35);
}
.rw-row-locked .rw-lock-btn:active {
  background: linear-gradient(180deg, #5a383c 0%, #4a3034 100%);
}
.rw-row-locked .rw-label {
  color: var(--m-err);
}
.rw-row-locked .rw-input {
  pointer-events: none;
  opacity: 0.92;
  border-color: rgba(107, 66, 69, 0.5);
  background: rgba(25, 18, 20, 0.45);
}
.rw-arrow:disabled,
.rw-arrow.rw-arrow-locked {
  opacity: 0.38;
  pointer-events: none;
  cursor: default;
}
.rw-checkbox:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.rw-row-locked .rw-checkbox {
  accent-color: var(--m-danger);
}
.rw-locks-hint {
  margin: 6px 0 10px;
  font-size: 0.72rem;
  line-height: 1.35;
}
.rw-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--m-primary-mid);
  cursor: pointer;
}
.rw-input {
  width: 80px;
  padding: 6px 4px;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  background: #0a1628;
  color: #e3f2fd;
  font-size: .85rem;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.rw-input::-webkit-inner-spin-button,
.rw-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.rw-input:focus { border-color: var(--m-focus); }
.rw-arrow {
  width: 32px;
  height: 32px;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  background: #1e3a5f;
  color: #8ecae6;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.rw-arrow:active { background: var(--m-primary); color: var(--m-on-accent); }
.rw-label-tippable { cursor: pointer; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; text-decoration-color: #8ecae644; }
.rw-tip { display: none; font-size: .72rem; color: #a0b4c8; background: #0d1f35; border-left: 2px solid var(--m-primary-mid); padding: 5px 8px; margin: -2px 0 4px 0; border-radius: 0 4px 4px 0; line-height: 1.35; }
.rw-tip-visible { display: block; }

/* ===== Select ===== */
.select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #1e3a5f;
  border-radius: 8px;
  background: #0a1628;
  color: #e3f2fd;
  outline: none;
  -webkit-appearance: none;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1e3a5f; border-radius: 2px; }

/* ===== Multi-policy Trading Hub (Phase 5) ===== */
/* Global master safety (emergency stop) banner */
.th-safety-section {
  border: 1px solid rgba(30, 58, 95, 0.85);
  border-left: 4px solid #22c55e;
  background: linear-gradient(135deg, rgba(8, 24, 18, 0.72), rgba(7, 17, 31, 0.88));
}
.th-safety-section.th-safety-engaged {
  border-left-color: #ef4444;
  background: linear-gradient(135deg, rgba(42, 10, 10, 0.72), rgba(7, 17, 31, 0.88));
}
.th-safety-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.th-safety-info { flex: 1 1 240px; min-width: 0; }
.th-safety-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.th-safety-icon { font-size: 1.15rem; line-height: 1; }
.th-safety-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.th-safety-badge.is-live {
  color: #86efac;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.th-safety-badge.is-danger {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.35);
}
.th-safety-hint { margin-top: 4px !important; }

.th-styled-switch {
  display: inline-flex;
  cursor: pointer;
  flex: 0 0 auto;
  user-select: none;
}
.th-styled-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.th-styled-switch-track {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 112px;
  height: 34px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid rgba(143, 176, 208, 0.28);
  background: rgba(8, 16, 26, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.th-styled-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: linear-gradient(180deg, #f8fafc, #cbd5e1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.th-styled-switch-text {
  position: relative;
  z-index: 1;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  transition: color 0.2s ease, opacity 0.2s ease;
}
.th-styled-switch-off { color: #94a3b8; opacity: 0.55; }
.th-styled-switch-on { color: #64748b; opacity: 0.45; }
.th-styled-switch.is-active .th-styled-switch-thumb { transform: translateX(100%); }
.th-styled-switch.is-active .th-styled-switch-off { opacity: 0.35; }
.th-styled-switch.is-active .th-styled-switch-on { opacity: 1; }

.th-styled-switch-safety.is-active .th-styled-switch-track {
  border-color: rgba(239, 68, 68, 0.55);
  background: linear-gradient(135deg, rgba(69, 10, 10, 0.95), rgba(127, 29, 29, 0.72));
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.18);
}
.th-styled-switch-safety.is-active .th-styled-switch-on { color: #fecaca; }
.th-styled-switch-safety:not(.is-active) .th-styled-switch-off { color: #86efac; opacity: 1; }
.th-styled-switch-safety:not(.is-active) .th-styled-switch-track {
  border-color: rgba(34, 197, 94, 0.35);
  background: linear-gradient(135deg, rgba(6, 36, 22, 0.92), rgba(8, 24, 18, 0.72));
}

.swap-send-wallet-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
}
.swap-send-wallet-identity { display:flex; align-items:center; gap:10px; min-width:0; }
.swap-send-wallet-identity > div { display:flex; flex-direction:column; gap:2px; min-width:0; }
.swap-send-wallet-identity span { color:#8fb0d0; font-size:.76rem; }
.th-scope-chips { display:flex; gap:8px; overflow-x:auto; padding:4px 0; -webkit-overflow-scrolling:touch; }
.th-chip { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:999px; border:1px solid #1e3a5f; background:#0d1b2e; color:#cbd5e1; white-space:nowrap; cursor:pointer; font-size:13px; }
.th-chip.active { background:#1d4ed8; border-color:#3b82f6; color:#fff; }
.th-chip-manager.active { background:#7c3aed; border-color:#a78bfa; }
/* Base size is used by the scope/filter chips; card heads use -lg, tables use -sm. */
.th-avatar { display:inline-flex; align-items:center; justify-content:center; width:34px; height:34px; border-radius:50%; overflow:hidden; background:#1e3a5f; color:#e2e8f0; font-size:13px; font-weight:700; flex:0 0 auto; }
.th-avatar img { width:100%; height:100%; object-fit:cover; display:block; }
.th-avatar-sm { width:28px; height:28px; font-size:11px; }
.th-avatar-lg { width:54px; height:54px; font-size:20px; }
.th-avatar-fallback { text-transform:uppercase; }

/* Avatar as the profile-image picker (card heads) */
.th-avatar-btn { position:relative; display:inline-flex; padding:0; border:0; background:transparent; border-radius:50%; cursor:pointer; line-height:0; flex:0 0 auto; }
.th-avatar-btn .th-avatar { transition:box-shadow .12s ease; }
.th-avatar-btn:hover .th-avatar, .th-avatar-btn:focus-visible .th-avatar { box-shadow:0 0 0 2px #3b82f6; }
.th-avatar-btn:focus { outline:none; }
/* Always visible on touch (no hover state to reveal it) */
.th-avatar-edit { position:absolute; right:-2px; bottom:-2px; display:flex; align-items:center; justify-content:center; width:20px; height:20px; border-radius:50%; background:#1d4ed8; border:2px solid #0a1628; color:#fff; font-size:10px; line-height:1; pointer-events:none; }

/* Display name as the rename control (card heads) */
.th-name-btn { display:inline-flex; align-items:center; gap:6px; max-width:100%; padding:0; border:0; background:transparent; color:#e2e8f0; font-weight:700; font-size:16px; text-align:left; cursor:pointer; }
.th-name-text { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; border-bottom:1px dashed #334155; }
.th-name-edit { flex:0 0 auto; font-size:12px; color:#64748b; }
.th-name-btn:hover .th-name-text, .th-name-btn:focus-visible .th-name-text { border-bottom-color:#3b82f6; }
.th-name-btn:hover .th-name-edit, .th-name-btn:focus-visible .th-name-edit { color:#3b82f6; }
.th-name-btn:focus { outline:none; }

.th-balance-head { display:flex; flex-wrap:wrap; gap:24px; margin:6px 0 10px; }
.th-balance-head strong { display:block; font-size:18px; color:#e2e8f0; }
.th-balance-label { font-size:11px; color:#94a3b8; text-transform:uppercase; letter-spacing:.04em; }
.th-token-list { display:flex; flex-direction:column; gap:6px; }
.th-token-row { display:grid; grid-template-columns:36px 1.6fr auto .9fr .9fr auto; align-items:center; gap:8px; padding:8px; background:#0d1b2e; border-radius:8px; }
.th-token-thumb-box { width:32px; height:32px; display:flex; align-items:center; justify-content:center; }
.th-token-thumb { width:32px; height:32px; border-radius:50%; object-fit:cover; border:1px solid var(--m-primary-mid); background:#112233; }
.th-token-thumb-ph { width:32px; height:32px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:1rem; background:linear-gradient(145deg, #1e3a5f 0%, var(--m-primary-mid) 100%); }
.th-token-main { display:flex; flex-direction:column; }
.th-token-name { font-size:11px; color:#94a3b8; }
.th-token-holders { display:flex; gap:4px; flex-wrap:wrap; justify-content:flex-end; }
.th-token-amt, .th-token-val { text-align:right; font-variant-numeric:tabular-nums; }
.th-token-val { display:flex; flex-direction:column; align-items:flex-end; gap:2px; }
.th-token-roi { font-size:11px; font-weight:700; white-space:nowrap; }
.th-token-actions { display:flex; align-items:center; justify-content:flex-end; gap:6px; }
.th-token-ignore, .th-token-burn, .th-token-chart, .th-token-force-sell { padding:5px 8px; white-space:nowrap; }
.th-token-ignore { opacity:.8; }
.th-token-burn { border-color:rgba(239,68,68,.55); background:rgba(127,29,29,.34); color:#fecaca; }
.th-ignored-tokens { margin-top:10px; }
.th-ignored-token-search { width:100%; margin:4px 0 8px; font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.th-ignored-token-row { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:8px 4px; border-top:1px solid rgba(148,163,184,.14); }
.th-ignored-token-row > div { min-width:0; display:flex; flex-direction:column; }
.th-ignored-token-row span { color:#94a3b8; font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.th-ignored-token-row > .th-ignored-token-actions { flex:0 0 auto; flex-direction:row; align-items:center; gap:6px; }
@media (max-width:560px) {
  .th-token-row { grid-template-columns:32px minmax(0,1fr) auto; }
  .th-token-thumb-box { grid-column:1; grid-row:1 / span 2; }
  .th-token-main { grid-column:2; grid-row:1; min-width:0; }
  .th-token-holders { grid-column:3; grid-row:1; }
  .th-token-amt { grid-column:2; grid-row:2; text-align:left; }
  .th-token-val { grid-column:3; grid-row:2; }
  .th-token-actions { grid-column:2 / span 2; grid-row:3; justify-self:end; }
}

/* Combined trade history reuses the shared optuna table theme (.optuna-trial-table
   / .optuna-trial-table-wrap) so it matches the paper/optuna trade tables, with a
   few overrides for the trader avatar column and to relax the wide min-width. */
.th-trade-wrap { margin-bottom: 6px; }
.th-trade-table { min-width: 0; }
.th-trade-table th { font-weight: 700; color: #8fbdf2; }
.th-trade-table .th-trade-time { color: #b8d7ff; }
.th-trade-table .th-trade-token strong { color: #e3f2fd; }
.th-trade-table td.positive, .th-trade-table th.positive { color: #4ade80; }
.th-trade-table td.negative, .th-trade-table th.negative { color: #f87171; }
.th-trade-table .th-trade-trader,
.trading-hub-trade-table .th-trade-trader { text-align: center; }
.th-trader-chip { border: 0; background: transparent; padding: 0; cursor: pointer; display: inline-flex; }
.th-trade-table .th-trade-sig a { color: #7ebdff; text-decoration: none; }
.th-trade-table .th-trade-sig a:hover { text-decoration: underline; }
.th-trades-count { margin-top: 6px; }

/* Section hints normally use a negative top margin to tuck under a title; when a
   hint follows an interactive control (select/button/form) that pulls it up ONTO
   the control. Neutralize it in the Trading Hub cards/forms to stop overlap. */
.th-card .section-hint,
.th-inline-form + .section-hint,
.th-treasury .section-hint,
.th-bands .section-hint,
.th-manager-empty .section-hint { margin-top: 4px; }
.th-manager-empty { display: flex; flex-direction: column; gap: 6px; }
.th-inline-form { margin-bottom: 2px; }
.th-side-buy { color:#4ade80; text-transform:uppercase; font-size:11px; }
.th-side-sell { color:#f87171; text-transform:uppercase; font-size:11px; }

.th-card { background:#0d1b2e; border:1px solid #1e3a5f; border-radius:12px; padding:12px; margin-bottom:10px; }
.th-card-manager { border-color:#7c3aed; background:linear-gradient(180deg,#151032,#0d1b2e); }
.th-card-head { display:flex; align-items:center; gap:10px; }
/* Policy and manager cards both toggle open/closed from the head. The manager
   card has nothing to reveal until a wallet is assigned, so it stays inert. */
.th-card-policy .th-card-head,
.th-card-manager:not(.th-manager-empty) .th-card-head { cursor:pointer; }
.th-card-title { display:flex; flex-direction:column; align-items:flex-start; gap:2px; flex:1 1 auto; min-width:0; }
.th-card-addr { font-size:11px; color:#94a3b8; cursor:pointer; }
.th-card-badges { display:flex; gap:4px; flex-wrap:wrap; }
/* Run toggle sits in the card head; never let the flexible title column shrink
   it, so Start/Stop stays tappable on narrow screens. */
.th-card-run { flex:0 0 auto; padding:5px 10px; white-space:nowrap; }
.th-card-caret { color:#94a3b8; margin-left:6px; }
.th-badge { font-size:10px; padding:2px 6px; border-radius:6px; background:#1e293b; color:#cbd5e1; }
.th-badge-run { background:#065f46; color:#d1fae5; }
.th-badge-armed { background:#b45309; color:#fde68a; }
.th-badge-warn { background:#7f1d1d; color:#fecaca; }
.th-manager-badge { font-size:10px; padding:2px 8px; border-radius:6px; background:#7c3aed; color:#fff; }
.th-card-body { margin-top:12px; display:flex; flex-direction:column; gap:12px; }
.th-card-actions, .th-brain-actions, .th-card-controls { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.th-brain { display:flex; flex-direction:column; gap:2px; padding:8px; background:#0a1524; border-radius:8px; }
.th-brain-empty { color:#fca5a5; }
.th-bands { padding:8px; background:#0a1524; border-radius:8px; margin-top:8px; }
.th-bands-title { font-weight:600; color:#cbd5e1; margin-bottom:6px; }
.th-bands-grid { display:grid; grid-template-columns:1fr 1fr 1fr; gap:8px; }
.th-bands-grid label { display:flex; flex-direction:column; font-size:11px; color:#94a3b8; gap:3px; }
.th-bands-foot { display:flex; justify-content:space-between; align-items:center; margin-top:8px; gap:8px; flex-wrap:wrap; }
.th-inline-form { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:8px; }
.th-inline-form .input { flex:1 1 auto; min-width:120px; }

/* Treasury panel (manager card) */
.th-treasury { margin-top:10px; padding:10px; background:#0a1524; border-radius:8px; border:1px solid #1e293b; }
.th-treasury-head { display:flex; align-items:center; gap:8px; margin-bottom:8px; color:#e2e8f0; }
.th-treasury-controls { display:flex; gap:12px; align-items:flex-end; flex-wrap:wrap; margin-bottom:8px; }
.th-treasury-controls label { display:flex; flex-direction:column; font-size:11px; color:#94a3b8; gap:3px; }
.th-treasury-actions { margin-top:8px; }

/* ===== Polling Archive ===== */
.archive-count-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.archive-count-grid .stat-val.warn { color: #f0c674; }
.archive-note {
  font-size: .78rem;
  color: #8ba6c4;
  line-height: 1.4;
  background: #0a1628;
  border-radius: 8px;
  padding: 10px;
}
.archive-note strong { color: #cfe0f2; }
.archive-audit {
  margin-top: 8px;
  font-size: .78rem;
  color: #f0c674;
}
.archive-audit.hidden { display: none; }
.archive-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.archive-date-input {
  background: #0a1628;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .9rem;
}
.archive-date-status { margin-top: 8px; }
.archive-date-status-row,
.archive-day-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: .8rem;
  color: #8ba6c4;
}
.archive-muted { color: #6b8aaa; font-size: .75rem; }
.archive-anomaly {
  margin-top: 8px;
  font-size: .8rem;
  color: #f0c674;
  background: rgba(120, 95, 40, 0.18);
  border-radius: 6px;
  padding: 6px 8px;
}
.archive-metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.archive-search {
  width: 100%;
  box-sizing: border-box;
  background: #0a1628;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .85rem;
  margin-bottom: 10px;
}
.archive-token-card { margin-bottom: 10px; }
.archive-token-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.archive-token-title { font-weight: 600; color: #e2e8f0; font-size: .9rem; }
.archive-token-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.archive-token-delete { flex: 0 0 auto; }
.archive-token-meta {
  font-size: .68rem;
  color: #5a7a9a;
  word-break: break-all;
  margin: 2px 0 6px;
}
.archive-token-flags { margin-bottom: 6px; }
.archive-chart-wrap { height: 200px; margin-bottom: 0; }
/* Status chips */
.archive-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: capitalize;
}
.archive-chip--cov-full,
.archive-chip--int-clean { background: rgba(52,107,95,.30); color: var(--m-ok); }
.archive-chip--cov-partial,
.archive-chip--int-suspicious { background: rgba(120,95,40,.30); color: #f0c674; }
.archive-chip--cov-current { background: #1e3a5f55; color: #8ecae6; }
.archive-chip--cov-pending,
.archive-chip--int-pending { background: #2a3444; color: #9db3cc; }
.archive-chip--int-corrupt { background: rgba(107,66,69,.35); color: var(--m-err); }
