/* 센터 화면(control-center/web/style.css)과 같은 모양: shadcn/ui 느낌 (zinc 기본 테마)을 CSS만으로. 색은 HSL 토큰.
 * 센터 쪽 공통 부품(1·2·알림)을 그대로 가져오고 detector 화면 것(3)만 더했다. 바꿀 때는 센터와 같은 모양을 유지한다
 * 목차: 1. 바탕(색 토큰·본문 기둥·상단 한 줄) 2. 공통 부품(카드·버튼·배지·입력·확인 창·대화상자·표) 3. 알림 4. 첫 화면 5. 검사 화면 6. 기록 화면
 */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --border: 240 5.9% 90%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --accent: 240 4.8% 95.9%;
  --destructive: 0 72% 51%;
  --success: 142 71% 36%;
  --warning: 38 92% 45%;
  --ring: 240 5% 64.9%;
  --radius: 0.5rem;
  /* 1200px 바깥 여백 */
  --outside: 240 5% 96%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 5.5%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --border: 240 3.7% 15.9%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --accent: 240 3.7% 15.9%;
    --destructive: 0 63% 50%;
    --success: 142 60% 45%;
    --warning: 38 92% 55%;
    --ring: 240 4.9% 83.9%;
    --outside: 240 10% 1.5%;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* 스크롤바를 늘 두어 내용 길이가 바뀌어도 화면이 옆으로 흔들리지 않게 */
html {
  overflow-y: scroll;
}

body {
  margin: 0;
  background: hsl(var(--outside));
  color: hsl(var(--foreground));
  font:
    14px/1.5 ui-sans-serif,
    system-ui,
    -apple-system,
    'Segoe UI',
    'Malgun Gothic',
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

.container {
  padding-inline: 24px;
}

/* 1200px 본문 기둥: 바깥은 연한 회색, 경계는 세로선 */
.page {
  max-width: 1200px;
  min-height: 100vh;
  margin: 0 auto;
  background: hsl(var(--background));
  border-left: 1px solid hsl(var(--border));
  border-right: 1px solid hsl(var(--border));
}

.muted {
  color: hsl(var(--muted-foreground));
}

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
}

/* 상단 한 줄: 이름 · 메뉴 탭 · 상태 */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: hsl(var(--background) / 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border));
}

.header-row {
  display: flex;
  align-items: stretch;
  gap: 24px;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 700;
}

.brand-name {
  font-weight: 600;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.tabs a {
  display: flex;
  align-items: center;
  text-decoration: none;
  padding: 0 12px;
  color: hsl(var(--muted-foreground));
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}

.tabs a:hover {
  color: hsl(var(--foreground));
}

.tabs a.active {
  color: hsl(var(--foreground));
  border-bottom-color: hsl(var(--foreground));
}

/* 메뉴 옆 경고 수 (릴레이) */
.tabs a .badge {
  margin-left: 6px;
  height: 18px;
  padding: 0 6px;
}

main {
  padding-top: 20px;
  padding-bottom: 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}

.page-title h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* 카드 */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
}

.card-header {
  padding: 16px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-content {
  padding: 16px 20px 20px;
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  transition: opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:hover {
  opacity: 0.9;
}

.btn:focus-visible,
.input:focus-visible,
.select:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.btn.outline {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.btn.outline:hover {
  background: hsl(var(--accent));
  opacity: 1;
}

/* 테두리 없는 버튼도 버튼으로 보이게 회색 바탕 (로그아웃·빼기) */
.btn.ghost {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.btn.ghost:hover {
  background: hsl(var(--border));
  opacity: 1;
}

.btn.destructive {
  background: hsl(var(--destructive));
  color: #fff;
}

.btn.secondary {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.btn.secondary:hover {
  background: hsl(var(--muted) / 0.8);
  opacity: 1;
}

.dialog-footer.end {
  justify-content: flex-end;
}

.btn.sm {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 배지 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: hsl(var(--muted-foreground));
}

.badge.plain::before {
  display: none;
}

.badge.ok::before {
  background: hsl(var(--success));
}

.badge.warn::before {
  background: hsl(var(--warning));
}

.badge.bad::before {
  background: hsl(var(--destructive));
}

/* 입력 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field.span-2 {
  grid-column: span 2;
}

.input,
.select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
  font-weight: 400;
}

/* 등록 폼: 위에서 아래로 한 칸씩 */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 880px;
}

/* 대화상자 칸 두 개를 한 줄에 50%씩 */
.field-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* 길면 한 줄로 줄임 (이름 등). 부모가 flex·grid면 이 요소가 줄어들 수 있어야 한다 */
.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 이름 칸 폭 고정 (긴 이름은 줄임). detector는 메뉴가 없어 판 줄 "x.y.z (dev) · 묶음 0000"이 들어가게 넓게 */
.brand > div {
  min-width: 0;
  width: 200px;
}

/* 확인 창 */
.dialog.confirm {
  width: min(400px, calc(100vw - 32px));
}

.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 24px;
}

.confirm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* 대화상자 (shadcn Dialog 모양) */
.dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 4px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 10px 38px rgb(0 0 0 / 0.2);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 66px);
}

.dialog-header {
  padding: 20px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* 내용이 길면 대화상자 안에서만 스크롤 */
.dialog-body {
  padding: 4px 24px 20px;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid hsl(var(--border));
}

/* 표 */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}

th {
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  font-size: 13px;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.link {
  cursor: pointer;
}

tbody tr.link:hover {
  background: hsl(var(--muted) / 0.6);
}

/* 알림: 아래 가운데. 실패는 빨강 */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(720px, calc(100vw - 48px));
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.15);
}

