/* ==========================================================================
   본부별 매출 — 디자인 시스템
   - 외부 리소스 없음 (CSP 'self'): 글꼴 Pretendard(OFL)를 /fonts 에 직접 둠
   - 순서: 글꼴 → 토큰(:root) → 다크 모드 → 기본 → 레이아웃 → 페이지 머리 → 카드 → 수치 카드 → 버튼·링크
           → 폼 → 알림 → 배지 → 탭·칩 → 표 → 화면별 → 반응형(넓은 화면 → 좁은 화면)
   - 색은 직접 쓰지 말고 토큰만. 새 색은 배경과 대비 4.5:1 이상
   - 구역 제목 주석은 "---------- 이름 ----------" 형식, 반응형 조건은 맨 아래 한 곳에서만
   ========================================================================== */

@font-face {
  font-family: "Pretendard Variable";
  src: url("../fonts/PretendardVariable.woff2") format("woff2-variations");
  font-weight: 45 920;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;

  /* 색은 전자결재 V2(SeoulIR_EDMS_V2 frontend/src/index.css)와 같은 토큰 값 — 2026-11-26 맞춤 */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f2f3f5;          /* 표 머리·호버·보조 영역 */
  --surface-3: #e9ebee;          /* 탭 바탕 */
  --border: #e5e7eb;
  --border-strong: #d3d7dd;

  --text: #16181d;
  --text-2: #464c57;
  --muted: #636975;              /* 흰 바탕 5.5 · 탭 바탕 4.6 */

  /* 회사 로고 빨강 — 로고·선택 표시·화면에서 가장 먼저 누를 버튼 하나에만 (V2 와 같은 규칙) */
  --brand: #e5121e;
  --brand-ink: #c40f19;          /* 옅은 빨강 바탕 위 글자 5.4 */
  --brand-soft: #fce7e8;
  --brand-btn: #e5121e;          /* 빨강 버튼 바탕 — 흰 글자 4.7, 두 모드 같은 색 */
  --brand-btn-hover: #c40f19;

  /* 링크·선택된 메뉴: 먹색 글자, 올리면 빨강 */
  --primary: #16181d;
  --primary-hover: #c40f19;
  --primary-soft: #f2f3f5;
  --primary-ring: rgba(229, 18, 30, .45);   /* 키보드 이동 표시 */
  --input-ring: rgba(22, 24, 29, .12);
  --selection: rgba(229, 18, 30, .2);
  --btn-bg: #16181d;             /* 주 버튼: 먹색 바탕 + 흰 글자 17.8 */
  --btn-bg-hover: #35373c;
  --btn-fg: #ffffff;

  --success: #15803d;
  --success-soft: #e8f2ec;
  --success-border: #bddbc9;
  --success-text: #157038;       /* 옅은 바탕 위 5.4 */
  --danger: #c81e1e;
  --danger-soft: #fae8e8;
  --danger-border: #f0c0c0;
  --danger-text: #ad1d1e;
  --warning: #b45309;
  --warning-soft: #f8eee6;
  --warning-border: #eacfba;
  --warning-text: #9c4a0c;
  --info: #2563eb;
  --info-soft: #e9effd;
  --info-text: #2358cc;
  --neutral-soft: #e9ebee;

  --row-hover: #f7f8f9;
  --glass: rgba(255, 255, 255, .82);
  --scrim: rgba(16, 24, 40, .35);
  --glow: #ffffff;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 2px 6px rgba(16, 24, 40, .06);

  --sidebar-w: 248px;
  color-scheme: light;
}

