:root {
  --header-bg: #213a66;
  --accent: #2f6fed;
  --accent-soft: #e8effd;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ec;
  --text: #1f2430;
  --text-sub: #6b7280;
  --heading: #1b2a4a;
  --danger: #d9443e;
  --danger-soft: #fdecec;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --good: #0f8a5f;
  --good-soft: #e3f5ec;
  --info: #2563eb;
  --info-soft: #e7effd;
  --muted-soft: #eef0f3;
  --partzone: #c2410c;
  --e2b: #0f766e;
  --on-color: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --header-bg: #1a2c4f;
    --accent: #6094ff;
    --accent-soft: #223050;
    --bg: #12151b;
    --surface: #1b1f27;
    --border: #2c323d;
    --text: #e7eaf0;
    --text-sub: #9aa4b2;
    --heading: #8fb4ff;
    --danger: #ef6b66;
    --danger-soft: #3a1f22;
    --warn: #f0b04a;
    --warn-soft: #3a2e17;
    --good: #4fd1a1;
    --good-soft: #173a2f;
    --info: #7aa7ff;
    --info-soft: #1f2d4d;
    --muted-soft: #262b35;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; color: var(--heading); }
h2 { font-size: 15px; margin: 0; color: var(--heading); }

/* ---------- 틀 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20; height: 52px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--header-bg); color: var(--on-color);
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { color: var(--on-color); font-weight: 700; font-size: 16px; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-sub { opacity: .7; font-size: 12px; white-space: nowrap; }
.menu-toggle { display: none; background: none; border: 0; color: var(--on-color); font-size: 20px; cursor: pointer; }
.org-select { height: 32px; border-radius: 6px; border: 0; padding: 0 8px; max-width: 260px; }
.user-name { font-size: 13px; opacity: .9; white-space: nowrap; }
.btn-ghost { background: transparent; color: var(--on-color); border-color: rgba(255,255,255,.4); }

.banner { background: var(--warn-soft); color: var(--warn); padding: 6px 16px; font-size: 13px; }
.link-btn { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }

.app-body { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
  width: 200px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 2px;
}
.sidebar a { padding: 9px 12px; border-radius: 6px; color: var(--text); font-weight: 600; }
.sidebar a:hover { background: var(--accent-soft); text-decoration: none; }
.sidebar a.active { background: var(--accent); color: var(--on-color); }
.nav-later { margin: 14px 0 8px; padding: 10px 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-sub); }
.nav-disabled { opacity: .7; padding-left: 4px; }
.nav-links { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; }
.nav-links a { font-weight: 400; font-size: 12px; color: var(--text-sub); padding: 5px 12px; }
.scrim { display: none; }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }

.gate { display: flex; justify-content: center; padding: 80px 16px; }
.gate-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; max-width: 420px; text-align: center; }
.gate-card p { color: var(--text-sub); line-height: 1.6; }
.gate-form { width: 100%; max-width: 380px; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.gate-form h1, .gate-form > p { text-align: center; margin: 0; }
.gate-form .field input { height: 40px; }
.wide-btn { width: 100%; justify-content: center; height: 40px; }
.gate-links { display: flex; justify-content: center; gap: 16px; font-size: 13px; }
.gate-actions { display: flex; flex-direction: column; gap: 8px; }
.gate-actions .btn { justify-content: center; }
.gate-msg { color: var(--good) !important; font-size: 13px; text-align: center; margin: 0; }
.btn-ghost-dark { background: transparent; border-color: transparent; color: var(--text-sub); }

/* ---------- 공통 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.head-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 10px; font-size: 13px; }
.loading, .empty { color: var(--text-sub); padding: 12px 0; text-align: center; }
.hint { color: var(--text-sub); font-size: 12px; margin: 8px 0; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 16px; border-radius: 8px; }
.form-error { color: var(--danger); font-size: 13px; margin: 8px 16px 0; }

.btn {
  display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-color); }
.btn-accent { color: var(--good); border-color: var(--good); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.icon-btn { background: none; border: 0; font-size: 16px; cursor: pointer; color: var(--text-sub); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-good { background: var(--good-soft); color: var(--good); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }
.tone-bad { background: var(--danger-soft); color: var(--danger); }
.tone-muted { background: var(--muted-soft); color: var(--text-sub); }
.org-chip { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; color: var(--on-color); background: var(--text-sub); }
.org-PARTZONE { background: var(--partzone); }
.org-E2B { background: var(--e2b); }

.dday { display: inline-block; min-width: 44px; text-align: center; padding: 1px 6px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.dday-over { background: var(--danger); color: var(--on-color); }
.dday-soon { background: var(--warn-soft); color: var(--warn); }
.dday-later { background: var(--muted-soft); color: var(--text-sub); }
.dday-done { color: var(--text-sub); font-weight: 400; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.chip b { color: var(--text-sub); font-weight: 600; margin-left: 2px; }
.chip.active { background: var(--heading); border-color: var(--heading); color: var(--surface); }
.chip.active b { color: inherit; }
.search { height: 32px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; min-width: 220px; background: var(--surface); color: var(--text); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.card .table-wrap { border: 0; border-radius: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { font-size: 12px; color: var(--text-sub); font-weight: 600; background: var(--bg); white-space: nowrap; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: var(--accent-soft); }
.table tr.done td { color: var(--text-sub); }
.table tr.current td { background: var(--good-soft); }
.table.compact th, .table.compact td { padding: 7px 8px; }
.table.compact tbody th { font-weight: 500; color: var(--text-sub); }
.table tr.total th, .table tr.total td { font-weight: 700; color: var(--text); border-top: 2px solid var(--border); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.table td:last-child { white-space: nowrap; }
.cell-title { font-weight: 600; min-width: 180px; }
.cell-title.small { font-size: 13px; }
.cell-sub { color: var(--text-sub); font-size: 12px; }
.mini-link { font-size: 12px; white-space: nowrap; }
td.empty { padding: 28px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0 10px; }
.card-head:not(:first-child) { margin-top: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.dl { margin: 0; display: grid; gap: 0; }
.dl > div { display: grid; grid-template-columns: 120px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-sub); }
.dl dd { margin: 0; word-break: break-word; }
.danger-zone { margin-top: 20px; text-align: right; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 10px 14px; color: var(--text-sub); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab.disabled { opacity: .45; cursor: not-allowed; }
.tab b { font-size: 11px; background: var(--muted-soft); padding: 1px 6px; border-radius: 999px; }

/* ---------- 대시보드 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; color: var(--text); display: flex; flex-direction: column; gap: 4px; }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat span { color: var(--text-sub); font-size: 13px; }
.stat b { font-size: 26px; color: var(--heading); }
.stat small { color: var(--text-sub); font-size: 12px; }
.stat-bad { border-color: var(--danger); }
.stat-bad b { color: var(--danger); }
.sub-head { font-size: 12px; color: var(--text-sub); margin: 12px 0 6px; }
.sub-head.bad { color: var(--danger); }
.deadlines { display: flex; flex-direction: column; }
.deadline { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--border); color: var(--text); }
.deadline:last-child { border-bottom: 0; }
.deadline:hover { background: var(--accent-soft); text-decoration: none; }
.deadline.done { opacity: .55; }
.deadline-date { font-variant-numeric: tabular-nums; color: var(--text-sub); width: 42px; flex: none; }
.deadline-kind { font-size: 12px; color: var(--text-sub); width: 58px; flex: none; }
.deadline-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.deadline-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deadline-main small { color: var(--text-sub); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.plain-list li:last-child { border-bottom: 0; }

/* ---------- 달력 ---------- */
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav b { min-width: 90px; text-align: center; }
.legend { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--border); gap: 1px; margin-bottom: 16px; }
.cal-head { background: var(--bg); padding: 6px; text-align: center; font-size: 12px; font-weight: 600; color: var(--text-sub); }
.cal-cell { background: var(--surface); min-height: 96px; padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-cell.blank { background: var(--bg); }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day { font-size: 12px; color: var(--text-sub); padding: 0 2px; }
.sun, .sun .cal-day { color: var(--danger); }
.sat, .sat .cal-day { color: var(--info); }
.cal-ev { display: block; font-size: 11px; padding: 2px 5px; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-ev:hover { text-decoration: none; filter: brightness(.95); }
.ev-notice { background: var(--warn-soft); color: var(--warn); }
.ev-milestone { background: var(--info-soft); color: var(--info); }
.cal-ev.over { background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.cal-ev.done { background: var(--muted-soft); color: var(--text-sub); text-decoration: line-through; }
.legend .cal-ev { display: inline-block; }

/* ---------- 공고 검색 ---------- */
.search-grid { display: grid; grid-template-columns: 2fr 1.4fr 1fr auto; gap: 12px; align-items: end; }
.search-actions { flex-direction: row; align-items: center; gap: 12px; }
.result-head { margin: 4px 2px 8px; }
.results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.result { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.result-main { flex: 1; min-width: 0; }
.result-side { flex: none; display: flex; align-items: flex-start; }
.result-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--text-sub); flex-wrap: wrap; }
.result h3 { font-size: 15px; margin: 6px 0 4px; }
.result h3 a { color: var(--heading); }
.result-sum { margin: 0 0 6px; color: var(--text-sub); font-size: 13px; line-height: 1.5; }
.result-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--text-sub); }
.tag { color: var(--accent); }
.ext-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ext-link { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; color: var(--text); }
.ext-link:hover { border-color: var(--accent); text-decoration: none; }
.ext-link small { color: var(--text-sub); }

