/* =========================================================================
   uv.css — 부속 프로그램 공통 UI. ACF(Adelaide Finance) 와 같은 디자인 토큰 · 구성요소.
   ACF 는 Tailwind + shadcn 이지만 여기는 Jinja2 라 같은 토큰을 CSS 클래스로 옮겼다.
   - 토큰: shadcn HSL 트리플렛 (라이트 기본, <html class="dark"> 로 다크)
   - 셸: 상단 머리줄(app-topnav) + 밑줄 탭 + 우측 사용자 메뉴(테마 전환은 메뉴 안) + 본문(max 1600px)
   - 구성요소: card · btn · input · select · badge · chip · tbl · table-footer · pagination · side-panel · toast
   ========================================================================= */

:root {
  --background: 0 0% 100%;
  --foreground: 222 47% 11%;
  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;
  --primary: 221 83% 53%;
  --primary-foreground: 0 0% 100%;
  --secondary: 210 40% 96%;
  --secondary-foreground: 222 47% 11%;
  --muted: 210 40% 96%;
  --muted-foreground: 215 16% 47%;
  --accent: 210 40% 94%;
  --accent-foreground: 222 47% 11%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 100%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 100%;
  --stage: 271 76% 53%;
  --stage-foreground: 0 0% 100%;
  --border: 214 18% 80%;
  --input: 214 16% 76%;
  --ring: 221 83% 53%;
  --radius: 0.5rem;
  --topnav: 221 44% 93%;
}
html.dark {
  --background: 222 47% 8%;
  --foreground: 210 40% 96%;
  --card: 222 44% 11%;
  --card-foreground: 210 40% 96%;
  --primary: 213 70% 72%;
  --primary-foreground: 222 47% 11%;
  --secondary: 217 33% 17%;
  --secondary-foreground: 210 40% 96%;
  --muted: 217 33% 17%;
  --muted-foreground: 215 20% 65%;
  --accent: 217 33% 20%;
  --accent-foreground: 210 40% 96%;
  --destructive: 0 63% 45%;
  --destructive-foreground: 210 40% 98%;
  --success: 142 65% 45%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 50%;
  --warning-foreground: 0 0% 8%;
  --stage: 271 72% 74%;
  --stage-foreground: 222 47% 11%;
  --border: 216 20% 34%;
  --input: 216 20% 38%;
  --ring: 213 70% 72%;
  --topnav: var(--card);
}

/* ── 기본 ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; border-color: hsl(var(--border)); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: hsl(var(--background)); color: hsl(var(--foreground));
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 14px; line-height: 1.5; font-feature-settings: "rlig" 1, "calt" 1;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.text-right { text-align: right; }
.text-muted { color: hsl(var(--muted-foreground)); }
.text-xs { font-size: 12px; } .text-sm { font-size: 14px; }
.font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* 스크롤 막대 — 가늘고 흐리게 (ACF globals.css) */
* { scrollbar-width: thin; scrollbar-color: hsl(var(--muted-foreground) / 0.28) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track, *::-webkit-scrollbar-corner { background: transparent; }
*::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.28); border-radius: 9999px; }
*::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.5); }
.no-scrollbar { scrollbar-width: none; } .no-scrollbar::-webkit-scrollbar { display: none; }