/* ---------- 다크 모드 ----------
   기본은 기기 설정을 따르고, 사용자가 버튼으로 고르면 <html data-theme="light|dark"> 가 우선 (theme.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f12;
    --surface: #17191d;
    --surface-2: #1f2228;
    --surface-3: #292d34;
    --border: #2d3139;
    --border-strong: #434853;

    --text: #f3f4f7;
    --text-2: #d2d7df;
    --muted: #a3aab6;

    --brand: #ff4b55;
    --brand-ink: #ff8088;
    --brand-soft: #2e1e23;
    --brand-btn: #e5121e;
    --brand-btn-hover: #c40f19;

    --primary: #f3f4f7;
    --primary-hover: #ff8088;
    --primary-soft: #1f2228;
    --primary-ring: rgba(255, 75, 85, .5);
    --input-ring: rgba(243, 244, 247, .14);
    --selection: rgba(255, 75, 85, .25);
    --btn-bg: #f3f4f7;             /* 주 버튼: 밝은 바탕 + 어두운 글자 16.9 */
    --btn-bg-hover: #d3d4d7;
    --btn-fg: #121317;

    --success: #4ade80;
    --success-soft: #1c2d27;
    --success-border: #255039;
    --success-text: #6ce298;
    --danger: #f87171;
    --danger-soft: #2e2225;
    --danger-border: #563235;
    --danger-text: #f78b8c;
    --warning: #fbbf24;
    --warning-soft: #2e2a1e;
    --warning-border: #57471f;
    --warning-text: #f9ca4e;
    --info: #60a5fa;
    --info-soft: #1e2733;
    --info-text: #7db5f9;
    --neutral-soft: #292d34;

    --row-hover: #1c1e24;
    --glass: rgba(18, 19, 23, .8);
    --scrim: rgba(0, 0, 0, .55);
    --glow: #17191d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #17191d;
  --surface-2: #1f2228;
  --surface-3: #292d34;
  --border: #2d3139;
  --border-strong: #434853;

  --text: #f3f4f7;
  --text-2: #d2d7df;
  --muted: #a3aab6;

  --brand: #ff4b55;
  --brand-ink: #ff8088;
  --brand-soft: #2e1e23;
  --brand-btn: #e5121e;
  --brand-btn-hover: #c40f19;

  --primary: #f3f4f7;
  --primary-hover: #ff8088;
  --primary-soft: #1f2228;
  --primary-ring: rgba(255, 75, 85, .5);
  --input-ring: rgba(243, 244, 247, .14);
  --selection: rgba(255, 75, 85, .25);
  --btn-bg: #f3f4f7;             /* 주 버튼: 밝은 바탕 + 어두운 글자 16.9 */
  --btn-bg-hover: #d3d4d7;
  --btn-fg: #121317;

  --success: #4ade80;
  --success-soft: #1c2d27;
  --success-border: #255039;
  --success-text: #6ce298;
  --danger: #f87171;
  --danger-soft: #2e2225;
  --danger-border: #563235;
  --danger-text: #f78b8c;
  --warning: #fbbf24;
  --warning-soft: #2e2a1e;
  --warning-border: #57471f;
  --warning-text: #f9ca4e;
  --info: #60a5fa;
  --info-soft: #1e2733;
  --info-text: #7db5f9;
  --neutral-soft: #292d34;

  --row-hover: #1c1e24;
  --glass: rgba(18, 19, 23, .8);
  --scrim: rgba(0, 0, 0, .55);
  --glow: #17191d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ---------- 기본 ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* hidden 속성은 항상 숨김 — fieldset 처럼 display 를 지정한 요소에선 브라우저 기본 [hidden] 이 지고 그대로 보였다 (건 편집 선택칸) */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss05";   /* V2 와 같은 Pretendard 글자 모양 */
}
::selection { background: var(--selection); }
/* 스크롤바 — 얇고 둥글게, 테마 색 (V2 와 같게) */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
h1, h2, h3 { letter-spacing: -0.02em; color: var(--text); }
h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 17px; font-weight: 650; margin: 0 0 16px; }
p { margin: 0 0 10px; }
code { font-size: .9em; background: var(--neutral-soft); padding: 1px 6px; border-radius: 6px; }
ul { margin: 6px 0 0; padding-left: 18px; }
svg { flex-shrink: 0; }

