/* 포탈(portal/style.css)과 같은 디자인 토큰 계열 */
:root {
  color-scheme: light;
  --bg: #f8f8fb;
  --surface: #ffffff;
  --surface-2: #f4f5f8;
  --border: #ececf1;
  --border-strong: #e0e1e8;
  --text: #1f2329;
  --text-sub: #495057;
  --text-dim: #9a9fa8;
  --accent: #4263eb;
  --accent-soft: #edf0fe;
  --positive: #2f9e44;
  --warn: #f08c00;
  --danger: #e03131;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 35, 41, 0.04), 0 8px 24px rgba(31, 35, 41, 0.05);

  /* 단계 색 */
  --st-prep: #adb5bd;
  --st-applied: #f08c00;
  --st-active: #4263eb;
  --st-done: #868e96;

  /* 규모 막대 */
  --fund-gov: #4263eb;
  --fund-private: #bac8ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont,
               'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── 상단 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; gap: 2px; }
.crumb { font-size: 12px; color: var(--text-dim); text-decoration: none; }
.crumb:hover { color: var(--accent); }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.sync-status { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.sync-status.ok { color: var(--positive); }
.sync-status.err { color: var(--danger); }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3b5bdb; }
.btn-danger { color: var(--danger); border-color: #ffc9c9; }
.btn-danger:hover { background: #fff5f5; }

/* ── 본문 ── */
.wrap { max-width: none; margin: 0; padding: 24px 32px 48px; display: flex; flex-direction: column; gap: 20px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi-label { font-size: 12.5px; color: var(--text-sub); }
.kpi-value { margin-top: 4px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; font-weight: 600; color: var(--text-sub); margin-left: 2px; }
.kpi-sub { margin-top: 2px; font-size: 12px; color: var(--text-dim); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--text-dim); }

/* ── 단계 표시 ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-sub);
  white-space: nowrap;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.st-prep    { color: #6c757d; background: #f1f3f5; }
.badge.st-applied { color: #d9480f; background: #fff4e6; }
.badge.st-active  { color: var(--accent); background: var(--accent-soft); }
.badge.st-done    { color: #868e96; background: #f1f3f5; }

/* ── 필터 ── */
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12.5px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }
.chip .n { margin-left: 4px; opacity: .65; font-variant-numeric: tabular-nums; }
#search {
  width: 220px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
}

/* ── 일정(간트) ── */
.timeline { position: relative; }
.tl-axis, .tl-row { display: grid; grid-template-columns: 220px 1fr; align-items: center; }
.tl-axis { height: 24px; font-size: 11.5px; color: var(--text-dim); }
.tl-track { position: relative; height: 100%; }
.tl-year {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid var(--border-strong);
  padding-left: 5px;
  font-variant-numeric: tabular-nums;
}
.tl-row { height: 30px; cursor: pointer; border-radius: 6px; }
.tl-row:hover { background: var(--surface-2); }
.tl-label { padding-right: 12px; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-sub); }
.tl-bar {
  position: absolute; top: 8px; height: 14px;
  border-radius: 4px;
  min-width: 4px;
}
.tl-bar.st-prep    { background: var(--st-prep); }
.tl-bar.st-applied { background: repeating-linear-gradient(45deg, var(--st-applied) 0 6px, #ffa94d 6px 12px); }
.tl-bar.st-active  { background: var(--st-active); }
.tl-bar.st-done    { background: var(--st-done); opacity: .55; }
.tl-grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); pointer-events: none; }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); pointer-events: none; z-index: 2; }
.tl-today span {
  position: absolute; top: -2px; left: 4px;
  font-size: 11px; font-weight: 600; color: var(--danger); white-space: nowrap;
}
.tl-overlay { position: absolute; top: 0; bottom: 0; right: 0; pointer-events: none; }
.tl-undated { margin-top: 10px; font-size: 12px; color: var(--text-dim); }

/* ── 목록 ── */
.table-wrap { overflow-x: auto; }
table.projects { width: 100%; border-collapse: collapse; min-width: 960px; }
.projects th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-sub);
  padding: 8px 10px; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.projects td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.projects tbody tr { cursor: pointer; }
