*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0f0f;
  --bg2: #111a1a;
  --bg3: #162020;
  --bg4: #1c2828;
  --border: #1e3030;
  --accent: #e8352e;
  --accent2: #c0392b;
  --up: #e8352e;
  --down: #2563eb;
  --text: #e8f0f0;
  --muted: #5a7a7a;
  --muted2: #8aabab;
  --gold: #f59e0b;
  --radius: 8px;
}

body {
  font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ── HEADER ── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 24px;
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-text { font-size: 18px; font-weight: 700; color: #fff; white-space: nowrap; }
.logo-sub { font-size: 11px; color: var(--muted2); white-space: nowrap; }

.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  gap: 8px;
  max-width: 560px;
}
.search-wrap input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 9px 14px;
  outline: none;
  font-family: inherit;
  transition: border-color .2s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap input::placeholder { color: var(--muted); }
.search-wrap button {
  padding: 9px 18px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: opacity .15s;
}
.search-wrap button:hover { opacity: .85; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 70px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
.search-dropdown.hidden { display: none; }
.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg4); }
.search-item .sym { font-weight: 700; color: var(--accent); min-width: 80px; font-size: 13px; }
.search-item .sname { color: var(--muted2); font-size: 13px; flex: 1; }
.search-item .sexch { font-size: 11px; color: var(--muted); }

.mode-toggle { display: flex; gap: 4px; flex-shrink: 0; }
.mode-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted2);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: all .2s;
}
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-btn[data-mode="gold"].active { background: var(--gold); border-color: var(--gold); color: #000; }

.rate-badge {
  font-size: 12px;
  color: var(--muted2);
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 20px;
}

/* ── GOLD BAR ── */
.gold-bar {
  background: linear-gradient(90deg, #1a1400, #1e1a00);
  border-bottom: 1px solid #3a2d00;
  padding: 7px 24px;
  font-size: 12px;
  color: var(--gold);
}
.gold-bar .gb-label { opacity: .8; }
.gold-info {
  font-size: 12px;
  color: var(--gold);
  white-space: nowrap;
}

/* ── MARKET BAR ── */
.market-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  overflow-x: auto;
  scrollbar-width: none;
}
.market-bar::-webkit-scrollbar { display: none; }
.market-bar-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  height: 54px;
  align-items: center;
}
.market-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 24px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  height: 100%;
  justify-content: center;
  flex-shrink: 0;
}
.market-card:first-child { padding-left: 0; }
.market-card:hover { background: var(--bg3); }
.market-card .mc-name { font-size: 11px; color: var(--muted); font-weight: 600; }
.market-card .mc-price { font-size: 15px; font-weight: 700; color: var(--text); }
.market-card .mc-change { font-size: 11px; }
.mc-change.up { color: var(--up); }
.mc-change.down { color: var(--down); }
.mc-change.neutral { color: var(--muted2); }
.market-loading { color: var(--muted); font-size: 13px; padding: 16px 0; }

/* ── MAIN ── */
main {
  flex: 1;
  display: flex;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 24px;
  gap: 20px;
  align-items: flex-start;
}

/* ── LEFT PANEL ── */
.left-panel {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 6px 18px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted2);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: all .15s;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.panel-hint { font-size: 11px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.stocks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.stocks-table thead th {
  padding: 10px 14px;
  text-align: right;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg3);
}
.stocks-table thead th.col-name,
.stocks-table thead th.col-code { text-align: left; }
.stocks-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.stocks-table tbody tr:last-child { border-bottom: none; }
.stocks-table tbody tr:hover { background: var(--bg4); }
.stocks-table tbody tr.selected { background: rgba(232,53,46,.12); }
.stocks-table td { padding: 11px 14px; text-align: right; white-space: nowrap; }
.stocks-table td.col-name,
.stocks-table td.col-code { text-align: left; }

.stock-name-wrap { display: flex; flex-direction: column; gap: 2px; }
.stock-sym { font-weight: 700; font-size: 13px; }
.stock-fullname { font-size: 11px; color: var(--muted); }
.col-code { color: var(--muted2); font-size: 12px; }
.col-price { font-weight: 700; font-size: 14px; }
.col-gold { font-weight: 700; font-size: 13px; color: var(--gold); }

.up { color: var(--up); }
.down { color: var(--down); }
.neutral { color: var(--muted2); }

.loading-row { text-align: center; padding: 40px; color: var(--muted); }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RIGHT PANEL ── */
.right-panel {
  width: 420px;
  flex-shrink: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 520px;
}
.detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 520px;
  color: var(--muted);
  gap: 16px;
}
.placeholder-icon { font-size: 48px; opacity: .4; }
.detail-placeholder p { text-align: center; line-height: 1.8; }

/* Detail */
.detail-content { padding: 20px; }
.detail-header { margin-bottom: 12px; }
.detail-sym { font-size: 20px; font-weight: 800; }
.detail-code { font-size: 12px; color: var(--muted2); margin-top: 2px; }

.price-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
.pb-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.pb-price { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.pb-change { font-size: 14px; margin-top: 6px; font-weight: 600; }
.pb-usd { font-size: 12px; color: var(--muted2); margin-top: 4px; }
.gold-block { border-color: #3a2d00; background: linear-gradient(135deg, #1a1500, #1e1a00); }
.gold-val { color: var(--gold) !important; }

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
  font-size: 12px;
}
.meta-item { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.mi-label { color: var(--muted); margin-bottom: 4px; }
.mi-value { font-weight: 700; font-size: 13px; }

.chart-wrap {
  margin-top: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.chart-title { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.range-btns { display: flex; gap: 4px; margin-bottom: 10px; }
.range-btn {
  padding: 3px 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted2);
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  transition: all .15s;
}
.range-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-wrap canvas { max-height: 180px; }

/* ── FOOTER ── */
footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  gap: 24px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}

/* ── RESPONSIVE ── */
@media (max-width: 1000px) {
  main { flex-direction: column; }
  .right-panel { width: 100%; }
}
@media (max-width: 640px) {
  .logo-sub, .rate-badge { display: none; }
  main { padding: 12px; }
}