.toast.error {
  background: hsl(var(--destructive));
  color: #fff;
}

/* 4. 첫 화면: 가운데 카드에 이름 표시, 플래그·비밀번호, 확인 (센터 로그인 화면과 같은 틀) */
.entry-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 0 16px 10vh;
}

.entry {
  width: min(360px, 100%);
  padding: 24px;
  display: grid;
  gap: 20px;
}

.entry .input.wrong {
  border-color: hsl(var(--destructive));
  outline-color: hsl(var(--destructive));
}

/* 수집 진행 (확인 버튼 아래) */
.progress {
  display: grid;
  gap: 6px;
  margin-top: -8px;
}

.progress-track {
  height: 4px;
  border-radius: 999px;
  background: hsl(var(--muted));
  overflow: hidden;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: hsl(var(--primary));
  transition: width 0.2s;
}

.entry-error {
  margin-top: -8px;
  color: hsl(var(--destructive));
}

/* 5. 검사 화면 */
.record-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.record-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* 위 두 칸은 같은 줄 수 (B가 없어도 '-'로 채운다), UA는 두 줄까지 */
.side-ua {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 3em;
}

/* 카드 맨 위 줄: 이름 · 현재 배지 · 검색 · 셀렉트 */
.side-pick {
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-pick .side-label {
  flex: none;
}

.compare-search {
  width: 140px;
  flex: none;
}

.side-pick .select {
  flex: 1;
  min-width: 0;
}

/* 아래 정보 부분: 누르면 기록 정보 전체 (대화상자) */
.side-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  margin: -6px;
  padding: 6px;
  border-radius: calc(var(--radius) - 2px);
}

.side-info.clickable {
  cursor: pointer;
}

.side-info.clickable:hover {
  background: hsl(var(--muted) / 0.4);
}

.seg button:disabled {
  cursor: default;
  opacity: 0.5;
}

