:root {
  --navy: #0b1f3a;
  --navy-2: #13294b;
  --blue: #1f5fbf;
  --gold: #c9a35b;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #1a1d23;
  --muted: #5d6573;
  --line: #e4e7ec;
  --lv-critical: #d92d20;
  --lv-high: #f17a0a;
  --lv-medium: #e6b100;
  --lv-low: #17a364;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1420;
    --surface: #152033;
    --surface-2: #1b2840;
    --ink: #e7ecf3;
    --muted: #9aa6b8;
    --line: #26354f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Pretendard", -apple-system, "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5; word-break: keep-all;
  font-size: 14px;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden, [hidden] { display: none !important; }
.spacer { flex: 1; }

/* ---------- Top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 0 20px; height: 64px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--gold); font-size: 22px; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.3px; }
.brand small { display: block; font-size: 11px; opacity: .6; letter-spacing: .5px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  background: none; border: 0; color: rgba(255, 255, 255, .7); padding: 8px 16px;
  border-radius: 999px; cursor: pointer; font-weight: 600;
}
.tab:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.tab.active { color: var(--navy); background: var(--gold); }
.project-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; opacity: .95; }
.project-pick select {
  background: var(--navy-2); color: #fff; border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 8px; padding: 7px 10px; max-width: 280px;
}

.user { display: flex; align-items: center; gap: 10px; font-size: 12px; color: rgba(255, 255, 255, .8); white-space: nowrap; }
.user a { color: var(--gold); font-weight: 600; text-decoration: none; }
.user a:hover { text-decoration: underline; }
.blocker { max-width: 560px; margin: 80px auto; text-align: center; }
.blocker h2 { font-size: 20px; margin-bottom: 10px; }
.blocker p { color: var(--muted); }

/* ---------- Layout ---------- */
.container { max-width: 1320px; margin: 0 auto; padding: 24px 20px 60px; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card h2 { font-size: 16px; letter-spacing: -.3px; }
.card h2 small { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 6px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.grid-2 > .card { margin-bottom: 20px; min-width: 0; }
.card { min-width: 0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--blue)); }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi strong { display: block; font-size: 26px; letter-spacing: -.5px; margin: 4px 0 2px; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.click { cursor: pointer; }
.kpi.click:hover { border-color: var(--accent, var(--blue)); }

/* ---------- Matrix ---------- */
.matrix-wrap { display: grid; grid-template-columns: 22px minmax(0, 1fr); grid-template-rows: 1fr auto; gap: 6px; }
.axis-y { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.axis-x { grid-column: 2; text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.matrix { display: grid; grid-template-columns: 70px repeat(5, minmax(0, 1fr)); gap: 4px; }
.matrix .lbl { font-size: 11px; color: var(--muted); display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.2; }
.matrix .cell {
  aspect-ratio: 1.6; border-radius: 8px; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #fff; transition: transform .15s;
}
.matrix .cell small { font-size: 10px; font-weight: 600; opacity: .85; }
.matrix .cell.empty { color: rgba(255, 255, 255, .9); font-weight: 500; font-size: 12px; opacity: .35; cursor: default; }
.matrix .cell:not(.empty):hover { transform: scale(1.05); }
.lv-bg-매우높음 { background: var(--lv-critical); }
.lv-bg-높음 { background: var(--lv-high); }
.lv-bg-보통 { background: var(--lv-medium); }
.lv-bg-낮음 { background: var(--lv-low); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 18px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 5px 12px; cursor: pointer; font-size: 12px; color: var(--muted); }
.seg button.active { background: var(--navy); color: #fff; }

/* ---------- Bars ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { font-weight: 600; }
.bar-track { height: 18px; background: var(--surface-2); border-radius: 5px; display: flex; overflow: hidden; }
.bar-track span { height: 100%; }
.bar-row .val { text-align: right; color: var(--muted); font-size: 12px; }
.bar-row .val b { color: var(--ink); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl.clickable tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .nowrap { white-space: nowrap; }
.tbl .title-cell { font-weight: 600; min-width: 220px; }
.tbl .title-cell small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.empty-row { text-align: center; color: var(--muted); padding: 36px 0 !important; }
.code { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
td.code { white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap; color: #fff;
}
.badge.lv-매우높음 { background: var(--lv-critical); }
.badge.lv-높음 { background: var(--lv-high); }
.badge.lv-보통 { background: var(--lv-medium); color: #3a2c00; }
.badge.lv-낮음 { background: var(--lv-low); }
.status {
  display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap;
}
.status.s-대응중 { color: #1f5fbf; border-color: #b9d0f3; background: #eef4fd; }
.status.s-종결 { color: #5d6573; text-decoration: line-through; }
.status.s-식별 { color: #8a5a00; border-color: #f2d699; background: #fff8e8; }
.status.s-평가 { color: #6b3fbf; border-color: #d6c6f3; background: #f5f0fd; }
.status.s-모니터링 { color: #0d7a52; border-color: #b6e3cf; background: #ecf8f2; }
.overdue-tag { color: var(--lv-critical); font-weight: 700; font-size: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--navy); color: #fff;
  border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 12px;
}
.chip button { background: rgba(255, 255, 255, .2); border: 0; color: #fff; border-radius: 50%; width: 18px; height: 18px; cursor: pointer; line-height: 1; }

/* ---------- Due lists ---------- */
.due-list { list-style: none; display: grid; gap: 8px; max-height: 300px; overflow: auto; }
.due-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.due-list li:hover { background: var(--surface-2); }
.due-list .t { font-weight: 600; font-size: 13px; }
.due-list .t small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.due-list .d { font-size: 12px; text-align: right; white-space: nowrap; }
.due-list .empty { cursor: default; color: var(--muted); grid-template-columns: 1fr; text-align: center; }

/* ---------- Toolbar & buttons ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; }
.toolbar input[type=search] { flex: 1 1 240px; }
.toolbar input[type=search], .toolbar select, .form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface);
}
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 16px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--blue); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--lv-critical); }
.btn.danger:hover { border-color: var(--lv-critical); }
.list-meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.list-meta b { color: var(--ink); }

/* ---------- Projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.pcard .type { font-size: 12px; color: var(--blue); font-weight: 700; }
.pcard h3 { font-size: 17px; margin: 4px 0 6px; letter-spacing: -.3px; }
.pcard .meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.pcard .stats { display: flex; gap: 18px; margin: 14px 0; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pcard .stats div span { display: block; font-size: 11px; color: var(--muted); }
.pcard .stats div b { font-size: 18px; }
.pcard .progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.pcard .progress span { display: block; height: 100%; background: var(--gold); }
.pcard .actions { display: flex; gap: 8px; }

/* ---------- Modal ---------- */
.modal {
  border: 0; border-radius: 16px; padding: 0; width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); margin: auto; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.modal.small { width: min(560px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(11, 31, 58, .55); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 10px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.modal-foot { border-bottom: 0; border-top: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; flex: 1; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.x { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.form-grid label > * { font-weight: 400; color: var(--ink); font-size: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.form-grid textarea { resize: vertical; }
.form-grid .invalid { border-color: var(--lv-critical) !important; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 16px; }
legend { padding: 0 6px; font-weight: 700; font-size: 13px; }
.score-preview, .emv-preview {
  display: flex; flex-direction: column; justify-content: center; padding: 8px 12px;
  border-radius: 10px; background: var(--surface-2); font-size: 12px; color: var(--muted);
}
.score-preview b, .emv-preview b { font-size: 18px; color: var(--ink); }
.form-error { color: var(--lv-critical); font-weight: 600; margin-top: 12px; min-height: 1em; }

/* ---------- Drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.drawer::before { content: ""; position: absolute; inset: 0; background: rgba(11, 31, 58, .4); opacity: 0; transition: opacity .2s; }
.drawer.open { pointer-events: auto; }
.drawer.open::before { opacity: 1; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface);
  transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(0, 0, 0, .2);
}
.drawer.open .drawer-panel { transform: none; }
.drawer-head { display: flex; gap: 12px; align-items: flex-start; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.drawer-head > div { flex: 1; }
.drawer-head h2 { font-size: 18px; margin-top: 4px; letter-spacing: -.3px; }
.drawer-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 13px; margin-bottom: 18px; }
.kv dt { color: var(--muted); }
.kv dd { white-space: pre-wrap; }
.score-cmp { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin-bottom: 18px; }
.score-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.score-box > span:first-child { font-size: 12px; color: var(--muted); display: block; }
.score-box b { font-size: 26px; display: block; margin: 2px 0 4px; }
.drawer h3 { font-size: 14px; margin: 18px 0 10px; }
.quick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.quick select, .note-form input, .note-form textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); }
.note-form { display: grid; gap: 8px; margin-bottom: 16px; }
.note-form .row { display: flex; gap: 8px; }
.note-form .row input { flex: 1; }
.timeline { list-style: none; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li { position: relative; padding: 0 0 14px 16px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.k-note::before { background: var(--blue); }
.timeline li.k-status::before { background: var(--gold); }
.timeline li.k-assess::before { background: var(--lv-high); }
.timeline li.k-create::before { background: var(--lv-low); }
.timeline .when { color: var(--muted); font-size: 11px; }
.timeline .msg { white-space: pre-wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0;
  background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 10px; font-weight: 600;
  transition: all .25s; z-index: 60; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--lv-critical); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; }
  .project-pick { margin-left: auto; }
  .user { order: 4; flex-basis: 100%; justify-content: flex-end; }
  .project-pick select { max-width: 150px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .project-grid { grid-template-columns: minmax(0, 1fr); }
  .container { padding: 16px 16px 48px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-3 { grid-column: span 2; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi strong { font-size: 21px; }
  .brand small { display: none; }
  .card { padding: 16px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: auto; }
  .matrix { grid-template-columns: 44px repeat(5, minmax(0, 1fr)); gap: 3px; }
  .matrix .cell { font-size: 15px; aspect-ratio: 1.2; }
  .matrix .lbl { font-size: 10px; }
  .bar-row { grid-template-columns: 70px 1fr 80px; }
}
