:root {
  color-scheme: light;
  --page-background:
    radial-gradient(circle at top left, rgba(204, 93, 52, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(69, 86, 166, 0.14), transparent 26%),
    linear-gradient(180deg, #dce6f2 0%, #f4efe8 42%, #f7f3ee 100%);
  --card: rgba(255, 252, 248, 0.92);
  --surface: rgba(255, 255, 255, 0.78);
  --card-border: rgba(255, 255, 255, 0.6);
  --paper-border: rgba(255, 255, 255, 0.6);
  --ink: #1b2430;
  --muted: #5c6472;
  --line: rgba(27, 36, 48, 0.14);
  --shadow: 0 24px 60px rgba(22, 35, 45, 0.14);
  --accent-text: #7a2bc0;
  --focus-ring: rgba(122, 43, 192, 0.16);
  --button-bg: #1f2717;
  --button-ink: #f6f4ef;
  --button-secondary-bg: rgba(255, 255, 255, 0.8);
  --button-secondary-ink: #1b2430;
  --button-secondary-border: rgba(27, 36, 48, 0.14);
  --search-hover: rgba(13, 138, 87, 0.1);
  --buy: #0d8a57;
  --sell: #ca5a18;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-background:
    radial-gradient(circle at top left, rgba(255, 155, 105, 0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(159, 173, 255, 0.16), transparent 26%),
    linear-gradient(180deg, #16212c 0%, #0c1219 44%, #090d12 100%);
  --card: rgba(13, 20, 29, 0.9);
  --surface: rgba(255, 255, 255, 0.05);
  --card-border: rgba(182, 205, 226, 0.18);
  --paper-border: rgba(182, 205, 226, 0.18);
  --ink: #f4f7fb;
  --muted: #c7d2df;
  --line: rgba(199, 210, 223, 0.22);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  --accent-text: #ff9b69;
  --focus-ring: rgba(255, 155, 105, 0.18);
  --button-bg: #23272a;
  --button-ink: #e0e0e0;
  --button-secondary-bg: rgba(255, 255, 255, 0.05);
  --button-secondary-ink: #f4f7fb;
  --button-secondary-border: rgba(199, 210, 223, 0.22);
  --search-hover: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page-background);
}

body,
.app-shell,
.search-box,
.search-results,
.stock-workspace,
.stock-tab,
.stock-bookmark,
.chart-panel,
.theme-toggle,
button,
select,
input[type="text"] {
  transition:
    background-color 120ms ease,
    color 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
}

a {
  color: inherit;
}

.page-shell {
  width: min(1120px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.theme-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
}

.theme-toggle {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--accent-text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 4px;
  border-radius: 999px;
}

.app-shell {
  width: 100%;
  padding: 24px;
  border: 1px solid var(--paper-border);
  border-radius: 28px;
  backdrop-filter: blur(10px);
  background: var(--card);
  box-shadow: var(--shadow);
  animation: panelRise 620ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.utility-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  font-size: 0.88rem;
}

.utility-links a {
  color: var(--muted);
  text-decoration: none;
}

.utility-links a:hover,
.utility-links a:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

.topbar {
  display: flex;
  gap: 20px;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;
}

.kicker {
  margin: 0;
  font-size: 0.86rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  line-height: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-family: "IBM Plex Mono", monospace;
}

label {
  font-size: 0.76rem;
  text-transform: uppercase;
  color: var(--muted);
}

select,
button,
input[type="text"] {
  border: 1px solid var(--button-secondary-border);
  background: var(--button-secondary-bg);
  color: var(--button-secondary-ink);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: "IBM Plex Mono", monospace;
}

button {
  cursor: pointer;
}

button:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

button:focus-visible,
select:focus-visible,
input[type="text"]:focus-visible {
  outline: 2px solid transparent;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input[type="text"] {
  cursor: text;
  text-transform: uppercase;
}

#refresh {
  background: var(--button-bg);
  color: var(--button-ink);
  border-color: transparent;
}

#copy-logs-btn,
#bookmark-current {
  font-size: 0.72rem;
  padding: 8px 12px;
  border-radius: 10px;
}

.search-bar {
  position: relative;
  margin-top: 14px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 16px;
}

.search-box:focus-within {
  border-color: var(--buy);
  box-shadow: 0 0 0 3px rgba(13, 138, 87, 0.12);
}

.search-icon {
  color: var(--muted);
  flex-shrink: 0;
}

.search-box input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  padding: 4px 0;
  font-size: 1rem;
  font-family: "IBM Plex Mono", monospace;
  outline: none;
  width: 100%;
  box-shadow: none;
}

.search-hint {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 7px;
  flex-shrink: 0;
  user-select: none;
}

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 6px;
  z-index: 100;
  box-shadow: 0 16px 48px rgba(30, 25, 10, 0.22);
}

.search-results.open {
  display: block;
}

.search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--line);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover,
.search-item.active {
  background: var(--search-hover);
}

.search-item .sym {
  font-weight: 600;
  min-width: 60px;
}

