/* Chart application layout (chart.html). */

html, body.app { height: 100%; }
body.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--bg);
  font-size: 13px;
  line-height: 1.4;
}

/* ---------------------------------------------------------------- top toolbar */

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; min-height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: visible; scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.brand-compact { margin-right: 6px; flex: none; font-size: 15px; gap: 8px; }

.symbol-box { position: relative; flex: none; }
.symbol-box input {
  width: 190px; height: 34px; padding: 0 30px 0 32px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text);
  font: 600 14px/1 var(--font); text-transform: uppercase;
}
.symbol-box input::placeholder { text-transform: none; font-weight: 400; color: var(--muted); font-size: 12px; }
.symbol-box input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.symbol-icon { position: absolute; left: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.symbol-kbd {
  position: absolute; right: 8px; top: 8px; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--muted); font-size: 11px; pointer-events: none;
}
.symbol-box input:focus ~ .symbol-kbd { display: none; }

.dropdown {
  position: fixed; z-index: 50; width: 380px; max-width: calc(100vw - 20px); max-height: 60vh; overflow-y: auto;
  margin-top: 4px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.sr-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); text-align: left; cursor: pointer; font: inherit;
}
.sr-item:hover, .sr-item.hl { background: var(--accent-soft); }
.sr-sym { font-weight: 700; }
.sr-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.sr-empty { padding: 12px; color: var(--muted); }

.tf-group {
  display: flex; flex: none; padding: 2px; gap: 1px;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border); margin: 0 4px;
}
.tf-group button {
  min-width: 34px; height: 30px; padding: 0 6px; border: 0; border-radius: 6px;
  background: none; color: var(--text-2); font: 500 13px/1 var(--font); cursor: pointer;
}
.tf-group button:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.tf-group button.active { color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.tf-group button:disabled { color: var(--border-strong); cursor: not-allowed; }

.tb-btn, .tb-icon {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 34px; padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-2); font: 500 13px/1 var(--font); cursor: pointer; white-space: nowrap;
}
.tb-icon { width: 34px; padding: 0; justify-content: center; }
.tb-btn:hover, .tb-icon:hover { background: var(--panel-2); color: var(--text); }
.tb-accent { color: var(--accent); }
.tb-accent:hover { color: var(--accent); background: var(--accent-soft); }
.count:not(:empty) {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700;
}

.menu-wrap { position: relative; flex: none; }
.menu {
  position: fixed; z-index: 50; min-width: 180px; padding: 4px; margin-top: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: 6px;
  background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer;
}
.menu button:hover { background: var(--accent-soft); }

.provider-wrap { flex: none; }
.provider-wrap select {
  height: 34px; padding: 0 28px 0 10px; max-width: 220px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text); font: 500 13px/1 var(--font); cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ---------------------------------------------------------------- workspace */

.workspace { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 0; }
.drawbar {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 46px; padding: 6px 0; overflow-y: auto; scrollbar-width: none;
  background: var(--panel); border-right: 1px solid var(--border);
}
.drawbar::-webkit-scrollbar { display: none; }
.tool {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-2); cursor: pointer;
}
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool-sep { width: 24px; height: 1px; background: var(--border); margin: 6px 0; flex: none; }

.chart-area { position: relative; min-width: 0; min-height: 0; background: var(--chart-bg); }
#chart { position: absolute; inset: 0; }

.chart-overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--chart-bg) 70%, transparent);
  backdrop-filter: blur(2px);
}
.chart-overlay[hidden] { display: none; }
.chart-panel {
  position: relative; width: min(460px, 100%); padding: 26px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  text-align: center; font-size: 14px; line-height: 1.55;
}
.chart-panel[data-kind="loading"] { width: auto; background: none; border: 0; box-shadow: none; color: var(--muted); }
.chart-panel h2 { font-size: 18px; }
.chart-panel p { color: var(--text-2); }
.chart-panel .error-text { color: var(--down); word-break: break-word; }
.panel-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 6px; }
.panel-close {
  position: absolute; top: 8px; right: 10px; width: 30px; height: 30px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font-size: 22px; cursor: pointer;
}
.panel-close:hover { background: var(--panel-2); color: var(--text); }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 12px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- status bar */

.statusbar {
  display: flex; align-items: center; gap: 14px; min-height: 30px; padding: 4px 12px;
  background: var(--panel); border-top: 1px solid var(--border); color: var(--muted); font-size: 12px;
  white-space: nowrap; overflow: hidden;
}
.status-live { display: inline-flex; align-items: center; gap: 6px; }
.status-live:empty { display: none; }
.status-live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-live[data-state="live"] { color: var(--up); }
.status-live[data-state="live"]::before { background: var(--up); box-shadow: 0 0 0 3px rgba(8, 153, 129, 0.2); }
.status-live[data-state="reconnecting"]::before, .status-live[data-state="connecting"]::before { background: #e0a100; }
.status-quote b { color: var(--text); }
.status-quote .up { color: var(--up); }
.status-quote .down { color: var(--down); }
.status-note { overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- dialogs */

.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5, 8, 15, 0.55); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 42px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-x {
  width: 32px; height: 32px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); font-size: 22px; cursor: pointer;
}
.dialog-x:hover { background: var(--panel-2); color: var(--text); }
.dialog-intro { padding: 0 20px; color: var(--text-2); font-size: 13px; }
.keys-list { overflow-y: auto; padding: 0 20px; }
.key-row { padding: 14px 0; border-top: 1px solid var(--border); }
.key-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.key-head .key-markets { margin-left: auto; }
.plan-pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.plan-free { background: rgba(8, 153, 129, 0.12); color: var(--up); }
.plan-paid { background: rgba(224, 161, 0, 0.14); color: #c28a00; }
:root[data-theme="dark"] .plan-paid { color: #f0b429; }
.key-input + .key-input { margin-top: 6px; }
.key-name { font-weight: 600; font-size: 14px; }
.key-markets { color: var(--muted); font-size: 12px; text-align: right; }
.key-input { display: flex; gap: 6px; }
.key-input input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text); font: 13px var(--mono);
}
.key-input input:focus { outline: none; border-color: var(--accent); }
.key-links { display: flex; gap: 16px; margin-top: 6px; font-size: 12px; }
.dialog-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); }

.ind-search-wrap { padding: 8px 20px 10px; }
.ind-search-wrap input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text); font: 14px var(--font);
}
.ind-search-wrap input:focus { outline: none; border-color: var(--accent); }
.ind-scroll { max-height: min(60vh, 520px); overflow-y: auto; padding: 0 12px 16px; }
.ind-group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 12px 8px 4px; }
.ind-list { list-style: none; margin: 0; padding: 0; }
.ind-item {
  display: grid; grid-template-columns: auto 56px 1fr; gap: 10px; align-items: center;
  padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.ind-item:hover { background: var(--panel-2); }
.ind-item input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.ind-name { font-weight: 700; }
.ind-desc { color: var(--text-2); }
.pad { padding: 12px 8px; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 44px; z-index: 60; transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: var(--radius);
  background: var(--text); color: var(--bg); font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 900px) {
  .brand-name, #chart-type-label, #indicators-btn > span:not(.count), #keys-btn span { display: none; }
  .symbol-box input { width: 140px; }
  .symbol-kbd { display: none; }
}
@media (max-width: 640px) {
  .drawbar { width: 40px; }
  .tool { width: 32px; height: 32px; }
  .status-note { display: none; }
  .provider-wrap select { max-width: 130px; }
}
