/* §12.3 视觉规范(壳层 UI) — dark shell + light chart canvas */

:root {
  --bg: #0f1419;
  --bg-elev: #1a222d;
  --bg-elev-2: #232d3b;
  --border: #2e3a4a;
  --text: #e7ecf3;
  --muted: #8b9bb0;
  --accent: #3d8bfd;
  --accent-dim: #2563b8;
  --ok: #3ecf8e;
  --warn: #f0a030;
  --danger: #e85d5d;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Chart pane (intentional light mix on dark shell) */
  --chart-bg: #f7f7f7;
  --chart-text: #202124;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 10px;
  gap: 12px;
  min-height: 0;
}

/* ——— Header / brand ——— */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2b6cb0, #1a365d);
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.ctrl-label {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ——— Form controls ——— */

select,
input,
button {
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

select,
input {
  height: 30px;
  padding: 0 8px;
  min-width: 72px;
  outline: none;
}

select:hover,
input:hover,
button:hover:not(:disabled) {
  border-color: #4a5d75;
}

select:focus,
input:focus {
  border-color: var(--accent);
}

#searchWindowSize {
  width: 56px;
  min-width: 56px;
  text-align: center;
  font-family: var(--mono);
}

#symbolSelect {
  width: 150px;
  min-width: 120px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
  background: var(--bg-elev-2);
}

.icon-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.icon-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* ——— Workspace / panels ——— */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  min-width: 0;
}

.chart-panel > .panel-head {
  gap: 10px;
  justify-content: flex-start;
  /* Fixed single-row height so PA flags show/hide never reflows the chart */
  height: 2.5rem;
  box-sizing: border-box;
  overflow: hidden;
  align-items: center;
}

.chart-panel > .panel-head h2 {
  flex: 0 0 auto;
  line-height: 1.2;
}

/* PA flags sit right after「图表」as rounded pills (same row as OHLC) */
#barFlags {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 1.5rem;
  overflow: hidden;
  pointer-events: none;
  font-size: 0.72rem;
}

.flag {
  flex: 0 0 auto;
  box-sizing: border-box;
  height: 1.5rem;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  color: var(--text);
  background: rgba(61, 139, 253, 0.16);
  border: 1px solid rgba(61, 139, 253, 0.35);
  border-radius: 999px;
  font-family: var(--mono);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

/* OHLC badge: size to content, push to the right edge of the header */
.chart-panel > .panel-head .badge {
  flex: 0 1 auto;
  width: max-content;
  max-width: min(100%, 42rem);
  margin-left: auto;
  text-align: left;
  /* Match flag / head row so presence of either never changes height */
  height: 1.5rem;
  line-height: 1.5rem;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-family: var(--mono);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* Connected status + OHLC legend share this green pill */
.badge.ok {
  color: #0d2b1c;
  background: var(--ok);
  border-color: transparent;
  font-weight: 600;
}

.badge.err {
  color: #fff;
  background: var(--danger);
  border-color: transparent;
  font-weight: 600;
}

.muted-badge {
  color: var(--muted);
  font-weight: 500;
}

/* ——— Chart pane (light canvas on dark shell) ——— */

.chart-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  overflow: hidden;
  background: var(--chart-bg);
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

#container {
  width: 100%;
  height: 100%;
  display: block;
}

/* ENV floating card — chart canvas top-left (draggable) */
#env {
  position: absolute;
  z-index: 6;
  top: 10px;
  left: 10px;
  right: auto;
  min-width: 168px;
  padding: 10px 12px;
  background: rgba(26, 34, 45, 0.96);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: move;
  user-select: none;
}

#env:empty {
  display: none;
  padding: 0;
  border: none;
  min-width: 0;
}

.env-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  line-height: 1.65;
}

.env-key {
  color: var(--muted);
  letter-spacing: 0.4px;
}

.env-val {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ——— Bottom Message / Terminal ——— */

.bottom {
  flex: 0 0 168px;
  display: flex;
  gap: 12px;
  min-height: 140px;
  max-height: 40vh;
}

.log-panel {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg);
  min-height: 0;
}

.log-time {
  color: var(--muted);
  margin-right: 8px;
}

.term-cmd {
  color: var(--accent);
}

.term-err {
  color: var(--danger);
}

#termInput {
  flex: 0 0 auto;
  width: 100%;
  height: 34px;
  padding: 8px 12px;
  color: var(--accent);
  background: var(--bg-elev-2);
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
  outline: none;
  font-family: var(--mono);
  font-size: 0.82rem;
}

#termInput::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

#termInput:focus {
  background: #1e2836;
}

/* ——— Footer ——— */

.footer {
  flex: 0 0 auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  padding-bottom: 2px;
}

.footer code {
  font-family: var(--mono);
  background: var(--bg-elev);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ——— Responsive ——— */

@media (max-width: 820px) {
  .app {
    padding: 10px;
    gap: 10px;
  }

  .header {
    align-items: flex-start;
  }

  .bottom {
    flex-direction: column;
    flex: 0 0 auto;
    max-height: none;
    height: auto;
  }

  .log-panel {
    flex: 0 0 120px;
  }

  #barFlags,
  .chart-wrap:has(#env:not(:empty)) #barFlags {
    top: auto;
    left: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
  }

  #env {
    top: 10px;
    left: 10px;
    right: auto;
    bottom: auto;
  }
}
