/* ══════════════════════════════════════════════════════════════════
   콘텐츠 경로 관리 — 공용 디자인 (모든 화면이 함께 쓴다)
   · 색은 모두 아래 토큰으로만 쓴다. 화면 파일의 예전 색은 토큰으로 바꿔 두었다.
   · 밝은/어두운 화면: <html data-theme="light|dark">, 값이 없으면 시스템 설정을 따른다.
   · 각 화면의 <style> 뒤에 읽혀서, 같은 이름의 규칙은 여기 것이 이긴다.
   ══════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Pretendard';
  src: url('/static/fonts/pretendard.woff2') format('woff2');
  font-weight: 45 920;
  font-display: swap;
}

:root {
  color-scheme: light;
  --font: 'Pretendard', -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --mono: Consolas, 'D2Coding', 'Pretendard', 'Malgun Gothic', monospace;

  --canvas: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #f1f3f6;
  --hover: rgba(15, 23, 42, .045);
  --active: rgba(15, 23, 42, .075);
  --border: #e6e8ec;
  --border-strong: #d7dbe1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8a94a6;

  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-text: #1d4ed8;
  --brand-soft: rgba(37, 99, 235, .09);
  --brand-ring: rgba(37, 99, 235, .16);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: rgba(220, 38, 38, .08);
  --danger-line: rgba(220, 38, 38, .28);
  --warn: #d97706;
  --warn-text: #b45309;
  --warn-soft: rgba(217, 119, 6, .1);
  --warn-line: rgba(217, 119, 6, .32);
  --ok: #059669;
  --ok-text: #047857;
  --ok-soft: rgba(5, 150, 105, .1);
  --ok-line: rgba(5, 150, 105, .3);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-card: 0 0 0 1px var(--border), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --sb-w: 248px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0b0c0f;
  --surface: #141519;
  --surface-2: #191b20;
  --surface-3: #20232a;
  --hover: rgba(255, 255, 255, .05);
  --active: rgba(255, 255, 255, .085);
  --border: #262931;
  --border-strong: #343843;
  --text: #eceef2;
  --text-2: #a9b0bd;
  --text-3: #707888;
  --brand: #4f8cff;
  --brand-hover: #6b9dff;
  --brand-text: #7aa7ff;
  --brand-soft: rgba(79, 140, 255, .14);
  --brand-ring: rgba(79, 140, 255, .25);
  --danger: #f2555a;
  --danger-hover: #f46e72;
  --danger-soft: rgba(242, 85, 90, .13);
  --danger-line: rgba(242, 85, 90, .35);
  --warn: #f59e0b;
  --warn-text: #fbbf24;
  --warn-soft: rgba(245, 158, 11, .13);
  --warn-line: rgba(245, 158, 11, .35);
  --ok: #10b981;
  --ok-text: #34d399;
  --ok-soft: rgba(16, 185, 129, .13);
  --ok-line: rgba(16, 185, 129, .35);
  --shadow-sm: none;
  --shadow-card: 0 0 0 1px var(--border);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --canvas: #0b0c0f; --surface: #141519; --surface-2: #191b20; --surface-3: #20232a;
    --hover: rgba(255, 255, 255, .05); --active: rgba(255, 255, 255, .085);
    --border: #262931; --border-strong: #343843;
    --text: #eceef2; --text-2: #a9b0bd; --text-3: #707888;
    --brand: #4f8cff; --brand-hover: #6b9dff; --brand-text: #7aa7ff;
    --brand-soft: rgba(79, 140, 255, .14); --brand-ring: rgba(79, 140, 255, .25);
    --danger: #f2555a; --danger-hover: #f46e72; --danger-soft: rgba(242, 85, 90, .13); --danger-line: rgba(242, 85, 90, .35);
    --warn: #f59e0b; --warn-text: #fbbf24; --warn-soft: rgba(245, 158, 11, .13); --warn-line: rgba(245, 158, 11, .35);
    --ok: #10b981; --ok-text: #34d399; --ok-soft: rgba(16, 185, 129, .13); --ok-line: rgba(16, 185, 129, .35);
    --shadow-sm: none; --shadow-card: 0 0 0 1px var(--border); --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  }
}

/* ── 기본 ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--canvas); }
body {
  margin: 0; min-height: 100vh;
  background: var(--canvas); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; letter-spacing: -0.005em;
}
button, input, select, textarea { font-family: inherit; letter-spacing: inherit; }
input, select, textarea { color: var(--text); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
::selection { background: var(--brand-ring); }
[hidden] { display: none !important; }
.ic { flex: none; display: block; }
code, kbd, .mono { font-family: var(--mono); }
/* 버튼·탭 글자 앞 선 아이콘 (예전 이모지 자리) */
.bi { display: inline-flex; vertical-align: -0.18em; margin-right: .35em; }
.bi .ic { width: 1.1em; height: 1.1em; }
:is(.btn, [class^="btn-"], [class*=" btn-"], .tab-btn, .mode-btn, .status-tab) .bi { margin-right: 0; }
:is(.tab-btn, .mode-btn, .status-tab) { display: inline-flex; align-items: center; gap: 6px; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ── 앱 틀: 사이드바 + 본문 ──────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  display: flex; flex-direction: column; gap: 2px; padding: 12px 10px 10px;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; }
.sb-logo {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff;
  background: linear-gradient(135deg, #3b82f6, #6366f1); box-shadow: 0 4px 12px rgba(59, 130, 246, .3);
}
.sb-brand b { display: block; font-size: 14.5px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; }
.sb-brand small { display: block; font-size: 11.5px; color: var(--text-3); }
.sidebar .sb-close { display: none; margin-left: auto; }
.sb-scroll { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px 12px; }
.sb-title { font-size: 11.5px; font-weight: 650; color: var(--text-3); padding: 14px 10px 5px; letter-spacing: .02em; }
.sb-title:first-child { padding-top: 4px; }
.sb-nav a {
  position: relative; display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px;
  border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: 13.5px; text-decoration: none;
  transition: background .12s, color .12s;
}
.sb-nav a:hover { background: var(--hover); color: var(--text); }
.sb-nav a .ic { color: var(--text-3); }
.sb-nav a.active { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.sb-nav a.active .ic { color: var(--brand); }
.sb-nav a .sb-lock { margin-left: auto; font-size: 10.5px; color: var(--text-3); font-weight: 600; }
.sb-sub { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 18px; padding-left: 10px; border-left: 1px solid var(--border); }
.sb-sub a { height: 30px; font-size: 13px; padding: 0 10px; }
.sb-sub a.on { color: var(--brand-text); background: var(--brand-soft); font-weight: 650; }
.sb-sub a.on .ic { color: var(--brand); }
.sb-foot { display: flex; align-items: center; gap: 6px; padding: 8px 4px 0; border-top: 1px solid var(--border); }
.sb-me { flex: 1; display: flex; align-items: center; gap: 9px; min-width: 0; padding: 4px; }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #64748b, #334155); color: #fff; font-weight: 700; font-size: 13px;
}
.sb-me-text { min-width: 0; line-height: 1.25; }
.sb-me-text b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-me-text small { display: block; font-size: 11.5px; color: var(--text-3); }
.sb-me-text small.admin { color: var(--warn-text); font-weight: 650; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; flex: none;
  border: 0; background: none; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.scrim { display: none; }

.main {
  min-width: 0; margin: 8px 8px 8px 0; padding: 22px 26px 60px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-sm); min-height: calc(100vh - 16px);
}
.mobile-bar { display: none; }

/* 화면 머리 (예전 색 띠 헤더 대신) */
.page-head { display: flex; align-items: center; gap: 14px; margin: 0 0 18px; min-height: 44px; }
.page-head .title-badge {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 18%, transparent);
}
.page-head h1 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.25; color: var(--text); }
.page-head p { margin: 2px 0 0; font-size: 13px; color: var(--text-3); }

