/* HealthyHub 경영분석 — 화면 스타일 */
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f6f9fd;
  --border: #e2e8f1;
  --border-strong: #cbd5e3;
  --text: #0f1b2d;
  --text-2: #46546e;
  --muted: #8390a7;
  --primary: #1f6fe0;
  --primary-600: #185fc4;
  --primary-700: #134c9e;
  --primary-50: #eaf2fd;
  --primary-100: #d4e4fb;
  --good: #0a7a0a;
  --good-bg: #e7f6e7;
  --warn: #8a5a00;
  --warn-bg: #fff3d1;
  --bad: #c22f2f;
  --bad-bg: #fde8e8;
  --st-good: #0ca30c;
  --st-warning: #fab219;
  --st-serious: #ec835a;
  --st-critical: #d03b3b;
  /* 차트 범주색 (검증된 순서 — 바꾸지 말 것) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --seq-1: #86b6ef;
  --seq-2: #3987e5;
  --seq-3: #1c5cab;
  --grid: #e8ecf3;
  --axis: #c3ccda;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .04), 0 6px 20px rgba(15, 27, 45, .05);
  --shadow-lg: 0 12px 40px rgba(15, 27, 45, .18);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  word-break: keep-all; overflow-wrap: anywhere;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
p { margin: 0; }
a { color: var(--primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ── 전체 레이아웃 ── */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 14px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); display: grid; place-items: center; flex: none; }
.brand-name { font-weight: 750; font-size: 16px; letter-spacing: -0.02em; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { padding: 6px 10px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; font-weight: 650; color: var(--muted); letter-spacing: .06em; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--text-2); font-weight: 550; text-decoration: none; margin-bottom: 2px;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-50); color: var(--primary-700); }
.nav a.active svg { opacity: 1; }
.side-foot { border-top: 1px solid var(--border); padding: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-100); color: var(--primary-700); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-name { font-weight: 650; line-height: 1.2; }
.user-role { font-size: 12px; color: var(--muted); }
.side-actions { display: flex; gap: 6px; margin-top: 8px; }
.side-actions button { flex: 1; }
.side-ver { margin-top: 8px; font-size: 11px; color: var(--muted); text-align: center; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(243, 246, 251, .92); backdrop-filter: blur(8px);
  padding: 16px 28px 12px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 20px; }
.topbar .desc { color: var(--text-2); font-size: 13px; }
.content { padding: 8px 28px 48px; max-width: 1560px; width: 100%; }
.icon-btn.menu-btn { display: none; }
svg.ico { flex: none; }