/* 보조 클래스 — 인라인 style 은 CSP(style-src 'self')로 막혀 있어 클래스로 쓴다 */
.muted { color: var(--muted); }
p.muted, .card.muted { color: var(--text-2); }   /* 안내 문단은 길어서 회색 라벨색이면 읽기 어려움 → 본문 보조색 */
.small { font-size: 13.5px; }
.inline { display: inline; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-bad { color: var(--danger); font-weight: 600; }

/* ---------- 앱 레이아웃 (사이드바) ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
}
/* 회사 로고(전자결재 V2 와 같은 그림) 아래 프로그램 이름 */
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 6px 8px 18px; color: var(--text); }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.brand-text small { font-size: 13px; color: var(--muted); }
/* 로고 이미지: 라이트는 회색 글자, 다크는 흰 글자 그림 */
.logo { display: inline-flex; flex-shrink: 0; }
.logo img { height: 24px; width: auto; display: block; }
.logo .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo .logo-dark { display: block; }
}
:root[data-theme="dark"] .logo .logo-light { display: none; }
:root[data-theme="dark"] .logo .logo-dark { display: block; }

.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 13px; font-weight: 600; color: var(--muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; color: var(--muted); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.nav-item.active svg { color: var(--primary); }

.side-user {
  display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; margin-top: 8px; border-top: 1px solid var(--border);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--primary-soft); color: var(--primary);
}
.side-user-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.25; }
.side-user-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-text small { font-size: 13px; color: var(--muted); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--neutral-soft); color: var(--text); }

/* 테마 버튼: 지금 라이트면 달(다크로), 다크면 해(라이트로) */
.theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.shell { margin-left: var(--sidebar-w); min-height: 100vh; }
/* 좌우·아래 여백은 변수로 — 하단 고정 버튼 바(.sticky-actions)가 같은 값만큼 바깥으로 넓어진다 */
.content { --pad-x: 32px; --pad-b: 64px; max-width: 1280px; margin: 0 auto; padding: 28px var(--pad-x) var(--pad-b); }
.mobile-bar { display: none; }
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 25; }

/* 로그인 전 화면 */
body.bare { background: radial-gradient(1200px 600px at 50% -10%, var(--glow) 0%, var(--bg) 60%); }
.bare-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; }
.bare-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 16px; }
.bare-brand .divider { width: 1px; height: 16px; background: var(--border-strong); }

/* ---------- 페이지 머리 (모든 화면 공통: 제목 + 설명 + 오른쪽 버튼) ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-head .actions a:not(.btn) {
  display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; border: 1px solid var(--border); background: var(--surface);
}
.page-sub { margin: 2px 0 0; color: var(--muted); }

/* ---------- 카드 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 24px 26px; margin-bottom: 18px;
}
.card.muted { background: var(--surface-2); box-shadow: none; }
.card.muted p { margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

/* 로그인 전 안내 카드 */
.notice {
  width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px 28px; text-align: center;
}
.notice h1 { font-size: 22px; margin-bottom: 10px; }
.notice p { color: var(--text-2); }
.notice .btn { margin-top: 8px; }
.notice .form-col { text-align: left; margin-top: 16px; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 12px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- 수치 카드 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stats:last-child { margin-bottom: 0; }
.stat {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--surface);
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.stat-label { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-value .unit { color: var(--muted); font-size: 15px; font-weight: 500; }
.stat.ok { border-color: var(--success-border); background: var(--success-soft); }
.stat.ok .stat-value { color: var(--success-text); }   /* 폰에서는 16px 라 "큰 글자" 기준을 못 받음 → 진한 글자색 (4.4 → 5.4) */
.stat.bad { border-color: var(--danger-border); background: var(--danger-soft); }
.stat.bad .stat-value { color: var(--danger-text); }

/* ---------- 버튼·링크 (클릭 요소는 밑줄 대신 색 변경 + 옅은 배경 하이라이트, 2026-10-29) ---------- */
a, .btn-link { text-decoration: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--btn-bg); background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--btn-bg-hover); border-color: var(--btn-bg-hover); }
.btn:hover { color: var(--btn-fg); }
/* 빨강 버튼 — 화면에서 가장 먼저 누를 것 하나에만 (대시보드 "원장 올리기"). V2 의 "결재 작성"과 같은 규칙 */
.btn-brand { background: var(--brand-btn); border-color: var(--brand-btn); color: #fff; box-shadow: 0 6px 16px -6px rgba(229, 18, 30, .55); }
.btn-brand:hover { background: var(--brand-btn-hover); border-color: var(--brand-btn-hover); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; }
/* 못 누르는 버튼: 흐리게(투명) 하지 않고 회색 바탕 + 읽을 수 있는 회색 글자 */
.btn[disabled], .btn:disabled,
.btn[disabled]:hover, .btn:disabled:hover {
  background: var(--neutral-soft); border-color: var(--border); color: var(--muted); box-shadow: none; cursor: not-allowed;
}
/* 제출 중인 폼(submit-once.js) — 다시 누를 수 없음을 보여 준다 */
form.is-submitting button { opacity: .6; cursor: progress; }
/* 흰 버튼·머리 영역 링크: 테두리와 글자가 파랗게 */
.btn-secondary:not([disabled]):hover,
.page-head .actions a:not(.btn):hover {
  border-color: var(--primary); color: var(--primary); background: var(--primary-soft);
}

.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; font-weight: 500; }
.btn-link.danger { color: var(--danger); }
/* 글자 링크: 옅은 배경이 깔리고 글자가 진해진다 (여백만큼 바깥으로 넓혀 글자 위치는 그대로) */
.btn-link, a:not([class]), table.grid a.primary, .card-head a.btn-link {
  border-radius: 6px; padding: 2px 6px; margin: -2px -6px; transition: background .15s, color .15s;
}
.btn-link:hover, a:not([class]):hover, table.grid a.primary:hover {
  background: var(--primary-soft); color: var(--primary-hover);
}
.btn-link.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* 키보드 이동 표시 (밑줄 대신 링) */
a:focus-visible, .btn-link:focus-visible, .btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .nav-item:focus-visible, .icon-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--primary-ring); border-radius: 8px;
}