.projects tbody tr:hover td { background: #fafbff; }
.projects .num { text-align: right; }
.unit { font-weight: 400; color: var(--text-dim); }

.p-program { font-size: 12px; color: var(--text-dim); }
.p-title { font-weight: 600; margin-top: 1px; }
.p-role { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-sub); vertical-align: 1px; }
.p-role.lead { background: var(--accent-soft); color: var(--accent); }
.p-agency { font-size: 12.5px; color: var(--text-sub); max-width: 200px; }
.p-managers { white-space: nowrap; }
.p-period { font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-period .sub { color: var(--text-dim); font-size: 11.5px; }

.elapsed { margin-top: 5px; width: 140px; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.elapsed > i { display: block; height: 100%; background: var(--text-dim); }

.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.money .total { font-weight: 700; }
.money .split { font-size: 11.5px; color: var(--text-dim); }
.money .note { font-size: 11.5px; color: var(--text-dim); max-width: 180px; white-space: normal; margin-left: auto; }
.fund-bar { display: flex; height: 6px; margin: 5px 0 3px auto; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.fund-bar .gov { background: var(--fund-gov); }
.fund-bar .pri { background: var(--fund-private); }

.progress { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress .ring-text { font-weight: 700; }
.progress .dim { color: var(--text-dim); }

.empty { text-align: center; color: var(--text-dim); padding: 28px 0; margin: 0; }
.foot-note { margin: 12px 0 0; font-size: 12px; color: var(--text-dim); }

/* ── 편집 창 ── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  background: rgba(31, 35, 41, .35);
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 720px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(31, 35, 41, .25);
  padding: 20px 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.icon-btn { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-dim); padding: 4px 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-sub); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 400;
  color: var(--text);
}
.form-grid textarea { resize: vertical; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.modal-foot { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.modal-foot .spacer { flex: 1; }

/* ── 좁은 화면 ── */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tl-axis, .tl-row { grid-template-columns: 120px 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .wrap { padding: 16px 16px 40px; }
  .kpi-value { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  #search { width: 100%; }
  .filters { width: 100%; }
}

/* 좁은 화면에서도 과제명 열이 너무 좁아지지 않게(표는 가로로 넘긴다) */
.projects td:nth-child(2) { min-width: 280px; }
.projects td:nth-child(3) { min-width: 150px; }

/* ── 연도별 수주 총사업비 ── 막대 = 총사업비, 안쪽 진한 색 = 정부지원금 */
.year-chart { display: flex; flex-direction: column; gap: 14px; }
.yc-sum { display: flex; gap: 28px; flex-wrap: wrap; }
.yc-sum div { display: flex; flex-direction: column; gap: 2px; }
.yc-sum span { font-size: 12px; color: var(--text-dim); }
.yc-sum b { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.yc-sum small { font-size: 12px; font-weight: 600; margin-left: 2px; color: var(--text-dim); }

.yc-plot {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 220px;
  padding: 26px 0 0 34px;   /* 위: 값 라벨 자리, 왼쪽: 눈금 글자 자리 */
  margin-bottom: 34px;      /* 연도 라벨 자리 */
}
.yc-grid {
  position: absolute;
  left: 34px;
  right: 0;
  border-top: 1px dashed rgba(20, 23, 38, 0.1);
  pointer-events: none;
}
.yc-grid span { position: absolute; left: -34px; top: -7px; font-size: 10px; color: var(--text-dim); font-style: normal; }
.yc-col {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  cursor: pointer;
}
.yc-bar {
  position: relative;
  width: min(56px, 70%);
  min-height: 2px;
  border-radius: 10px 10px 4px 4px;
  background: #c7d2fe;
  overflow: hidden;
  transform-origin: bottom;
  animation: yc-grow 0.7s cubic-bezier(.2, .7, .2, 1) both;
  transition: filter 0.15s, transform 0.15s;
}
.yc-bar i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); border-radius: 0 0 4px 4px; }
.yc-col:nth-child(n) .yc-bar { animation-delay: calc(var(--d, 0) * 1ms); }
@keyframes yc-grow { from { transform: scaleY(0); } }
.yc-col:hover .yc-bar { filter: brightness(1.06) saturate(1.15); transform: translateY(-2px); }
.yc-col.picked .yc-bar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.yc-col.now .yc-bar { background: #a5b4fc; }
.yc-val {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #17191c;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.yc-year {
  position: absolute;
  bottom: -32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: #3d4048;
}
.yc-year small { font-size: 10px; font-weight: 500; color: var(--text-dim); }
.yc-col.picked .yc-year { color: var(--accent); }
.yc-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); }
.yc-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.yc-legend i.t { background: #c7d2fe; }
.yc-legend i.g { background: var(--accent); margin-left: 8px; }
@media (prefers-reduced-motion: reduce) { .yc-bar { animation: none; } }
@media (max-width: 640px) { .yc-plot { gap: 6px; } .yc-val { font-size: 10px; } }

/* 총사업비 기준 전환(당사분 / 컨소시엄 전체) */
.yc-basis { flex-direction: row !important; align-self: flex-start; padding: 3px; gap: 0 !important; border-radius: 10px; background: #f2f3f7; }
.yc-basis button { font: inherit; font-size: 12px; font-weight: 600; color: var(--text-dim); padding: 5px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.yc-basis button[aria-pressed="true"] { background: #fff; color: #17191c; box-shadow: 0 1px 3px rgba(20, 23, 38, 0.1); }
/* 과제 유형 꼬리표 */
.p-type { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; background: #f2f3f7; color: #5c616b; font-size: 11px; font-weight: 600; }

/* 기간(연도) 선택 */
.range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
}
.range-label { font-size: 13px; font-weight: 700; color: #17191c; margin-right: 4px; }
.range select {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.range-dash { color: var(--text-dim); }
.range-quick { display: inline-flex; padding: 3px; margin-left: 6px; border-radius: 10px; background: #f2f3f7; }
.range-quick button { font: inherit; font-size: 12px; font-weight: 600; color: var(--text-dim); padding: 5px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; }
.range-quick button[aria-pressed="true"] { background: #fff; color: #17191c; box-shadow: 0 1px 3px rgba(20, 23, 38, 0.1); }
.range-hint { margin-left: auto; font-size: 11px; color: var(--text-dim); }
/* 한 해만 볼 때 달 눈금 */
.tl-year.tl-month { font-size: 10px; opacity: 0.75; }
.tl-grid-line.tl-grid-month { opacity: 0.45; }

/* 새로고침 버튼 — 다른 대시보드와 같은 모양(파란 알약 + 아이콘, 누르면 한 바퀴) */
.refresh-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #4263eb; color: #fff;
  border: 0; border-radius: 999px;
  padding: 8px 14px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  white-space: nowrap;
}
.refresh-btn:hover { background: #3651c8; transform: translateY(-1px); }
.refresh-btn:active { transform: translateY(0); }
.refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.refresh-btn .refresh-icon { width: 14px; height: 14px; transition: transform 0.6s; }
.refresh-btn.spinning .refresh-icon { transform: rotate(360deg); }