/* ── 셸 ─────────────────────────────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; max-width: 100%; overflow-x: hidden; height: 100vh; height: 100dvh; }
.app-topnav { flex-shrink: 0; border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--topnav)); }
.topnav-inner { margin: 0 auto; display: flex; max-width: 1600px; flex-wrap: wrap; align-items: center; column-gap: 16px; padding: 0 16px; }
.brand { display: flex; height: 56px; align-items: center; gap: 10px; flex: 1 1 0; min-width: 0; }
.brand-mark { display: flex; height: 36px; flex-shrink: 0; align-items: center; justify-content: center; border-radius: calc(var(--radius) - 2px); background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); padding: 0 8px; font-size: 15px; font-weight: 800; letter-spacing: -0.01em; line-height: 1; }
.brand-text { min-width: 0; line-height: 1.2; display: flex; flex-direction: column; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; display: block; }
.brand-sub { font-size: 10px; font-weight: 600; letter-spacing: 0.04em; color: hsl(var(--muted-foreground)); display: block; }
.topnav-right { display: flex; height: 56px; flex-shrink: 0; align-items: center; gap: 6px; margin-left: auto; order: 2; }
.topnav-tabs { display: flex; height: 44px; min-width: 0; flex-basis: 100%; align-items: stretch; gap: 2px; overflow-x: auto; order: 3; scrollbar-width: none; }
.topnav-tabs::-webkit-scrollbar { display: none; }
.nav-tab { display: flex; flex: 1 0 auto; align-items: center; justify-content: center; white-space: nowrap; border-bottom: 2px solid transparent; padding: 0 10px; font-size: 14px; font-weight: 500; color: hsl(var(--muted-foreground)); transition: color .15s; }
.nav-tab:hover { color: hsl(var(--foreground)); }
.nav-tab.active { border-bottom-color: hsl(var(--primary)); color: hsl(var(--primary)); }
@media (min-width: 768px) {
  .topnav-inner { height: 56px; flex-wrap: nowrap; padding: 0 24px; }
  .brand { flex: 0 0 auto; }
  .topnav-tabs { height: 56px; flex: 1 1 auto; flex-basis: auto; margin-left: 24px; order: 1; }
  .nav-tab { flex: none; justify-content: flex-start; padding: 0 12px; }
  .topnav-right { order: 2; }
}
.app-main { margin: 0 auto; width: 100%; max-width: 1600px; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px 16px 8px; scrollbar-gutter: stable; }
@media (min-width: 640px) { .app-main { padding-left: 24px; padding-right: 24px; } }
.app-footer { flex-shrink: 0; border-top: 1px solid hsl(var(--border)); padding: 6px 24px; font-size: 11px; color: hsl(var(--muted-foreground)); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
@media (max-width: 767px) {
  .app-shell { height: auto; min-height: 100vh; min-height: 100dvh; overflow-x: clip; }
  .app-shell > .app-topnav { position: sticky; top: 0; z-index: 30; }
  .app-main { overflow: visible; flex: none; }
  input[class], select[class], textarea[class] { font-size: 16px; }
}

/* 아이콘 단추 · 사용자 메뉴 */
.icon-btn { display: inline-flex; height: 36px; width: 36px; align-items: center; justify-content: center; border-radius: calc(var(--radius) - 2px); color: hsl(var(--foreground)); }
.icon-btn:hover { background: hsl(var(--accent)); }
.icon-btn svg, .menu-item svg, .btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 6px; border-radius: calc(var(--radius) - 2px); padding: 6px 8px; font-size: 14px; font-weight: 500; }
.user-btn:hover { background: hsl(var(--accent)); }
.user-btn svg { width: 16px; height: 16px; color: hsl(var(--muted-foreground)); transition: transform .15s; }
.user-menu.open .user-btn svg { transform: rotate(180deg); }
.user-pop { display: none; position: absolute; right: 0; top: 100%; z-index: 60; margin-top: 6px; width: 240px; overflow: hidden; border-radius: var(--radius); border: 1px solid hsl(var(--border)); background: hsl(var(--card)); box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1); }
.user-menu.open .user-pop { display: block; }
.user-pop-head { border-bottom: 1px solid hsl(var(--border)); padding: 12px 16px; }
.user-pop-head .name { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; }
.user-pop-head .sub { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.user-pop-sec { padding: 6px; }
.user-pop-sec + .user-pop-sec { border-top: 1px solid hsl(var(--border)); }
.user-pop-label { padding: 6px 12px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
.menu-item { display: flex; width: 100%; align-items: center; gap: 10px; border-radius: calc(var(--radius) - 2px); padding: 8px 12px; font-size: 14px; font-weight: 500; color: hsl(var(--muted-foreground)); text-align: left; }
.menu-item:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.menu-item .grow { flex: 1 1 auto; }
.menu-item .on { color: hsl(var(--primary)); }

/* ── 카드 ─────────────────────────────────────────────────────────────── */
.card { border-radius: var(--radius); border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--card-foreground)); box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05); }
.card + .card { margin-top: 16px; }
.card-header { display: flex; flex-direction: column; gap: 6px; padding: 20px; }
.card-header.row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-weight: 600; line-height: 1; letter-spacing: -0.01em; font-size: 15px; }
.card-desc { font-size: 13px; color: hsl(var(--muted-foreground)); }
.card-content { padding: 20px; padding-top: 0; }
.card-content.flush { padding: 0; }
.card-footer { display: flex; align-items: center; gap: 8px; padding: 0 20px 20px; }
.card-count { font-size: 13px; font-weight: 500; color: hsl(var(--muted-foreground)); margin-left: 6px; }

