/* One-Click Cuboid web. Bảng màu lấy từ bản desktop (src/cvat_dialog.py, PANEL_BG, COLOR_NOSE):
   nền than tối, xanh ngọc cho hành động chính / trạng thái đang chọn, cam chỉ cho chỗ cần chú ý. */
:root {
  --bg: #16181d;
  --card: #1f2229;
  --field: #2a2e37;
  --line: #2c3039;
  --accent: #16b8a6;
  --accent-hover: #1fd1bd;
  --accent-soft: rgba(22, 184, 166, 0.14);
  --warn: #ff8c00;
  --warn-soft: rgba(255, 140, 0, 0.12);
  --err: #ff6b6b;
  --fg: #e8e8ea;
  --muted: #8b90a0;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
  font: 11px/1.6 var(--font);
  text-align: center;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- nút dùng chung ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: #3a3f4b; background: #323743; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d1f1d; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent-soft); border-color: var(--accent-hover); color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--field); border-color: transparent; color: var(--fg); }

/* ================= màn hình bắt đầu ================= */
.start {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.start-card {
  width: min(440px, 100%);
  padding: 32px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .2px; }
.brand-mark {
  width: 22px; height: 22px; flex: none;
  border: 2px solid var(--accent);
  border-radius: 5px;
  position: relative;
}
.brand-mark::after {           /* cạnh đầu xe màu cam, như trên BEV */
  content: ""; position: absolute; top: -2px; bottom: -2px; right: -2px; width: 2px;
  background: var(--warn); border-radius: 2px;
}
.start-card h1 { margin: 22px 0 6px; font-size: 22px; font-weight: 600; line-height: 1.3; }
.start-card .lead { margin: 0 0 24px; color: var(--muted); }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.field input:not([type=radio]) {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--field);
}
.field input:focus { outline: none; border-color: var(--accent); }
.sets { display: grid; gap: 8px; }
.set {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.set:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.set input { flex: none; margin: 4px 0 0; accent-color: var(--accent); }
.set b { display: block; font-weight: 600; }
.set small { color: var(--muted); }
.start-card .btn-primary { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; font-size: 15px; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--err); font-size: 13px; }
.how { margin: 26px 0 0; padding: 18px 0 0; border-top: 1px solid var(--line); list-style: none; display: grid; gap: 10px; }
.how li { display: flex; gap: 10px; color: var(--muted); font-size: 13px; }
.how li::before {
  counter-increment: how; content: counter(how);
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--field); color: var(--fg); font-size: 11px;
}
.how { counter-reset: how; }
.note { margin: 18px 0 0; color: var(--muted); font-size: 12px; }

/* ================= màn hình gán ================= */
.workspace {
  height: 100vh;
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  grid-template-rows: 52px minmax(0, 1fr) 62px;
  grid-template-areas: "top top" "side stage" "tools tools";
}

