:root {
  --bg: #ffffff;
  --bg-2: #f3f5f9;
  --panel: #f7f9fc;
  --card: #ffffff;
  --card-2: #eef1f7;
  --border: #d9e0ec;
  --border-soft: #e8ecf4;
  --text: #1b2436;
  --muted: #5c6a86;
  --muted-2: #8591a8;
  --accent: #0fb98a;
  --accent-press: #0aa278;
  --accent-soft: rgba(15, 185, 138, 0.14);
  --blue: #3b82f6;
  --up: #f6465d;
  --down: #2f81f7;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.10);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(20, 224, 166, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(59, 130, 246, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
}

button {
  font-family: inherit;
  border: none;
  background: var(--accent);
  color: #052016;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}
button:hover { background: var(--accent-press); }
button:active { transform: translateY(1px); }
button.secondary {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--card-2); }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); border-color: var(--accent); }
button.danger { background: transparent; color: var(--up); border: 1px solid rgba(246,70,93,0.4); }
button.danger:hover { background: rgba(246,70,93,0.12); }

.chart-periods { display: flex; gap: 6px; margin: 4px 0 8px; }
.chart-period {
  padding: 4px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--card-2);
  color: var(--muted);
  border: 1px solid var(--border-soft);
}
.chart-period:hover { background: var(--card-2); color: var(--text); }
.chart-period.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

input, select {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: var(--muted-2); }
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 14px;
}
label input, label select { margin-top: 7px; }

