:root {
  --navy: #0f1a33;
  --navy-light: #16264a;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --border: #e5e7eb;
  --text: #1f2328;
  --muted: #6b7280;
  --bg: #f6f7f9;
  --green: #16a34a;
  --red: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Pretendard, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }

/* Top bar */
.topbar {
  background: var(--navy);
  color: #fff;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.6rem 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: #fff;
  line-height: 1.15;
  font-weight: 700;
}
.brand-logo {
  height: 32px;
  width: auto;
  display: block;
}
.brand-text { display: flex; flex-direction: column; }
.brand-line1 { font-size: 0.85rem; opacity: 0.75; }
.brand-line2 { font-size: 1.05rem; }

.nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.nav-link {
  text-decoration: none;
  color: #cdd5e5;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}
.nav-link.active, .nav-link:hover {
  background: var(--blue);
  color: #fff;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role {
  font-size: 0.7rem;
  color: #cdd5e5;
  background: var(--navy-light);
  border-radius: 999px;
  padding: 0 0.5rem;
  display: inline-block;
  width: fit-content;
}
.logout {
  text-decoration: none;
  color: #cdd5e5;
  font-size: 0.8rem;
  border-left: 1px solid #34405f;
  padding-left: 0.75rem;
  margin-left: 0.25rem;
}

/* Page */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.page-title { margin: 0 0 0.25rem; font-size: 1.4rem; }
.page-subtitle { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }

/* Flash */
.flash-stack { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash { padding: 0.6rem 1rem; border-radius: 8px; font-size: 0.88rem; }
.flash-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Toolbar */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.input, select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  background: #fff;
}
.input { min-width: 260px; }
.spacer { flex: 1; }

.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* Cards */
.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
}
.card-label { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.4rem; }
.card-value { font-size: 1.3rem; font-weight: 700; }
.card-value.pos { color: var(--green); }
.card-value.neg { color: var(--red); }

/* Table */
.table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

/* 가로로 넓은 표: 아래쪽에 가로 스크롤바를 두고 첫 번째 열(기업명)은 스크롤해도 고정 */
.table-wrap.scroll-sticky {
  overflow-x: auto;
  overflow-y: hidden;
}
.scroll-sticky table th:first-child,
.scroll-sticky table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}
.scroll-sticky table thead th:first-child {
  background: var(--navy);
  z-index: 2;
}
.scroll-sticky table tbody tr:hover td:first-child {
  background: #fafafa;
}
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
thead th {
  background: var(--navy);
  color: #fff;
  text-align: left;
  padding: 0.7rem 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}
tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }
td.num, th.num { text-align: right; }
.entity-link { color: var(--blue); font-weight: 600; text-decoration: none; }
.muted { color: var(--muted); }
.count-line { margin-bottom: 0.6rem; color: var(--muted); font-size: 0.85rem; }

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-progress { background: var(--blue-light); color: var(--blue); }
.badge-done { background: #f3f4f6; color: var(--muted); }
.badge-neutral { background: #f3f4f6; color: #6b7280; border: 1px solid #e5e7eb; }
.badge-success { background: #ecfdf5; color: var(--green); border: 1px solid #a7f3d0; }
.badge-transferred { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.badge-impaired { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }

/* 잔여현금 추이 구분 필터 팝오버 */
.filter-toggle-btn {
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.68rem;
  margin-left: 0.25rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-weight: 400;
  color: var(--text);
}
.filter-popover {
  display: none;
  position: absolute;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-weight: 400;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 51, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

/* Forms */
.form-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 560px;
}
.form-row { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.form-row label { font-size: 0.85rem; font-weight: 600; }
.form-row input, .form-row select {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}
.form-actions { display: flex; gap: 0.6rem; margin-top: 1.25rem; }

/* Detail */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
}
.detail-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.3rem; }
.detail-value { font-size: 1.05rem; font-weight: 700; }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 1.75rem 0 0.75rem; }

/* Inline recovery-plan add row */
.align-right th, .align-right td { text-align: right; }
.new-row td { background: #fafbfe; }
.row-input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  width: 100%;
  max-width: 160px;
  text-align: right;
}

/* Import history: clickable row + detail panel */
.clickable-row { cursor: pointer; }
.hidden { display: none; }
.snapshot-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  padding: 0.6rem 0.2rem;
  font-size: 0.85rem;
  background: #fafafa;
}

.login-wrap {
  max-width: 380px;
  margin: 4rem auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}
.login-title { text-align: center; margin-bottom: 1.5rem; }
