:root {
  --bg: #0f1115;
  --card: #171a21;
  --card2: #1e222b;
  --line: #2a2f3a;
  --fg: #e6e9ef;
  --dim: #98a1b3;
  --accent: #5b9dff;
  --ok: #2ecc71;
  --warn: #f5a623;
  --bad: #ff5f56;
  --cat: #c084fc;
  --dog: #38bdf8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 system-ui, "Noto Sans KR", "Malgun Gothic", sans-serif;
}

code, pre, kbd { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; }
code { background: #0b0d11; padding: 1px 5px; border-radius: 4px; font-size: .88em; color: #cbd5e1; }
kbd {
  background: #0b0d11; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-size: .8em; color: var(--dim);
}

header {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: 12px; padding: 14px 22px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; }
h1 { margin: 0; font-size: 19px; letter-spacing: .5px; }
.sub { margin: 0; font-size: 12px; color: var(--dim); }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--card2); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: var(--dim); white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: #245c3c; }
.pill.bad { color: var(--bad); border-color: #5c2424; }

.tabs { display: flex; gap: 4px; padding: 10px 22px 0; border-bottom: 1px solid var(--line); background: var(--card); }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--dim); padding: 9px 16px; cursor: pointer; font-size: 14px; border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--fg); background: #ffffff08; }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }
.badge {
  background: var(--warn); color: #1a1200; border-radius: 999px;
  padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: 4px;
}

