:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --line: #2a313b;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4c8dff;
  --buy: #ff5b5b;     /* 국내 관례: 매수 빨강 */
  --sell: #4c8dff;    /* 매도 파랑 */
  --ok: #2fbf71;
  --warn: #e6a700;
  --err: #ff5b5b;
  --radius: 8px;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; }
.brand span { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.status-row { display: flex; gap: 10px; align-items: center; flex: 1; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
.meta { color: var(--muted); font-size: 12px; }

.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.ok { background: rgba(47,191,113,.15); border-color: var(--ok); color: var(--ok); }
.pill.bad { background: rgba(255,91,91,.15); border-color: var(--err); color: var(--err); }
.pill.warn { background: rgba(230,167,0,.15); border-color: var(--warn); color: var(--warn); }

.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger-outline { border-color: var(--err); color: var(--err); background: transparent; }
.btn.kill { min-width: 150px; font-weight: 700; }
.btn.kill.on { background: var(--ok); border-color: var(--ok); color: #06210f; }
.btn.kill.off { background: var(--err); border-color: var(--err); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }

.banner { padding: 8px 20px; font-size: 13px; }
.banner.warn { background: rgba(230,167,0,.15); color: var(--warn); border-bottom: 1px solid var(--warn); }
.banner.error { background: rgba(255,91,91,.12); color: var(--err); border-bottom: 1px solid var(--err); }

main { padding: 16px 20px 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 20px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab { background: none; border: none; color: var(--muted); padding: 8px 14px; cursor: pointer; font-size: 14px;
  border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--panel-2); position: sticky; top: 0; }
.grid.compact th, .grid.compact td { padding: 5px 8px; font-size: 12px; }
.grid td.num, .grid th.num { text-align: right; }
.grid tbody tr:hover { background: rgba(76,141,255,.06); }
.grid tr.clickable { cursor: pointer; }
.grid tr.dim td { color: var(--muted); }
.grid tr.selected { background: rgba(76,141,255,.12); }
.grid td.wrap { white-space: normal; min-width: 280px; }
.buy { color: var(--buy); }
.sell { color: var(--sell); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.err-text { color: var(--err); }
.sub { color: var(--muted); font-size: 11px; display: block; }

.switch { position: relative; width: 38px; height: 20px; border-radius: 10px; background: var(--line); border: none;
  cursor: pointer; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: left .15s; }
.switch.on { background: var(--ok); }
.switch.on::after { left: 20px; }

.detail { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; }
.detail-head h3 { margin: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.notes { color: var(--warn); font-size: 12px; margin: 6px 0; }
h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }

.filters { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.filters label { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font-size: 13px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 0; width: min(1100px, 96vw); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
#cfg-form { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.dlg-head h3 { margin: 0; }
.dlg-body { padding: 14px 18px; overflow: auto; display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
fieldset label { display: flex; flex-direction: column; gap: 3px; margin-bottom: 9px; font-size: 12px; color: var(--muted); }
fieldset label input { color: var(--text); }
fieldset label small { color: var(--muted); font-size: 11px; }
fieldset label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.inline { display: flex; gap: 4px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
input.invalid { border-color: var(--err); }
.preview { grid-row: span 2; }
.ladder { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.ladder td.mid { text-align: center; color: var(--muted); font-size: 11px; background: var(--panel-2); }
.form-error { grid-column: 1 / -1; color: var(--err); background: rgba(255,91,91,.1); border: 1px solid var(--err);
  border-radius: 6px; padding: 8px 10px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 420px; }
.toast.error { border-color: var(--err); color: var(--err); }

@media (max-width: 900px) {
  .dlg-body, .form-grid, .detail-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- 공통 추가 */
a { color: var(--accent); }
.brand.plain { color: var(--text); text-decoration: none; }
.btn.big { padding: 11px 22px; font-size: 15px; }
a.btn { text-decoration: none; display: inline-block; }
.banner.info { background: rgba(76,141,255,.10); color: var(--accent); border-bottom: 1px solid var(--accent); }
.small { font-size: 12px; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; overflow-x: auto; }
pre code { background: none; border: none; padding: 0; }

/* 계정 메뉴 */
.usermenu { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); display: flex; flex-direction: column; }
.menu a, .menu button { background: none; border: none; color: var(--text); text-align: left; padding: 8px 10px;
  border-radius: 6px; font-size: 13px; cursor: pointer; text-decoration: none; }
.menu a:hover, .menu button:hover { background: var(--panel-2); }
.menu-who { padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; }

/* 작은 대화상자(계정·비밀번호) */
dialog.small-dlg { width: min(460px, 94vw); }
dialog.small-dlg form { display: flex; flex-direction: column; }
.dlg-body.single { display: flex; flex-direction: column; gap: 12px; }
.dlg-body.single label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.dlg-body.single label input, .dlg-body.single label select { color: var(--text); }
.dlg-body.single label small { font-size: 11px; }
.dlg-body.single label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
fieldset:disabled { opacity: .75; }

/* ---------------------------------------------------------------- 공개 페이지(랜딩·로그인·설명서) */
body.site { min-height: 100vh; display: flex; flex-direction: column; }
.site-nav { display: flex; align-items: center; justify-content: space-between; padding: 14px 28px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.site-nav nav { display: flex; gap: 16px; align-items: center; }
.site-nav nav a:not(.btn) { color: var(--muted); text-decoration: none; }
.site-nav nav a:not(.btn):hover { color: var(--text); }

.lead { color: var(--muted); font-size: 16px; line-height: 1.7; max-width: 680px; }
.site-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 28px; display: flex;
  justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 10px 12px; font-size: 15px; color: var(--text); }
.login-card .btn { width: 100%; }

.guide { display: grid; grid-template-columns: 230px 1fr; gap: 32px; max-width: 1180px; margin: 0 auto;
  padding: 28px; width: 100%; }
.toc { position: sticky; top: 76px; align-self: start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; font-size: 13px; }
.toc ol { padding-left: 18px; margin: 10px 0 0; line-height: 1.9; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); }
.doc { min-width: 0; line-height: 1.75; }
.doc h1 { margin-top: 0; font-size: 28px; }
.doc h2 { margin-top: 44px; padding-top: 8px; font-size: 20px; border-top: 1px solid var(--line); scroll-margin-top: 70px; }
.doc section:first-of-type h2 { border-top: none; }
.doc h3 { font-size: 15px; margin: 22px 0 6px; }
.doc ul, .doc ol { padding-left: 22px; }
.doc ol.steps li { margin-bottom: 8px; }
.doc-table { margin: 10px 0 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.doc-table td { white-space: normal; vertical-align: top; line-height: 1.55; }
.callout { background: rgba(76,141,255,.08); border: 1px solid rgba(76,141,255,.4); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 14px; margin: 14px 0; }
.callout.warn { background: rgba(230,167,0,.08); border-color: rgba(230,167,0,.45); border-left-color: var(--warn); }
.faq dt { font-weight: 600; margin-top: 16px; }
.faq dd { margin: 4px 0 0 0; color: var(--muted); }

@media (max-width: 860px) {
  .guide { grid-template-columns: 1fr; }
  .toc { position: static; }
  .site-nav { padding: 12px 16px; }
}

/* ---------------------------------------------------------------- 수동 주문 */
.manual-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.manual-form fieldset { display: flex; flex-direction: column; gap: 2px; }
.manual-form select, .manual-form input { width: 100%; }
.side-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.side-btn { padding: 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  font-weight: 700; cursor: pointer; }
.side-btn.buy.active { background: var(--buy); border-color: var(--buy); color: #fff; }
.side-btn.sell.active { background: var(--sell); border-color: var(--sell); color: #fff; }
.side-btn:disabled { opacity: .5; cursor: default; }
.btn.buy-bg { background: var(--buy); border-color: var(--buy); color: #fff; font-weight: 700; }
.btn.sell-bg { background: var(--sell); border-color: var(--sell); color: #fff; font-weight: 700; }
.m-quote { margin: -4px 0 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.m-quote button { background: none; border: none; padding: 0; cursor: pointer; font: inherit; }
.m-total { display: flex; justify-content: space-between; padding: 8px 0 10px; border-top: 1px solid var(--line); margin-top: 4px; }
.m-status { min-height: 18px; margin-top: 8px; white-space: normal; }
.m-status.ok { color: var(--ok); }
.m-status.bad { color: var(--err); }
.check-inline { flex-direction: row !important; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; border: 1px solid var(--line); }
.tag.manual { border-color: var(--warn); color: var(--warn); }
@media (max-width: 1000px) { .manual-grid { grid-template-columns: 1fr; } }