.search-item .name {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.stock-workspace {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: var(--surface);
}

.stock-tabs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 220px;
}

.stock-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  background: var(--surface);
}

.stock-tab.active {
  border-color: rgba(13, 138, 87, 0.5);
  box-shadow: 0 0 0 2px rgba(13, 138, 87, 0.12);
}

.stock-tab-btn,
.stock-tab-close,
.stock-bookmark-btn,
.stock-bookmark-remove {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  font-size: 0.76rem;
  font-family: "IBM Plex Mono", monospace;
  box-shadow: none;
}

.stock-tab-btn,
.stock-bookmark-btn {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.stock-tab-close,
.stock-bookmark-remove {
  opacity: 0.65;
  padding: 0 2px;
}

.stock-tab-close:hover,
.stock-bookmark-remove:hover {
  opacity: 1;
  transform: none;
}

.stock-bookmarks-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-bookmarks-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
}

.stock-bookmarks {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.stock-bookmark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 4px 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
}

.poll-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  display: inline-block;
  align-self: center;
}

.poll-dot.live {
  background: var(--buy);
  animation: pulse 1.2s ease infinite;
}

.chart-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
}

.chart {
  height: 70vh;
  min-height: 420px;
  max-height: 760px;
  width: 100%;
}

.notes {
  margin-top: 12px;
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.5;
}

.app-note {
  margin-top: 10px;
}

.public-ai-note {
  color: var(--accent-text);
}

.hidden {
  display: none !important;
}

.chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--button-bg);
  color: var(--button-ink);
  box-shadow: 0 18px 38px rgba(18, 24, 32, 0.22);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 22px 44px rgba(18, 24, 32, 0.30);
}

.chat-toggle svg {
  width: 24px;
  height: 24px;
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 45;
  width: min(420px, calc(100vw - 24px));
  max-height: min(76vh, 760px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--paper-border);
  border-radius: 28px;
  background: var(--card);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
}

.chat-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.chat-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.chat-kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-panel h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
}

.chat-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-model-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
}

.chat-model-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b94a0;
}

.chat-model-status.online::before {
  background: var(--buy);
}

.chat-model-status.warn::before {
  background: #d28c19;
}

.chat-model-status.offline::before {
  background: var(--sell);
}

.chat-close {
  border-radius: 999px;
}

.chat-security-note {
  margin: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
}

.chat-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "IBM Plex Mono", monospace;
}

.chat-settings label {
  min-width: 40px;
}

.chat-settings select {
  flex: 1;
}

.chat-key-banner {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-family: "IBM Plex Mono", monospace;
}

.chat-key-banner p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

.chat-key-controls {
  display: flex;
  gap: 8px;
}

.chat-key-controls input {
  flex: 1;
}

.chat-messages {
  min-height: 220px;
  max-height: min(42vh, 420px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 2px 2px;
}

.chat-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.55;
}

.chat-msg.user {
  align-self: flex-end;
  border-color: rgba(13, 138, 87, 0.28);
  background: rgba(13, 138, 87, 0.12);
}

.chat-msg.assistant {
  align-self: flex-start;
}

.chat-msg.system {
  align-self: center;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
}

.chat-msg.executed {
  align-self: center;
  border-color: rgba(13, 138, 87, 0.28);
  color: var(--buy);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
}

.chat-msg pre,
.chat-msg code {
  font-family: "IBM Plex Mono", monospace;
}

.chat-msg pre {
  margin: 10px 0 0;
  padding: 10px;
  overflow-x: auto;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.14);
}

.chat-image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.img-thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(12, 18, 25, 0.76);
  color: #f4f7fb;
}

.chat-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-input-wrap textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  border: 1px solid var(--button-secondary-border);
  border-radius: 14px;
  padding: 12px;
  background: var(--button-secondary-bg);
  color: var(--button-secondary-ink);
  font: inherit;
  font-family: "IBM Plex Mono", monospace;
}

.chat-input-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#chat-send {
  background: var(--button-bg);
  color: var(--button-ink);
  border-color: transparent;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

@keyframes panelRise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 600px) {
  .page-shell {
    width: calc(100vw - 16px);
    padding: 16px 0 28px;
  }

  .app-shell {
    padding: 18px;
    border-radius: 24px;
  }

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

  .stock-tabs-row {
    align-items: stretch;
  }

  .stock-tabs {
    min-width: 0;
  }

  .chart {
    height: 62vh;
    min-height: 360px;
  }

  .chat-toggle {
    right: 12px;
    bottom: 12px;
  }

  .chat-panel {
    right: 10px;
    left: 10px;
    bottom: 70px;
    width: auto;
    max-height: min(72vh, 640px);
    padding: 18px;
  }

  .chat-panel-header,
  .chat-key-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-panel-actions {
    justify-content: space-between;
  }

  .chat-msg {
    max-width: 100%;
  }
}

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.78rem;
  color: var(--muted, #9ca3af);
  letter-spacing: 0.04em;
}