.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; margin: 16px calc(-1 * var(--pad-x)) calc(-1 * var(--pad-b)); padding: 14px var(--pad-x);
  background: var(--glass); backdrop-filter: blur(8px); border-top: 1px solid var(--border);
}

/* ---------- 폼 ---------- */
input:not([type=checkbox]):not([type=radio]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 12px; height: 44px; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text-2); box-shadow: 0 0 0 3px var(--input-ring); }
/* 잠긴 칸: 회색 바탕으로 "못 고침"을 보이되 값은 읽혀야 한다 — 브라우저 기본 opacity(.7)까지 겹치면 대비 2.9:1 */
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); opacity: 1; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
input[type=file] { padding: 7px 10px; height: auto; max-width: 100%; }   /* 좁은 화면에서 밖으로 나가지 않게 */
input[type=file]::file-selector-button {
  font: inherit; font-weight: 600; margin-right: 12px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); cursor: pointer;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); cursor: pointer; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.form-row > label { flex: 1 1 180px; min-width: 0; max-width: 100%; }
.form-row > label.check { flex: 0 0 auto; height: 40px; }
.form-col { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: start; }
.ratio-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 4px 0 12px; }
.ratio-grid input { width: 100%; text-align: right; font-variant-numeric: tabular-nums; }
.form-inline { display: flex; gap: 8px; align-items: center; }
.form-inline input { height: 38px; }
.direct-lines { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* 선택지 묶음: 체크박스·라디오를 눌러 고르는 칩으로 가로로 나란히 (설명 문구는 다음 줄) */
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0;
  display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px;
}
legend { font-size: 13.5px; font-weight: 600; color: var(--text-2); padding: 0 6px; }
fieldset label.check {
  height: 42px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .15s, background .15s;
}
fieldset label.check:hover { border-color: var(--border-strong); background: var(--surface-2); }
fieldset label.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }   /* 선택 표시는 로고 빨강 */
fieldset label.check:has(input:disabled) { cursor: default; }
/* 잠긴(확정된) 화면: 고르지 않은 것만 흐리게 — 저장된 값(선택된 것)은 또렷하게 (흐리면 대비 2.8:1 로 기준 4.5:1 미달) */
fieldset label.check:has(input:disabled:not(:checked)) { opacity: .7; }
fieldset > label.check { flex: 0 0 auto; }
fieldset > .muted.small { margin-top: 2px; line-height: 1.5; }
fieldset > .muted.small, fieldset > span.small { flex-basis: 100%; }

