/* ==================== TERMINAL WIDGET SYSTEM ==================== */

:root {
  --t-border: #e2e8f0;
  --t-accent: #2563eb;
  --t-accent-hover: #1d4ed8;
  --t-danger: #ef4444;
  --t-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
  --t-shadow-drag: 0 12px 40px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.08);
}

/* ==================== OVERRIDE GRID → BLOCK ==================== */

.t-canvas.layout.demo-layout {
  display: block !important;
  position: relative;
  overflow: hidden;
  grid-template-columns: unset !important;
  grid-template-rows: unset !important;
  grid-template-areas: unset !important;
  height: calc(100vh - 56px);
  background: var(--bg, #f6f8fb);
}

/* Kill grid-area on all children so they don't try to place themselves */
.t-canvas .tools-panel-compact,
.t-canvas .chart-tabs-bar,
.t-canvas .chart-area,
.t-canvas .orderbook-panel,
.t-canvas .positions-panel,
.t-canvas .control-panel.modern {
  grid-area: unset !important;
}

/* Hide old panel resizer */
.t-canvas .panel-resizer { display: none !important; }

/* ==================== WIDGETS BUTTON (header) ==================== */

.t-widgets-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}
.t-widgets-btn:hover {
  background: linear-gradient(135deg, #6d28d9 0%, #5b21b6 100%);
  box-shadow: 0 4px 16px rgba(124,58,237,0.4);
  transform: translateY(-1px);
}

/* ==================== WIDGETS ==================== */

.t-widget {
  position: absolute;
  background: #ffffff;
  border-radius: 6px;
  box-shadow: var(--t-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  transition: box-shadow 0.15s;
}
.t-widget.dragging {
  box-shadow: var(--t-shadow-drag);
  z-index: 10000 !important;
  opacity: 0.95;
}
.t-widget.t-widget-hidden {
  display: none !important;
}

.t-widget-header {
  display: flex;
  align-items: center;
  height: 28px;
  min-height: 28px;
  padding: 0 6px 0 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  cursor: grab;
  user-select: none;
  gap: 6px;
}
.t-widget-header:active { cursor: grabbing; }

.t-widget-title {
  flex: 1;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.t-widget-actions { display: flex; gap: 1px; }

.t-widget-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 24px !important;
  height: 24px !important;
  border: none !important;
  background: rgba(0,0,0,0.04) !important;
  border-radius: 4px !important;
  cursor: pointer !important;
  color: #475569 !important;
  transition: all 0.12s;
  padding: 0 !important;
  flex-shrink: 0 !important;
}
.t-widget-btn svg {
  width: 14px !important;
  height: 14px !important;
  min-width: 14px !important;
  min-height: 14px !important;
  display: block !important;
  stroke: currentColor !important;
}
.t-widget-btn:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}
.t-widget-btn.close:hover {
  background: rgba(239,68,68,0.15) !important;
  color: var(--t-danger) !important;
}

.t-widget-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ==================== CHART SEARCH BUTTON ==================== */

.t-widget-search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 20px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  border-radius: 4px;
  cursor: pointer;
  color: #64748b;
  transition: all 0.12s;
  padding: 0;
  flex-shrink: 0;
}
.t-widget-search-btn:hover {
  background: #f1f5f9;
  color: #7c3aed;
  border-color: #7c3aed;
}
.t-widget-search-btn svg {
  width: 12px !important;
  height: 12px !important;
  display: block;
}

/* ==================== CHART WIDGET ==================== */

#widget-chart {
  overflow: visible !important;
}
#widget-chart .t-widget-body {
  flex-direction: row !important;
  overflow: visible !important;
}

/* Tools strip (left side inside chart widget) */
#widget-chart .tools-panel-compact {
  flex-shrink: 0;
  width: 42px !important;
  height: auto !important;
  overflow: visible !important;
  border: none !important;
  border-right: 1px solid #e2e8f0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  padding: 4px 2px !important;
  background: #f8fafc;
  position: static !important;
}
#widget-chart .tools-panel-compact .tool-btn {
  width: 32px !important;
  height: 32px !important;
}

/* Chart main column (right of tools) */
#widget-chart .t-chart-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Tabs bar inside chart (SBER 1H, +) */
#widget-chart .chart-tabs-bar {
  flex-shrink: 0;
  height: auto !important;
  width: auto !important;
  position: static !important;
}