/* thanh trên */
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar .info { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .info b { color: var(--fg); font-weight: 600; }
.topbar .info .todo { color: var(--warn); }
.topbar .actions { display: flex; gap: 8px; }

/* cột loại vật */
.side {
  grid-area: side;
  display: flex; flex-direction: column;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.side h2 { margin: 0 8px 8px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; }
.cls {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 7px 10px;
  border: 0; border-left: 3px solid transparent;
  border-radius: 0 6px 6px 0;
  background: transparent;
  text-align: left;
}
.cls:hover { background: var(--field); }
.cls.active { border-left-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }
.cls.active kbd { border-color: rgba(22, 184, 166, .4); color: var(--accent-hover); }
.side .credit { margin-top: auto; padding: 14px 8px 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

/* vùng ảnh */
.stage {
  grid-area: stage;
  position: relative;
  display: grid; place-items: center;
  padding: 8px;
  overflow: hidden;
}
#view {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
  background: #000;
}
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(22, 24, 29, .82);
  z-index: 5;
}
.overlay .box { text-align: center; color: var(--muted); }
.overlay .box p { margin: 0 0 14px; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 3px solid var(--field); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* thanh công cụ dưới */
.tools {
  grid-area: tools;
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, .18);
  overflow-x: auto;
}
.tools .sep { width: 1px; height: 28px; margin: 0 6px; background: var(--line); flex: none; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-size: 13px;
  white-space: nowrap;
  flex: none;
}
.tool svg { width: 18px; height: 18px; flex: none; }
.tool:hover { background: var(--field); }
.tool.warn { border-color: rgba(255, 140, 0, .55); color: #ffb35c; }
.tool.warn:hover { background: var(--warn-soft); }
.tool.primary { background: var(--accent); color: #0d1f1d; font-weight: 600; }
.tool.primary:hover { background: var(--accent-hover); }
.tool.on { color: var(--accent-hover); }
.tool.dim { opacity: .42; }
.tool.dim:hover { background: transparent; }
.tools .spacer { flex: 1; min-width: 8px; }
@media (max-width: 1480px) { .tool .opt { display: none; } }

/* thẻ nổi: chấm điểm, hướng dẫn */
.drawer {
  position: absolute; top: 16px; right: 16px; bottom: 16px;
  width: min(360px, calc(100% - 32px));
  display: flex; flex-direction: column;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
  z-index: 4;
}
.drawer header, .modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; }
.drawer h3, .modal h3 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer .body { flex: 1; overflow-y: auto; padding: 0 18px 16px; }
.drawer footer { padding: 12px 18px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 16px; }
.stat { padding: 10px; border-radius: var(--radius); background: var(--field); }
.stat b { display: block; font-size: 20px; font-weight: 600; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; }
.pair { padding: 10px 0; border-top: 1px solid var(--line); }
.pair .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.pair .row span { color: var(--muted); }
.bar { height: 6px; margin: 7px 0 5px; border-radius: 3px; background: var(--field); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.bar i.low { background: var(--warn); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--warn-soft); color: #ffb35c; font-size: 11px; }
.empty { color: var(--muted); font-size: 13px; }
.icon-btn { padding: 4px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); line-height: 0; }
.icon-btn:hover { background: var(--field); color: var(--fg); }
.icon-btn svg { width: 18px; height: 18px; }

.backdrop { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(10, 11, 14, .6); z-index: 10; }
.modal { width: min(560px, 100%); max-height: 100%; overflow-y: auto; border-radius: 12px; background: var(--card); box-shadow: 0 16px 50px rgba(0, 0, 0, .5); }
.modal .body { padding: 4px 22px 8px; }
.modal footer { display: flex; align-items: center; gap: 8px; padding: 14px 22px 20px; }
.modal footer .dots { flex: 1; display: flex; gap: 6px; }
.modal footer .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--field); }
.modal footer .dots i.on { background: var(--accent); }
.tabs { display: flex; gap: 4px; padding: 0 18px 8px; }
.tabs button { padding: 6px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.tabs button.on { background: var(--field); color: var(--fg); }
.step-num { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-bottom: 10px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.step h4 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.step p { margin: 0 0 10px; color: #c6c8cf; }
.step .hint { color: var(--muted); font-size: 13px; }
.keys { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.keys td:first-child { width: 38%; color: var(--muted); }
.warn-text { color: #ffb35c; }

/* ---------- nút chuyển BEV / 3D (và nút chọn kiểu đăng nhập) ---------- */
.seg { display: inline-flex; padding: 3px; border-radius: var(--radius); background: var(--field); flex: none; }
.seg button { padding: 5px 14px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 600; }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--accent); color: #0d1f1d; }
.seg-wide { display: flex; }
.seg-wide button { flex: 1; font-weight: 500; }

/* ---------- CVAT trên thanh trên ---------- */
.cvat-ctl { display: inline-flex; gap: 2px; align-items: center; }
#btn-push.pushing { border-color: var(--accent); color: var(--accent-hover); }
#btn-push.ok { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }
#btn-push.fail { border-color: rgba(255, 107, 107, .6); color: var(--err); }
#btn-cvat { padding-left: 8px; padding-right: 10px; max-width: 190px; }
#btn-cvat .opt { overflow: hidden; text-overflow: ellipsis; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--field); color: var(--fg); font-size: 11px; font-weight: 600;
}
.avatar.ready { background: var(--accent-soft); color: var(--accent-hover); box-shadow: inset 0 0 0 1px rgba(22, 184, 166, .5); }
.avatar.demo { box-shadow: inset 0 0 0 1px rgba(255, 140, 0, .55); color: #ffb35c; }
@media (max-width: 1480px) { .topbar .opt { display: none; } }

/* ---------- chế độ 3D: 1 khung lớn + 3 khung chiếu ---------- */
.v3d {
  position: absolute; inset: 8px;
  display: grid; gap: 8px;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 28%, 420px);
  grid-template-rows: repeat(3, minmax(0, 1fr));
}
.pane { position: relative; min-height: 0; overflow: hidden; border-radius: 8px; background: #0f1116; box-shadow: inset 0 0 0 1px var(--line); }
.pane-main { grid-row: 1 / span 3; }
.pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pane canvas.ov { touch-action: none; }
.pane-label {
  position: absolute; top: 8px; left: 10px;
  padding: 2px 8px; border-radius: 6px;
  background: rgba(22, 24, 29, .78); color: var(--fg); font-size: 12px; font-weight: 600;
  pointer-events: none;
}
.pane-label span { color: var(--muted); font-weight: 400; }
.pane-tools { position: absolute; top: 6px; right: 8px; display: flex; gap: 6px; }
.pane-tools .btn { padding: 4px 10px; font-size: 12px; background: rgba(22, 24, 29, .78); }
.pane-empty {
  position: absolute; inset: 0; margin: 0; padding: 36px 16px 16px;
  display: grid; place-items: center; text-align: center;
  color: var(--muted); font-size: 12px; pointer-events: none;
}
.legend3d {
  position: absolute; left: 10px; bottom: 8px;
  padding: 3px 8px; border-radius: 6px; background: rgba(22, 24, 29, .78);
  color: var(--muted); font-size: 11px; pointer-events: none;
}
.legend3d i { display: inline-block; width: 10px; height: 3px; margin: 0 4px 2px 8px; border-radius: 2px; vertical-align: middle; }
.legend3d i.ok { background: #33f24d; }
.legend3d i.float { background: #ff4019; }
.legend3d i.sunk { background: #ffcc1a; }
.cam-thumb {
  position: absolute; right: 10px; bottom: 10px;
  width: min(34%, 340px); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5), 0 0 0 1px var(--line);
  cursor: zoom-in;
}
.cam-thumb.big { width: min(70%, 680px); cursor: zoom-out; }

/* ---------- hộp thoại tài khoản CVAT ---------- */
#cvat .modal { width: min(620px, 100%); }
.cvat-body .field { margin-bottom: 12px; }
.cvat-body select, .cvat-body .field input {
  width: 100%; padding: 8px 10px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--field); color: var(--fg);
}
.cvat-body select:focus, .cvat-body .field input:focus { outline: none; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 110px 110px 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; color: #c6c8cf; font-size: 13px; }
.check input { accent-color: var(--accent); }
.scope-note { margin: 0 0 14px; padding: 9px 12px; border-radius: var(--radius); background: var(--field); color: #c6c8cf; font-size: 13px; }
.scope-note.warn { background: var(--warn-soft); color: #ffb35c; }
.hint-line { margin: -4px 0 8px; color: var(--muted); font-size: 12px; }
.cvat-status { min-height: 20px; margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.cvat-status.ok { color: var(--accent-hover); }
.cvat-status.err { color: var(--err); }
.modal footer .spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%);
  padding: 9px 16px; border-radius: var(--radius);
  background: var(--field); color: var(--fg); font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  z-index: 20;
}
.toast.error { color: var(--err); }