/* ---------- 알림 ---------- */
.alert {
  display: block; padding: 12px 14px 12px 40px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid transparent;
  position: relative; font-size: 14.5px;
}
.alert::before {
  content: ""; position: absolute; left: 14px; top: 14px; width: 16px; height: 16px; border-radius: 50%;
  background: currentColor; -webkit-mask: var(--alert-icon) center/contain no-repeat; mask: var(--alert-icon) center/contain no-repeat;
}
.alert.ok { background: var(--success-soft); color: var(--success-text); border-color: var(--success-border);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E"); }
.alert.error { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M12 7v6M12 17h.01'/%3E%3C/svg%3E"); }
.alert.warn { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-border);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M12 7v6M12 17h.01'/%3E%3C/svg%3E"); }
.alert.ok::before { background: var(--success); }
.alert.error::before { background: var(--danger); }
.alert.warn::before { background: var(--warning); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
/* 목록이 상자의 첫 내용이면(제목 줄 없이) 위 여백을 없앤다 — 글자가 내려가 왼쪽 아이콘과 줄이 어긋났다 (건 편집 계산 결과) */
.alert > ul:first-child { margin-top: 0; }
.alert .check { margin-top: 10px; color: inherit; }

/* ---------- 배지 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 25px; padding: 0 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap; vertical-align: middle; letter-spacing: 0;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
/* 배지 글자는 진한 글자색 — 기준색 그대로면 옅은 바탕 위 대비가 4.4 로 모자람 */
.badge-draft { background: var(--info-soft); color: var(--info-text); }
.badge-ok { background: var(--success-soft); color: var(--success-text); }
.badge-bad { background: var(--danger-soft); color: var(--danger-text); }
.badge-warn { background: var(--warning-soft); color: var(--warning-text); }
.badge-muted { background: var(--neutral-soft); color: var(--text-2); }
h1 .badge { font-size: 13px; }

/* ---------- 탭·칩 ---------- */
.tabs {
  display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 14px; flex-wrap: wrap;
  background: var(--neutral-soft); border-radius: 10px;
}
.tab {
  height: 36px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 8px;
  color: var(--text-2); font-weight: 500; font-size: 14px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: var(--shadow); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.chip {
  height: 34px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 14px; font-weight: 500;
}
.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ---------- 표 ---------- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.card > .table-wrap:last-child { margin-bottom: 0; }   /* 카드 안 표는 카드 가장자리까지 */
.table-wrap + p { margin-top: 10px; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
table.grid th, table.grid td { padding: 13px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; white-space: normal; word-break: keep-all; overflow-wrap: anywhere; }
table.grid thead th, table.grid .num, table.grid .cell-action { white-space: nowrap; overflow-wrap: normal; }
table.grid thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted);
  font-size: 13.5px; font-weight: 600;
}
table.grid tbody tr:hover td { background: var(--row-hover); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tfoot th, table.grid tfoot td { background: var(--surface-2); font-weight: 700; border-top: 1px solid var(--border-strong); border-bottom: 0; }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid .nowrap { white-space: nowrap; }
table.grid th a { color: inherit; }
table.grid th a:hover { color: var(--primary); }
table.grid a { font-weight: 500; }
table.grid tr.neg td.num { color: var(--danger); }
table.grid tr.row-bad td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.grid tr.excluded td { color: var(--muted); }
table.grid tr.excluded td:nth-child(3), table.grid tr.excluded td:nth-child(4) { text-decoration: line-through; }
table.grid tr.sub-row td:first-child { color: var(--text-2); padding-left: 28px; }
td.cell-warn { background: var(--warning-soft) !important; }

/* 두 줄 칸: 주 내용 + 회색 보조 줄 (열 수를 줄여 좌우 스크롤 방지) */
table.grid .primary { display: block; font-weight: 600; color: var(--text); }
table.grid a.primary { display: inline-block; color: var(--primary); }
table.grid td .sub, table.grid th .sub { display: block; margin-top: 3px; font-size: 13.5px; font-weight: 400; color: var(--muted); line-height: 1.5; }
table.grid td .sub.text-bad { color: var(--danger); font-weight: 600; white-space: nowrap; }
table.grid .code { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }

/* 카드 보기에서만 보이는 칸 (예: 배분 작업 편집 버튼 — 데스크톱은 거래처 이름을 눌러 이동) */
table.grid .card-only { display: none; }

/* 배분 작업 목록 (열이 많음) */
table.grid.work th, table.grid.work td { padding: 12px 14px; }
table.grid.work td:first-child { min-width: 180px; }

/* ---------- 사용자 관리 ---------- */
.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); }
.user-row.inactive { background: var(--surface-2); }
.user-row.inactive .user-email strong { color: var(--muted); }
.user-email { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 2px; }
.row-actions { display: flex; gap: 16px; justify-content: flex-end; margin-top: 10px; font-size: 14px; }

/* ---------- 대시보드 ---------- */
.progress { height: 6px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.progress.done > span { background: var(--success); }
.progress-cell { display: flex; align-items: center; gap: 10px; }
.progress-cell .small { min-width: 54px; text-align: right; }
progress.bar {
  -webkit-appearance: none; appearance: none; width: 120px; height: 6px; border: 0; border-radius: 999px;
  background: var(--neutral-soft); overflow: hidden; vertical-align: middle;
}
progress.bar::-webkit-progress-bar { background: var(--neutral-soft); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress.bar::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
progress.bar.done::-webkit-progress-value { background: var(--success); }
progress.bar.done::-moz-progress-bar { background: var(--success); }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; counter-reset: step; }
.step {
  counter-increment: step; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); font-size: 14px; background: var(--surface);
}
.step::before {
  content: counter(step); flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px;
}
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* ---------- 본부별 매출 — 좁은 화면 카드 (넓은 화면은 표) ---------- */
.division-cards { display: none; }
.division-card {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.division-card:hover { border-color: var(--primary); }
.division-card .dc-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; font-weight: 650; }
.division-card .dc-head strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.division-card .dc-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-2); }
.division-card .dc-row span:last-child { font-variant-numeric: tabular-nums; color: var(--text); }
.division-card.total { background: var(--primary-soft); border-color: transparent; }
.division-card.total .dc-head { margin: 0; color: var(--primary); }

