:root {
  --bg: #0c1220;
  --bg-soft: #131d33;
  --text: #d5e2ff;
  --muted: #93a8d4;
  --line: #263455;
  --blue: #1871e8;
  --red: #d94a5c;
  --green: #2fa66a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Noto Sans KR", "Segoe UI", sans-serif; font-size: 14px; line-height: 1.45; background: var(--bg); color: var(--text); }
a { color: var(--text); text-decoration: none; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; background: #0a0f1c; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: 0.3px; font-size: 15px; }
.nav { display: flex; align-items: center; gap: 10px; }
.container { max-width: 1200px; margin: 16px auto; padding: 0 12px; }
.card { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.card h2, .card h3 { margin-top: 0; margin-bottom: 10px; font-size: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; font-size: 13px; }
.col-id { width: 52px; }
.col-email { width: 220px; }
.col-character { width: 130px; }
.col-balance { width: 150px; }
.col-position { width: 72px; }
.col-pnl { width: 110px; }
.col-action { width: 72px; }
.col-manage { width: 210px; }
.action-col,
.manage-col { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.inline-form { display: flex; gap: 8px; }
input, select, textarea { width: 100%; background: #0f1729; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.btn { border: 1px solid var(--line); background: #1a2542; color: var(--text); border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.manage-col .row-btns { width: 100%; justify-content: flex-start; flex-wrap: nowrap; }
.badge { padding: 3px 7px; border-radius: 8px; font-size: 12px; border: 1px solid var(--line); }
.badge.running, .badge.ok { background: rgba(47,166,106,.2); color: #6be09e; }
.badge.error { background: rgba(217,74,92,.2); color: #ff8998; }
.badge.stopped { background: rgba(147,168,212,.2); color: #bdd0ff; }
.status-line { display: flex; gap: 8px; align-items: center; margin-top: 8px; margin-bottom: 8px; }
.logs { margin: 8px 0 0; background: #0a1120; border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: #99b3e7; font-size: 12px; max-height: 190px; overflow: auto; }
.login-page { min-height: 100vh; display: flex; justify-content: center; align-items: center; }
.login-card { width: 360px; }
.error { background: rgba(217,74,92,.25); color: #ff93a1; border: 1px solid #8d3140; border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; margin-top: 10px; }
.feed-state-desc { color: var(--muted); margin-left: 6px; font-size: 13px; }
.json-help-link { color: #8fc0ff; cursor: pointer; font-size: 12px; margin-left: 8px; text-decoration: underline; }
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.drawer-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 950; }
.drawer-backdrop.open { display: block; }
.side-drawer { position: fixed; top: 0; right: 0; width: min(460px, 92vw); height: 100vh; background: #10192c; border-left: 1px solid var(--line); z-index: 960; transition: transform 0.2s ease; transform: translateX(100%); padding: 16px; display: flex; flex-direction: column; }
.side-drawer.open { transform: translateX(0); }
.side-drawer.wide { width: min(760px, 96vw); }
.drawer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 100%;
  cursor: ew-resize;
  z-index: 2;
  background: linear-gradient(90deg, rgba(143, 192, 255, 0.18), rgba(143, 192, 255, 0.04));
}
.drawer-resize-handle::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 88px;
  border-radius: 999px;
  background: rgba(191, 224, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(12, 18, 32, 0.4), 0 0 14px rgba(143, 192, 255, 0.35);
}
.drawer-resize-handle:hover {
  background: linear-gradient(90deg, rgba(143, 192, 255, 0.26), rgba(143, 192, 255, 0.08));
}
body.drawer-resizing {
  user-select: none;
  cursor: ew-resize;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.drawer-logs { flex: 1; min-height: 0; max-height: none !important; height: 100% !important; margin-top: 0; overflow: auto; }
.drawer-frame { width: 100%; height: calc(100vh - 78px); border: 0; background: #0f1729; border-radius: 10px; }
.modal-card { width: min(760px, 100%); max-height: 85vh; overflow: auto; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.json-help-list { display: grid; gap: 10px; }
.json-help-item { background: #0f1729; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.json-help-key { color: #8fc0ff; font-family: monospace; font-size: 13px; margin-bottom: 4px; }
.json-help-rec { color: #bfe08b; margin-top: 6px; font-size: 13px; }
.checkline { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.checkline input { width: auto; }
/* 액션 버튼 */
.btn-form { display: inline; margin: 0; }
.btn-action {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #0f1729;
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-action:hover { background: #12203a; }

/* ▶ 시작 버튼 */
.play-btn { color: #6be09e; border-color: #2fa66a; }
.play-btn:hover { background: rgba(47,166,106,.2); }

/* ■ 정지 버튼 — 무지개 스피닝 (이지모드 방식) */
@keyframes rainbow-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.stop-btn {
  color: #fff;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #0f1729;
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.stop-btn::before {
  content: "";
  position: absolute;
  inset: -220%;
  background: conic-gradient(#ff6b6b, #fbbf24, #34d399, #60a5fa, #a78bfa, #ff6b6b);
  animation: rainbow-spin 2.2s linear infinite;
  opacity: 0.75;
  z-index: -2;
}
.stop-btn::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 8px;
  background: #0f1729;
  z-index: -1;
}
.stop-btn > * { position: relative; }
.stop-btn:hover { filter: brightness(1.15); }

/* ⏹ 중지시도 버튼 — 스패닝 없이 흐리게 */
.stopping-btn {
  color: #f0a040;
  border-color: #a06010;
  background: #1a1200;
  opacity: 0.7;
  cursor: not-allowed;
}
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .table { font-size: 13px; }
}

/* ═══════════════════════════════════════
   Mobile Responsive  (≤ 768px)
   ═══════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Base ── */
  body { font-size: 13px; }

  /* ── Topbar ── */
  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand { font-size: 14px; }
  .nav { gap: 6px; }
  .nav .btn { padding: 5px 8px; font-size: 12px; }

  /* ── Container ── */
  .container {
    margin: 10px auto;
    padding: 0 10px;
  }

  /* ── Cards ── */
  .card {
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 10px;
  }
  .card h2, .card h3 { font-size: 14px; }

  /* ── Grid ── */
  .grid2 { gap: 10px; }

  /* ── Section head ── */
  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* ── Table: horizontal scroll + compact cells ── */
  .card:has(.table) {
    padding: 12px 0;
    overflow: hidden;
  }
  .card:has(.table) .section-head {
    padding: 0 12px;
  }
  .card:has(.table) > .table,
  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12px;
  }
  .table th, .table td {
    padding: 7px 8px;
    font-size: 11px;
    white-space: nowrap;
  }
  /* 모바일에서 fixed 컬럼 너비 해제 */
  .col-id { width: 36px; }
  .col-email { width: auto; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
  .col-character { width: auto; }
  .col-balance { width: auto; }
  .col-position { width: 50px; }
  .col-pnl { width: auto; }
  .col-action { width: 44px; }
  .col-manage { width: auto; }

  /* ── Row buttons compact ── */
  .row-btns {
    gap: 4px;
    flex-wrap: nowrap;
  }
  .manage-col .row-btns .btn.small {
    padding: 4px 6px;
    font-size: 11px;
  }

  /* ── Action buttons ── */
  .btn-action {
    width: 32px;
    height: 32px;
    font-size: 12px;
    border-radius: 8px;
  }
  .right-actions .row-btns {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* ── Inline form ── */
  .inline-form {
    flex-direction: column;
    gap: 8px;
  }
  .inline-form .btn { width: 100%; }

  /* ── Status line ── */
  .status-line {
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
  }

  /* ── Buttons ── */
  .btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
  }
  .btn.small { padding: 4px 8px; font-size: 11px; }

  /* ── Inputs ── */
  input, select, textarea {
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 8px;
  }

  /* ── Logs ── */
  .logs {
    font-size: 11px;
    padding: 8px;
    max-height: 160px;
    border-radius: 8px;
  }

  /* ── Drawers: full width ── */
  .side-drawer {
    width: 100vw !important;
    padding: 12px;
    border-radius: 0;
  }
  .drawer-resize-handle { display: none; }
  .drawer-head {
    margin-bottom: 8px;
  }
  .drawer-logs {
    font-size: 11px;
  }
  .drawer-frame {
    height: calc(100vh - 60px);
    border-radius: 8px;
  }

  /* ── Modal ── */
  .modal-card {
    width: calc(100vw - 24px);
    padding: 16px;
    border-radius: 12px;
    max-height: 80vh;
  }

  /* ── Login ── */
  .login-card {
    width: calc(100vw - 32px);
    max-width: 360px;
    padding: 20px;
  }

  /* ── Error ── */
  .error {
    font-size: 12px;
    padding: 8px;
    border-radius: 6px;
  }

  /* ── Badges ── */
  .badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 6px;
  }

  /* ── Muted ── */
  .muted { font-size: 12px; }
  .feed-state-desc { font-size: 12px; }
}

/* ── LP Mode Toggle ── */
.lp-mode-toggle {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #263455;
}
.mode-btn {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-btn:hover {
  background: rgba(24, 113, 232, 0.1);
  color: #fff;
}
.mode-btn.active {
  background: var(--blue);
  color: #fff;
}
.mode-btn.active[data-mode="v2"] {
  background: linear-gradient(135deg, #22c55e, #3b82f6);
}

/* ── Ultra-small (≤ 480px) ── */
@media (max-width: 480px) {
  .topbar {
    padding: 8px 10px;
  }
  .container {
    padding: 0 8px;
  }
  .table th, .table td {
    padding: 6px;
    font-size: 10px;
  }
  .manage-col .row-btns .btn.small {
    padding: 3px 5px;
    font-size: 10px;
  }
}