/* ---------- 연구노트 ---------- */
.row-gap { display: flex; gap: 6px; flex-wrap: wrap; }
.demo-user { height: 24px; margin-left: 4px; font-size: 12px; }
.warn-text { color: var(--warn); }
.note-view h4 { font-size: 12px; color: var(--text-sub); margin: 14px 0 4px; }
.note-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-sub); }
.note-meta b { color: var(--text); }
.note-title { font-size: 17px; margin: 8px 0 0; color: var(--heading); }
.note-text { line-height: 1.65; white-space: normal; word-break: break-word; }
.note-att { margin: 0; padding-left: 18px; }
.sign-box { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sign-box > div { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.sign-box span { font-size: 12px; color: var(--text-sub); }
.sign-box small { color: var(--text-sub); }
.hash { font-size: 11px; color: var(--text-sub); word-break: break-all; margin: 8px 0 0; }
.hash code { font-size: 11px; }
.confirm-field { margin-top: 12px; }
.rev { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.rev-head { font-size: 13px; color: var(--text-sub); }
.rev details { margin-top: 6px; }
.rev summary { cursor: pointer; color: var(--accent); font-size: 13px; }

/* 인쇄·보관본 */
body.print-mode .app-header, body.print-mode .sidebar, body.print-mode .banner { display: none; }
body.print-mode .main { max-width: 860px; margin: 0 auto; }
.print-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.print-page { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px 28px; margin-bottom: 20px; }
.print-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--text); padding-bottom: 8px; margin-bottom: 12px; font-size: 13px; }
.print-no { font-weight: 700; font-size: 15px; white-space: nowrap; }
.paper-sign { margin-top: 18px; display: flex; flex-direction: column; gap: 14px; font-size: 13px; }
.print-foot { margin-top: 16px; font-size: 11px; color: var(--text-sub); text-align: right; }
@media print {
  body { background: #fff; color: #000; }
  .no-print { display: none !important; }
  body.print-mode .main { padding: 0; max-width: none; }
  .print-page { border: 0; border-radius: 0; padding: 0; margin: 0; break-after: page; }
  .print-page:last-child { break-after: auto; }
  .sign-box > div { border-color: #999; }
  a { color: #000; }
}

/* ---------- 사업비·증빙·인력 ---------- */
.neg { color: var(--danger); }
.bar { height: 8px; background: var(--muted-soft); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.form-grid.three { grid-template-columns: repeat(3, 1fr); margin-bottom: 12px; }
.plan-table input { width: 100%; height: 32px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; text-align: right; background: var(--surface); color: var(--text); font: inherit; }
textarea.full { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font: inherit; background: var(--surface); color: var(--text); }
.docs { display: flex; flex-direction: column; gap: 4px; }
.doc { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.doc:hover { background: var(--bg); }
.doc span { flex: 1; }
.doc-add { display: flex; gap: 6px; margin-top: 4px; }
.doc-add input { flex: 1; height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; background: var(--surface); color: var(--text); font: inherit; }

/* ---------- 모달·폼 ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-sub); }
.field em { color: var(--danger); font-style: normal; }
.field small { font-size: 11px; color: var(--text-sub); }
.field input, .field select, .field textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
.field textarea { height: auto; padding: 8px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.checks { display: flex; flex-direction: column; gap: 6px; }
.checks input, .check-line input { width: auto; height: auto; }
.check-line { flex-direction: row; align-items: center; gap: 8px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--heading); color: var(--surface); padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* ---------- 모바일 ---------- */
@media (max-width: 900px) {
  .grid-2, .stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .menu-toggle { display: block; }
  .logo-sub, .user-name { display: none; }
  .org-select { max-width: 140px; }
  .sidebar { position: fixed; top: 52px; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 52px 0 0 0; z-index: 25; background: rgba(0,0,0,.3); }
  .main { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; }
  .search-grid, .ext-links, .form-grid.three { grid-template-columns: 1fr; }
  .result { flex-direction: column; }
  .cal-cell { min-height: 64px; }
  .cal-ev { font-size: 10px; padding: 1px 3px; }
  .dl > div { grid-template-columns: 96px 1fr; }
  .deadline-kind { display: none; }
}