/* ===== Auth ===== */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 460px;
}
.auth-promo {
  padding: 64px 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(700px 400px at 20% 20%, rgba(20,224,166,0.10), transparent 60%),
    linear-gradient(160deg, #eef2f8, #f7f9fc);
  border-right: 1px solid var(--border-soft);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.brand .dot {
  width: 13px; height: 13px; border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
}
.auth-promo h1 {
  font-size: 2.6rem;
  line-height: 1.12;
  letter-spacing: -0.03em;
  margin: 36px 0 16px;
}
.auth-promo p { color: var(--muted); line-height: 1.7; max-width: 460px; }
.auth-stats { display: flex; gap: 36px; margin-top: 44px; }
.auth-stats div span { display: block; }
.auth-stats .big { font-size: 1.6rem; font-weight: 700; }
.auth-stats .lbl { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
}
.auth-card h2 { font-size: 1.6rem; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-card .sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 28px; }
.auth-card form > button[type="submit"] { width: 100%; padding: 12px; margin-top: 4px; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--muted); font-size: 0.88rem; }
.auth-switch a { color: var(--accent); cursor: pointer; font-weight: 600; }

/* ===== App shell ===== */
.shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { padding: 4px 8px 26px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.94rem;
  transition: all 0.13s ease;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .ic { width: 18px; text-align: center; opacity: 0.9; }
.sidebar .spacer { flex: 1; }
.side-user {
  border-top: 1px solid var(--border-soft);
  padding-top: 16px;
  display: flex;
  align-items: center;
  gap: 11px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #04121f;
}
.side-user .meta { overflow: hidden; flex: 1; }
.side-user .meta .nm { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .meta .rl { font-size: 0.74rem; color: var(--muted); }
.logout-btn {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.74rem;
  cursor: pointer;
  white-space: nowrap;
}
.logout-btn:hover { color: var(--text); border-color: var(--muted-2); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 30px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(10px);
  z-index: 20;
}
.topbar h1 { font-size: 1.2rem; margin: 0; letter-spacing: -0.02em; white-space: nowrap; }
.title-wrap { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
/* 출처 툴팁이 있는 표 헤더 — 점선 밑줄로 hover 안내 */
th.has-src { text-decoration: underline dotted var(--muted-2); text-underline-offset: 3px; }
/* 원화로 보기 토글 버튼 */
.krw-toggle { padding: 4px 10px; font-size: 0.78rem; white-space: nowrap; }
.view-source:hover { border-color: var(--accent); color: var(--accent); }

/* 데이터 출처 상세 모달 */
.info-modal { max-width: min(940px, 97vw); }
.info-modal-title { font-weight: 700; font-size: 1.05rem; margin: 2px 36px 4px 4px; }
.info-modal-body { font-size: 0.82rem; line-height: 1.5; }
.src-intro { color: var(--muted); margin: 4px 4px 12px; font-size: 0.8rem; }
.src-note { color: var(--muted-2); margin: 14px 4px 2px; font-size: 0.74rem; line-height: 1.5; }
.src-legend { background: var(--card-2); border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px 12px; margin: 0 0 16px; display: flex; flex-direction: column; gap: 4px; font-size: 0.76rem; color: var(--muted); }
.src-legend b { color: var(--text); }
.src-sec { margin: 0 0 16px; }
.src-sec h4 { margin: 0 0 6px; font-size: 0.92rem; }
.src-sec.active h4 { color: var(--accent); }
.src-now { font-size: 0.66rem; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 8px; margin-left: 6px; vertical-align: middle; }
.src-table-wrap { overflow-x: auto; }
.src-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.src-table th, .src-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.src-table th { font-size: 0.7rem; color: var(--muted-2); font-weight: 600; white-space: nowrap; }
.src-table .sk { width: 26%; color: var(--text); }
.src-table .sv { width: 16%; color: var(--text); font-weight: 600; }
.src-table .se { width: 30%; color: var(--muted); font-size: 0.74rem; word-break: break-all; }
.src-table .sc { width: 12%; color: var(--muted); font-size: 0.74rem; white-space: nowrap; }
.src-table .so { width: 16%; color: var(--muted); font-size: 0.74rem; }
.view-source {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 3px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-box { position: relative; flex: 1; max-width: 560px; margin-left: auto; }
.search-box .filters { display: flex; gap: 8px; }
.search-box .filters select { width: 86px; flex: none; }
.search-box .filters input { flex: 1; }
.suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 340px;
  overflow: auto;
  z-index: 50;
}
.suggestion {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover { background: var(--card-2); }
.suggestion .sym { font-weight: 500; min-width: 76px; color: var(--muted); font-size: 0.82rem; }
.suggestion .nm { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggestion .add { color: var(--accent); font-size: 1.2rem; font-weight: 700; }
.badge {
  font-size: 0.68rem; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}

.content { padding: 28px 30px 60px; }

/* KPI cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.kpi {
  background: linear-gradient(160deg, var(--card), var(--bg-2));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
}
.cur-head { font-size: 0.82rem; color: var(--muted); font-weight: 600; letter-spacing: 0.03em; margin: 6px 2px 10px; }
.cur-head:not(:first-child) { margin-top: 18px; }
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 0 var(--accent-soft);
  animation: livePulse 1.6s infinite; vertical-align: middle; margin-right: 2px;
}
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(20,224,166,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(20,224,166,0); }
  100% { box-shadow: 0 0 0 0 rgba(20,224,166,0); }
}
.kpi .lbl { color: var(--muted); font-size: 0.82rem; }
.kpi .val { font-size: 1.7rem; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 0.82rem; margin-top: 6px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.panel-head h3 { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
.panel-head .hint { color: var(--muted); font-size: 0.8rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.92rem;
}
tbody tr { transition: background 0.1s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--card-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tk { font-weight: 700; }
.tk small { display: block; color: var(--muted); font-weight: 400; font-size: 0.78rem; }

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

.grip { width: 30px; text-align: center; padding-left: 6px; padding-right: 0; }
.drag-handle {
  color: var(--muted-2);
  cursor: grab;
  user-select: none;
  font-size: 1.05rem;
  line-height: 1;
}
.drag-handle:hover { color: var(--text); }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: 0.55; background: var(--card-2); }
tbody tr.clickable { cursor: pointer; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .big { font-size: 1.05rem; color: var(--text); margin-bottom: 6px; }

.grid-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

/* Drawer (stock detail) */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 15, 0.6);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0;
  animation: fade 0.18s forwards;
}
@keyframes fade { to { opacity: 1; } }

/* 도움말 ⓘ 버튼 */
.info-btn {
  width: 20px; height: 20px; flex: 0 0 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-style: italic;
  font-weight: 700;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.info-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* 이미지 안내 팝업(라이트박스) */
.img-lightbox {
  position: fixed; inset: 0;
  background: rgba(4, 7, 15, 0.7);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  opacity: 0;
  animation: fade 0.18s forwards;
}
.img-lightbox-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  max-width: min(1000px, 96vw);
  max-height: 92vh;
  overflow: auto;
  padding: 16px;
}
.img-lightbox-cap {
  font-size: 0.86rem;
  color: var(--text);
  margin: 2px 36px 12px 4px;
  line-height: 1.5;
}
.img-lightbox-card img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
}
.img-lightbox-close {
  position: absolute; top: 10px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--muted);
  font-size: 1.2rem; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.img-lightbox-close:hover { color: var(--text); border-color: var(--muted-2); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(1400px, 96vw);
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
  z-index: 101;
  overflow-y: auto;
  padding: 26px 28px 60px;
  transform: translateX(100%);
  animation: slidein 0.22s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes slidein { to { transform: translateX(0); } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.drawer-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.drawer-head .tags { margin-top: 8px; display: flex; gap: 8px; }
.close-x {
  background: var(--card); border: 1px solid var(--border);
  color: var(--muted); width: 36px; height: 36px; border-radius: 9px;
  font-size: 1.1rem; cursor: pointer;
}
.close-x:hover { color: var(--text); }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
.metric {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  padding: 14px;
}
.metric .lbl { color: var(--muted); font-size: 0.76rem; }
.metric .val { font-size: 1.15rem; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.metric .msub { color: var(--muted); font-size: 0.72rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.krw-eq { color: var(--muted); font-size: 0.66rem; font-weight: 400; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.price-row { display: flex; gap: 8px; align-items: flex-end; }
.price-row label { flex: 1; margin-bottom: 0; }

h4.section { font-size: 0.92rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 26px 0 12px; }

/* Toasts */
#toast-host {
  position: fixed; right: 22px; bottom: 22px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  min-width: 240px; max-width: 360px;
  padding: 13px 16px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: toastin 0.2s ease;
}
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }
.toast.success { border-color: rgba(20,224,166,0.45); }
.toast.error { border-color: rgba(246,70,93,0.5); }
.toast.info { border-color: var(--border); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast.success .t-title { color: var(--accent); }
.toast.error .t-title { color: var(--up); }

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

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto;
    flex-direction: row; align-items: center; z-index: 60;
    padding: 8px 12px; border-top: 1px solid var(--border); border-right: none;
  }
  .sidebar .brand, .sidebar .spacer, .side-user { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav-item .lbl { display: none; }
  .main { padding-bottom: 64px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-forms, .metric-grid { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-promo { display: none; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .content { padding: 18px 16px 80px; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
}
