:root {
  --bg: #0e1014;
  --panel: #161a21;
  --panel-2: #1c212b;
  --border: #2a303c;
  --text: #e9edf3;
  --muted: #98a2b3;
  --accent: #5b9cff;
  --up: #ff4d5e;
  --down: #3b82f6;
  --flat: #3a4150;
}

/* 한국식(상승 빨강/하락 파랑) 기본, 미국식은 body.scheme-us */
body.scheme-us {
  --up: #22c55e;
  --down: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "맑은 고딕", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}

button:hover { border-color: #3d4759; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }

.hidden { display: none !important; }

/* ---------- dashboard ---------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: .08em;
  font-size: 14px;
  white-space: nowrap;
}
.brand span {
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  margin-left: 8px;
  font-size: 12px;
}

.seg {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: #11141a;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
}
.seg button.active { background: var(--accent); color: #fff; }
.seg button:hover:not(.active) { background: #222836; color: var(--text); }

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  display: inline-block; background: #6b7280; margin-right: 5px;
}
.dot.open { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
.dot.pre { background: #f59e0b; }
.dot.closed { background: #6b7280; }

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: #11141a;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}
.legend-bar {
  height: 8px;
  flex: 0 0 220px;
  border-radius: 4px;
  border: 1px solid #00000044;
}
.legend-note { margin-left: auto; }

.board {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #0b0d11;
}

.group-label {
  position: absolute;
  overflow: hidden;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  color: #cfd6e3;
  padding: 2px 4px;
  pointer-events: none;
  text-overflow: ellipsis;
}
.group-label span { font-weight: 500; margin-left: 5px; }

.tile {
  position: absolute;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, .35);
  border-radius: 2px;
  padding: 5px 6px;
  color: #fff;
  transition: filter .12s ease;
  will-change: left, top, width, height;
}
.tile:hover { filter: brightness(1.14); z-index: 5; }
.tile-inner { height: 100%; overflow: hidden; }
.tile-name {
  font-weight: 700;
  font-size: 12px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.tile-code {
  font-size: 10px;
  opacity: .72;
  font-weight: 400;
  margin-left: 4px;
}
.tile-price {
  font-size: 12px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.tile-pct {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.tile-sub {
  font-size: 10px;
  opacity: .82;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  padding: 30px;
  line-height: 1.8;
}

.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: #0b0e13ee;
  border: 1px solid #3a4353;
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 210px;
  max-width: 300px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5);
  font-size: 12px;
  line-height: 1.6;
}
.tooltip b { font-size: 13px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .t-row span:first-child { color: var(--muted); }
.tooltip .t-sep { height: 1px; background: var(--border); margin: 6px 0; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 96vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(0,0,0,.45);
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }

.drawer-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-head .sub { color: var(--muted); font-size: 11px; margin-top: 3px; }
.drawer-close { margin-left: auto; }
.drawer-body { padding: 14px 16px; overflow: auto; }
.drawer-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin-bottom: 14px;
}
.stat .k { color: var(--muted); font-size: 10px; }
.stat .v { font-size: 14px; font-variant-numeric: tabular-nums; }
canvas { width: 100%; display: block; }
.chart-label { color: var(--muted); font-size: 11px; margin: 12px 0 4px; }

/* ---------- admin ---------- */
.admin {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px;
}
.admin-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-head h1 { font-size: 19px; margin: 0; }
.admin-head .spacer { flex: 1; }
.admin-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: #cdd5e3;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h3 .count { color: var(--muted); font-weight: 400; }

.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid transparent;
}
.cat-item:hover { background: var(--panel-2); }
.cat-item.active { background: #1b2433; border-color: #2f4a72; }
.cat-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .n { color: var(--muted); font-size: 11px; }
.cat-item button { padding: 2px 6px; font-size: 11px; background: transparent; border-color: transparent; color: var(--muted); }
.cat-item button:hover { color: var(--text); border-color: var(--border); }

.inline-form { display: flex; gap: 6px; margin-top: 10px; }
.inline-form input { flex: 1; }

input[type="text"], input[type="search"], select {
  background: #0f131a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }

.search-wrap { position: relative; }
.search-row { display: flex; gap: 8px; }
.search-row .search-wrap { flex: 1; }
.search-row input { width: 100%; }

.suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #171c25;
  border: 1px solid #394354;
  border-radius: 8px;
  box-shadow: 0 14px 30px rgba(0,0,0,.5);
  max-height: 330px;
  overflow: auto;
  z-index: 80;
}
.suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #232936;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover, .suggest-item.active { background: #222c3d; }
.suggest-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-item .mk { color: var(--muted); font-size: 10px; }
.code-badge {
  font-family: Consolas, "D2Coding", monospace;
  font-size: 11px;
  background: #0d1117;
  border: 1px solid #2d3646;
  border-radius: 4px;
  padding: 2px 5px;
  color: #9fc2ff;
  letter-spacing: .02em;
}
.suggest-empty { padding: 10px; color: var(--muted); font-size: 12px; }

.selected {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
}
.selected .chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #1d2736;
  border: 1px solid #33445c;
  border-radius: 20px;
  padding: 3px 10px 3px 6px;
  color: var(--text);
}
.selected .chip button { border: 0; background: transparent; padding: 0 2px; color: var(--muted); }

.table-wrap { overflow: auto; }
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.grid th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid td {
  padding: 7px 8px;
  border-bottom: 1px solid #202632;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.grid tr:hover td { background: #191e27; }
table.grid .right { text-align: right; }
table.grid .muted { color: var(--muted); }
table.grid select { padding: 3px 5px; font-size: 11px; }
table.grid .row-actions { display: flex; gap: 4px; }
table.grid .row-actions button { padding: 3px 6px; font-size: 11px; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  background: #10141b;
  border: 1px solid #394354;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 420px;
  box-shadow: 0 14px 34px rgba(0,0,0,.5);
  font-size: 12px;
  line-height: 1.5;
  animation: toastIn .16s ease-out;
}
.toast.err { border-left-color: #ef4444; }
.toast.ok { border-left-color: #22c55e; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid #ffffff44;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}
.mono { font-family: Consolas, "D2Coding", monospace; }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .status { width: 100%; margin-left: 0; }
  .legend-note { display: none; }
}