main { padding: 20px 22px 60px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 8px; font-size: 16px; }
.hint { color: var(--dim); font-size: 12.5px; margin: 0 0 12px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.filters { gap: 8px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }

button {
  background: var(--accent); color: #06131f; border: 0; border-radius: 8px;
  padding: 8px 15px; cursor: pointer; font-size: 13px; font-weight: 600;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary-big { padding: 11px 20px; font-size: 14px; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--dim); font-weight: 500; }
button.ghost:hover { color: var(--fg); border-color: var(--dim); }

input[type=text], input[type=number], select {
  background: var(--card2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 7px 10px; font-size: 13px;
}
input[type=text] { min-width: 200px; }
input[type=number] { width: 90px; }
label { color: var(--dim); font-size: 13px; display: flex; gap: 6px; align-items: center; }

.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 34px;
  text-align: center; cursor: pointer; transition: .15s; background: #ffffff04;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #5b9dff12; }
.drop-icon { font-size: 30px; color: var(--accent); }
.drop-inner { display: grid; gap: 6px; }

.summary {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.summary .box {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; min-width: 110px;
}
.summary .n { font-size: 22px; font-weight: 700; }
.summary .k { font-size: 12px; color: var(--dim); }

.alerts { margin-bottom: 14px; }
.alerts .a {
  background: #3a2a08; border: 1px solid #6b4d0d; color: #ffce6b;
  border-radius: 8px; padding: 9px 14px; margin-bottom: 6px; font-size: 13px;
}

.grid { display: grid; gap: 12px; }
.results { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.thumbs { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.rescard {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.rescard img { width: 100%; height: 175px; object-fit: cover; display: block; background: #000; }
.rescard .body { padding: 10px 12px 12px; }
.rescard .fn { font-size: 11.5px; color: var(--dim); word-break: break-all; margin-bottom: 6px; }
.state {
  display: inline-block; border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 700;
}
.state.확정 { background: #123726; color: #4ade80; }
.state.보류 { background: #3a2a08; color: #ffce6b; }
.state.미지 { background: #3a1414; color: #ff8b84; }
.verdict { font-size: 17px; font-weight: 700; margin: 6px 0 8px; }
.bar { height: 7px; background: #0b0d11; border-radius: 4px; overflow: hidden; margin: 3px 0 8px; }
.bar > i { display: block; height: 100%; }
.bar.cat > i { background: var(--cat); }
.bar.dog > i { background: var(--dog); }
.plabel { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--dim); }
.meta { font-size: 11.5px; color: var(--dim); margin-top: 6px; }
.err { color: var(--bad); font-size: 12.5px; padding: 12px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; min-width: 130px;
}
.stat .k { font-size: 11.5px; color: var(--dim); }
.stat .v { font-size: 18px; font-weight: 700; }
.stat .d { font-size: 11.5px; color: var(--dim); margin-top: 2px; }

.thumb {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; position: relative;
}
.thumb img { width: 100%; height: 120px; object-fit: cover; display: block; background: #000; cursor: zoom-in; }
.thumb .t-body { padding: 7px 8px; }
.thumb .t-name { font-size: 10.5px; color: var(--dim); word-break: break-all; height: 26px; overflow: hidden; }
.thumb .t-row { display: flex; gap: 4px; margin-top: 5px; }
.thumb .t-row button { padding: 3px 8px; font-size: 11px; flex: 1; }
.tag {
  position: absolute; top: 6px; left: 6px; font-size: 10.5px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; background: #000a; backdrop-filter: blur(3px);
}
.tag.cat { color: var(--cat); }
.tag.dog { color: var(--dog); }
.tag.split { left: auto; right: 6px; color: var(--dim); }

.pager { justify-content: center; margin-top: 14px; }
.pager button { min-width: 38px; }
.pager .cur { background: var(--card2); border: 1px solid var(--accent); color: var(--fg); }

.labeler { min-height: 200px; }
.labeler-body { display: grid; grid-template-columns: 1fr 300px; gap: 20px; }
.labeler-img { background: #000; border-radius: 10px; display: flex; align-items: center; justify-content: center; min-height: 380px; }
.labeler-img img { max-width: 100%; max-height: 460px; object-fit: contain; }
.labeler-side { display: flex; flex-direction: column; gap: 12px; }
.labeler-empty { text-align: center; color: var(--dim); padding: 40px; }
.lab-meta { background: var(--card2); border-radius: 8px; padding: 12px; font-size: 12.5px; color: var(--dim); }
.lab-meta b { color: var(--fg); }
.lab-buttons { display: grid; gap: 8px; }
button.big { padding: 14px; font-size: 15px; text-align: left; }
button.big.cat { background: var(--cat); color: #1a0b2e; }
button.big.dog { background: var(--dog); color: #04202e; }
button.big.neither { background: var(--card2); color: var(--fg); border: 1px solid var(--line); }
/* '둘 다 있음' — 클래스가 아니라 판정 불가 표시라 다른 색으로 구분한다 */
button.big.both {
  background: transparent; color: var(--warn);
  border: 1px dashed var(--warn); font-size: 14px; padding: 11px 14px;
}
button.big.both:hover { background: #f5a62318; }

.labeled-list { display: grid; gap: 4px; max-height: 260px; overflow: auto; font-size: 12px; }
.labeled-list .li { display: flex; gap: 12px; padding: 5px 8px; background: var(--card2); border-radius: 6px; }
.labeled-list .li span:first-child { color: var(--dim); }

/* 임계값 표시 (읽기 전용) */
.thv {
  background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; color: var(--dim);
}
.thv b { color: var(--fg); font-size: 15px; margin-left: 6px;
  font-family: ui-monospace, Menlo, monospace; }

.log, .yaml {
  background: #0b0d11; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-size: 11.5px; color: #cbd5e1; max-height: 320px; overflow: auto;
  white-space: pre-wrap; word-break: break-all; margin: 10px 0 0;
}

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--dim); font-weight: 600; font-size: 11.5px; }

/* ───────────────────────────────── 박스 그리기 모달 */
.modal {
  position: fixed; inset: 0; background: #000b; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 1150px; max-height: 92vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal-head b { font-size: 15px; }
.modal-head .hint { margin: 0 0 0 10px; display: inline; }
.modal-body {
  display: grid; grid-template-columns: 1fr 300px; gap: 18px;
  padding: 18px 20px; overflow: auto;
}
.boxed-canvas {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  align-self: start; cursor: crosshair; user-select: none;
}
.boxed-canvas img { width: 100%; display: block; pointer-events: none; }
.boxed-canvas .bx {
  position: absolute; border: 3px solid; border-radius: 2px;
}
.boxed-canvas .bx.cat { border-color: var(--cat); background: #c084fc22; }
.boxed-canvas .bx.dog { border-color: var(--dog); background: #38bdf822; }
.boxed-canvas .bx.draft { border-style: dashed; }
.boxed-canvas .bx b {
  position: absolute; top: 0; left: 0; transform: translateY(-100%);
  font-size: 12px; padding: 2px 8px; border-radius: 3px 3px 0 0;
  line-height: 1.5; white-space: nowrap;
}
/* 위·오른쪽 끝에 붙은 박스의 라벨이 캔버스 밖으로 잘리지 않게 안쪽으로 넣는다 */
.boxed-canvas .bx.at-top b { transform: none; border-radius: 0 0 3px 0; }
.boxed-canvas .bx.at-right b { left: auto; right: 0; border-radius: 3px 3px 0 0; }
.boxed-canvas .bx.at-top.at-right b { border-radius: 0 0 0 3px; }
.boxed-canvas .bx.cat b { background: var(--cat); color: #1a0b2e; }
.boxed-canvas .bx.dog b { background: var(--dog); color: #04202e; }

.boxed-side { display: flex; flex-direction: column; gap: 10px; }
.boxed-labels { display: grid; gap: 8px; }
.boxed-labels .mode-opt { min-width: 0; }
.boxed-labels .mode-card { padding: 10px 14px; }
.boxed-labels .mode-text b { font-size: 14px; margin: 0; }
.boxed-list { display: grid; gap: 5px; max-height: 200px; overflow: auto; }
.boxed-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--card2); border-radius: 7px; padding: 6px 10px; font-size: 12px;
}
.boxed-item .sw { width: 10px; height: 10px; border-radius: 2px; }
.boxed-item button { padding: 2px 8px; font-size: 11px; }

.sep { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.boxed-verdict b { font-size: 13.5px; }
.boxed-verdict .fix-row { flex-wrap: wrap; }
.boxed-verdict .fix-row button { flex: 1 1 45%; padding: 8px 6px; font-size: 12.5px; }
.boxed-verdict .fix-row button.done { background: var(--ok); color: #04210f; }

/* 결과 카드 삭제 버튼 */
.rescard { position: relative; }
.card-del {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 26px; height: 26px; padding: 0; border-radius: 50%;
  background: #000a; color: #fff; border: 1px solid #fff3;
  font-size: 14px; line-height: 1; backdrop-filter: blur(3px);
}
.card-del:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

@media (max-width: 900px) {
  .modal-body { grid-template-columns: 1fr; }
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 20px; font-size: 13px; z-index: 100; box-shadow: 0 8px 30px #0008;
}
.toast.bad { border-color: var(--bad); color: #ff8b84; }
.hidden { display: none !important; }

/* ───────────────────────────────── 로그인 화면 */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 34px 32px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px #0006;
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .logo { font-size: 40px; display: block; margin-bottom: 8px; }
.login-brand h1 { font-size: 24px; margin: 0 0 4px; }
.login-box .field { display: block; margin-bottom: 14px; }
.login-box .field span {
  display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 5px;
}
.login-box input {
  width: 100%; background: var(--card2); border: 1px solid var(--line);
  color: var(--fg); border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }
.login-error {
  background: #3a1414; border: 1px solid #6b2020; color: #ff8b84;
  border-radius: 8px; padding: 9px 12px; font-size: 12.5px; margin-top: 12px;
}
.login-note {
  color: var(--dim); font-size: 11.5px; text-align: center;
  margin: 22px 0 0; line-height: 1.6;
}

/* ───────────────────────────────── 판정 방식 선택
   "체크하는 건 줄 몰랐다" 는 피드백을 받아, 작은 라디오 대신
   큰 카드 + 눈에 보이는 동그란 체크 표식으로 바꿨다. */
.mode-title {
  font-size: 13px; color: var(--fg); font-weight: 600;
  margin: 16px 0 8px;
}
.mode-switch { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.mode-opt { flex: 1; min-width: 230px; cursor: pointer; display: block; }
.mode-opt input { position: absolute; opacity: 0; pointer-events: none; }

.mode-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 16px 18px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card2);
  transition: .15s; height: 100%;
}
/* 눈에 보이는 체크 표식 — 라디오처럼 생겼지만 훨씬 크다 */
.mode-mark {
  flex: 0 0 auto; width: 22px; height: 22px; margin-top: 2px;
  border: 2px solid var(--dim); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.mode-mark::after {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: transparent; transition: .15s;
}
.mode-text b {
  display: block; font-size: 16px; color: var(--fg); font-weight: 700;
  margin-bottom: 4px;
}
.mode-text b em {
  font-style: normal; font-size: 11px; font-weight: 700; vertical-align: middle;
  background: var(--accent); color: #06131f; border-radius: 999px;
  padding: 1px 8px; margin-left: 6px;
}
.mode-text small { display: block; font-size: 12.5px; color: var(--dim); line-height: 1.55; }

.mode-opt:hover .mode-card { border-color: var(--dim); background: #ffffff08; }
.mode-opt input:checked + .mode-card {
  border-color: var(--accent); background: #5b9dff1f;
}
.mode-opt input:checked + .mode-card .mode-mark { border-color: var(--accent); }
.mode-opt input:checked + .mode-card .mode-mark::after { background: var(--accent); }
.mode-opt input:focus-visible + .mode-card { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 자동 모드 카드 — 두 결과를 다 심어두고 한쪽만 보여준다 (넘겨보기가 즉시 되도록) */
.rescard[data-show="detect"] .pane-classify,
.rescard[data-show="classify"] .pane-detect { display: none; }

/* 자동 모드에서 "왜 이 방식을 골랐는지" 를 카드에 표시 */
.why {
  font-size: 11.5px; color: var(--dim); background: #ffffff08;
  border-left: 2px solid var(--accent); padding: 5px 9px;
  border-radius: 0 5px 5px 0; margin: 7px 0;
}
.why.warn {
  border-left-color: var(--warn); background: #f5a62314; color: #ffce6b;
}
.flip { margin-top: 8px; }
.flip button { width: 100%; padding: 6px; font-size: 11.5px; }

/* ───────────────────────────────── 검출 결과 (이미지 위 박스) */
.det-wrap { position: relative; line-height: 0; background: #000; }
.det-wrap img { width: 100%; height: auto; display: block; }
.det-box {
  position: absolute; border: 3px solid; border-radius: 3px;
  box-shadow: 0 0 0 1px #0008 inset;
}
.det-box.cat { border-color: var(--cat); }
.det-box.dog { border-color: var(--dog); }
.det-tag {
  position: absolute; top: -1px; left: -3px; transform: translateY(-100%);
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 3px 3px 0 0;
  line-height: 1.5; white-space: nowrap;
}
/* 박스가 이미지 맨 위에 붙으면 라벨이 위로 나가 잘린다 → 박스 안쪽으로 내린다 */
.det-box.at-top .det-tag { transform: none; top: 0; left: 0; border-radius: 0 0 3px 0; }
/* 오른쪽 끝에 붙으면 라벨이 오른쪽으로 넘친다 → 오른쪽 정렬로 붙인다 */
.det-box.at-right .det-tag { left: auto; right: -3px; border-radius: 3px 3px 0 0; }
.det-box.at-top.at-right .det-tag { right: 0; border-radius: 0 0 0 3px; }
.det-tag.cat { background: var(--cat); color: #1a0b2e; }
.det-tag.dog { background: var(--dog); color: #04202e; }
.results { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

/* 추론 결과 카드에서 바로 라벨을 확정하는 버튼들 */
.fix-row { display: flex; gap: 4px; margin-top: 9px; }
.fix-row button { flex: 1; padding: 5px 4px; font-size: 11.5px; }
.fix-row button.done { background: var(--ok); color: #04210f; }
.fix-note { font-size: 11px; color: var(--dim); margin-top: 6px; }

@media (max-width: 800px) {
  .labeler-body { grid-template-columns: 1fr; }
}