/* ---------- 원장 직접 입력 — 칸 안에 입력칸을 꽉 채운다 ---------- */
table.manual-entry td { padding: 6px 8px; vertical-align: middle; }
table.manual-entry input { width: 100%; }
table.manual-entry .col-date { width: 136px; }
table.manual-entry .col-code { width: 120px; }
table.manual-entry .col-name { width: 22%; }
table.manual-entry .col-amount { width: 150px; }
table.manual-entry input.num { text-align: right; font-variant-numeric: tabular-nums; }
table.manual-entry tfoot th { padding: 12px 8px; }
.manual-total { margin-top: 18px; align-items: center; }
.manual-total label { width: 220px; }
.manual-total p { margin: 0; flex: 1 1 240px; }

/* ==========================================================================
   반응형 — 넓은 화면부터 좁은 화면 순서
   - 1101~1280px : 사이드바는 있지만 본문이 좁은 노트북
   - ≤ 1100px    : 사이드바 → 햄버거 메뉴
   - ≤ 900px     : 목록 표 → 카드 (table.stack)
   - ≤ 640px     : 휴대폰
   ========================================================================== */
@media (max-width: 1280px) and (min-width: 1101px) {
  .content { --pad-x: 24px; --pad-b: 56px; padding-top: 24px; }
  .card { padding: 20px 20px; }
  table.grid.work th, table.grid.work td { padding: 12px 10px; }
}

