/* 스마트 펜스 관제 UI 디자인 시스템: 토큰, 레이아웃, 공용 컴포넌트 */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e4e8f0;
  --line-2: #eef1f6;
  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --brand-soft: #e8efff;
  --side: #0b1220;
  --side-2: #131c30;
  --ok: #15803d;        --ok-soft: #e7f6ec;
  --caution: #a16207;   --caution-soft: #fdf3d6;
  --warning: #c2410c;   --warning-soft: #ffead9;
  --critical: #b91c1c;  --critical-soft: #fde7e7;
  --info: #1d4ed8;      --info-soft: #e8efff;
  --off: #475569;       --off-soft: #e9edf3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .05);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.5; -webkit-font-smoothing: antialiased; word-break: keep-all; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 레이아웃 ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #cbd5e1; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: .72rem; color: #7c8aa5; }
.nav-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #5d6b86; padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: #b4c0d4; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: #1e293b; color: #fff; box-shadow: inset 3px 0 0 #3b82f6; }
.side-foot { margin-top: auto; padding: 12px; font-size: .78rem; color: #6b7a96; border-top: 1px solid #1a2438; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 62px; display: flex; align-items: center; gap: 14px; padding: 0 28px; background: rgba(243, 245, 249, .85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 26px 28px 40px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.55rem; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { border-color: #cbd5e1; }
.badge-dot { position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 99px; background: var(--critical); color: #fff; font-size: .68rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 4px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.user-chip b { font-size: .88rem; display: block; line-height: 1.1; }
.user-chip small { color: var(--muted); font-size: .72rem; }
.user-chip form { margin: 0; }
.pop { position: absolute; right: 0; top: 48px; width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 14px 40px rgba(15, 23, 42, .16); z-index: 30; overflow: hidden; }
.pop-head { padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; }
.pop a.item { display: block; padding: 11px 16px; border-bottom: 1px solid var(--line-2); color: var(--ink); }
.pop a.item:hover { background: #f8fafc; }
.pop .empty { padding: 22px; text-align: center; color: var(--muted); }
.bell-wrap { position: relative; }

/* ---------- 카드·그리드 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-h h2 { font-size: 1.02rem; }
.card-b { padding: 20px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 18px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 1fr) 380px; }
.stack { display: grid; gap: 18px; align-content: start; }
.mt { margin-top: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.kpi .value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; line-height: 1.15; }
.kpi .sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line); }
.kpi.ok::before { background: #22c55e; } .kpi.ok .value { color: var(--ok); }
.kpi.caution::before { background: #eab308; } .kpi.caution .value { color: var(--caution); }
.kpi.warning::before { background: #f97316; } .kpi.warning .value { color: var(--warning); }
.kpi.critical::before { background: #ef4444; } .kpi.critical .value { color: var(--critical); }
.kpi.primary::before { background: var(--brand); }

/* ---------- 배지·칩 ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--off-soft); color: var(--off); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.b-info { background: var(--info-soft); color: var(--info); }
.b-caution { background: var(--caution-soft); color: var(--caution); }
.b-warning { background: var(--warning-soft); color: var(--warning); }
.b-critical { background: var(--critical-soft); color: var(--critical); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-off { background: var(--off-soft); color: var(--off); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #94a3b8; flex: none; }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px #22c55e33; } .dot.fault { background: #f97316; } .dot.offline { background: #94a3b8; } .dot.critical { background: #ef4444; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .85rem; font-weight: 500; cursor: pointer; }
.chip:hover { border-color: #b8c2d4; color: var(--ink); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .n { font-size: .75rem; opacity: .75; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #e9edf4; border-radius: 12px; width: fit-content; }
.tabs a { padding: 7px 16px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }

/* ---------- 버튼·폼 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b8c2d4; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
.btn.danger { color: var(--critical); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--critical-soft); color: var(--critical); }
.btn.sm { padding: 5px 11px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: .84rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .8rem; color: var(--muted); }
.req { color: var(--critical); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #d5dbe6; border-radius: 10px; background: #fff; color: var(--ink); font: inherit; font-size: .93rem; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg 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'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center; }
input[type=date], input[type=time], input[type=number], input[type=text], input[type=password], input[type=email], select { min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3ff; border-color: var(--brand); }
textarea { min-height: 88px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; accent-color: var(--brand); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-error, .validation-summary-errors { color: var(--critical); font-size: .82rem; }
.validation-summary-errors ul { margin: 0 0 12px; padding: 10px 14px 10px 30px; background: var(--critical-soft); border-radius: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 20px; }
.filters .field { margin: 0; min-width: 140px; }
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--critical-soft); color: var(--critical); }
.alert.info { background: var(--info-soft); color: var(--info); }
.keybox { font-family: ui-monospace, Menlo, monospace; background: #0f172a; color: #86efac; padding: 12px 16px; border-radius: 10px; word-break: break-all; margin-top: 8px; }

/* ---------- 테이블·리스트 ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; min-width: 640px; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: none; padding: 11px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfd; }
.table tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.table .title { font-weight: 600; color: var(--ink); }
.table .sub { color: var(--muted); font-size: .82rem; }
.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line-2); color: var(--muted); font-size: .88rem; }
.pager nav { display: flex; gap: 4px; }
.pager a, .pager span.cur { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 8px; border-radius: 9px; color: var(--ink-2); border: 1px solid var(--line); background: var(--surface); }
.pager span.cur { background: var(--ink); border-color: var(--ink); color: #fff; }
.pager a:hover { border-color: #b8c2d4; }
.list-item { display: flex; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line-2); align-items: flex-start; color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover { background: #fafbfd; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; color: var(--ink); }
.dl { display: grid; grid-template-columns: 120px 1fr; gap: 11px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .87rem; }
.dl dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid #94a3b8; }
.timeline li.hot::before { border-color: var(--brand); }
.timeline .when { font-size: .8rem; color: var(--muted); }
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }

/* ---------- 디바이스 카드·측정값 ---------- */
.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; padding: 18px 20px; }
.dev-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff; display: block; color: inherit; transition: border-color .15s, box-shadow .15s; }
.dev-card:hover { border-color: #b8c2d4; box-shadow: var(--shadow); color: inherit; }
.dev-card.st-offline { background: #f8fafc; }
.dev-card.st-sensorfault { border-color: #fdba74; }
.dev-card .name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dev-card .meta { font-size: .8rem; color: var(--muted); margin: 2px 0 10px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.metric { background: #f6f8fb; border-radius: 9px; padding: 7px 8px; }
.metric small { display: block; color: var(--muted); font-size: .7rem; }
.metric b { font-size: .98rem; }
.metric.hot b { color: var(--critical); }
.zone-title { padding: 14px 20px 0; font-weight: 700; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.sensor-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.sensor-row:last-child { border-bottom: 0; }
.snapshot { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; background: #0f172a; display: block; }

/* ---------- 인증 화면 ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-art { background: radial-gradient(900px 500px at 10% 0%, #1e3a8a 0%, transparent 60%), linear-gradient(160deg, #0b1220, #0f1d3a 70%); color: #e2e8f0; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art h2 { font-size: 2.1rem; line-height: 1.25; color: #fff; margin: 0 0 14px; }
.auth-art p { color: #a9b6cf; max-width: 430px; }
.auth-art ul { list-style: none; padding: 0; margin: 30px 0 0; display: grid; gap: 14px; }
.auth-art li { display: flex; gap: 12px; align-items: flex-start; color: #cdd7ea; }
.auth-art li span.ic { width: 34px; height: 34px; border-radius: 10px; background: #ffffff14; display: grid; place-items: center; flex: none; color: #93b4ff; }
.auth-form { display: grid; place-items: center; padding: 40px 28px; background: var(--surface); }
.auth-card { width: 100%; max-width: 440px; }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.role-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
.role-pick label { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: block; }
.role-pick label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.role-pick input { position: absolute; opacity: 0; pointer-events: none; }
.role-pick b { display: block; font-size: .93rem; }
.role-pick small { color: var(--muted); font-size: .78rem; }
.demo-box { margin-top: 22px; padding: 14px 16px; border: 1px dashed #c3cbd9; border-radius: 12px; background: #f8fafc; font-size: .85rem; }
.demo-box button { margin: 4px 6px 0 0; }
.toast-host { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 50; }
.toast { background: #0f172a; color: #fff; padding: 13px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); max-width: 360px; border-left: 4px solid var(--brand); }
.toast.critical { border-left-color: #ef4444; }

@media (max-width: 1180px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-main { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 248px; z-index: 40; transition: left .2s; }
  body.nav-open .side { left: 0; }
  .menu-btn { display: grid; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .cols-3, .cols-2, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .auth { grid-template-columns: 1fr; } .auth-art { display: none; }
  .user-chip .who { display: none; }
}
