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

:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1f2937;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --gold: #f59e0b;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,0.08);
  --up: #34d399;
  --down: #f87171;
}

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── AUTH LOADING ── */
#auth-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 999;
  font-size: 14px;
  color: var(--muted);
}

/* ── SPINNER ── */
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(99,102,241,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading-spinner.small { width: 22px; height: 22px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── NAV ── */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 40px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,26,0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.logo span { color: var(--accent-light); }

.nav-right { display: flex; align-items: center; gap: 16px; }

.nav-email {
  font-size: 13px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-logout:hover { border-color: rgba(255,255,255,0.2); color: var(--text); }

/* ── MAIN ── */
main {
  padding: 24px 40px 40px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ── STATUS BAR ── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.exchange-status {
  font-weight: 500;
  color: var(--muted);
  transition: color .3s;
}
.exchange-status.connected    { color: var(--up); }
.exchange-status.disconnected { color: var(--down); }

.coin-count-badge {
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.3);
  color: var(--accent-light);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.status-center {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

#last-update { color: var(--muted); font-size: 12px; }

/* ── CONTROLS BAR ── */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 260px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  pointer-events: none;
  line-height: 1;
}

#coin-search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px 8px 32px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
#coin-search::placeholder { color: var(--muted); opacity: .6; }
#coin-search:focus { border-color: var(--accent); }

.btn-neg-filter {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  letter-spacing: .2px;
}
.btn-neg-filter:hover { border-color: rgba(255,255,255,0.2); color: var(--text); }
.btn-neg-filter.active {
  background: rgba(248,113,113,0.12);
  border-color: rgba(248,113,113,0.45);
  color: var(--down);
}

/* ── TABLE WRAPPER ── */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  overflow-x: auto;
}

#table-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 20px;
  color: var(--muted);
  font-size: 13px;
}

#table-placeholder.error { color: var(--down); }

/* ── TABLE ── */
#price-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

thead tr {
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

th {
  padding: 13px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  white-space: nowrap;
}

th.th-coin    { text-align: left; min-width: 110px; padding-left: 20px; }
th.th-price   { text-align: right; min-width: 150px; }
th.th-fee     { text-align: right; min-width: 120px; }
th.th-premium { text-align: right; min-width: 130px; }
th.sortable   { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
#sort-arrow   { font-size: 12px; margin-left: 4px; }
th.th-vol     { text-align: right; min-width: 130px; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }

td {
  padding: 11px 14px;
  font-size: 13px;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── COIN CELL ── */
.coin-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 6px;
  width: 100%;
}

.coin-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-light);
  flex-shrink: 0;
  letter-spacing: -.5px;
}

.coin-symbol {
  font-weight: 600;
  font-size: 14px;
}

/* ── PRICE / CHANGE / PREMIUM CELLS ── */
td.price-bithumb,
td.price-binance,
td.price-binance-krw,
td.premium,
td.change {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.price-bithumb    { font-weight: 500; }
td.price-binance    { color: var(--muted); }
td.price-binance-krw { color: var(--muted); }

td.premium          { font-weight: 700; font-size: 13px; }
td.premium.pos      { color: var(--up); }
td.premium.neg      { color: var(--down); }
td.premium.neutral  { color: var(--muted); }

td.change           { font-size: 12px; font-weight: 500; }
td.change.up        { color: var(--up); }
td.change.down      { color: var(--down); }
td.change.flat      { color: var(--muted); }

td.fee-bithumb {
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}
td.fee-bithumb.fee-rate { color: var(--accent-light); }
td.fee-bithumb.fee-none { color: var(--muted); }

td.vol-bithumb,
td.vol-binance      { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ── COIN CELL EXPAND ARROW ── */
.expand-arrow {
  margin-left: auto;
  font-size: 16px;
  color: var(--muted);
  transition: transform .2s, color .2s;
  line-height: 1;
  padding-left: 6px;
}

tr.main-row { cursor: pointer; }
tr.main-row:hover .expand-arrow { color: var(--accent-light); }
tr.main-row.open .expand-arrow  { transform: rotate(90deg); color: var(--accent-light); }

/* ── EXPAND ROW ── */
tr.expand-row td {
  padding: 0 20px 16px;
  background: rgba(255,255,255,0.015);
}

/* 2-컬럼 그리드: 빗썸 | 구분선 | 바이낸스 */
.di-grid {
  display: grid;
  grid-template-columns: 200px 1px 1fr;
  gap: 0 24px;
  padding: 14px 6px 6px;
  border-top: 1px solid var(--border);
}

.di-vline {
  background: var(--border);
  width: 1px;
}

/* 각 거래소 섹션 */
.di-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.di-section-head {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.di-ex-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .6px;
  min-width: 52px;
}

.di-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
}
.di-status.ok  { color: var(--up);   background: rgba(52,211,153,0.12); }
.di-status.off { color: var(--down); background: rgba(248,113,113,0.12); }

/* 네트워크 레이블 */
.di-net-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0;
}
.di-net-count {
  color: var(--accent-light);
  font-weight: 700;
}

/* 네트워크 태그 그리드 — 각 태그를 개별로 줄바꿈 허용 */
.di-net-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.di-net {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid;
  letter-spacing: .3px;
  white-space: nowrap;
}
.di-net.ok {
  color: var(--accent-light);
  border-color: rgba(129,140,248,0.35);
  background: rgba(99,102,241,0.1);
}
.di-net.off {
  color: var(--muted);
  border-color: var(--border);
  background: transparent;
  text-decoration: line-through;
  opacity: .55;
}

.di-no-net {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
  font-style: italic;
}

.di-loading {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 0;
  display: block;
}

/* ── FLASH ANIMATIONS ── */
@keyframes flash-up   { 0%,100%{background:transparent} 40%{background:rgba(52,211,153,.15)} }
@keyframes flash-down { 0%,100%{background:transparent} 40%{background:rgba(248,113,113,.15)} }
.flash-up   { animation: flash-up   .55s ease; }
.flash-down { animation: flash-down .55s ease; }

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 18px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  nav  { padding: 13px 16px; }
  main { padding: 14px 12px 28px; }
  .nav-email { display: none; }
  .status-center { order: -1; width: 100%; text-align: center; }
  .search-wrap { max-width: 100%; }
}
