/* IRUDA CCTV 관제 서버 — 공통 디자인 시스템 (Tailwind 유틸리티 위에 얹는 컴포넌트 클래스)
   오프라인(NAS/폐쇄망)에서도 동작하도록 외부 폰트/CDN 없음. */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e4e8ee;
  --line-strong: #cfd6e0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --brand-soft: #e8efff;
  --ok: #16a34a;
  --ok-soft: #e7f7ec;
  --warn: #d97706;
  --warn-soft: #fff4e0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --side-bg: #0b1220;
  --side-bg-2: #111a2e;
  --side-text: #c7d0e0;
  --side-muted: #6b7a94;
  --side-active: #1e3a8a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 1px rgba(15, 23, 42, .03);
  --sidebar-w: 236px;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  word-break: keep-all;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--brand-soft); }

/* ---------- 앱 셸 ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; flex: none;
}
.brand-title { color: #fff; font-weight: 800; letter-spacing: -.01em; font-size: 15px; line-height: 1.1; }
.brand-sub { color: var(--side-muted); font-size: 11px; margin-top: 2px; }
.nav { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { color: var(--side-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--side-text); text-decoration: none; font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--side-bg-2); color: #fff; }
.nav-link.active { background: var(--side-active); color: #fff; }
.nav-link svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 1px 7px; border-radius: 999px; text-align: center;
  font-size: 11px; font-weight: 700; background: var(--warn); color: #fff; line-height: 18px;
}
.sidebar-foot { margin-top: auto; padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12px; color: var(--side-muted); display: flex; align-items: center; gap: 8px; }
.sidebar-foot .who { color: #e2e8f0; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot a { color: var(--side-muted); text-decoration: none; }
.sidebar-foot a:hover { color: #fca5a5; }

.main { min-width: 0; }
.topbar { display: none; }
.scrim { display: none; }
.content { padding: 28px 32px 48px; max-width: 1240px; }
.content.wide { max-width: none; }

/* 모바일: 사이드바 → 상단 바 + 드로어 */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .18s ease; height: 100vh; }
  #nav-toggle:checked ~ .sidebar { transform: none; }
  #nav-toggle:checked ~ .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 12px; height: 54px; padding: 0 16px;
    background: var(--side-bg); color: #fff; position: sticky; top: 0; z-index: 20; }
  .topbar label { cursor: pointer; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; }
  .topbar label:hover { background: var(--side-bg-2); }
  .content { padding: 18px 16px 40px; }
}

/* ---------- 페이지 머리 ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.page-desc { color: var(--text-2); margin-top: 4px; font-size: 13.5px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.crumb { font-size: 12.5px; color: var(--text-3); margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }
.crumb a { color: var(--text-2); text-decoration: none; }
.crumb a:hover { color: var(--brand); }

/* ---------- 카드 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-title { font-weight: 700; font-size: 14.5px; }
.card-sub { color: var(--text-3); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.card.muted { opacity: .6; }
.section-title { font-size: 12px; font-weight: 700; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 8px; }

/* ---------- 통계 타일 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; display: block; }
.stat:hover { border-color: var(--line-strong); }
.stat-label { color: var(--text-2); font-size: 12.5px; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--ok); } .stat-value.warn { color: var(--warn); } .stat-value.brand { color: var(--brand); } .stat-value.danger { color: var(--danger); }
.stat-hint { color: var(--text-3); font-size: 12px; margin-top: 4px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer;
  text-decoration: none; transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: #b9c2cf; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-danger { color: var(--danger); border-color: #f3c3c3; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #eaa3a3; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn svg { width: 15px; height: 15px; }
.link { color: var(--brand); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--danger); text-decoration: none; font-weight: 500; }
.link-danger:hover { text-decoration: underline; }

/* ---------- 폼 ---------- */
.field { display: block; }
.field > .label, .label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.label .hint { font-weight: 400; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font-size: 13.5px; outline: none; transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; padding: 8px 11px; min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-3); }
.select { padding-right: 30px; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.help { font-size: 12px; color: var(--text-3); }

/* 토글 스위치 (checkbox 기반, JS 불필요) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.switch input:disabled + .track { opacity: .45; cursor: not-allowed; }
.switch.ok input:checked + .track { background: var(--ok); }
.switch.warn input:checked + .track { background: var(--warn); }
.switch.sm .track { width: 32px; height: 18px; } .switch.sm .track::after { width: 12px; height: 12px; }
.switch.sm input:checked + .track::after { transform: translateX(14px); }
.switch.busy .track { opacity: .6; }

/* 요일 칩 */
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip span { display: block; min-width: 32px; height: 30px; line-height: 28px; text-align: center; border-radius: 8px; border: 1px solid var(--line-strong);
  font-size: 12.5px; color: var(--text-2); background: #fff; padding: 0 6px; transition: all .12s; }
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.chip:hover span { border-color: #b9c2cf; }

/* ---------- 표 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { text-align: left; font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--surface-2);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-2); }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 8px; }
.table .muted { color: var(--text-3); }
.table.dense th, .table.dense td { padding: 7px 12px; }
.row-off td { opacity: .55; }

/* ---------- 배지 · 상태 ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-gray { background: #eef2f6; color: var(--text-2); }
.badge-blue { background: var(--brand-soft); color: var(--brand-2); }
.badge-green { background: var(--ok-soft); color: #15803d; }
.badge-amber { background: var(--warn-soft); color: #b45309; }
.badge-red { background: var(--danger-soft); color: #b91c1c; }
.badge-dark { background: #0f172a; color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.dot-off { background: #cbd5e1; }
.dot-warn { background: var(--warn); }
.kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 6px; padding: 1px 6px; color: var(--text-2); }

/* ---------- 안내 상자 ---------- */
.note { border-radius: var(--radius-sm); padding: 11px 14px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid; }
.note-info { background: var(--brand-soft); border-color: #c7d7fe; color: #1e3a8a; }
.note-warn { background: var(--warn-soft); border-color: #fcd9a6; color: #92400e; }
.note-danger { background: var(--danger-soft); border-color: #f5b5b5; color: #991b1b; }
.note-ok { background: var(--ok-soft); border-color: #b7e4c7; color: #166534; }
.note b { font-weight: 700; }

.empty { text-align: center; color: var(--text-3); padding: 40px 16px; font-size: 13.5px; }
.empty .big { font-size: 28px; margin-bottom: 6px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.stack > * + * { margin-top: 12px; }
.meta { font-size: 12px; color: var(--text-3); }
.tabular { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 상세 접기 */
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .chev { transition: transform .15s; }
details.card[open] > summary .chev { transform: rotate(90deg); }

/* 토스트 */
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(2, 6, 23, .3); opacity: 0; transform: translateY(8px); transition: all .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); }
