:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#root { min-height: 100vh; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 250px;
  background: #111827;
  color: #e5e7eb;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 800; color: #fff;
  padding: 6px 10px 20px;
}
.brand i { color: #818cf8; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #cbd5e1; cursor: pointer; font-size: 14.5px; font-weight: 600;
  border: none; background: transparent; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #1f2937; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item i { width: 18px; text-align: center; }
.nav-sep { height: 1px; background: #1f2937; margin: 10px 6px; }
.nav-item.nav-admin { color: #a5b4fc; }
.nav-item.nav-admin.active { background: #4338ca; color: #fff; }
.nav-spacer { flex: 1 1 auto; min-height: 12px; }
.nav-user {
  border-top: 1px solid #1f2937;
  padding-top: 10px; margin-top: 4px;
  display: flex; flex-direction: column; gap: 8px;
}
.nav-user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px; color: #cbd5e1; min-width: 0;
}
.nav-user-info i { font-size: 20px; color: #818cf8; flex-shrink: 0; }
.nav-user-meta { display: flex; flex-direction: column; min-width: 0; }
.nav-user-name {
  font-size: 13.5px; font-weight: 700; color: #e5e7eb;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-user-email {
  font-size: 11.5px; color: #94a3b8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-item.nav-logout { color: #fca5a5; }
.nav-item.nav-logout:hover { background: #7f1d1d; color: #fff; }
.nav-item.nav-help { color: #a5b4fc; }
.nav-item.nav-help:hover { background: #312e81; color: #fff; }

/* Main */
.main { flex: 1; padding: 26px 32px 60px; overflow-x: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px; margin-bottom: 24px;
}
.page-title { font-size: 24px; font-weight: 800; margin: 0; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

.month-picker {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 10px;
}
.month-picker input {
  border: none; outline: none; font-size: 14px; font-weight: 600;
  color: var(--ink); background: transparent;
}
.month-picker select {
  border: none; outline: none; font-size: 14px; font-weight: 600;
  color: var(--ink); background: transparent; cursor: pointer;
  max-width: 240px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.company-picker { border: 1px solid #c7d2fe; background: #eef2ff; border-radius: 10px; padding: 2px 6px; }
.company-picker select { background: transparent; border: none; }

/* Cards */
.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
}
.card h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; }

.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; display:flex; align-items:center; gap:7px; }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 10px; letter-spacing: -.5px; }
.kpi-value small { font-size: 15px; font-weight: 600; color: var(--muted); }
.kpi-bar { height: 7px; border-radius: 99px; background: #eef2f7; margin-top: 14px; overflow: hidden; }
.kpi-bar > span { display: block; height: 100%; border-radius: 99px; transition: width .5s; }

/* Progress ring substitute */
.progress-track { height: 10px; background:#eef2f7; border-radius:99px; overflow:hidden; }
.progress-fill { height:100%; border-radius:99px; transition: width .5s; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); text-transform: uppercase;
  letter-spacing: .3px;
}
.tbl td { padding: 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: #fafbfd; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700;
}

/* Buttons */
.btn {
  border: none; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px;
  transition: transform .06s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-start; justify-content: center; z-index: 100;
  padding: 20px;
  overflow-y: auto;                 /* 내용이 길면 백드롭 자체가 스크롤 */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal {
  background: #fff; border-radius: 18px; width: 100%; max-width: 460px;
  padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: pop .18s ease;
  /* 화면이 낮아도 위/아래가 잘리지 않도록 높이 제한 + 내부 스크롤 */
  margin: auto;                     /* 공간이 있으면 중앙, 없으면 위부터 스크롤 */
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);  /* 모바일 주소창 대응 */
  overflow-y: auto;
  overscroll-behavior: contain;
}
@keyframes pop { from { transform: scale(.96); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.modal h3 { margin: 0 0 18px; font-size: 18px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px;
  /* 스크롤 시에도 저장/취소 버튼이 하단에 고정되어 보이도록 */
  position: sticky; bottom: 0;
  background: #fff; padding: 14px 0 4px;
  border-top: 1px solid var(--line);
}

/* 낮은 해상도/짧은 화면: 여백 축소로 더 많은 내용 표시 */
@media (max-height: 700px) {
  .modal-backdrop { padding: 12px; }
  .modal {
    padding: 18px 20px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    border-radius: 14px;
  }
  .modal h3 { margin: 0 0 12px; font-size: 16.5px; }
  .field { margin-bottom: 11px; }
}

@media (max-height: 520px) {
  .modal-backdrop { padding: 8px; }
  .modal { padding: 14px 16px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
}

.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.empty i { font-size: 34px; display:block; margin-bottom: 12px; color: #cbd5e1; }

.hidden { display: none !important; }


.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.filters select, .filters input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13.5px; background: #fff; outline: none;
}
/* 기간 조회 (시작일 ~ 종료일) */
.date-range {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px 0 2px;
}
.date-range input[type="date"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; background: #fff; outline: none; color: inherit;
}
.date-range input[type="date"]:focus { border-color: var(--brand, #4f46e5); }

.tag-dot { width: 10px; height: 10px; border-radius: 99px; display:inline-block; }

/* 계층(대항목/소항목) */
.row-major td { background: #fbfcfe; }
.row-major > td { border-bottom: 1px solid var(--line); }
.row-major:hover td, .row-major[data-toggle-row]:hover td { background: #f4f7fc; cursor: default; }
.row-major[data-toggle-row] { cursor: pointer; }
.row-sub td { background: #fff; }
.row-sub:hover td { background: #fafbfd; }

.lvl-badge {
  display: inline-block; margin-left: 8px; padding: 2px 8px;
  font-size: 11px; font-weight: 700; border-radius: 99px;
  background: #eef2ff; color: #4f46e5; vertical-align: middle;
}
.move-group {
  display: inline-flex; align-items: center; gap: 2px;
  margin-right: 4px; vertical-align: middle;
}
.move-btn { padding: 4px 6px !important; line-height: 1; }
.move-btn:disabled { opacity: .3; cursor: not-allowed; }
.move-btn i { font-size: 11px; }

.proj-badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  font-size: 11px; font-weight: 600; border-radius: 99px;
  background: #ccfbf1; color: #0f766e; vertical-align: middle;
}

/* 예산 산출 계산 패널 */
.calc-panel {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin: 4px 0 14px;
}
.calc-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px; padding: 5px 0; color: #475569;
}
.calc-row strong { font-variant-numeric: tabular-nums; color: #0f172a; }
.calc-row.calc-total {
  margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--line);
  font-size: 15px;
}
.calc-row.calc-total strong { color: var(--brand); font-size: 17px; font-weight: 800; }
.calc-hint { font-size: 12px; color: #94a3b8; margin-top: 6px; }
.calc-line { font-size: 11.5px; color: #94a3b8; font-weight: 500; margin-top: 2px; }

/* 표 합계 행 */
.row-total td {
  background: #f1f5ff; border-top: 2px solid #c7d2fe; padding: 14px 12px;
}
.row-total strong { font-weight: 800; }

/* 상단 합계 요약 스트립 */
.summary-strip {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 18px;
  background: linear-gradient(135deg, #f5f7ff 0%, #eef2ff 100%);
  border: 1px solid #c7d2fe;
}
.summary-top {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 18px;
}
.summary-main .kpi-value { margin-top: 4px; color: var(--brand); }
.summary-items {
  display: flex; align-items: center; gap: 28px; flex-wrap: wrap;
}
.summary-items > div { text-align: right; min-width: 92px; }
.summary-num {
  font-size: 17px; font-weight: 800; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -.3px;
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .sidebar { width: 66px; padding: 18px 8px; }
  .brand span, .nav-item span { display: none; }
  .brand { justify-content: center; }
  .nav-item { justify-content: center; }
  .nav-user-info { display: none; }
  .nav-user { align-items: center; }
  .main { padding: 18px 16px 50px; }
  .kpis { grid-template-columns: 1fr; }
}

/* ---------- Admin (관리자 페이지) ---------- */
.admin-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px; margin-bottom: 18px;
}
.admin-note {
  font-size: 13px; color: #475569; line-height: 1.6;
  background: #eef2ff; border: 1px solid #c7d2fe; border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 12px 16px; max-width: 820px;
}
.admin-note i { color: var(--brand); margin-right: 6px; }

/* 관리자 KPI 카드 */
.card.kpi { display: flex; align-items: center; gap: 14px; padding: 18px 20px; }
.kpi-icon {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.kpi-body { min-width: 0; }
.kpi-body .kpi-value { margin-top: 4px; font-size: 22px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* 상태 pill */
.pill-ok { background: #dcfce7; color: #15803d; }
.pill-off { background: #f1f5f9; color: #94a3b8; }

@media (max-width: 720px) {
  .admin-head { flex-direction: column; align-items: stretch; }
}

/* ---------- 인증 (로그인 / 회원가입) ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px 16px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 45%, #ecfeff 100%);
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 18px;
  padding: 30px 28px; box-shadow: 0 18px 50px rgba(15, 23, 42, .12);
  border: 1px solid #eef2f7;
}
.auth-brand {
  font-size: 26px; font-weight: 800; color: var(--brand);
  display: flex; align-items: center; gap: 10px; justify-content: center;
}
.auth-brand i { font-size: 24px; }
.auth-tag { text-align: center; color: #94a3b8; font-size: 13px; margin: 6px 0 20px; }
.auth-promo { margin-top: 14px; text-align: center; }
.auth-promo a {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  color: #64748b; padding: 7px 14px; border: 1px solid #e2e8f0; border-radius: 999px;
  transition: all .15s;
}
.auth-promo a:hover { color: var(--brand); border-color: #c7d2fe; background: #eef2ff; text-decoration: none; }
.auth-tabs { display: flex; gap: 6px; background: #f1f5f9; padding: 5px; border-radius: 12px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 9px;
  font-size: 13.5px; font-weight: 700; color: #64748b; cursor: pointer; transition: all .15s;
}
.auth-tab.active { background: #fff; color: var(--brand); box-shadow: 0 1px 4px rgba(15, 23, 42, .1); }
.auth-error { color: #ef4444; font-size: 12.5px; min-height: 16px; margin: 2px 0 6px; }
.auth-submit { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 4px; }
.auth-note {
  margin-top: 18px; font-size: 12.5px; color: #475569; line-height: 1.7;
  background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 12px 14px;
}
.auth-note i { color: var(--brand); margin-right: 5px; }

/* ---------- 상단 사용자 메뉴 / 구독 배지 ---------- */
.sub-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700;
  padding: 6px 11px; border-radius: 999px; white-space: nowrap;
}
.user-menu { position: relative; }
.user-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 7px 12px; font-size: 13.5px; font-weight: 700; color: #334155;
}
.user-btn:hover { border-color: #c7d2fe; }
.user-btn .user-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-drop {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 230px; background: #fff; border: 1px solid #eef2f7; border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .16); overflow: hidden;
}
.user-drop.open { display: block; }
.user-drop-head { padding: 14px 16px; border-bottom: 1px solid #f1f5f9; }
.user-drop-head strong { font-size: 14px; }
.user-drop-item {
  width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 12px 16px; font-size: 13.5px; color: #334155; display: flex; align-items: center; gap: 9px;
}
.user-drop-item:hover { background: #f8fafc; color: #ef4444; }

/* ---------- 관리자: 승인 배너 / 표 스크롤 ---------- */
.pending-banner {
  display: flex; align-items: center; gap: 10px;
  background: #fffbeb; border: 1px solid #fde68a; border-left: 4px solid #f59e0b;
  color: #92400e; border-radius: 10px; padding: 12px 16px; margin-bottom: 18px;
  font-size: 13.5px; line-height: 1.55;
}
.pending-banner i { color: #f59e0b; font-size: 16px; }
.pill-warn { background: #fef3c7; color: #b45309; }
.tbl-scroll { overflow-x: auto; }

/* ---------- 정기결제 신청 ---------- */
.subscribe-btn { padding: 5px 11px; font-size: 12.5px; }
.sub-note {
  font-size: 12.5px; color: #475569; line-height: 1.7; background: #eef2ff;
  border: 1px solid #c7d2fe; border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 11px 14px; margin-bottom: 14px;
}
.sub-note i { color: var(--brand); margin-right: 5px; }
.plan-list { display: flex; flex-direction: column; gap: 9px; margin-bottom: 12px; }
.plan-row {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  border: 1.5px solid #e2e8f0; border-radius: 12px; padding: 13px 15px;
  transition: all .15s; background: #fff;
}
.plan-row:hover { border-color: #c7d2fe; }
.plan-row.selected { border-color: var(--brand); background: #f5f3ff; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.plan-row input[type="radio"] { width: 18px; height: 18px; accent-color: var(--brand); }
.plan-main { flex: 1; }
.plan-name { font-weight: 800; font-size: 14.5px; }
.plan-desc { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.plan-price { font-weight: 800; font-size: 16px; color: var(--brand); font-variant-numeric: tabular-nums; }
.sub-summary {
  background: #f8fafc; border: 1px solid #eef2f7; border-radius: 10px;
  padding: 12px 15px; margin-bottom: 14px; font-size: 13px;
}
.sub-summary > div { display: flex; justify-content: space-between; padding: 3px 0; color: #64748b; }
.sub-summary > div b { color: #0f172a; font-variant-numeric: tabular-nums; }
.sub-summary .sub-total { border-top: 1px dashed #cbd5e1; margin-top: 6px; padding-top: 8px; font-size: 14.5px; }
.sub-summary .sub-total b { color: var(--brand); font-size: 16px; }
.sub-account {
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 10px;
  padding: 12px 15px; margin-bottom: 14px; font-size: 13px;
}
.sub-account-title {
  font-weight: 800; color: #4338ca; font-size: 13px;
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.sub-account-title i { font-size: 13px; }
.sub-account-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 3px 0; color: #64748b; gap: 10px;
}
.sub-account-row b { color: #1e1b4b; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.sub-account-note {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed #a5b4fc;
  color: #b45309; font-weight: 700; display: flex; align-items: center; gap: 6px;
}
.sub-account-note i { color: #d97706; }
.tax-check {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 700; color: #334155;
  border: 1px solid #e2e8f0; border-radius: 10px; padding: 11px 14px; margin-bottom: 10px;
}
.tax-check input { width: 18px; height: 18px; accent-color: var(--brand); }
.tax-fields { background: #fffbeb; border: 1px dashed #fcd34d; border-radius: 10px; padding: 12px 14px 2px; margin-bottom: 10px; }

/* ---------- 관리자: 세금계산서 신청 정보 ---------- */
.tax-info { font-size: 11.5px; color: #64748b; margin-top: 6px; line-height: 1.6; }
.tax-info > div { white-space: nowrap; }
.tax-info b { color: #94a3b8; font-weight: 700; margin-right: 4px; }