/* Chart area — fills remaining space */
#widget-chart .chart-area {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  height: auto !important;
  width: auto !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  position: relative !important;
  border: none !important;
  border-radius: 0 !important;
}

#widget-chart .chart-card {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

#widget-chart .chart-surface {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  position: relative !important;
  overflow: hidden !important;
  border-radius: 0 !important;
}

#widget-chart #chart-root {
  position: absolute !important;
  inset: 0 !important;
}

#widget-chart #drawing-overlay {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

#widget-chart .indicator-panes-wrapper {
  flex-shrink: 0;
}

/* ==================== POSITIONS WIDGET ==================== */

#widget-positions .t-widget-body { overflow: auto; }
#widget-positions .positions-panel {
  height: auto !important;
  width: auto !important;
  min-height: 100%;
  position: static !important;
  border: none !important;
}

/* ==================== TRADING WIDGET ==================== */

#widget-trading .t-widget-body { overflow-y: auto; }
#widget-trading .control-panel.modern {
  height: auto !important;
  width: auto !important;
  overflow: visible;
  position: static !important;
  border: none !important;
}

/* ==================== ORDERBOOK WIDGET ==================== */

#widget-orderbook .t-widget-body { overflow: hidden; }
#widget-orderbook .orderbook-panel {
  height: 100% !important;
  width: auto !important;
  position: static !important;
}

/* ==================== RESIZE HANDLES ==================== */

.t-widget-resize {
  position: absolute;
  z-index: 5;
}
.t-widget-resize-e  { top: 0; right: -3px; width: 6px; height: 100%; cursor: ew-resize; }
.t-widget-resize-s  { bottom: -3px; left: 0; width: 100%; height: 6px; cursor: ns-resize; }
.t-widget-resize-se { bottom: -3px; right: -3px; width: 12px; height: 12px; cursor: nwse-resize; }

/* ==================== WIDGET CATALOG ==================== */

