:root {
  --bg: #0b0e11;
  --panel: #161a1e;
  --panel2: #1e2329;
  --line: #2b3139;
  --text: #eaecef;
  --muted: #848e9c;
  --green: #0ecb81;
  --red: #f6465d;
  --yellow: #f0b90b;
  --blue: #7b8cff;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif; }
code { background: var(--panel2); padding: 1px 4px; border-radius: 4px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.g { color: var(--green); } .r { color: var(--red); }
.spacer { flex: 1; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 15px; color: var(--yellow); }
.badge { padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: #2a3a2f; color: var(--green); letter-spacing: .5px; }
.badge.demo { background: #2b2d4a; color: var(--blue); }
.badge.mainnet { background: #4a1d24; color: #ff8a98; animation: pulse 2s infinite; }
.badge.muted { background: var(--panel2); color: var(--muted); }
.badge.ok { background: #233528; color: var(--green); }
@keyframes pulse { 50% { opacity: .6; } }
.feed { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); }

/* buttons & inputs */
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: #474d57; }
.btn.primary { background: var(--yellow); color: #181a20; border-color: var(--yellow); font-weight: 700; }
.btn.danger { background: #3a1a20; color: #ff8a98; border-color: #5a2530; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--yellow); }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--yellow); }
input[type=range] { padding: 0; border: none; background: transparent; accent-color: var(--c, var(--yellow)); width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.row { display: flex; gap: 6px; } .row > input { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; padding: 12px; }
.left { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.right { padding: 14px; align-self: start; position: sticky; top: 60px; max-height: calc(100vh - 72px); overflow: auto; }
.right h3 { margin: 0 0 10px; font-size: 14px; }
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 8px; }
  .right { position: static; max-height: none; }
}

.symbolbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.symbolbar #inpSymbol { width: 130px; font-weight: 700; text-transform: uppercase; }
.pricebox { display: flex; align-items: baseline; gap: 8px; margin-left: 6px; }
.price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chg { font-weight: 600; }
.up { color: var(--green); } .down { color: var(--red); }
.chartcard { position: relative; padding: 0; overflow: hidden; }
#chart { height: 460px; }
.chart-hint { position: absolute; left: 10px; top: 8px; color: var(--muted); background: rgba(11, 14, 17, .7); padding: 2px 8px; border-radius: 4px; pointer-events: none; z-index: 3; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: none; color: var(--muted); padding: 9px 12px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--yellow); }
.tabs.small button { padding: 7px 9px; font-size: 12px; }
.tabpane { display: none; padding: 10px 12px; }
.tabpane.active { display: block; }
.toolbar { display: flex; gap: 6px; margin-bottom: 8px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td .btn { margin-right: 4px; }
.status { padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.status.running { background: #233528; color: var(--green); }
.status.stopped { background: var(--panel2); color: var(--muted); }
.status.done { background: #26304a; color: var(--blue); }
.status.error { background: #4a1d24; color: #ff8a98; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel2); color: var(--muted); }
.tag.live { background: #4a1d24; color: #ff8a98; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.details td { background: #12161a; white-space: normal; }

/* strategy form */
.desc { color: var(--muted); font-size: 12px; margin: 8px 0 10px; }
.sform, .common { display: flex; flex-direction: column; gap: 10px; }
.common { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; background: var(--panel2); color: var(--muted); border: none; padding: 7px 6px; cursor: pointer; font: inherit; font-size: 12px; }
.seg button.active { background: #2b3139; color: var(--text); font-weight: 700; }
.seg button.buy.active { background: rgba(14, 203, 129, .18); color: var(--green); }
.seg button.sell.active { background: rgba(246, 70, 93, .18); color: var(--red); }

.linectl { border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.linectl .head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.linectl .head b { color: var(--c); font-size: 12px; }
.linectl .pct { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.linectl .vals { display: flex; gap: 6px; }
.linectl .vals input[type=number] { flex: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.linectl.off { opacity: .55; }

.preview { background: var(--panel2); border-radius: 6px; padding: 8px 10px; font-size: 12px; line-height: 1.7; }
.preview .warn { color: var(--yellow); }
.preview .err { color: var(--red); }
.bt-row, .actions { display: flex; gap: 6px; align-items: center; }
.actions .btn.primary { flex: 1; }
.sliderange { display: flex; align-items: center; gap: 6px; }
.sliderange select { padding: 2px 4px; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; max-width: 900px; }
.grid-form .full { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.grid-form .seg { grid-column: 1 / -1; max-width: 420px; }

/* backtest */
#btSummary .kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 10px; }
.kpi { background: var(--panel2); border-radius: 6px; padding: 8px 10px; }
.kpi .k { color: var(--muted); font-size: 11px; }
.kpi .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
#btChart { height: 200px; margin-bottom: 10px; }

/* logs */
.logs { max-height: 340px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.logs div { padding: 2px 0; border-bottom: 1px dashed #1f252b; white-space: pre-wrap; }
.logs .trade { color: var(--yellow); }
.logs .error { color: #ff8a98; }
.logs .warn { color: #f8d12f; }
.logs time { color: var(--muted); margin-right: 8px; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: min(560px, calc(100vw - 32px)); padding: 18px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog h3 { margin: 0 0 4px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; display: flex; flex-direction: column; gap: 8px; }
legend { color: var(--muted); font-size: 12px; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--yellow); padding: 10px 12px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); animation: in .2s; }
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes in { from { transform: translateY(10px); opacity: 0; } }

body.is-spot .linear-only { display: none !important; }
body:not(.is-linear) .limit-only.hide-market { display: none; }
a { color: var(--yellow); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ───────── 확인 레이어 (기본 confirm 대체) ───────── */
dialog.ask { width: min(420px, calc(100vw - 32px)); padding: 22px 22px 18px; border-radius: 14px; border: 1px solid var(--line); background: #1a1f25; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); animation: askIn .16s ease-out; }
dialog.ask::backdrop { background: rgba(5, 7, 9, .62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fadeIn .16s ease-out; }
dialog.ask.closing { animation: askOut .12s ease-in forwards; }
dialog.ask.closing::backdrop { opacity: 0; transition: opacity .12s; }
@keyframes askIn { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes askOut { to { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes fadeIn { from { opacity: 0; } }
.ask-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ask-head h3 { margin: 0; font-size: 16px; }
.ask-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; flex: none; background: rgba(240, 185, 11, .14); color: var(--yellow); }
.ask.danger .ask-icon, .ask.sell .ask-icon { background: rgba(246, 70, 93, .14); color: var(--red); }
.ask.buy .ask-icon { background: rgba(14, 203, 129, .14); color: var(--green); }
.ask.primary .ask-icon { background: rgba(123, 140, 255, .14); color: var(--blue); }
.ask-msg { margin: 0 0 12px; color: #c4cad3; line-height: 1.6; font-size: 13.5px; }
.ask-details { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 14px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.ask-details dt { color: var(--muted); }
.ask-details dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-all; }
.ask-check { margin: 0 0 14px; font-size: 13px; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.ask-actions .btn { min-width: 88px; height: 38px; font-weight: 600; }
.btn.danger-solid { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.btn.buy-solid { background: var(--green); border-color: var(--green); color: #0b0e11; font-weight: 700; }
.btn.danger-solid:hover, .btn.buy-solid:hover { filter: brightness(1.08); }

/* ───────── 휴대폰 ───────── */
@media (max-width: 600px) {
  .topbar { gap: 6px 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { font-size: 14px; }
  .topbar .btn { padding: 5px 9px; font-size: 12px; }
  #keyBadge, #userName, #runCount { display: none; }
  .feed span { display: none; }
  .symbolbar { gap: 8px; padding: 8px 10px; }
  .symbolbar #inpSymbol { width: 110px; }
  .price { font-size: 18px; }
  #chart { height: 340px; }
  .chart-hint { display: none; }
  .layout { gap: 8px; }
  .tabs button { padding: 9px 10px; }
  dialog { padding: 16px; }
}
@media (display-mode: standalone) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}