.side-label {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

.side-title {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* 요약 한 줄: 다름·같음·한쪽만 수 + 다른 것만 보기 */
.summary-row {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge.diff::before {
  background: hsl(var(--warning));
}

.badge.only::before {
  background: hsl(var(--muted-foreground));
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

/* 요약 줄 오른쪽: 전체/다른 것만 + 내려받기 */
.summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.seg button {
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.seg button.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

/* 분류 타일 (iphey처럼 한눈에): 4칸씩 (우리 6 + fingerprint.com 1 = 2줄), 누르면 그 분류로 */
.overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.tile {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px 16px;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.tile:hover {
  background: hsl(var(--muted) / 0.6);
}

.tile.has-diff {
  border-color: hsl(var(--warning) / 0.6);
}

.tile .placeholder {
  visibility: hidden;
}

.tile-title {
  font-weight: 600;
}

/* 분류 묶음: 제목 아래에 그룹 카드 (상단 줄에 가리지 않게 여백) */
.category {
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-margin-top: 72px;
}

.category-title {
  font-size: 18px;
  font-weight: 600;
  padding-top: 8px;
  border-top: 1px solid hsl(var(--border));
}

/* 값 표: 키는 다 보이게 줄바꿈, 값은 3줄까지 (누르면 대화상자에 전체) */
.values {
  table-layout: fixed;
}

.values th,
.values td {
  white-space: normal;
  vertical-align: top;
  padding: 7px 10px;
}

.values col.key {
  width: 30%;
}

.values td.key {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.values td.val {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.values td.val > div {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.values tbody tr {
  cursor: pointer;
}

.values tbody tr:hover {
  background: hsl(var(--muted) / 0.6);
}

.values tr.diff td {
  background: hsl(var(--warning) / 0.14);
}

.values tr.diff td.key {
  box-shadow: inset 3px 0 hsl(var(--warning));
}

/* 매번 바뀌는 값 (비교 제외): 색 없이 흐리게 */
.values tr.volatile td {
  color: hsl(var(--muted-foreground));
}

.values tr.only td {
  background: hsl(var(--muted) / 0.7);
}

.values tr.only td.key {
  box-shadow: inset 3px 0 hsl(var(--muted-foreground));
}

.values .none {
  color: hsl(var(--muted-foreground));
  font-style: italic;
  font-family: inherit;
}

.values .has-desc::after {
  content: ' ⓘ';
  color: hsl(var(--muted-foreground));
}

/* fingerprint.com 값: 한국어 이름·값 풀이 + 원래 키·값 작게 (fp-labels.js) */
.values td.key .fp-name,
.fp-readable {
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    'Segoe UI',
    'Malgun Gothic',
    sans-serif;
  font-size: 13px;
}

.values td.val > div.raw-sub,
.values td.key .raw-sub {
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  -webkit-line-clamp: 1;
}

.dialog-body .fp-readable {
  margin-bottom: 4px;
  font-weight: 500;
}

.group-card .card-content {
  padding: 8px 8px 8px;
}

.group-card .card-header .muted {
  font-weight: 400;
}

/* 키 대화상자: 설명 + 양쪽 전체 값 + 목록 차이 */
.detail-key {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.detail-desc {
  margin: 4px 0 14px;
  line-height: 1.6;
}

.detail-value {
  margin: 4px 0 14px;
  padding: 8px 10px;
  border: 1px solid hsl(var(--border));
  border-radius: 6px;
  background: hsl(var(--muted) / 0.5);
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 260px;
  overflow-y: auto;
}

.list-diff span {
  display: block;
}

.list-diff .add {
  color: hsl(var(--success));
}

.list-diff .del {
  color: hsl(var(--destructive));
}

/* 따라오는 리모컨: 1200px 기둥 오른쪽 바깥 아래 (바깥 여백이 좁으면 화면 오른쪽 끝) */
.remote {
  position: fixed;
  bottom: 24px;
  left: min(calc(50% + 600px + 12px), calc(100% - 108px));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 96px;
  padding: 4px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 2px);
  background: hsl(var(--background) / 0.95);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.08);
}

.remote button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  height: 28px;
  padding: 0 8px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* B가 있을 때 분류 옆 다름 수 (0이면 흐리게) */
.remote-count {
  flex: none;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}

.remote-count.diff {
  color: hsl(var(--warning));
  font-weight: 600;
  opacity: 1;
}

.remote button:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.remote button.active {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  font-weight: 600;
}

.remote button.top {
  margin-top: 2px;
  border-top: 1px solid hsl(var(--border));
  border-radius: 0 0 calc(var(--radius) - 2px) calc(var(--radius) - 2px);
}

/* 6. 기록 화면 (records.js): 위 A·B 두 칸(검사 화면 카드와 같은 틀) + 비교 버튼, 아래 기록 표 */
.slot-gap {
  flex: 1;
}

.summary-row .records-actions {
  margin-left: auto;
}

.records-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.records-search {
  width: 280px;
}

.records {
  table-layout: fixed;
  font-size: 13px;
}

.records td {
  padding: 6px 10px;
  vertical-align: middle;
}

.records th {
  padding: 8px 10px;
}

.records col.num {
  width: 64px;
}

.records col.group {
  width: 64px;
}

.records col.time {
  width: 160px;
}

.records col.ua {
  width: 210px;
}

.records col.addr {
  width: 130px;
}

.records col.fp {
  width: 200px;
}

.records col.slots {
  width: 92px;
}

.records col.actions {
  width: 64px;
}

.records td.num {
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}

.flag-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.slot-pair {
  display: flex;
  gap: 4px;
}

.records .slot-btn {
  flex: none;
  width: 34px;
  padding: 0;
}

.records td.actions {
  text-align: right;
}

/* 고른 줄: A·B 칸에 들어간 기록 */
.records tr.picked-a td,
.records tr.picked-b td {
  background: hsl(var(--muted) / 0.6);
}

.records td.empty {
  text-align: center;
  padding: 24px;
}

/* 좁은 화면(모바일): 검사·기록 화면 대신 안내만 (util.js NARROW). 여백 16px */
.narrow-note {
  display: grid;
  gap: 6px;
  text-align: center;
}

@media (max-width: 1199px) {
  .container {
    padding-inline: 16px;
  }
}