/* ── 카드처럼 쓰이는 상자들 — 그림자 대신 얇은 테두리 ─────────────────── */
.top-bar, .filter-box, .stats-bar, .search-section, .input-section, .info-bar,
.status-tabs, .table-wrap, .rule-card, .rmp-hist-wrap {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-card);
}
.content { padding: 0; }
.tab-content { padding: 18px 0 0; }

/* ── 버튼 ──────────────────────────────────────────────────────── */
.btn, .btn-primary, .btn-secondary, .btn-reset, .btn-export, .btn-submit, .btn-clear-form,
.btn-backup, .btn-restore, .btn-delete-all, .btn-back {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 9px; font-size: 13px; font-weight: 600; line-height: 1;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .08s;
}
.btn:hover, .btn-secondary:hover, .btn-reset:hover, .btn-clear-form:hover, .btn-back:hover { background: var(--surface-2); }
.btn:active, .btn-primary:active, .btn-export:active, .btn-submit:active { transform: translateY(1px); }
.btn.primary, .btn-primary, .btn-submit { background: var(--brand); border-color: transparent; color: #fff; }
.btn.primary:hover, .btn-primary:hover, .btn-submit:hover { background: var(--brand-hover); }
.btn-export, .btn-backup { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-export:hover, .btn-backup:hover { background: var(--surface-2); }
.btn.danger, .btn-delete-all { background: var(--danger); border-color: transparent; color: #fff; }
.btn.danger:hover, .btn-delete-all:hover { background: var(--danger-hover); }
.btn-restore { color: var(--danger); border-color: var(--danger-line); }
.btn-restore:hover { background: var(--danger-soft); }
.btn.warn { background: var(--warn); border-color: transparent; color: #fff; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled, .btn-primary:disabled, .btn-secondary:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ── 입력칸 ────────────────────────────────────────────────────── */
.filter-row input[type=text], .filter-row input[type=number], .filter-row input[type=date],
.filter-row input[type=month], .filter-row select, .search-box, .search-col-select,
.per-page-select, .form-input, .input-field {
  height: 34px; padding: 0 11px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.form-input, textarea.input-field { height: auto; padding: 8px 11px; }
.filter-row input:focus, .filter-row select:focus, .search-box:focus, .search-col-select:focus,
.per-page-select:focus, .form-input:focus, .input-field:focus, .rule-list:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); outline: none;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }

/* ── 탭 ────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; padding: 3px; margin: 0 0 4px; width: fit-content; max-width: 100%; overflow-x: auto;
  background: var(--surface-3); border: 0; border-radius: 11px;
}
.tab-btn {
  padding: 6px 14px; margin: 0; border: 0; border-radius: 8px; background: none;
  font-size: 13.5px; font-weight: 600; color: var(--text-2); white-space: nowrap;
}
.tab-btn:hover { background: none; color: var(--text); }
.tab-btn.active { background: var(--surface); color: var(--text); font-weight: 650; border: 0;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.tab-sep { width: 1px; margin: 6px 4px; background: var(--border-strong); flex: none; }

.status-tabs { overflow: hidden; }
.status-tab { color: var(--text-2); font-weight: 600; }
.status-tab:hover { background: var(--hover); }
.status-tab.active { color: var(--brand-text); background: var(--brand-soft); border-bottom-color: var(--brand); }
.tab-count { background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums; }
.status-tab.active .tab-count { background: var(--brand); color: #fff; }

.mode-btn { border-radius: 10px !important; }

/* ── 표 ────────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; }
table { font-variant-numeric: tabular-nums; }
thead th {
  background: var(--surface-2); color: var(--text-2); font-weight: 650; font-size: 12px;
  border-bottom: 1px solid var(--border);
}
thead th:hover { background: var(--surface-3); }
tbody tr { border-bottom-color: var(--border); }
tbody td { border-bottom-color: var(--border); }
tbody tr:hover { background: var(--hover); }
tbody tr:nth-child(even) { background: transparent; }
tbody tr:nth-child(even):hover { background: var(--hover); }
tbody tr.selected { background: var(--brand-soft) !important; }

/* ── 페이지 넘김 ───────────────────────────────────────────────── */
.page-btn, .pager button {
  min-width: 32px; height: 32px; padding: 0 9px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.page-btn:hover:not(:disabled), .pager button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.page-btn.active, .pager button.cur { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ── 배지 · 알약 ───────────────────────────────────────────────── */
.badge { background: var(--brand-soft); color: var(--brand-text); border-radius: 6px; font-weight: 650; }
.pill { border-radius: 6px; font-weight: 650; }

/* ── 창(모달) ──────────────────────────────────────────────────── */
.overlay, .modal-overlay { background: rgba(15, 23, 42, .35); backdrop-filter: blur(3px); }
.modal {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head, .modal-header {
  background: var(--surface); color: var(--text); border-bottom: 1px solid var(--border);
}
.modal-head h3, .modal-header h3 { color: var(--text); font-size: 16px; letter-spacing: -0.01em; }
.modal-head .x, .modal-close { color: var(--text-3); border-radius: 8px; }
.modal-head .x:hover, .modal-close:hover { background: var(--hover); color: var(--text); }
.modal-foot, .modal-footer { background: var(--surface-2); border-top: 1px solid var(--border); }

/* ── 알림(토스트) ──────────────────────────────────────────────── */
#toast, .toast { border-radius: 12px; background: #111827; color: #f9fafb; box-shadow: var(--shadow-lg); font-weight: 500; }
#toast.err, .toast.err, .toast.error { background: var(--danger); }
:root[data-theme="dark"] #toast:not(.err) { background: #f3f4f6; color: #111827; }

/* ── 카드 · 요약 숫자 (홈 · 운영 상태 화면) ─────────────────────────── */
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 16px 18px; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
.card-head .ic { color: var(--text-3); }
.card-head a { font-size: 12.5px; color: var(--brand-text); text-decoration: none; font-weight: 600; }
.kpi-label { font-size: 12.5px; color: var(--text-3); font-weight: 600; }
.kpi-num { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 650; background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.tag.ok { background: var(--ok-soft); color: var(--ok-text); }
.tag.warn { background: var(--warn-soft); color: var(--warn-text); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--brand-soft); color: var(--brand-text); }
.rows { display: flex; flex-direction: column; }
.rows > .row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-top: 1px solid var(--border); font-size: 13px; min-width: 0; }
.rows > .row:first-child { border-top: 0; }
.rows .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 650; padding: 6px 8px; border-bottom: 1px solid var(--border); background: none; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--hover); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--brand); }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px;
  font-size: 13px; line-height: 1.55; margin-bottom: 14px;
}
.alert.warn { background: var(--warn-soft); color: var(--warn-text); }
.alert.ok { background: var(--ok-soft); color: var(--ok-text); }
.alert ul { margin: 0; padding-left: 18px; }
.empty { color: var(--text-3); font-size: 13px; padding: 14px 2px; }
pre.code {
  margin: 8px 0 0; padding: 10px 12px; border-radius: 9px; background: var(--surface-3); color: var(--text);
  font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-all;
}
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

/* ── 반응형: 좁은 화면에서는 사이드바를 서랍으로 ─────────────────────── */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(290px, 86vw); z-index: 1000;
    background: var(--canvas); transform: translateX(-100%); transition: transform .22s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .scrim { display: block; position: fixed; inset: 0; z-index: 999; background: rgba(15, 23, 42, .35); }
  .sidebar .sb-close { display: inline-grid; }
  .main { margin: 0; border: 0; border-radius: 0; padding: 0 14px 60px; min-height: 100vh; }
  .mobile-bar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 50;
    margin: 0 -14px 12px; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .mobile-bar b { font-size: 15px; }
  .page-head { margin-bottom: 12px; }
  .page-head .title-badge { display: none; }
  .page-head h1 { font-size: 19px; }
  .status-tabs { overflow-x: auto; }
  .status-tab { flex: none; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media print {
  .sidebar, .mobile-bar { display: none !important; }
  .app { display: block; }
  .main { margin: 0; border: 0; box-shadow: none; }
}
