:root {
  --bg-color: #0d1117;
  --card-bg: #161b22;
  --text-main: #c9d1d9;
  --border: #30363d;
  --green: #238636;
  --green-hover: #2ea043;
  --red: #da3633;
  --red-hover: #f85149;
  --orange: #d29922;
  --accent: #58a6ff;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace, sans-serif; 
}

body { 
  background: var(--bg-color); 
  color: var(--text-main); 
  padding: 12px; 
}

.container { 
  max-width: 1100px; 
  margin: 0 auto; 
}

/* Header & Quick Tickers */
.header { 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
  margin-bottom: 15px; 
}

.header h1 {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tag { 
  font-size: 11px; 
  background: var(--border); 
  padding: 3px 8px; 
  border-radius: 4px; 
  color: var(--accent); 
}

/* Horizontal scroll area for mobile quick-ticker buttons */
.quick-tickers { 
  display: flex; 
  gap: 8px; 
  overflow-x: auto; 
  padding-bottom: 6px; 
  -webkit-overflow-scrolling: touch;
}

.btn-quick { 
  background: var(--border); 
  border: none; 
  color: #fff; 
  padding: 8px 14px; 
  border-radius: 4px; 
  cursor: pointer; 
  white-space: nowrap;
  font-weight: 600;
  min-height: 38px;
}

.btn-quick.active { 
  background: var(--accent); 
  color: #000; 
}

/* Responsive Grid */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

@media (min-width: 768px) {
  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  /* Left column fixed-ish, right column flexible */
  .card.controls-panel { flex: 0 0 360px; }
  .card.chain-panel { flex: 1 1 520px; }
  .card.positions-panel { flex: 1 1 360px; }
  .card.orders-panel { flex: 1 1 360px; }
}

.card { 
  background: var(--card-bg); 
  border: 1px solid var(--border); 
  padding: 15px; 
  border-radius: 8px; 
}

.card { min-width: 260px; }
.card.dragging { opacity: 0.6; transform: scale(0.995); }

.drag-handle {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 20px;
  text-align: center;
  margin-right: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: grab;
  user-select: none;
  background: rgba(255,255,255,0.02);
}
.drag-handle:active { cursor: grabbing; }

.card h2 { 
  font-size: 15px; 
  margin-bottom: 12px; 
  border-bottom: 1px solid var(--border); 
  padding-bottom: 6px; 
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 10px;
  font-weight: 700;
}

.card-body { margin-top: 8px; }
.card.collapsed .card-body { display: none; }

/* Form Controls */
.form-group { 
  margin-bottom: 12px; 
  display: flex; 
  flex-direction: column; 
  gap: 6px; 
}

.checkbox-group { 
  flex-direction: row; 
  align-items: center; 
  justify-content: space-between; 
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

input[type="text"], 
input[type="number"] {
  background: #0d1117; 
  border: 1px solid var(--border); 
  color: #fff; 
  padding: 10px; 
  border-radius: 6px; 
  width: 100%;
  font-size: 16px; /* Prevents auto-zoom on iOS Safari */
}

.risk-controls {
  background: rgba(255, 255, 255, 0.02);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 10px;
}

.risk-controls .form-group input[type="number"] {
  width: 80px;
}

/* Execution Buttons */
.action-buttons { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 10px; 
  margin-top: 15px; 
}

.btn { 
  border: 1px solid rgba(88, 166, 255, 0.6); 
  background: linear-gradient(180deg, #1f6feb 0%, #0b5ed7 100%);
  padding: 14px; 
  border-radius: 6px; 
  font-weight: 700; 
  font-size: 15px;
  cursor: pointer; 
  color: #f3f8ff; 
  width: 100%; 
  min-height: 48px; /* High-speed touch target */
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(13, 110, 253, 0.18);
}

.btn:hover { filter: brightness(1.08); }

.btn-call { background: var(--green); border-color: rgba(35, 134, 54, 0.8); }
.btn-call:active { background: var(--green-hover); }

.btn-put { background: var(--red); border-color: rgba(218, 54, 51, 0.8); }
.btn-put:active { background: var(--red-hover); }

.btn-flatten { 
  background: linear-gradient(180deg, #f0b24b 0%, #d99b1f 100%); 
  border-color: rgba(210, 153, 34, 0.8);
  margin-top: 12px; 
  color: #1f1b12;
  font-size: 16px; 
}

.btn-scale,
.btn-cancel {
  background: rgba(13, 17, 23, 0.9);
  border: 1px solid var(--border);
  color: var(--text-main);
  box-shadow: none;
}

.scale-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
}

.scale-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scale-qty,
.scale-limit-price {
  width: 80px;
  min-width: 80px;
}

.scale-limit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-main);
}

.scale-limit-price:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Table Responsive Wrapper */
.positions-panel {
  /* allow horizontal scrolling when table is wider than viewport */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile-specific layout tweaks so action controls remain visible */
@media (max-width: 420px) {
  .card { padding: 10px; }
  .card { min-width: 100%; }

  /* Simplify tables into stacked cards per-row */
  .positions-table thead { display: none; }
  .positions-table tbody tr { display: block; margin-bottom: 10px; border-bottom: 1px solid var(--border); }
  .positions-table td { display: flex; justify-content: space-between; padding: 8px 6px; font-size: 14px; }
  .positions-table td:first-child { font-weight: 700; }

  /* Action cell stack: input and button share space */
  .positions-table td:last-child { display: flex; gap: 8px; }
  .positions-table .scale-qty { width: 48%; max-width: 120px; }
  .positions-table .btn-scale { width: 48%; min-width: 80px; }

  /* Reduce header font and button padding for small screens */
  .header h1 { font-size: 1rem; }
  .btn { padding: 10px; min-height: 44px; font-size: 14px; }
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.positions-table { 
  width: 100%; 
  border-collapse: collapse; 
  text-align: left; 
  min-width: 320px;
}

.positions-table th, 
.positions-table td { 
  padding: 10px 8px; 
  border-bottom: 1px solid var(--border); 
  font-size: 14px;
}

.chain-table tbody tr.chain-option-row {
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chain-table tbody tr.chain-option-row:hover {
  background: rgba(88, 166, 255, 0.08);
}

.chain-table tbody tr.chain-option-row.selected {
  background: rgba(88, 166, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(88, 166, 255, 0.8);
}

.empty { 
  text-align: center; 
  color: #8b949e; 
  padding: 20px 0;
}

/* Logs Console */
.logs-container { margin-top: 15px; }
.status-console { 
  background: #000; 
  border: 1px solid var(--border); 
  padding: 10px; 
  height: 110px; 
  overflow-y: auto; 
  color: #7ee787; 
  font-size: 12px; 
  border-radius: 6px;
  font-family: monospace;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.log-entry {
  background: rgba(88, 166, 255, 0.08);
  border-left: 2px solid var(--accent);
  color: #dfeeff;
  padding: 4px 8px;
  border-radius: 4px;
  width: 100%;
  word-break: break-word;
}

.log-entry.error {
  color: #ffd7d7;
  border-left-color: var(--red);
  background: rgba(218, 54, 51, 0.08);
}

.status-console .error { color: var(--red); }