/* === Dark Trading Theme === */
:root {
  --bg-0: #0b0f17;
  --bg-1: #11161f;
  --bg-2: #181f2b;
  --bg-3: #1f2735;
  --line: #232c3d;
  --text: #e6ebf2;
  --muted: #8a93a6;
  --accent: #4cc9f0;
  --accent-2: #6c5ce7;
  --green: #2ecc71;
  --red: #ef4444;
  --yellow: #fbbf24;
  --shadow: 0 6px 28px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Apple SD Gothic Neo', sans-serif;
  background: linear-gradient(180deg, var(--bg-0), var(--bg-1));
  color: var(--text);
  font-size: 14px;
}

/* === Topbar === */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: rgba(11,15,23,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display:flex; align-items:center; gap:8px; font-weight: 700; }
.brand .logo { font-size: 18px; color: var(--accent); }
.brand .title { letter-spacing: 0.5px; }
.tabs { display:flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted);
  border: none; padding: 8px 16px; border-radius: 8px;
  cursor: pointer; font-weight: 600; font-size: 13px;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: var(--bg-2); }
.tab.active { color: var(--text); background: var(--bg-3); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-right { display:flex; gap: 10px; align-items:center; }
.fx-pill {
  background: var(--bg-2); padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.fx-pill b { color: var(--accent); margin-left: 6px; font-weight: 600; }

.auto-refresh { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.auto-refresh .toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }
.auto-refresh .toggle input { accent-color: var(--accent); cursor: pointer; }
.auto-refresh .last-update { font-size: 11px; color: var(--muted); opacity: 0.8; }

.btn {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg-3); }
.btn.primary { background: var(--accent); color: #00121b; border-color: transparent; }
.btn.primary:hover { background: #6dd1f2; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--red); border-color: rgba(239,68,68,0.3); }
.btn.danger:hover { background: rgba(239,68,68,0.1); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* === Layout === */
main {
  padding: 20px 12px 40px;
  max-width: 1920px;
  margin: 0 auto;
}

/* === 사용자 메뉴 (우측 상단) === */
.user-menu {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 12px; padding-left: 12px;
  border-left: 1px solid var(--line);
}
.user-name {
  font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 4px 8px; background: var(--bg-3); border-radius: 6px;
}

.view { display: none; }
.view.active { display: block; }

.row { display: flex; gap: 16px; margin-bottom: 16px; }
.row > * { flex: 1; }
.grid-2 {
  display: grid; gap: 16px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 16px;
}
@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.stat-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}

/* === Card === */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card.stat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px;
}
.card.stat .label { font-size: 12px; color: var(--muted); }
.card.stat .value { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.card.stat .sub { font-size: 12px; color: #b8c0cf; }
.card.stat .sub.strong { color: #d6dde9; font-weight: 500; }
.card-subtle { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }

/* 폼 grid (라벨 + 입력) */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.form-grid .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-grid .field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid .field input,
.form-grid .field select {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 8px 12px; border-radius: 8px;
  font-size: 13px; width: 100%;
}
.form-grid .field input:focus, .form-grid .field select:focus {
  outline: none; border-color: var(--accent);
}
.form-grid .field button { width: 100%; padding: 9px 12px; }

/* 시나리오 비교 테이블 */
.compare-table th, .compare-table td { text-align: left; padding: 12px 16px; }
.compare-table th { font-size: 12px; }
.compare-table td:first-child { color: var(--muted); font-size: 13px; font-weight: 600; width: 220px; }
.compare-table td:nth-child(2),
.compare-table td:nth-child(3) {
  font-size: 14px;
  font-weight: 600;
}
.compare-table td .sub-line {
  display: block;
  font-size: 11px;
  color: #b8c0cf;
  font-weight: 400;
  margin-top: 2px;
}
.compare-table tr.row-highlight td { background: rgba(76,201,240,0.08); }
.compare-table tr.row-highlight td:nth-child(2) { color: var(--accent); }
.compare-table .v-up { color: var(--green); }
.compare-table .v-dim { color: var(--muted); }
.card.stat.highlight { background: linear-gradient(135deg, var(--bg-2), var(--bg-3)); border-color: rgba(76,201,240,0.3); }
.card.stat.highlight .value { color: var(--accent); }

.card-title { font-weight: 700; margin-bottom: 12px; font-size: 14px; }
.card-title-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.card-title-row .card-title { margin-bottom: 0; }

.chart-card { padding: 16px; min-height: 320px; display: flex; flex-direction: column; }
.chart-card .card-title { flex: 0 0 auto; }
.chart-card .card-title-row { flex: 0 0 auto; }
.chart-card canvas {
  width: 100% !important;
  height: 260px !important;
  max-height: 260px;
  min-height: 220px;
}

/* 정렬 가능한 헤더 */
.dash-table th.sortable { cursor: pointer; user-select: none; }
.dash-table th.sortable:hover { color: var(--text); }
.dash-table th.sortable::after { content: " ⇅"; opacity: 0.35; font-size: 11px; }
.dash-table th.sortable.sort-asc::after { content: " ▲"; opacity: 1; color: var(--accent); }
.dash-table th.sortable.sort-desc::after { content: " ▼"; opacity: 1; color: var(--accent); }

/* 매도 폼 인라인 */
.sell-row td, .edit-row td { background: var(--bg-2); }
.sell-row form, .edit-row form { display: flex; gap: 6px; align-items: center; padding: 8px; flex-wrap: wrap; }
.sell-row input, .edit-row input { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); padding: 4px 8px; border-radius: 6px; width: 110px; font-size: 12px; }

/* 환율 표시 (차트 카드 제목 옆) */
.fx-current {
  font-weight: 700; font-size: 16px; color: var(--accent);
  display: flex; align-items: baseline; gap: 2px;
}
.fx-current .fx-unit { font-size: 11px; color: var(--muted); margin-left: 2px; }

/* 커스텀 자동완성 드롭다운 */
.ac-wrap { position: relative; display: inline-block; }
.ac-wrap input { width: auto; }
.ac-suggestions {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 180px;
}
.ac-suggestions.show { display: block; }
.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.highlighted {
  background: var(--bg-2);
  color: var(--accent);
}
.ac-item .ac-sub { color: var(--muted); font-size: 11px; margin-left: 6px; }

/* === Top 3 상승/하락 === */
.top-list { display: flex; flex-direction: column; gap: 8px; }
.top-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-2);
  border-radius: 8px;
  border: 1px solid var(--line);
}
.top-rank { font-weight: 700; font-size: 16px; color: var(--muted); text-align: center; }
.top-rank.r1 { color: #fbbf24; }
.top-rank.r2 { color: #cbd5e1; }
.top-rank.r3 { color: #fb923c; }
.top-info { min-width: 0; }
.top-info .ticker { font-weight: 700; color: var(--accent); font-size: 14px; }
.top-info .name { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-price { font-size: 13px; color: var(--text); text-align: right; }
.top-pct { font-weight: 700; font-size: 14px; min-width: 70px; text-align: right; }
.top-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 13px; }

/* === 뉴스 === */
.news-list { display: flex; flex-direction: column; gap: 1px; }
.news-empty { color: var(--muted); padding: 20px; text-align: center; font-size: 13px; }
.news-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
  transition: background 0.15s;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: var(--bg-2); }
.news-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 16px; flex-shrink: 0;
  font-weight: 700;
}
.news-mark.positive { background: rgba(46,204,113,0.15); color: var(--green); }
.news-mark.negative { background: rgba(239,68,68,0.15); color: var(--red); }
.news-mark.neutral { background: var(--bg-3); color: var(--muted); }
.news-body { flex: 1; min-width: 0; }
.news-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; line-height: 1.4; }
.news-orig { font-size: 11px; color: var(--muted); margin-bottom: 4px; opacity: 0.7; font-style: italic; }
.news-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.news-meta .news-ticker { color: var(--accent); font-weight: 600; }
.news-summary { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; max-height: 2.8em; overflow: hidden; }

/* === Indices === */
.indices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.index-cell {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 8px;
}
.index-cell .iname { color: var(--muted); font-size: 12px; }
.index-cell .iprice { font-size: 17px; font-weight: 700; margin-top: 2px; }
.index-cell .ichange { font-size: 12px; margin-top: 2px; }
.up { color: var(--green); }
.down { color: var(--red); }

/* === Tables === */
.dash-table-wrap { overflow-x: auto; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dash-table th, .dash-table td {
  padding: 10px 6px; text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
/* 마지막 컬럼(액션 버튼)이 항상 보이도록 우측 고정 */
#holdingsTable th:last-child,
#holdingsTable td:last-child {
  position: sticky;
  right: 0;
  background: var(--bg);
  box-shadow: -8px 0 12px -8px rgba(0,0,0,0.35);
  z-index: 2;
}
#holdingsTable thead th:last-child {
  background: var(--bg-2);
  z-index: 3;
}
#holdingsTable tbody tr:hover td:last-child { background: var(--bg-2); }
.dash-table th {
  background: var(--bg-2);
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  position: sticky; top: 0;
}
.dash-table th:first-child, .dash-table td:first-child,
.dash-table th:nth-child(2), .dash-table td:nth-child(2),
.dash-table th:nth-child(3), .dash-table td:nth-child(3) {
  text-align: left;
}
.dash-table tr:hover td { background: var(--bg-2); }
.dash-table .ticker { font-weight: 700; color: var(--accent); }
.dash-table.compact th, .dash-table.compact td { padding: 6px 6px; font-size: 12px; }
.market-tag {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; background: var(--bg-3); color: var(--muted);
}
.market-tag.us { color: #4cc9f0; }
.market-tag.kr { color: #ffd166; }

/* === Forms === */
.inline-form {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.inline-form input, .inline-form select {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 8px 12px; border-radius: 8px;
  font-size: 13px; min-width: 0;
}
.inline-form input:focus, .inline-form select:focus {
  outline: none; border-color: var(--accent);
}
.filter-row { display:flex; gap:8px; }
.filter-row input, .filter-row select {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 6px 12px; border-radius: 8px;
  font-size: 13px;
}
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* === Toast === */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 8px; color: var(--text);
  opacity: 0; pointer-events: none; transition: all 0.25s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); color: var(--green); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--line); }