/* ── 카드 ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; }
.card-head .hint { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 14px 20px 18px; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.c-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.c-3-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px; }
.section-title h2 { font-size: 16px; }
.section-title .hint { color: var(--muted); font-size: 12.5px; }

/* ── 지표 타일 ── */
.tile { padding: 16px 18px; }
.tile .label { color: var(--text-2); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.15; }
.tile .value .unit { font-size: 14px; font-weight: 600; color: var(--text-2); margin-left: 3px; }
.tile .foot { margin-top: 6px; font-size: 12.5px; color: var(--text-2); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.delta { font-weight: 650; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ── 버튼·입력 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad); border-color: #efc4c4; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }
.btn:focus-visible, .input:focus-visible, select:focus-visible, .nav a:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.input, select.input {
  height: 36px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface);
  min-width: 0; width: 100%;
}
select.input { padding-right: 28px; cursor: pointer; }
.input:focus { border-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.seg { display: inline-flex; background: #e9eef6; border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 7px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(15, 27, 45, .12); }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filters .input { width: auto; }
.filters .search { width: 260px; }

/* ── 배지 ── */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; background: #edf1f7; color: var(--text-2); }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.blue { background: var(--primary-50); color: var(--primary-700); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ── 표 ── */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); max-height: 72vh; }
table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-2); font-weight: 650; font-size: 12.5px;
  border-bottom: 1px solid var(--border-strong); user-select: none;
}
.tbl thead th.sortable { cursor: pointer; }
.tbl thead th.sortable:hover { color: var(--text); }
.tbl thead th .arrow { opacity: .9; margin-left: 3px; font-size: 10px; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover td { background: #f8fafd; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl td.name { white-space: normal; min-width: 200px; max-width: 380px; }
.tbl tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 650; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.tbl .group-row td { background: var(--surface-2); font-weight: 650; }
.pager { display: flex; align-items: center; gap: 10px; padding: 10px 2px 0; color: var(--text-2); font-size: 13px; flex-wrap: wrap; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* 손익계산서 표 */
.pnl-table th, .pnl-table td { padding: 8px 14px; }
.pnl-table td.item { white-space: nowrap; }
.pnl-table tr.lv0 td { font-weight: 700; background: #f4f8fe; border-top: 1px solid var(--border-strong); }
.pnl-table tr.lv1 td.item { padding-left: 28px; font-weight: 600; }
.pnl-table tr.lv2 td.item { padding-left: 46px; color: var(--text-2); }
.pnl-table tr.lv2 td { color: var(--text-2); font-size: 12.5px; }
.pnl-table tr.rate td { color: var(--text-2); font-size: 12.5px; border-bottom-color: var(--border-strong); }
.pnl-table td.cur, .pnl-table th.cur { background: #f1f6fe; }
.pnl-table tr.lv0 td.cur { background: #e6effc; }
.pnl-table .toggle { cursor: pointer; user-select: none; }
.pnl-table .caret { display: inline-block; width: 14px; color: var(--muted); font-size: 10px; }

/* ── 차트 ── */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .dlabel { fill: var(--text-2); font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .mark { transition: opacity .12s; }
.chart .dim .mark { opacity: .35; }
.chart .dim .mark.on { opacity: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-top: 8px; }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .line-key { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.tooltip {
  position: fixed; z-index: 200; pointer-events: none; background: #14213a; color: #fff; border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; box-shadow: var(--shadow-lg); max-width: 320px; line-height: 1.45;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; opacity: .9; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.tooltip .tt-key { width: 12px; height: 0; border-top: 2px solid; display: inline-block; margin-right: 6px; vertical-align: middle; }
.chart-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* 미터(목표 대비) */
.meter { position: relative; height: 10px; border-radius: 999px; background: var(--primary-100); margin: 12px 0 28px; }
.meter .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--primary); min-width: 4px; }
.meter.bad { background: #f8d7d7; }
.meter.bad .fill { background: var(--st-critical); }
.meter.good { background: #cfeccf; }
.meter.good .fill { background: var(--st-good); }
.meter .target { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--text); border-radius: 2px; }
.meter .target-label { position: absolute; top: 15px; transform: translateX(-50%); font-size: 11px; color: var(--text-2); white-space: nowrap; font-weight: 600; }
.meter .target-label.end { transform: translateX(-100%); }
.meter .target-label.start { transform: none; }
.meter .scale { position: absolute; top: 13px; font-size: 10.5px; color: var(--muted); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── 알림·안내 ── */
.notice { border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); background: var(--surface); }
.notice.info { background: var(--primary-50); border-color: var(--primary-100); color: #17406f; }
.notice.warn { background: var(--warn-bg); border-color: #f2dc9b; color: #6b4700; }
.notice.bad { background: var(--bad-bg); border-color: #f1c2c2; color: #8c1f1f; }
.notice.good { background: var(--good-bg); border-color: #bfe3bf; color: #0b5c0b; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #14213a; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; }
.toast.bad { background: #a52626; }
.toast.good { background: #0d6b0d; }

/* ── 모달·서랍 ── */
.overlay { position: fixed; inset: 0; background: rgba(15, 27, 45, .42); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(560px, 100%); }
.modal.wide { width: min(860px, 100%); }
.modal-head { padding: 18px 22px 0; display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 0 22px 20px; display: flex; gap: 8px; justify-content: flex-end; }
.drawer-overlay { position: fixed; inset: 0; background: rgba(15, 27, 45, .3); z-index: 90; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--surface); z-index: 95; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.drawer-head { padding: 18px 22px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h3 { font-size: 16px; line-height: 1.35; }
.drawer-body { padding: 18px 22px 28px; overflow: auto; flex: 1; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── 로그인 ── */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(180deg, #eaf2fd 0%, var(--bg) 46%); }
.auth-card { width: min(420px, 100%); padding: 30px 30px 26px; }
.auth-card h1 { font-size: 21px; margin-top: 18px; }
.auth-card .lead { color: var(--text-2); margin: 6px 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .btn { height: 42px; }
.auth-foot { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }

/* ── 업로드 ── */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 34px 20px; text-align: center; background: var(--surface);
  transition: border-color .12s, background .12s; cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-50); }
.dropzone .big { font-size: 16px; font-weight: 650; margin-top: 10px; }
.dropzone svg { width: 36px; height: 36px; color: var(--primary); }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step { display: flex; gap: 10px; align-items: center; font-size: 13.5px; color: var(--text-2); }
.step .ico { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; display: grid; place-items: center; font-size: 11px; }
.step.done { color: var(--text); }
.step.done .ico { background: var(--st-good); border-color: var(--st-good); color: #fff; }
.step.run .ico { border-color: var(--primary); border-top-color: transparent; animation: spin .8s linear infinite; }
.step.err .ico { background: var(--st-critical); border-color: var(--st-critical); color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--primary-100); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 60px 0; color: var(--text-2); }
.progress { height: 8px; border-radius: 999px; background: var(--primary-100); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s; }

.matrix td.cell-ok { color: var(--good); font-weight: 600; }
.matrix td.cell-none { color: var(--border-strong); }
.perm-grid { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--primary-700); border-bottom-color: var(--primary); }
.tabs button:hover { color: var(--text); }

.cov { display: flex; flex-wrap: wrap; gap: 8px; }
.cov .chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--text-2); display: inline-flex; gap: 6px; align-items: center; }
.cov .chip b { color: var(--text); font-weight: 650; }

@media (max-width: 1180px) {
  .grid.c4, .grid.c5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c-2-1, .grid.c-3-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 8px 16px 40px; }
  .grid.c2, .grid.c3, .grid.c4, .grid.c5 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters .search { width: 100%; }
}
@media print {
  .sidebar, .topbar .row, .filters, .btn { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; }
}
