/* asset-manager 공통 스타일. CSP 때문에 인라인 스타일은 쓰지 않는다. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #647084;
  --border: #dde1e8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --gain: #d32f2f;   /* 이익: 빨강 (국내 관례) */
  --loss: #1565c0;   /* 손실: 파랑 */
  --danger: #b3261e;
  --info-bg: #e8f0fc;
  --error-bg: #fdecea;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ef;
    --muted: #9aa5b8;
    --border: #2d3441;
    --accent: #6ea4ff;
    --accent-text: #0d1320;
    --gain: #ff6b66;
    --loss: #6aa9ff;
    --danger: #ff8a80;
    --info-bg: #1c2a44;
    --error-bg: #3a1f1d;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
code, pre, .num { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a {
  padding: .4rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent); color: var(--accent-text); }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }

.notice { padding: .5rem 1rem; background: var(--info-bg); border-bottom: 1px solid var(--border); font-size: .95rem; }
.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-narrow { max-width: 420px; padding-top: 12vh; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
.crumb { color: var(--muted); font-size: .9rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }

.form { display: grid; gap: .5rem; }
.form-narrow { max-width: 360px; }
.form label { font-size: .9rem; color: var(--muted); margin-top: .35rem; }
.form label.check { display: flex; align-items: center; gap: .4rem; color: var(--text); }
input[type=text], input[type=password], input[type=number], select {
  width: 100%; padding: .6rem .7rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-block; padding: .55rem .9rem; font: inherit; cursor: pointer; text-decoration: none;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-quiet { padding: .3rem .6rem; font-size: .9rem; }
.form .btn { margin-top: .6rem; justify-self: start; }
.page-narrow .form .btn { justify-self: stretch; }

.alert { padding: .6rem .8rem; border-radius: 8px; margin: 0 0 .75rem; }
.alert-info { background: var(--info-bg); }
.alert-error { background: var(--error-bg); color: var(--danger); }
.badge {
  display: inline-block; padding: .1rem .5rem; font-size: .8rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
}
.code {
  padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  overflow-x: auto; font-size: 1rem; letter-spacing: .04em;
}

.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: .3rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
}
.tile-disabled { opacity: .65; }

.table-wrap { overflow-x: auto; margin-bottom: .75rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; }
.table td.ua { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.table form { margin: 0; }
.table .num, .num { text-align: right; }

.steps { padding-left: 1.2rem; }
.qr { display: inline-block; padding: .5rem; background: #ffffff; border-radius: 8px; line-height: 0; }
.qr svg { display: block; width: 260px; max-width: 70vw; height: auto; }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; max-width: 360px; }
.codes code { display: block; padding: .4rem .6rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 1.05rem; text-align: center; }

/* 손익 색상: 이익 빨강, 손실 파랑 */
.gain { color: var(--gain); }
.loss { color: var(--loss); }

@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  .nav { order: 3; flex-basis: 100%; }
  .logout { margin-left: auto; }
  .page-narrow { padding-top: 6vh; }
}
@media print {
  .topbar, .notice, .no-print { display: none; }
  body { background: #ffffff; color: #000000; }
  .card { border: 0; padding: 0; }
  .page { max-width: none; padding: 0; }
}

/* ---- 급여, 설정 화면 (M2) ---- */
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-row h1 { margin: 0; }
.pills { display: flex; gap: .3rem; flex-wrap: wrap; }
.pills a { padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text); background: var(--surface); }
.pills a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.table-num td, .table-num thead th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot th, .table tfoot td { font-weight: 600; border-top: 2px solid var(--border); }
.table-compact th, .table-compact td { padding: .3rem .4rem; }
.row-empty td { text-align: left; }
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 1rem; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem .9rem; margin: 0 0 1rem; min-width: 0; }
legend { padding: 0 .4rem; font-weight: 600; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, 150px); gap: .5rem; align-items: center; margin-bottom: .4rem; }
.field-row label { font-size: .92rem; }
.field-row input { padding: .4rem .55rem; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.is-calc { color: var(--muted); font-style: italic; }
.badge-calc { border-style: dashed; }
.expected { color: var(--muted); }
.check { display: flex; align-items: center; gap: .4rem; margin-top: .4rem; }
.kv { margin: 0; display: grid; gap: .25rem; }
.kv div { display: flex; justify-content: space-between; gap: 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.kv-strong { font-weight: 700; font-size: 1.1rem; padding: .3rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.kv-strong dt { color: var(--text); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }
.actions form { margin: 0; }
.inline-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin: 0; }
.inline-form input[type=text] { width: auto; min-width: 0; flex: 1 1 90px; padding: .35rem .5rem; }
.inline-form select { width: auto; padding: .35rem .5rem; }
.table input[type=text] { padding: .3rem .45rem; min-width: 70px; }
.report-ok { color: var(--muted); }
.report-bad { color: var(--danger); font-weight: 700; }
@media (max-width: 860px) {
  .split, .cols { grid-template-columns: 1fr; }
}

/* ---- 투자, 대시보드 화면 (M3) ---- */
.pricebar { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; align-items: center; margin-bottom: 1rem; font-size: .95rem; color: var(--muted); }
.pricebar strong { color: var(--text); }
.pricebar form { margin: 0; }
.badge-warn { color: var(--danger); border-color: var(--danger); }
.cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 1rem; }
.kpi { display: flex; flex-direction: column; gap: .15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi-label { color: var(--muted); font-size: .88rem; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi > span:last-child { font-size: .88rem; font-variant-numeric: tabular-nums; }
.card-ref { border-style: dashed; }
.table td.left, .table th.left, .table-num thead th.left { text-align: left; }
.table td.memo { max-width: 260px; white-space: normal; color: var(--muted); font-size: .85rem; }
.row-watch th, .row-watch td { opacity: .55; }
.form-wide { max-width: 760px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; }
.grid2 label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .2rem; }
textarea { width: 100%; padding: .6rem .7rem; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.goal-head { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: baseline; }
.goal-head h2 { margin: 0; }
.progress-row { display: flex; align-items: center; gap: .75rem; margin: .5rem 0 1rem; }
progress { flex: 1; height: 14px; accent-color: var(--accent); }
.chart-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-bottom: 1rem; }
.chart-box { position: relative; height: 280px; }
.chart-wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.section-title { font-size: 1rem; color: var(--muted); margin: 1rem 0 .5rem; }
.progress-tight { margin: 0; min-width: 160px; }
.chart-short { height: 200px; }

/* ---- 보유 종목 표: 열을 묶어 폭을 줄이고, 좁은 화면에서는 카드로 바꾼다 ---- */
.page { max-width: 1280px; }
.page-narrow { max-width: 420px; }
.holdings { table-layout: auto; }
.holdings th, .holdings td { white-space: normal; vertical-align: top; }
.holdings tbody th { min-width: 9rem; font-weight: 600; }
.holdings .sub { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }
.holdings .sub.memo { max-width: 28rem; }
.holdings .two { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.35; }
.holdings .two > span { white-space: nowrap; }
.holdings td:not(.row-actions) { font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; text-align: right; width: 1%; }
.row-actions form { display: inline; margin: 0; }
.row-actions .btn { padding: .2rem .5rem; font-size: .85rem; }

@media (max-width: 760px) {
  .holdings thead { display: none; }
  .holdings, .holdings tbody, .holdings tfoot { display: block; }
  .holdings tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .75rem;
    padding: .7rem 0; border-bottom: 1px solid var(--border);
  }
  .holdings tr.row-none { display: block; }
  .holdings th, .holdings td { display: block; padding: 0; border: 0; text-align: left; }
  .holdings tbody th, .holdings tfoot th { grid-column: 1 / -1; }
  .holdings td:empty { display: none; }
  .holdings td[data-label]:not([data-label=""])::before {
    content: attr(data-label); display: block; font-size: .75rem; color: var(--muted);
  }
  .holdings .two { align-items: flex-start; }
  .holdings .row-actions { grid-column: 1 / -1; width: auto; text-align: left; }
  .holdings tfoot tr { border-bottom: 0; border-top: 2px solid var(--border); }
  .holdings tfoot th, .holdings tfoot td { border-top: 0; }
}

/* ---- 계획, 지출 화면 (M5) ---- */
.plan-table td { vertical-align: top; }
.plan-table input[type=text] { min-width: 90px; }
.plan-table input.w-xs, .table input.w-xs { min-width: 0; width: 3.5rem; }
.plan-table input.w-s { min-width: 0; width: 4.5rem; }
.table input.w-m { min-width: 0; width: 7rem; }
.plan-table .memo-input { margin-top: .25rem; font-size: .85rem; color: var(--muted); }
.grid-table input[type=text] { min-width: 0; width: 5.5rem; padding: .25rem .35rem; }
.grid-table th:first-child { white-space: nowrap; }
.watch-item h2 { margin: 0; }
.watch-item p { margin: .4rem 0 0; }

/* ---- 월 이체 계획 목록: 읽기 전용 표. 좁은 화면에서는 카드로 바꾼다 ---- */
.plan-list th, .plan-list td { white-space: normal; vertical-align: top; }
.plan-list tbody th { font-weight: 600; }
.plan-list td:first-child, .plan-list thead th { white-space: nowrap; }
.plan-list .sub { display: block; font-size: .82rem; font-weight: 400; color: var(--muted); }
.plan-list td.num, .plan-list th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge-cat { color: var(--text); white-space: nowrap; }
@media (max-width: 700px) {
  .plan-list thead { display: none; }
  .plan-list, .plan-list tbody, .plan-list tfoot { display: block; }
  .plan-list tr { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .6rem; align-items: baseline; padding: .6rem 0; border-bottom: 1px solid var(--border); }
  .plan-list tr.row-none { display: block; }
  .plan-list th, .plan-list td { display: block; padding: 0; border: 0; text-align: left; }
  .plan-list tbody th { grid-column: 1 / -1; order: -1; }
  .plan-list td:empty { display: none; }
  .plan-list td.num { text-align: right; font-weight: 600; grid-column: 3; }
  .plan-list tfoot tr { border-top: 2px solid var(--border); border-bottom: 0; }
  .plan-list tfoot th { grid-column: 1 / 3; order: 0; }
}
.budget-table { max-width: 640px; }
.budget-table td.num, .budget-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.budget-table .cat-row th, .budget-table .cat-row td { font-weight: 700; border-top: 1px solid var(--border); }
.budget-table .sub-row td { color: var(--muted); font-size: .92rem; border-bottom: 0; padding-top: .15rem; padding-bottom: .15rem; }
.budget-table .sub-row td:first-child { padding-left: 1.6rem; }

/* ---- 연말정산 화면 (M6) ---- */
.row-strong th, .row-strong td { font-weight: 700; background: var(--bg); }
.fold > summary { cursor: pointer; }
.fold[open] > summary { margin-bottom: .75rem; }
.ye-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 200px); gap: .4rem .75rem; align-items: center; }
.ye-grid label { font-size: .92rem; }
.ye-grid input, .ye-grid select { padding: .4rem .55rem; }
.formula-table td { white-space: normal; }
.formula-table code { font-size: .8rem; word-break: break-all; }
.formula-table td.num { white-space: nowrap; text-align: right; }
@media (max-width: 640px) { .ye-grid { grid-template-columns: 1fr; } .ye-grid label { margin-top: .4rem; } }
