/* ============================================
   ETF 리밸런싱 계산기 — Light Theme
   Aesthetic: Clean finance dashboard, warm & airy
   ============================================ */

:root {
  --bg-primary: #f5f6f8;
  --bg-secondary: #edeef2;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fb;
  --bg-input: #f0f2f5;

  --border: #dfe2e8;
  --border-focus: #3b7ddd;
  --border-subtle: #e8eaef;

  --text-primary: #1a1d26;
  --text-secondary: #555d6e;
  --text-muted: #8b93a1;

  --accent: #3b7ddd;
  --accent-light: #2563c7;
  --accent-glow: rgba(59, 125, 221, 0.12);
  --accent-soft: rgba(59, 125, 221, 0.06);

  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.08);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.06);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.07);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);

  --font-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-sans); background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; min-height: 100vh; }

.app {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---- Header ---- */
.header {
  padding: 32px 0 24px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 28px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 14px; }

.logo-icon {
  width: 48px; height: 48px;
  background: var(--accent-soft);
  border: 1px solid rgba(59,125,221,0.15);
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  color: var(--accent);
}

.logo h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.82rem; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

/* ---- Data Actions (Export/Import) ---- */
.data-actions { display: flex; gap: 6px; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 14px;
  font-family: var(--font-sans); font-size: 0.78rem; font-weight: 600;
  color: var(--text-muted); background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); outline: none;
}
.btn-icon:hover {
  color: var(--text-primary); border-color: var(--accent); background: var(--accent-soft);
}
.btn-icon svg { flex-shrink: 0; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-header-right { display: flex; align-items: center; gap: 8px; }

/* ---- Budget Input ---- */
.budget-input-wrap { position: relative; display: flex; align-items: center; }
.currency-symbol {
  position: absolute; left: 16px;
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 600;
  color: var(--text-muted); pointer-events: none;
}
.budget-input {
  width: 100%; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px 14px 40px;
  font-family: var(--font-mono); font-size: 1.4rem; font-weight: 600;
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.budget-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }
.budget-input::placeholder { color: var(--text-muted); font-weight: 400; }

/* ---- Ratio Badge ---- */
.ratio-badge {
  font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600;
  padding: 5px 12px; border-radius: 100px;
  background: var(--green-soft); color: var(--green);
  border: 1px solid rgba(22,163,74,0.15);
  transition: all var(--transition);
}
.ratio-badge.warn { background: var(--amber-soft); color: var(--amber); border-color: rgba(217,119,6,0.15); }
.ratio-badge.error { background: var(--red-soft); color: var(--red); border-color: rgba(220,38,38,0.15); }

/* ---- ETF Table Header ---- */
.etf-table-header {
  display: grid;
  grid-template-columns: 68px 1.5fr 0.75fr 1.1fr 0.75fr 0.75fr 40px;
  gap: 10px; padding: 0 4px 10px;
  border-bottom: 1px solid var(--border-subtle); margin-bottom: 8px;
}
.etf-table-header span {
  font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---- ETF Row ---- */
.etf-row {
  display: grid;
  grid-template-columns: 68px 1.5fr 0.75fr 1.1fr 0.75fr 0.75fr 40px;
  gap: 10px; padding: 8px 4px; border-radius: var(--radius-sm);
  transition: background var(--transition);
  animation: slideIn 200ms ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.etf-row:hover { background: var(--bg-card-hover); }

/* ---- Inputs ---- */
.input {
  width: 100%; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: var(--font-sans); font-size: 0.9rem;
  color: var(--text-primary); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }
.input.mono { font-family: var(--font-mono); font-size: 0.85rem; text-align: right; }
.input.loading { opacity: 0.5; cursor: wait; }
.input::placeholder { color: var(--text-muted); }

/* ---- Market Select ---- */
.select-market {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  text-align: center;
  padding-right: 8px;
}

/* ---- Exchange Rate Note ---- */
.rate-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 10px;
  padding-left: 4px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; font-family: var(--font-sans); font-weight: 600; font-size: 0.88rem;
  border: none; border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition); outline: none;
}
.btn-add {
  width: 100%; padding: 12px; margin-top: 8px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px dashed rgba(59,125,221,0.3);
}
.btn-add:hover { background: rgba(59,125,221,0.1); border-color: rgba(59,125,221,0.5); }

.btn-delete {
  width: 32px; height: 32px; padding: 0;
  background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm); align-self: center;
}
.btn-delete:hover { background: var(--red-soft); color: var(--red); }