/* 화면 머리 */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-sub { font-size: 13px; color: hsl(var(--muted-foreground)); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
@media (max-width: 767px) { .toolbar > * { flex: 1 1 8rem; min-width: 0; } .toolbar .input { width: 100%; } }

/* ── 단추 ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; border-radius: calc(var(--radius) - 2px); height: 36px; padding: 0 16px; font-size: 14px; font-weight: 500; transition: background .15s, color .15s; border: 1px solid transparent; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--ring)); }
.btn:disabled, .btn[aria-disabled="true"] { pointer-events: none; opacity: .5; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / .9); }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-destructive:hover { background: hsl(var(--destructive) / .9); }
.btn-outline { border-color: hsl(var(--border)); background: hsl(var(--background)); }
.btn-outline:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover { background: hsl(var(--secondary) / .8); }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 40px; padding: 0 24px; }
.btn-icon { width: 36px; padding: 0; }

/* ── 입력 ─────────────────────────────────────────────────────────────── */
.input, .select, .textarea { display: flex; width: 100%; border-radius: calc(var(--radius) - 2px); border: 1px solid hsl(var(--input)); background: hsl(var(--background)); padding: 4px 12px; font-size: 14px; box-shadow: 0 1px 2px 0 rgb(0 0 0 / .05); transition: border-color .15s, box-shadow .15s; }
.input, .select { height: 36px; }
.input.sm, .select.sm { height: 32px; font-size: 13px; }
.textarea { min-height: 70px; padding: 8px 12px; }
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--ring)); }
.input:disabled, .select:disabled, .input[readonly] { cursor: not-allowed; opacity: .6; }
.input[readonly] { cursor: default; color: hsl(var(--muted-foreground)); }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23738099' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 30px; }
.label { font-size: 14px; font-weight: 500; color: hsl(var(--foreground)); display: block; margin-bottom: 6px; }
.label .req { font-size: 11px; color: hsl(var(--destructive)); margin-left: 4px; font-weight: 700; }
.field { display: flex; flex-direction: column; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.side-panel .form-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding-top: 26px; }
.check input { width: 16px; height: 16px; accent-color: hsl(var(--primary)); }
.form-section { margin-bottom: 20px; }
.form-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid hsl(var(--border)); }
.form-errors { display: none; border-radius: calc(var(--radius) - 2px); border: 1px solid hsl(var(--destructive) / .4); background: hsl(var(--destructive) / .08); color: hsl(var(--destructive)); padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.form-errors.show { display: block; }

/* ── 배지 · 칩 ───────────────────────────────────────────────────────── */
.badge { display: inline-flex; flex-shrink: 0; align-items: center; white-space: nowrap; border-radius: 9999px; padding: 2px 8px; font-size: 12px; font-weight: 500; line-height: 1.3; }
.badge-default { background: hsl(var(--primary) / .1); color: hsl(var(--primary)); }
.badge-success { background: hsl(var(--success) / .15); color: hsl(var(--success)); }
.badge-warning { background: hsl(var(--warning) / .15); color: hsl(var(--warning)); }
.badge-destructive { background: hsl(var(--destructive) / .15); color: hsl(var(--destructive)); }
.badge-muted { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.badge-stage { background: hsl(var(--stage) / .15); color: hsl(var(--stage)); }
.badge-outline { border: 1px solid hsl(var(--primary) / .4); color: hsl(var(--primary)); }
.badge + .badge { margin-left: 4px; }
.chip { border-radius: 9999px; border: 1px solid hsl(var(--border)); padding: 4px 10px; font-size: 12px; font-weight: 500; color: hsl(var(--muted-foreground)); background: transparent; }
.chip:hover, .chip.on { border-color: hsl(var(--primary)); color: hsl(var(--primary)); }

/* ── 표 ─────────────────────────────────────────────────────────────── */
.tbl-wrap { width: 100%; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl thead tr { border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--muted) / .4); }
.tbl th { padding: 6px 12px; text-align: left; font-size: 12px; font-weight: 500; color: hsl(var(--muted-foreground)); white-space: nowrap; }
.tbl td { padding: 6px 12px; border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; white-space: nowrap; }
.tbl td.wrap { white-space: normal; }
.tbl td.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover td { background: hsl(var(--accent) / .45); }
.tbl tbody tr.selected td { background: hsl(var(--primary) / .08); }
.tbl tbody tr.flash td { animation: uvFlash 1.6s ease-out; }
.tbl tfoot td { font-weight: 600; background: hsl(var(--muted) / .3); }
.tbl .empty { text-align: center; padding: 28px 12px; color: hsl(var(--muted-foreground)); }
.tbl a.link { color: hsl(var(--primary)); font-weight: 600; }
.tbl a.link:hover { text-decoration: underline; }
.tbl.kv th { width: 120px; background: hsl(var(--muted) / .4); border-bottom: 1px solid hsl(var(--border)); font-size: 13px; }
.tbl.kv td { font-size: 13px; white-space: normal; word-break: keep-all; }
@keyframes uvFlash { 0% { background: hsl(var(--success) / .2); } 100% { background: transparent; } }
.table-footer { display: flex; flex-shrink: 0; flex-wrap: wrap; align-items: center; gap: 4px 12px; border-top: 1px solid hsl(var(--border)); padding: 4px 12px; font-size: 14px; }
.pagination { display: flex; align-items: center; gap: 2px; }
.pg-btn { display: flex; height: 28px; min-width: 28px; align-items: center; justify-content: center; border-radius: calc(var(--radius) - 2px); padding: 0 8px; font-size: 14px; font-weight: 500; color: hsl(var(--muted-foreground)); transition: background .15s, color .15s; }
.pg-btn:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.pg-btn.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.pg-btn.disabled { opacity: .3; pointer-events: none; }
.pg-btn svg { width: 16px; height: 16px; }
.pg-info { font-size: 12px; color: hsl(var(--muted-foreground)); margin-left: auto; }

/* ── 우측 패널 (ACF SidePanel: 덮개 + 오른쪽 기둥) ─────────────────── */
.panel-backdrop { display: none; position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .4); justify-content: flex-end; }
.panel-backdrop.open { display: flex; }
.side-panel { display: flex; height: 100%; width: 100%; max-width: 480px; flex-direction: column; border-left: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--card-foreground)); box-shadow: 0 25px 50px -12px rgb(0 0 0 / .25); padding-bottom: env(safe-area-inset-bottom, 0px); transform: translateX(100%); transition: transform .25s ease; }
.panel-backdrop.open .side-panel { transform: none; }
.side-panel.wide { max-width: 720px; }
.side-panel-head { display: flex; flex-shrink: 0; align-items: center; gap: 8px; border-bottom: 1px solid hsl(var(--border)); padding: 12px 16px; }
.side-panel-head h3 { min-width: 0; flex: 1 1 auto; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-panel-body { min-height: 0; flex: 1 1 auto; overflow-y: auto; padding: 16px; }
.side-panel-foot { display: flex; flex-shrink: 0; justify-content: flex-end; gap: 8px; border-top: 1px solid hsl(var(--border)); padding: 12px; }
.side-panel-foot:empty { display: none; }
.panel-loading { color: hsl(var(--muted-foreground)); font-size: 13px; padding: 20px; }

/* ── 토스트 ───────────────────────────────────────────────────────────── */
.toast-wrap { position: fixed; top: 64px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 14px; border-radius: calc(var(--radius) - 2px); font-size: 13px; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--card-foreground)); box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1); transition: opacity .4s; }
.toast.ok, .toast.success { border-color: hsl(var(--success) / .6); }
.toast.error { border-color: hsl(var(--destructive) / .6); color: hsl(var(--destructive)); }
.toast.fade { opacity: 0; }

/* ── 기타 ─────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.stat .k { font-size: 12px; color: hsl(var(--muted-foreground)); }
.center-box { max-width: 560px; margin: 40px auto; }

/* 마크가 한 글자 B 이면 Bgent 파비콘과 같은 글꼴 — 흰 세리프 굵은 이탤릭(Georgia), 바탕 #134ECD (외주관리 시스템 등 범용 서비스) */
.brand-mark.mark-b { width: 36px; padding: 0; background: #134ECD; color: #fff; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 700; font-size: 23px; }
