/* UI-02/UI-03 presentation candidate. Responsive behaviour is CSS-only (no viewport events reach components):
   phone < 600px is single column with a drawer index; 600px and wider shows the index as a sidebar. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #0b111b;
  color: #e8edf3;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}
:root {
  --ot-canvas: #101010; --ot-sidebar: #101010; --ot-surface: #181818;
  --ot-border: #303030; --ot-text: #f2f2f2; --ot-muted: #b7b7b7;
  --ot-focus: #f2f2f2; --ot-selected: #303030; --ot-radius: 6px;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
button { font: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid #9ecbff; outline-offset: 2px; }
.boot-loading { margin: 24px; color: #a9c1dc; }

/* Page frame: persistent fixture banner, then the phase content. */
.candidate-root { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.candidate-stage {
  flex: 1 1 auto; min-height: 0; position: relative;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}

/* Fixture banner and scenario control. */
.fixture-banner {
  flex: 0 0 auto; position: relative; z-index: 60;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: calc(env(safe-area-inset-top) + 4px) max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
  background: #2f2300; color: #ffd166; border-bottom: 1px solid #6b4f00;
  font-size: 12px; line-height: 1.35;
}
.fixture-banner-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; flex: 1 1 auto; min-width: 0; }
.fixture-banner-detail { color: #e9c46a; opacity: 0.85; }
.fixture-panel > summary { cursor: pointer; padding: 2px 8px; border: 1px solid #6b4f00; border-radius: 999px; list-style: none; white-space: nowrap; }
.fixture-panel > summary::-webkit-details-marker { display: none; }
.fixture-panel[open] > summary { background: #4a3800; }
.fixture-panel-body {
  position: absolute; left: 0; right: 0; top: 100%; max-height: 60vh; overflow-y: auto;
  padding: 8px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
  background: #1d1600; border-bottom: 1px solid #6b4f00; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 8px;
}
.fixture-panel fieldset { border: 1px solid #4d3a00; border-radius: 8px; margin: 0; padding: 6px 8px 8px; min-width: 0; }
.fixture-panel fieldset[disabled] { opacity: 0.5; }
.fixture-panel legend { padding: 0 4px; color: #ffd166; }
.fixture-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.fixture-label { min-width: 9em; color: #e9c46a; }
.fixture-panel button { border: 1px solid #8a6a00; background: #2a2000; color: #ffe8a3; border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.fixture-panel button[aria-pressed="true"] { background: #ffd166; color: #1d1600; }
.fixture-counters { display: flex; flex-wrap: wrap; gap: 12px; margin: 0; }

/* Login (login-v1). Phone: single column; tablet/desktop: bounded card. The page scrolls so the submit stays
   reachable when an on-screen keyboard shrinks the viewport. margin:auto centres without clipping the top. */
.login-page {
  height: 100%; overflow-y: auto; display: flex;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 42%, #121b2a 0%, #0b111b 58%, #080d15 100%);
}
.login-card {
  margin: auto; width: 100%; max-width: 440px;
  display: flex; flex-direction: column; gap: 18px;
  padding: 36px 24px 28px;
  background: rgba(17, 24, 36, 0.92);
  border: 1px solid rgba(95, 145, 195, 0.28); border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.login-logo { width: min(300px, 86%); height: auto; }
.login-subtitle { margin: 0; color: #a9c1dc; font-size: 1.05rem; letter-spacing: 0.01em; }
.credential-form { display: flex; flex-direction: column; gap: 16px; }
.login-field { display: flex; flex-direction: column; gap: 8px; }
.login-label { color: #eef3f8; font-size: 0.95rem; font-weight: 500; }
.login-input {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid rgba(120, 150, 185, 0.38); border-radius: 10px;
  background: #1b2433; color: #e8eef5; font: inherit; font-size: 16px; outline: none;
}
.login-input::placeholder { color: #8195ad; }
.login-input:focus-visible { border-color: #32e6c8; box-shadow: 0 0 0 3px rgba(50, 230, 200, 0.18); }
.password-wrap { position: relative; }
.password-wrap .login-input { padding-right: 52px; }
.password-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: #c9d6e4; cursor: pointer;
}
.password-toggle svg { width: 22px; height: 22px; }
.login-action {
  min-height: 52px; margin-top: 6px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(90deg, #32e6c8, #4ce6ff); color: #041316; font-weight: 700; font-size: 1.1rem;
}
.login-action:focus-visible { outline: 3px solid #ffffff; outline-offset: 2px; }
.login-action--busy { filter: saturate(0.7); opacity: 0.85; cursor: progress; }
.login-spinner { width: 18px; height: 18px; border: 2px solid rgba(4, 19, 22, 0.35); border-top-color: #041316; border-radius: 50%; animation: candidate-spin 0.8s linear infinite; }
@keyframes candidate-spin { to { transform: rotate(360deg); } }
.login-meta { margin: 4px 0 0; text-align: center; color: #8ea3ba; font-size: 0.85rem; }
.login-status { margin: 0; text-align: center; color: #a9c1dc; }
.login-feedback {
  margin: 0; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px;
  border: 1px solid rgba(255, 107, 107, 0.5); border-radius: 10px;
  background: rgba(80, 20, 24, 0.55); color: #ffd7d7; overflow-wrap: anywhere;
}
.login-refusal { margin: 0; color: #ffd166; overflow-wrap: anywhere; }
.ended-title { margin: 0; text-align: center; font-size: 1.35rem; }
.ended-detail { margin: 0; color: #a9c1dc; overflow-wrap: anywhere; }
@media (min-width: 600px) {
  .login-card { max-width: 460px; padding: 40px 36px 32px; }
}

/* Signed-in shell (chat-navigation-v3). */
.app-shell {
  --index-w: 264px;
  position: relative; height: 100%; min-height: 0;
  display: grid;
  grid-template-columns: var(--index-w) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "index bar" "index notices" "index content";
  background: var(--ot-canvas); color: var(--ot-text);
}
@media (min-width: 1200px) { .app-shell { --index-w: 280px; } }

.startup-screen {
  grid-column: 1 / -1; grid-row: 1 / -1; display: flex; overflow-y: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); background: #0b111b; color: #e8edf3;
}
.startup-card { margin: auto; width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.startup-card h1 { margin: 0; font-size: 1.4rem; }
.startup-card p { margin: 0; overflow-wrap: anywhere; }
.startup-logo { align-self: center; width: min(240px, 70%); height: auto; }
.startup-description, .startup-status { color: #a9c1dc; }
.startup-failure { color: #ffd7d7; border: 1px solid rgba(255, 107, 107, 0.5); background: rgba(80, 20, 24, 0.55); border-radius: 10px; padding: 10px 12px; }
.startup-footer { margin-top: 8px; }
.text-button { background: none; border: 1px solid rgba(255, 255, 255, 0.28); color: inherit; border-radius: 999px; padding: 8px 18px; cursor: pointer; }

.nav-index {
  grid-area: index; display: flex; flex-direction: column; min-height: 0;
  background: var(--ot-sidebar); border-right: 1px solid var(--ot-border);
}
.index-header { display: flex; align-items: center; gap: 6px; min-height: 76px; padding: 12px 18px 12px 22px; border-bottom: 1px solid #222; }
.index-brand { flex: 1; min-width: 0; font: 400 1.8rem Georgia, "Times New Roman", serif; letter-spacing: -.025em; color: var(--ot-text); }
.index-logo { height: 22px; width: auto; margin-right: auto; }
.index-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 10px 12px; scrollbar-color: #444 transparent; scrollbar-width: thin; }
.index-footer {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid #222;
}
.nav-section-label { margin: 14px 10px 4px; font-size: 0.8rem; font-weight: 500; color: #8c8c8c; letter-spacing: 0.02em; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item {
  display: flex; flex-wrap: wrap; align-items: center; column-gap: 14px; min-height: 48px; padding: 10px 12px;
  border-radius: 8px; color: var(--ot-text); text-decoration: none; font-size: .98rem;
}
.nav-item:hover { background: #1c1c1c; }
.nav-item.active { background: var(--ot-selected); }
.nav-item:focus-visible { outline-offset: -2px; }
.nav-item.disabled { color: #6f6f6f; cursor: not-allowed; }
.nav-item.disabled:hover { background: none; }
.nav-icon { flex: 0 0 auto; width: 23px; height: 23px; }
.nav-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.nav-lock { width: 14px; height: 14px; flex: 0 0 auto; }
.nav-item-reason { flex-basis: 100%; padding-left: 34px; font-size: 0.78rem; color: #8c8c8c; }
.menu-note { margin: 10px 10px 2px; font-size: 0.8rem; color: #d6b13a; overflow-wrap: anywhere; }
.recents { margin-top: 14px; padding-top: 4px; border-top: 1px solid #222; }
.recents-placeholder { margin: 4px 10px; font-size: 0.85rem; color: #9a9a9a; overflow-wrap: anywhere; }

.avatar-button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid #333; background: #161616; color: #ececec; font-weight: 600; cursor: pointer; }
.new-chat-button {
  flex: 1 1 auto; height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; background: #f4f4f4; color: #111; font-weight: 600; font-size: 1rem; cursor: pointer;
}
.new-chat-button svg { width: 20px; height: 20px; }
.account-menu { position: relative; }
.menu-anchor { position: relative; }
.menu-popup {
  position: absolute; z-index: 50; min-width: 220px; max-width: min(320px, 80vw);
  display: flex; flex-direction: column; padding: 6px;
  background: #1c1c1c; border: 1px solid #333; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.account-popup { bottom: calc(100% + 8px); left: 0; }
.chat-more-popup { top: calc(100% + 6px); right: 0; }
.menu-item { display: block; padding: 10px 12px; border: 0; border-radius: 8px; background: none; color: #ececec; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: #2a2a2a; }
.menu-popup .menu-note { margin: 6px 12px; color: #9a9a9a; }
.account-user { margin: 6px 12px 8px; font-size: 0.85rem; color: #9a9a9a; overflow-wrap: anywhere; }

.icon-button {
  flex: 0 0 auto; width: 44px; height: 44px; display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: #ececec; cursor: pointer;
}
.icon-button svg { width: 22px; height: 22px; }
.icon-button.circled { border: 1px solid #333; }
.icon-button.small { width: 32px; height: 32px; }
.icon-button.small svg { width: 18px; height: 18px; }
.icon-button:disabled { opacity: 0.4; cursor: not-allowed; }

.app-bar { grid-area: bar; display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 8px 20px; border-bottom: 1px solid #222; }
.app-bar-ai { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; padding: 8px; min-height: 44px; flex-shrink: 0; color: var(--ot-text); text-decoration: none; }
.app-bar-ai svg { width: 24px; height: 24px; }
.app-bar-title { margin: 0; font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.shell-notices { grid-area: notices; display: flex; flex-direction: column; min-width: 0; }
.recovery-notice, .engine-notification {
  margin: 10px 16px 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
}
.recovery-notice { border: 1px solid rgba(110, 170, 255, 0.45); background: rgba(22, 40, 66, 0.6); color: #dbe9ff; }
.engine-notification { border: 1px solid rgba(255, 107, 107, 0.6); background: rgba(80, 20, 24, 0.75); color: #ffd7d7; }
.notice-text { display: flex; flex-direction: column; gap: 4px; flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.notice-meta { font-size: 0.8rem; opacity: 0.8; }
.notice-actions { display: flex; align-items: center; gap: 6px; }
.notice-action { padding: 6px 12px; border: 1px solid currentColor; border-radius: 999px; color: inherit; text-decoration: none; font-size: 0.85rem; white-space: nowrap; }
.shell-content { grid-area: content; min-height: 0; min-width: 0; overflow-y: auto; padding: 24px 24px calc(24px + env(safe-area-inset-bottom)); scrollbar-color: #444 transparent; }
.route-stub { max-width: 760px; }
.route-stub h2 { margin: 0 0 8px; font-size: 1.3rem; }
.route-stub p { color: #bdbdbd; overflow-wrap: anywhere; }
.stub-control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
.stub-control { padding: 10px 18px; border: 1px solid #444; border-radius: 10px; background: #1f1f1f; color: #ececec; cursor: pointer; }

/* ChatKit adapter slot. Always the grid "content" item; hidden (display: none) whenever it is not shown. */
.chatkit-adapter { grid-area: content; position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ot-canvas); }
.chat-header { display: flex; align-items: center; gap: 8px; min-height: 76px; padding: 10px 20px; border-bottom: 1px solid #222; }
.chat-title { margin: 0 auto 0 6px; min-width: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 1.5rem; overflow-wrap: anywhere; }
.chat-slot { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-slot-error { margin: 16px; color: #ffd7d7; }
.fixture-chat { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.fixture-chat-label {
  align-self: center; max-width: 720px; margin: 10px 16px 0; padding: 6px 10px;
  border: 1px dashed #c9a227; border-radius: 8px; color: #ffd166; font-size: 0.8rem; text-align: center; overflow-wrap: anywhere;
}
.chat-welcome {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 18px;
  padding: 16px; text-align: center;
}
.fixture-chat-thread { margin: 0; font-size: 0.8rem; color: #8c8c8c; }
.chat-welcome-title { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.chat-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.chat-chip { padding: 12px 20px; border: 1px solid #3a3a3a; border-radius: 999px; background: transparent; color: #ececec; cursor: pointer; }
.chat-composer {
  align-self: center; width: calc(100% - 32px); max-width: 920px;
  display: flex; align-items: center; gap: 10px;
  margin: 0 16px calc(16px + env(safe-area-inset-bottom)); padding: 10px 10px 10px 18px;
  border: 1px solid #333; border-radius: 26px; background: #1b1b1b;
}
.chat-composer:focus-within { border-color: #9ecbff; }
.chat-composer textarea { flex: 1 1 auto; min-height: 24px; max-height: 140px; resize: none; border: 0; outline: none; background: transparent; color: #ececec; font: inherit; font-size: 16px; }
.chat-composer textarea::placeholder { color: #8c8c8c; }
.chat-send { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #3a3a3a; color: #bbb; }
.chat-send svg { width: 20px; height: 20px; }

/* Tablet and desktop: persistent sidebar; the index can be hidden, and an expanded chat takes the whole width. */
@media (min-width: 600px) {
  .only-phone { display: none !important; }
  .app-shell[data-sidebar-collapsed="true"],
  .app-shell[data-root="true"][data-chat-expanded="true"] { grid-template-columns: 0 minmax(0, 1fr); }
  .app-shell[data-sidebar-collapsed="true"] .nav-index,
  .app-shell[data-root="true"][data-chat-expanded="true"] .nav-index { display: none; }
}

/* Phone: one column; the index is a drawer over the content; the chat fills the usable viewport. */
/* Trading pages use the tablet width for data; Home retains its persistent tablet index.
   The existing drawer events and focus return apply at this breakpoint too. */
@media (min-width: 600px) and (max-width: 1199.98px) {
  .app-shell[data-root="false"] { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "notices" "content"; }
  .app-shell[data-root="false"] .only-wide { display: none !important; }
  .app-shell[data-root="false"] .only-phone { display: inline-grid !important; }
  .app-shell[data-root="false"] .nav-index { position: absolute; inset: 0 auto 0 0; z-index: 40; width: min(86%,360px); display: none; box-shadow: 8px 0 40px #0008; }
  .app-shell[data-root="false"][data-drawer-open="true"] .nav-index { display: flex; }
  .app-shell[data-root="false"] .drawer-scrim { position: absolute; inset: 0; z-index: 35; background: #0008; }
}
@media (max-width: 599.98px) {
  .only-wide { display: none !important; }
  .fixture-banner-detail { display: none; }
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "notices" "content"; }
  .nav-index {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 40; width: min(86%, 360px);
    display: none; box-shadow: 8px 0 40px rgba(0, 0, 0, 0.6);
  }
  .app-shell[data-drawer-open="true"] .nav-index { display: flex; }
  .drawer-scrim { position: absolute; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.55); }
  .chat-header { min-height: 56px; padding: 6px 8px; }
  .chat-title { font-size: 1.25rem; }
  .index-header { padding: 14px 12px 14px 20px; }
  .index-brand { font-size: 1.65rem; }
  .app-bar { padding: 8px 10px; gap: 6px; min-height: 60px; }
  .app-bar-title { font-size: 1rem; }
  .shell-content { padding: 12px 14px calc(20px + env(safe-area-inset-bottom)); }
  .chat-composer { width: calc(100% - 24px); margin: 0 12px calc(12px + env(safe-area-inset-bottom)); }
}

/* Duplicate-login confirmation (existing OT behaviour), inline inside the credential form. */
.duplicate-login {
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
  border: 1px solid rgba(95, 145, 195, 0.35); border-radius: 14px; background: rgba(30, 40, 56, 0.95);
  overflow-wrap: anywhere;
}
.duplicate-login:focus-visible { outline: 2px solid #9ecbff; outline-offset: 2px; }
.duplicate-login-message { margin: 0; color: #eef3f8; }
.duplicate-login-question { margin: 0; color: rgba(215, 224, 233, 0.8); font-size: 0.95rem; }
.duplicate-login-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.duplicate-login-confirm-button {
  min-height: 44px; padding: 8px 16px; border: 0; border-radius: 10px; cursor: pointer;
  background: #f0a63a; color: #1b1203; font-weight: 700;
}
.duplicate-login-confirm-button[aria-busy="true"] { opacity: 0.85; cursor: progress; }
.duplicate-login .text-button { min-height: 44px; }

/* Feature order includes Ontology AI. Conversation history stays outside the editable list. */
.navigation-order-button { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 12px; border: 0; background: transparent; color: #aaa; font: inherit; font-size: .8rem; cursor: pointer; }
.navigation-order-button:hover { color: #fff; }
.navigation-order-control { border-bottom: 1px solid #30343a; margin-bottom: 6px; }
.navigation-order-dialog { box-sizing: border-box; margin: auto; inset: 0; color: #eceff2; background: #17191d; border: 1px solid #41464e; border-radius: 14px; width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 16px; overflow-y: auto; }
.navigation-order-dialog::backdrop { background: #000a; }
.navigation-order-dialog header, .navigation-order-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.navigation-order-dialog h2 { font-size: 1.15rem; margin: 0; }
.navigation-order-dialog p, .navigation-order-dialog footer span { color: #adb4bd; font-size: .85rem; }
.navigation-order-dialog button { min-height: 44px; min-width: 44px; border: 1px solid #4b525b; border-radius: 8px; color: #f1f4f7; background: #252a31; padding: 6px 10px; font: inherit; cursor: pointer; }
.navigation-order-dialog button:disabled { opacity: .35; cursor: default; }
.navigation-order-dialog footer button { flex-shrink: 0; white-space: nowrap; }
.navigation-order-dialog button:focus-visible { outline: 2px solid #72c7eb; outline-offset: 2px; }
.navigation-order-list { list-style: none; padding: 0; margin: 16px 0; }
.navigation-order-list li { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #30343a; }
.navigation-order-list li span { overflow-wrap: anywhere; font-size: .9rem; }
.navigation-order-list button { padding: 0; font-size: 1.25rem; }
.navigation-order-dialog .navigation-order-error { color: #ffb4ab; }
