/* KMS 관제 플랫폼 — 공통 디자인 토큰 & 컴포넌트.
   방향: 에스원 앱 참고 — 흰색/밝은 회색 베이스 위에 경비상태 카드만 진한 색 블록(파랑=경비중,
   초록=해제중)으로 강조. 밝은 모드가 기본값. 다크는 [data-theme="dark"] 명시적 선택시만(추후 토글용). */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@1.3.9/dist/web/static/pretendard.css');

:root {
  --paper: #f1f2f5;
  --surface: #ffffff;
  --surface-2: #f4f5f8;
  --ink: #171a1f;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --line: rgba(15, 23, 42, 0.08);
  --line-strong: rgba(15, 23, 42, 0.15);

  /* 단일 accent: 블루 — 에스원 앱의 주 브랜드 색상과 맞춤. 변수명(--teal)은 레거시, 값은 블루. */
  --teal: #2f6fed;
  --teal-soft: rgba(47, 111, 237, 0.1);
  --amber: #b8721f;
  --amber-soft: rgba(184, 114, 31, 0.1);

  /* 경비=파랑(활성/경계), 해제=초록(평시/안전) — 에스원 앱 관용 색상. */
  --armed: #2f6fed;
  --armed-soft: rgba(47, 111, 237, 0.1);
  --disarmed: #18a35a;
  --disarmed-soft: rgba(24, 163, 90, 0.1);

  --danger: #d13c2e;
  --danger-soft: rgba(209, 60, 46, 0.1);
  --success: #18a35a;
  --success-soft: rgba(24, 163, 90, 0.1);
  --warning: #b8721f;
  --warning-soft: rgba(184, 114, 31, 0.1);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 1px rgba(15, 23, 42, 0.04), 0 16px 32px -16px rgba(15, 23, 42, 0.2);
  --inset-hi: inset 0 1px 0 rgba(255, 255, 255, 0.6);

  --font-display: 'Pretendard', -apple-system, sans-serif;
}