@media (max-width: 1100px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .shell { margin-left: 0; }
  .mobile-bar {
    display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; height: 56px; padding: 0 10px;
    position: sticky; top: 0; z-index: 20; background: var(--glass); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  }
  .mobile-bar strong { text-align: center; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { --pad-x: 16px; --pad-b: 48px; padding-top: 20px; }
  .sticky-actions { padding-top: 12px; padding-bottom: 12px; }
}

@media (max-width: 640px) {
  h1 { font-size: 21px; }
  .card { padding: 16px; border-radius: 10px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head { align-items: flex-start; }
}

/* 목록 표를 카드로 (table.stack)
   td 역할: .cell-title(굵게, 왼쪽) .cell-amount(오른쪽 금액) .cell-sub(회색 한 줄) .cell-action(버튼) .hide-sm(숨김)
   그 외 td 는 data-label 이름표와 함께 한 줄씩. 빈 칸은 숨김. 카드 안 순서는 DOM 과 무관하게 제목·금액 → 부가 줄 → 세부 → 버튼 */
@media (max-width: 900px) {
  .table-wrap:has(> table.stack) { border: 0; overflow: visible; }
  table.stack, table.stack tbody, table.stack tfoot { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 3px; align-items: baseline; grid-auto-flow: row dense;
    padding: 12px 14px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  }
  table.stack tbody tr:hover td { background: transparent; }
  table.stack td, table.stack th {
    display: block; grid-column: 1 / -1; padding: 0; border: 0; white-space: normal; text-align: left; font-size: 14px; order: 2;
  }
  table.stack td:empty, table.stack .hide-sm { display: none; }
  table.stack td[data-label]::before, table.stack th[data-label]::before {
    content: attr(data-label); display: inline-block; min-width: 72px; margin-right: 8px; color: var(--muted); font-size: 13px; font-weight: 500;
  }
  table.stack td.num { text-align: left; }
  table.stack .cell-title { grid-column: 1; font-size: 15.5px; font-weight: 650; color: var(--text); order: 0; }
  /* 배분 작업 카드: 거래처명만 왼쪽 칸(금액 옆), 날짜·적요 줄은 카드 전체 폭.
     표일 때의 최소 폭(180px)이 남아 있으면 긴 거래처명이 금액을 덮는다 → 칸 자체를 풀어 이름과 적요를 각각 배치 */
  table.stack.work td.cell-title { display: contents; }
  /* 위치는 원래 칸 여백(table.grid.work td 12px 14px)에 맞춘다. 링크는 오버 배경용 여백(2px 6px)을 빼고 */
  table.stack.work td.cell-title > a { grid-column: 1; order: 0; min-width: 0; justify-self: start; margin: 10px 8px 0; }
  table.stack.work td.cell-title > .sub { grid-column: 1 / -1; order: 1; padding: 0 14px 12px; margin-top: -1px; }   /* row-gap 3px - 링크 아래 여백 2px */
  table.stack.work td.cell-amount { padding-bottom: 0; padding-left: 0; }   /* 왼쪽은 칸 간격(column-gap)으로 충분 → 거래처명 폭 확보 */
  table.stack .cell-amount { grid-column: 2; text-align: right; font-size: 15.5px; font-weight: 700; font-variant-numeric: tabular-nums; order: 0; }
  table.stack .cell-sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 4px; order: 1; }
  /* 월별 검증 카드: 배지가 둘이면(확정 + 엑셀·직접 수정) 오른쪽 칸이 제목을 밀어 "2026 / 년 8월"로 끊겼다
     → 제목은 한 줄 고정(왼쪽 칸 = 글자 폭), 배지는 남은 폭에서 오른쪽 정렬로 줄바꿈 */
  table.stack.months tr { grid-template-columns: auto minmax(0, 1fr); align-items: start; }
  table.stack.months .cell-title { white-space: nowrap; }
  table.stack .cell-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
  table.stack .cell-title::before, table.stack .cell-amount::before, table.stack .cell-sub::before { content: none !important; }
  table.stack .cell-action { margin-top: 8px; order: 3; }
  table.stack .cell-action a, table.stack .cell-action .btn { width: 100%; }
  table.stack .card-only { display: block; }
  table.stack td .sub { display: block; }
  table.stack .cell-title .sub { font-size: 13.5px; font-weight: 400; }
  table.stack tfoot tr { background: var(--surface-2); }
  table.stack tfoot th { font-size: 14px; }
  table.stack tfoot th.cell-title, table.stack tfoot th.cell-amount { font-size: 15.5px; }
  table.stack tfoot th:empty { display: none; }
  table.stack tr.row-bad { border-color: var(--danger-border); box-shadow: inset 3px 0 0 var(--danger); }
  table.stack tr.row-bad td:first-child { box-shadow: none; }
  table.stack tr.excluded { background: var(--surface-2); }
  table.stack tr.excluded td { text-decoration: none !important; }
  table.stack progress.bar { width: 100%; }
  table.stack .progress-cell { width: 100%; }

  /* 숫자 행렬 표(본부별 요약)는 숨기고 본부별 카드로 */
  .table-wrap:has(> table.summary) { display: none; }
  table.summary th:first-child, table.summary td:first-child {
    position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 1px 0 0 var(--border);
  }
  table.summary thead th:first-child, table.summary tfoot th:first-child { background: var(--surface-2); }
  table.summary th, table.summary td { padding: 10px 12px; }
  .division-cards { display: grid; gap: 8px; margin-bottom: 10px; }

  /* 원장 직접 입력: 한 건 = 카드 한 장, 두 칸씩 — 날짜|금액 / 적요 / 거래처코드|거래처명 / 삭제 */
  table.manual-entry tbody tr { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 10px; row-gap: 10px; }
  table.manual-entry td { padding: 0; }
  table.manual-entry td[data-label]::before { display: block; margin: 0 0 4px; }
  table.manual-entry td:nth-child(1) { grid-column: 1; grid-row: 1; }
  table.manual-entry td:nth-child(5) { grid-column: 2; grid-row: 1; }
  table.manual-entry td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  table.manual-entry td:nth-child(3) { grid-column: 1; grid-row: 3; }
  table.manual-entry td:nth-child(4) { grid-column: 2; grid-row: 3; }
  table.manual-entry td.cell-action { grid-column: 1 / -1; grid-row: 4; text-align: right; }

  /* 필터 탭: 한 줄 + 가로 스크롤 */
  .tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  /* 수치 카드 촘촘하게 */
  .stats { gap: 8px; margin-bottom: 8px; }
  .stat { padding: 10px 12px; gap: 2px; border-radius: 10px; }
  .stat-label { font-size: 13px; }
  .stat-value { font-size: 16px; }

  /* 건 편집 직접 입력: 대상 + 금액 한 줄 */
  .direct-lines .form-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 8px; }
  .direct-lines .form-row + .form-row label { font-size: 0; gap: 0; }   /* 두 번째 줄부터 이름표 생략 */
  .direct-lines select, .direct-lines input { width: 100%; }

  .actions-row .btn { flex: 1 1 auto; }
  .page-head .actions { width: 100%; }
  .page-head .actions a:not(.btn) { flex: 1 1 auto; justify-content: center; }
  .card-head .btn { width: 100%; }
}

/* 휴대폰 입력 칸 — iPhone 은 16px 미만 입력 칸을 누르면 화면을 확대한다 → 16px (위 ≤900px 규칙보다 뒤에 와야 함) */
@media (max-width: 640px) {
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  .direct-lines .form-row + .form-row label select, .direct-lines .form-row + .form-row label input { font-size: 16px; }
}

/* 아주 좁은 휴대폰(320px 등) — 직접 입력 카드의 두 칸(날짜|금액)에 "2026-03-03"이 다 보이도록 여백을 줄인다 */
@media (max-width: 380px) {
  /* 배분 작업 카드: 거래처명 옆에 금액을 둘 폭이 없다(띄어쓰기 없는 회사명이 중간에서 끊김) → 금액을 이름 아래 줄로 */
  table.stack.work tbody tr { grid-template-columns: minmax(0, 1fr); }
  table.stack.work td.cell-amount { grid-column: 1; text-align: left; padding: 0 14px; }
  table.manual-entry tbody tr { padding-inline: 10px; column-gap: 8px; }
  table.manual-entry input:not([type=checkbox]) { padding-inline: 8px; }   /* 기본 입력 칸 규칙(input:not():not())보다 우선해야 적용된다 */
}