/* ---- Buy Mode Toggle ---- */
.qty-with-mode { display: flex; gap: 4px; align-items: stretch; }
.qty-with-mode .input { flex: 1; min-width: 0; }
.btn-buy-mode {
  flex-shrink: 0; width: 26px; padding: 0;
  font-family: var(--font-mono); font-size: 0.65rem; font-weight: 700;
  color: var(--text-muted); background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); line-height: 1;
}
.btn-buy-mode[data-buy-mode="amount"] {
  color: var(--accent); background: var(--accent-soft);
  border-color: rgba(59,125,221,0.3);
}
.btn-buy-mode:hover { border-color: var(--accent); color: var(--accent); }

.btn-calculate {
  width: 100%; padding: 16px; margin-bottom: 20px;
  background: var(--accent); color: #fff; font-size: 1rem;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(59,125,221,0.25);
}
.btn-calculate:hover { background: #2563c7; box-shadow: 0 4px 16px rgba(59,125,221,0.3); transform: translateY(-1px); }
.btn-calculate:active { transform: translateY(0); }

/* ---- Error Box ---- */
.error-box {
  background: var(--red-soft); border: 1px solid rgba(220,38,38,0.15);
  color: var(--red); padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 0.88rem; font-weight: 500; margin-bottom: 20px;
  animation: slideIn 200ms ease-out;
}

/* ---- Result Section ---- */
.result-card { animation: resultAppear 400ms ease-out; }
@keyframes resultAppear {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.summary-item {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px; text-align: center;
}
.summary-item.accent { background: var(--accent-soft); border-color: rgba(59,125,221,0.15); }
.summary-label {
  display: block; font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
.summary-value { display: block; font-family: var(--font-mono); font-size: 1.05rem; font-weight: 600; color: var(--text-primary); }
.summary-item.accent .summary-value { color: var(--accent); }

/* Result Table */
.result-table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
.result-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.result-table th {
  padding: 10px 12px; font-size: 0.7rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  text-align: right; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.result-table th:first-child { text-align: left; }
.result-table th.highlight-col { color: var(--accent); }
.result-table td {
  padding: 12px; text-align: right;
  font-family: var(--font-mono); font-size: 0.82rem;
  color: var(--text-secondary); border-bottom: 1px solid var(--border-subtle); white-space: nowrap;
}
.result-table td:first-child { text-align: left; font-family: var(--font-sans); font-weight: 600; color: var(--text-primary); }
.result-table td.highlight-cell { color: var(--accent); font-weight: 600; }
.result-table td.zero-ratio { color: var(--text-muted); font-style: italic; }
.result-table tbody tr:hover { background: var(--bg-card-hover); }

/* ---- Chart Section ---- */
.chart-section { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border-subtle); }
.chart-section h3 { font-size: 0.88rem; font-weight: 600; margin-bottom: 16px; }
.chart-area { display: flex; flex-direction: column; gap: 14px; }
.chart-row { display: grid; grid-template-columns: 100px 1fr 60px; align-items: center; gap: 12px; }
.chart-label { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bars { position: relative; height: 28px; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.chart-bar { height: 11px; border-radius: 3px; transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1); min-width: 2px; }
.chart-bar.target { background: rgba(59,125,221,0.15); border: 1px solid rgba(59,125,221,0.3); }
.chart-bar.actual { background: var(--accent); }
.chart-pct { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.chart-legend { display: flex; gap: 20px; margin-top: 12px; justify-content: center; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-muted); }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 2px; }
.chart-legend-dot.target { background: rgba(59,125,221,0.15); border: 1px solid rgba(59,125,221,0.3); }
.chart-legend-dot.actual { background: var(--accent); }

/* ---- Toast Notification ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary); color: var(--bg-card);
  padding: 10px 20px; border-radius: var(--radius-md);
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow-lg);
  opacity: 0; transition: all 300ms ease;
  z-index: 1000; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden-input { display: none; }

/* ---- Footer ---- */
.footer { padding: 32px 0; text-align: center; border-top: 1px solid var(--border-subtle); margin-top: 20px; }
.footer p { font-size: 0.78rem; color: var(--text-muted); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .app { padding: 0 14px; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 16px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .etf-table-header { display: none; }
  .etf-row { grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px 8px; border-bottom: 1px solid var(--border-subtle); }
  .etf-row .input-group:nth-child(2) { grid-column: 1 / -1; }
  .etf-row .btn-delete { grid-column: 2; justify-self: end; align-self: end; }
  .input-group label { display: block; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
  .result-table { font-size: 0.78rem; }
  .result-table th, .result-table td { padding: 8px 6px; }
  .chart-row { grid-template-columns: 70px 1fr 50px; }
}
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
  .budget-input { font-size: 1.1rem; }
  .data-actions { width: 100%; }
  .btn-icon { flex: 1; }
}
