:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #182033;
  --line: #243049;
  --text: #e6ebf5;
  --muted: #8a96ad;
  --accent: #4f8cff;
  /* 한국 관례: 상승 빨강, 하락 파랑 */
  --up: #f04452;
  --down: #3485fa;
  --warn: #f5a524;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 'Noto Sans KR', system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--up); min-height: 1.2em; margin: 0; }
.danger { color: var(--up); }
.up { color: var(--up); }
.down { color: var(--down); }
.r { text-align: right; }
h2 { font-size: 15px; margin: 8px 0 0; }

.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 9px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { border-color: var(--up); color: var(--up); background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

input, select { width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text); padding: 9px 11px; border-radius: 8px; font: inherit; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

/* 로그인 */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0; }

/* 상단 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 56px; background: rgba(11,15,23,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none; }
nav a:hover { color: var(--text); }
nav a.active { color: var(--text); background: var(--panel-2); }
.me { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.live { color: #fff; background: var(--up); border-color: var(--up); }
.badge.mock { color: var(--warn); border-color: var(--warn); }

main { max-width: 1240px; margin: 0 auto; padding: 20px; }
.panel { display: none; flex-direction: column; gap: 16px; }
.panel.active { display: flex; }

/* 자산 */
.summary { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.big .value { font-size: 26px; }
.stat .sub { font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--panel-2); }
.bar span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-align: left; }
.table th.r { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: var(--panel-2); }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 5px; background: var(--panel-2); color: var(--muted); }
.tag.KR { color: #7dd3a8; } .tag.US { color: #8ab4ff; } .tag.CRYPTO { color: #f5c26b; }
.notice { background: rgba(245,165,36,.08); border: 1px solid rgba(245,165,36,.35); color: var(--warn); padding: 10px 14px; border-radius: 8px; font-size: 13px; }

/* 뷰어 */
.viewer-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 240px; }
.search-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-height: 320px; overflow-y: auto; }
.search-results div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.search-results div:hover, .search-results div.sel { background: var(--panel-2); }
.quote-box { text-align: right; }
.v-name { font-weight: 700; font-size: 16px; }
.v-price { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.star { background: none; border: 0; color: var(--warn); font-size: 18px; cursor: pointer; padding: 0 4px; }
.viewer-body { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
.chart { height: 480px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.order { display: flex; flex-direction: column; gap: 12px; align-self: start; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 8px; border-radius: 6px; cursor: pointer; font: inherit; }
.seg button.active.buy { background: var(--up); color: #fff; }
.seg button.active.sell { background: var(--down); color: #fff; }
#orderBtn.sell { background: var(--down); border-color: var(--down); }
#orderBtn.buy { background: var(--up); border-color: var(--up); }

/* 설정·사용자 */
.form-grid { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.modes { display: grid; gap: 8px; }
.modes label { flex-direction: row; align-items: center; gap: 10px; color: var(--text); background: var(--bg); border: 1px solid var(--line); padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.modes input { width: auto; }
.modes span { margin-left: auto; text-align: right; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 10px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-body h3 { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-variant-numeric: tabular-nums; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }

@media (max-width: 900px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .stat.big { grid-column: 1 / -1; }
  .viewer-body { grid-template-columns: 1fr; }
  .chart { height: 360px; }
  .inline-form { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .top { gap: 10px; padding: 0 12px; height: auto; flex-wrap: wrap; padding-top: 8px; }
  nav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
  .me { margin-left: auto; }
  .quote-box { text-align: left; }
}