.t-catalog {
  position: fixed;
  top: 0; right: 0;
  width: 280px;
  height: 100vh;
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 20000;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
  color: #1e293b;
}
.t-catalog.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.t-catalog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid #e2e8f0;
}
.t-catalog-header h3 { font-size: 0.95rem; font-weight: 700; color: #1e293b; }

.t-catalog-close {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: none;
  background: transparent; border-radius: 6px;
  cursor: pointer; color: #64748b;
  transition: all 0.12s;
}
.t-catalog-close:hover { background: #f1f5f9; color: #1e293b; }

.t-catalog-body {
  flex: 1; overflow-y: auto; padding: 12px 16px;
}

.t-catalog-category { margin-bottom: 16px; }
.t-catalog-category-title {
  font-size: 0.68rem; font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.t-catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.t-catalog-item {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  padding: 12px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.15s;
  color: #334155;
}
.t-catalog-item:hover {
  border-color: #7c3aed;
  background: rgba(124,58,237,0.06);
}
.t-catalog-item.active {
  border-color: #22c55e;
  background: rgba(34,197,94,0.06);
}
.t-catalog-item-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9;
  border-radius: 10px; color: #64748b;
}
.t-catalog-item:hover .t-catalog-item-icon {
  background: rgba(124,58,237,0.1); color: #7c3aed;
}
.t-catalog-item.active .t-catalog-item-icon {
  background: rgba(34,197,94,0.1); color: #22c55e;
}
.t-catalog-item-label {
  font-size: 0.72rem; font-weight: 600;
  text-align: center; line-height: 1.2;
  color: #334155;
}
.t-catalog-hint {
  font-size: 0.72rem;
  color: #94a3b8;
  margin: 0 0 12px;
  line-height: 1.4;
}

/* ==================== COLOR LINKING ==================== */

.t-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.1);
  transition: all 0.12s;
  position: relative;
}
.t-color-dot:hover {
  transform: scale(1.3);
}
.t-color-dot[data-color="none"] { background: #cbd5e1; }
.t-color-dot[data-color="red"] { background: #ef4444; }
.t-color-dot[data-color="blue"] { background: #3b82f6; }
.t-color-dot[data-color="green"] { background: #22c55e; }
.t-color-dot[data-color="yellow"] { background: #eab308; }
.t-color-dot[data-color="purple"] { background: #8b5cf6; }
.t-color-dot[data-color="orange"] { background: #f97316; }

.t-color-picker {
  position: fixed;
  display: none;
  flex-direction: row;
  gap: 4px;
  padding: 6px 8px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 50000;
}
.t-color-picker.open {
  display: flex;
}
.t-color-picker-option {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.1s;
}
.t-color-picker-option:hover {
  transform: scale(1.2);
  border-color: #1e293b;
}
.t-color-picker-option.selected {
  border-color: #1e293b;
}
.t-color-picker-option[data-color="none"] { background: #cbd5e1; }
.t-color-picker-option[data-color="red"] { background: #ef4444; }
.t-color-picker-option[data-color="blue"] { background: #3b82f6; }
.t-color-picker-option[data-color="green"] { background: #22c55e; }
.t-color-picker-option[data-color="yellow"] { background: #eab308; }
.t-color-picker-option[data-color="purple"] { background: #8b5cf6; }
.t-color-picker-option[data-color="orange"] { background: #f97316; }

/* Dynamic widget placeholder */
.t-dyn-widget-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.85rem;
  text-align: center;
  padding: 16px;
}

/* Live status in header */
.header-right .live-status-modern {
  padding: 4px 10px;
  font-size: 0.72rem;
}

/* ==================== MODE BADGE ==================== */

.mode-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 10px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  white-space: nowrap;
}
.mode-badge.demo-mode {
  color: #16a34a;
  animation: pulseDemoMode 2s ease-in-out infinite;
}
.mode-badge.combat-mode {
  color: #dc2626;
  animation: pulseCombatMode 2s ease-in-out infinite;
}
@keyframes pulseDemoMode {
  0%, 100% { opacity: 1; box-shadow: 0 1px 6px rgba(22,163,74,0.12); }
  50% { opacity: 0.7; box-shadow: 0 1px 12px rgba(22,163,74,0.3); }
}
@keyframes pulseCombatMode {
  0%, 100% { opacity: 1; box-shadow: 0 1px 6px rgba(220,38,38,0.12); }
  50% { opacity: 0.7; box-shadow: 0 1px 12px rgba(220,38,38,0.35); }
}

/* Mode toggle buttons — wider for longer labels */
.mode-toggle .mode-btn {
  font-size: 0.7rem;
  padding: 4px 10px;
}

/* Tool dropdowns inside chart widget — render as fixed overlay */
#widget-chart .tool-dropdown-wrapper,
#widget-chart .trash-dropdown-wrapper {
  position: relative;
  z-index: 100;
}
#widget-chart .tool-dropdown,
#widget-chart .trash-dropdown {
  position: fixed !important;
  z-index: 55000;
  left: auto;
  top: auto;
  min-width: 180px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  border-radius: 10px;
}
#widget-chart .indicators-popup {
  z-index: 55000;
}

/* ==================== BODY STATES ==================== */

body.t-dragging { cursor: grabbing !important; user-select: none !important; }
body.t-dragging * { pointer-events: none !important; }
body.t-dragging .t-widget.dragging { pointer-events: auto !important; }

body.t-resizing-ew { cursor: ew-resize !important; user-select: none !important; }
body.t-resizing-ns { cursor: ns-resize !important; user-select: none !important; }
body.t-resizing-nwse { cursor: nwse-resize !important; user-select: none !important; }
body.t-resizing-ew *,
body.t-resizing-ns *,
body.t-resizing-nwse * { pointer-events: none !important; }

/* ==================== DYNAMIC CHART WIDGET ==================== */

.dyn-chart-toolbar {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  background: #1e222d;
  border-bottom: 1px solid rgba(42,46,57,0.5);
  flex-shrink: 0;
}

.dyn-interval-select {
  background: #2a2e39;
  color: #d1d4dc;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
}

.dyn-chart-container {
  background: #131722;
}

.t-dyn-widget-body {
  overflow: hidden !important;
}

/* Dynamic ticker popup — uses same classes as main popup (.modal-overlay, .ticker-popup-modern) */
#dyn-ticker-overlay {
  z-index: 60000;
}