/* 다크 모드 — 명시적으로 data-theme="dark"를 지정했을 때만 (추후 토글 기능용, 현재 기본은 밝은 모드) */
:root[data-theme='dark'] {
  --paper: #0c0f0d;
  --surface: #151916;
  --surface-2: #1e2320;
  --ink: #ece9e0;
  --muted: #9fa89c;
  --faint: #626d64;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --teal: #4a84f0;
  --teal-soft: rgba(74, 132, 240, 0.15);
  --amber: #c98a5e;
  --amber-soft: rgba(201, 138, 94, 0.15);
  --armed: #4a84f0;
  --armed-soft: rgba(74, 132, 240, 0.16);
  --disarmed: #3fbf82;
  --disarmed-soft: rgba(63, 191, 130, 0.16);
  --danger: #f0806a;
  --danger-soft: rgba(240, 128, 106, 0.18);
  --success: #5cc286;
  --success-soft: rgba(92, 194, 134, 0.16);
  --warning: #dcae5e;
  --warning-soft: rgba(220, 174, 94, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 20px 44px -18px rgba(0, 0, 0, 0.7);
  --inset-hi: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  position: relative;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Pretendard', 'IBM Plex Sans KR', 'Malgun Gothic', -apple-system, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; text-wrap: balance; letter-spacing: -0.015em; }
p { margin: 0; }
a { color: var(--teal); }
.mono { font-family: 'IBM Plex Mono', 'D2Coding', Consolas, monospace; font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
@media (hover: hover) { a:hover { opacity: 0.85; } }

/* ---- layout ---- */
.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.app.wide { max-width: 1080px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 18px;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
}
.topbar h1 { font-family: var(--font-display); font-size: 17px; font-weight: 800; letter-spacing: -0.015em; color: var(--ink); }
.topbar .back {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}
.topbar .back:active { background: var(--surface-2); }
@media (hover: hover) { .topbar .back:hover { background: var(--surface-2); opacity: 1; } }
.topbar .spacer { flex: 1; }
.topbar .site-switch {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

main.content {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 22px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
main.content.centered { justify-content: center; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 0; }
.card-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--faint);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* ---- 접었다 펼치는 카드 — 자주 안 보는 참고성 정보(가입 정보 등)를 기본 접힘으로 둘 때 쓴다 ---- */
.card.collapsible { padding: 0; }
.card.collapsible > summary.card-title {
  cursor: pointer;
  list-style: none;
  margin: 0;
  padding: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card.collapsible > summary.card-title::-webkit-details-marker { display: none; }
.card.collapsible > summary.card-title::after { content: '▸'; font-size: 11px; transition: transform 0.15s ease; flex-shrink: 0; }
.card.collapsible[open] > summary.card-title::after { transform: rotate(90deg); }
.card.collapsible > .card-body { padding: 0 22px 22px; }

/* ---- 매일 안 보는 하위 페이지로 가는 바로가기(감지기 대장, 가입 정보 등) ---- */
.quick-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 18px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
@media (hover: hover) { .quick-link:hover { transform: translateY(-1px); box-shadow: var(--shadow); opacity: 1; } }
.quick-link .quick-link-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- status card (경비/해제) ---- */
.status-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 26px 24px;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}
.status-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 110% at 6% -10%, rgba(255, 255, 255, 0.18), transparent 55%);
  pointer-events: none;
}
.status-card::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}
/* 경비상태별 그라데이션 — .status-card(상세 페이지 히어로)와 .site-card(목록 카드) 둘 다 공유 */
.status-card.armed, .site-card.armed { background: linear-gradient(150deg, #4a7ef5 0%, #2657d6 55%, #163b9e 100%); }
.status-card.disarmed, .site-card.disarmed { background: linear-gradient(150deg, #27c07f 0%, #14985f 55%, #0a6b43 100%); }
.status-card.partial, .site-card.partial { background: linear-gradient(150deg, #e8ab3f 0%, #c17f1f 55%, #8a5710 100%); }
.status-card.unknown, .site-card.unknown { background: linear-gradient(150deg, #6b7280 0%, #4b5261 55%, #2e3340 100%); }
.status-card .site-name { position: relative; font-size: 12.5px; opacity: 0.78; letter-spacing: 0.01em; }
.status-card .state-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.status-card .state-main { display: flex; align-items: center; gap: 11px; }
.status-card .state-icon { flex-shrink: 0; opacity: 0.95; }
.status-card .state-label { font-family: var(--font-display); font-size: 27px; font-weight: 800; letter-spacing: -0.02em; }
.status-card .state-sub { font-size: 12.5px; opacity: 0.78; margin-top: 4px; display: flex; align-items: center; gap: 5px; }

/* ---- 침입 경고 배너 ---- */
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.alert-banner .icon-wrap { flex-shrink: 0; margin-top: 1px; }
.alert-banner .alert-title { font-size: 14.5px; font-weight: 700; color: var(--danger); }
.alert-banner .alert-sub { font-size: 12.5px; color: var(--danger); opacity: 0.85; margin-top: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .alert-banner { animation: alert-pulse 2.2s ease-in-out infinite; }
}
@keyframes alert-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 22%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 0%, transparent); }
}

/* ---- icons ---- */
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.icon-inline { display: inline-flex; align-items: center; gap: 5px; }

/* ---- 도어 상태 행 ---- */
.door-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 2px;
}
.door-row + .door-row { border-top: 1px solid var(--line); }
.door-row .door-label { display: flex; align-items: center; gap: 13px; font-size: 15px; font-weight: 700; }
.door-row .door-icon-chip {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.door-row .door-icon-chip.closed { background: var(--success-soft); color: var(--success); }
.door-row .door-icon-chip.open { background: var(--warning-soft); color: var(--warning); }
.door-row .door-icon-chip.door-unknown { background: var(--surface-2); color: var(--faint); }
.door-row .door-text { display: flex; flex-direction: column; gap: 5px; }
.door-row .door-actions { display: flex; gap: 8px; }
.door-row .door-actions .btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
}

/* ---- buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--surface);
  box-shadow: 0 4px 14px -6px color-mix(in srgb, var(--teal) 60%, transparent);
}
@media (hover: hover) { .btn-primary:hover { opacity: 0.92; } }
.btn-on-status { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.28); color: #fff; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--teal); padding: 8px 10px; min-height: auto; }
.btn-outline { background: transparent; border-color: var(--line-strong); border-radius: var(--radius-sm); }
@media (hover: hover) { .btn-outline:hover { background: var(--surface-2); } }
.btn-sm { padding: 8px 14px; min-height: 36px; font-size: 12.5px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- pill-link: 로그아웃/상세/뒤로가기 같은 보조 내비게이션 —
   그냥 파란 텍스트 링크 대신 아이콘+옅은 배경의 "버튼처럼 보이는" 캡슐로 디자인한다. */
.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px 7px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}
@media (hover: hover) { .pill-link:hover { background: var(--line-strong); color: var(--ink); opacity: 1; } }
.pill-link.icon-only { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--faint); letter-spacing: 0.02em; text-transform: uppercase; }
.field input, .field select {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 15px;
  min-height: 44px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.field input:focus, .field select:focus { border-color: var(--teal); background: var(--surface); box-shadow: 0 0 0 3px var(--teal-soft); outline: none; }
.field .hint { font-size: 12px; color: var(--faint); }
.form-stack { display: flex; flex-direction: column; gap: 16px; }

/* ---- badges ----
   진짜 중요한 상태(경비/해제, 침입, 도어, 센서이상)만 채워진 필(pill)로 강조하고, 나머지 통상적인
   메타정보(접속여부, 명령결과, 역할태그, 승인코드상태)는 .quiet로 — 화면마다 색 뱃지가 줄줄이
   붙는 "알록달록한 MVP" 느낌을 줄이려는 의도적 구분이다. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.quiet {
  background: transparent;
  border-color: transparent;
  padding: 0;
  font-weight: 500;
  color: var(--muted);
}
.badge.quiet::before { width: 5px; height: 5px; }

.badge.b-armed { background: var(--armed-soft); color: var(--armed); }
.badge.b-disarmed { background: var(--disarmed-soft); color: var(--disarmed); }
.badge.b-partial { background: var(--warning-soft); color: var(--warning); }
.badge.b-unknown { background: var(--surface-2); color: var(--faint); }
.badge.b-intrusion { background: var(--danger-soft); color: var(--danger); }
@media (prefers-reduced-motion: no-preference) {
  .badge.b-intrusion { animation: badge-pulse 1.3s ease-in-out infinite; }
}
@keyframes badge-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.badge.b-health { background: var(--warning-soft); color: var(--warning); }
/* 도어: 닫힘=안전(초록), 열림=주의(호박), 미확인=중립 — 경비상태 색과는 별개 체계, 물리 상태라 계속 필로 강조 */
.badge.b-open { background: var(--warning-soft); color: var(--warning); }
.badge.b-closed { background: var(--success-soft); color: var(--success); }
.badge.b-door-unknown { background: var(--surface-2); color: var(--faint); }

/* 통상 메타정보 — 배경/테두리 없이 색+점만(quiet). HTML을 안 건드리고 CSS만으로 처리. */
.badge.b-online, .badge.b-offline, .badge.b-ack, .badge.b-nack, .badge.b-timeout,
.badge.b-pending, .badge.b-admin, .badge.b-customer, .badge.b-device {
  background: transparent;
  border-color: transparent;
  padding: 0;
  font-weight: 500;
}
.badge.b-online { color: var(--success); }
.badge.b-offline { color: var(--danger); }
.badge.b-ack { color: var(--success); }
.badge.b-nack, .badge.b-timeout { color: var(--danger); }
.badge.b-pending { color: var(--amber); }
.badge.b-admin { color: var(--amber); }
.badge.b-customer { color: var(--muted); }
.badge.b-device { color: var(--muted); }

/* ---- lists / rows ---- */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
  transition: opacity 0.15s ease;
}
.row:last-child { border-bottom: none; }
.row .row-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.row .row-title { font-size: 14.5px; font-weight: 700; font-family: var(--font-display); letter-spacing: -0.005em; }
.row .row-sub { font-size: 12.5px; color: var(--muted); }
/* 표/리스트에서 "이름"에 해당하는 핵심 텍스트 — 진하고 표시체로, 옆의 번호·날짜 등 부가정보와
   위계를 분명히 나눈다. 링크로 쓰일 땐 파란 링크색 대신 이 색을 쓰고 hover에서만 강조한다. */
.cell-title { font-family: var(--font-display); font-weight: 700; color: var(--ink); letter-spacing: -0.005em; }
a.cell-title { text-decoration: none; }
@media (hover: hover) { a.cell-title:hover { color: var(--teal); opacity: 1; } }
.dim { color: var(--muted); }
/* 감지기 목록: "몇 번 감지기인지" 안 보인다는 피드백 반영 — 감지기마다 X-Y 번호를 붙여 한 줄씩 구분 */
.row .detector-sub { display: flex; flex-direction: column; gap: 5px; }
.row .detector-num {
  display: inline-block;
  margin-right: 7px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
a.row-link { text-decoration: none; color: inherit; } /* .row의 flex display를 유지하기 위해 display는 여기서 지정하지 않음 */
@media (hover: hover) { a.row-link:hover { opacity: 0.7; } }

/* ---- site list card ----
   에스원 앱 참고 — 목록 카드 자체를 경비상태 그라데이션으로 꽉 채운다(뱃지 몇 개로 상태를 표시하는
   대신, 카드 색 자체가 상태). .status-card와 같은 그라데이션 세트를 공유해서 상세 페이지와 톤이 이어진다. */
.site-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  color: #fff;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.site-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 110% at 6% -10%, rgba(255, 255, 255, 0.18), transparent 55%);
  pointer-events: none;
}
.site-card > * { position: relative; }
@media (hover: hover) {
  .site-card:hover { transform: translateY(-1px); box-shadow: 0 1px 1px rgba(15, 23, 42, 0.05), 0 20px 40px -16px rgba(15, 23, 42, 0.35); opacity: 1; }
}
.site-card .site-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.site-card .site-top { display: flex; align-items: center; gap: 8px; }
.site-card .site-name { font-family: var(--font-display); font-size: 15px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-card .site-sub { font-size: 11.5px; color: rgba(255, 255, 255, 0.75); font-family: 'IBM Plex Mono', monospace; }
/* 경비상태·도어상태를 각각 별도의 필(glass pill)로 — 옅은 흰 텍스트 대신이라 카드 배경색이
   뭐든 또렷하게 읽힌다. 도어 열림처럼 "확인이 필요한" 상태만 불투명 흰 배경 + 경고색 텍스트로
   한 단계 더 강조한다. */
.site-card .site-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.site-card .site-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 12px;
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
.site-card .site-pill.is-open {
  background: #fff;
  border-color: transparent;
  color: var(--warning);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.3);
}
.site-card .chev { color: rgba(255, 255, 255, 0.7); font-size: 16px; flex-shrink: 0; }

/* ---- bottom actions ---- */
.bottom-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 60%, transparent);
  display: flex;
  gap: 10px;
}

/* ---- empty / loading ---- */
.empty-state { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 13.5px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: var(--danger); color: #fff; }

/* ---- admin: dashboard tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.tile .tile-label { font-size: 11px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.tile .tile-value { font-family: var(--font-display); font-size: 30px; font-weight: 800; margin-top: 5px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
@media (max-width: 420px) { .tiles { grid-template-columns: 1fr 1fr; } }

/* ---- admin: table (desktop) / stacked rows (mobile) ----
   같은 데이터를 두 군데(.table-wrap, .stack-rows)에 렌더링해두고 화면폭에 따라 CSS로만 전환한다.
   표를 그대로 축소하면 가로 스크롤이 생기는데, 스크롤 단서가 잘 안 보여서 "잘려 보인다"는
   문제가 있었다 — 그래서 모바일에서는 표 대신 카드형 목록(.stack-rows)을 보여준다. */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table.data { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 560px; }
table.data th, table.data td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); font-weight: 600; background: var(--surface-2); }
table.data tr:last-child td { border-bottom: none; }
table.data td.num { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
@media (hover: hover) { table.data tbody tr:hover { background: var(--surface-2); } }

.stack-rows { display: none; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 4px 18px; box-shadow: var(--shadow-sm); }
.stack-rows .row { flex-wrap: wrap; }
.stack-rows .row .row-badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- nav (admin side) ---- */
.admin-shell { display: flex; min-height: 100dvh; position: relative; z-index: 1; }
.admin-nav {
  width: 216px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.admin-nav-links { display: flex; flex-direction: column; gap: 2px; }
.admin-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}
@media (hover: hover) { .admin-nav a:hover { background: var(--surface-2); color: var(--ink); opacity: 1; } }
.admin-nav a.active { background: var(--teal-soft); color: var(--teal); }
.admin-nav-logout { margin-top: auto; color: var(--faint) !important; }
.admin-main { position: relative; z-index: 1; flex: 1; min-width: 0; padding: 30px 32px; display: flex; flex-direction: column; gap: 20px; }
.admin-brand { font-family: var(--font-display); font-weight: 800; font-size: 16px; letter-spacing: -0.01em; padding: 6px 13px 22px; color: var(--ink); }

@media (max-width: 760px) {
  table.data { display: none; }
  .table-wrap { display: none; }
  .stack-rows { display: flex; flex-direction: column; }

  .admin-shell { flex-direction: column; }
  /* 좁은 화면: 좌측 세로 메뉴 대신 아이콘+라벨 하단 탭바로 전환 — 항목이 화면 밖으로 넘쳐 잘리는 문제를 원천 차단 */
  .admin-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    flex-direction: row;
    align-items: stretch;
    border-right: none;
    border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    backdrop-filter: saturate(160%) blur(16px);
    z-index: 20;
    gap: 0;
    box-shadow: 0 -6px 20px -10px rgba(20, 24, 20, 0.25);
  }
  .admin-nav-links { flex-direction: row; flex: 1; gap: 0; }
  .admin-nav a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    text-align: center;
    font-size: 10.5px;
    padding: 7px 2px;
    border-radius: var(--radius-sm);
  }
  .admin-nav a.active { background: transparent; }
  .admin-nav a.active .icon { color: var(--teal); }
  .admin-nav-logout { margin-top: 0; flex-direction: column; gap: 3px; font-size: 10.5px; padding: 7px 2px; }
  .admin-brand { display: none; }
  .admin-main { padding: 18px 16px calc(84px + env(safe-area-inset-bottom)); }
  .tiles { grid-template-columns: 1fr 1fr; }
}

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h2 { font-family: var(--font-display); font-size: 22px; font-weight: 800; letter-spacing: -0.015em; }
.page-head .sub { font-size: 13px; color: var(--muted); }
