* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, Arial, sans-serif; background: #0f1115; color: #e6e6e6; }
header { display: flex; align-items: baseline; gap: 16px; padding: 12px 20px; background: #171a21; border-bottom: 1px solid #262b36; }
header h1 { font-size: 18px; margin: 0; }
.muted { color: #8a93a3; font-size: 13px; }
main { display: grid; grid-template-columns: minmax(360px, 42%) 1fr; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
h2 { font-size: 15px; margin: 0 0 10px; color: #c7cedb; }

.live img { width: 100%; background: #000; border-radius: 8px; border: 1px solid #262b36; min-height: 200px; }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bar input, .bar select { background: #1b1f27; color: #e6e6e6; border: 1px solid #2c323d; border-radius: 6px; padding: 6px 10px; }
.btn { background: #1b1f27; color: #e6e6e6; border: 1px solid #2c323d; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: #3d8bfd; }
.btn:disabled { opacity: .4; cursor: default; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }

/* Date picker (calendar popup tự viết) */
.datepick { position: relative; display: inline-block; }
.cal { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; width: 260px;
  background: #171a21; border: 1px solid #2c323d; border-radius: 10px; padding: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.cal.hidden { display: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 13px; font-weight: 600; color: #c7cedb; }
.cal-nav { background: #1b1f27; color: #e6e6e6; border: 1px solid #2c323d; border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-size: 16px; line-height: 1; }
.cal-nav:hover { border-color: #3d8bfd; }
.cal-wd, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd span { text-align: center; font-size: 11px; color: #8a93a3; padding: 2px 0; }
.cd { text-align: center; font-size: 13px; padding: 6px 0; border-radius: 6px; cursor: pointer;
  color: #e6e6e6; user-select: none; }
.cd:hover:not(.empty) { background: #2a3140; }
.cd.empty { cursor: default; }
.cd.today { outline: 1px solid #5a6473; }
.cd.sel { background: #3d8bfd; color: #fff; font-weight: 600; }
.cal-foot { display: flex; gap: 8px; margin-top: 8px; }
.cal-foot .btn { flex: 1; font-size: 12px; padding: 5px 8px; }

/* Thống kê tổng quan (đầu trang) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
  padding: 14px 16px 0; }
.stat { background: #171a21; border: 1px solid #262b36; border-radius: 10px; padding: 12px 14px; }
.stat-val { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: #8a93a3; margin-top: 4px; }
.stat-sub { font-size: 11px; margin-top: 2px; }

/* Phân trang */
.pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; justify-content: center; }

/* Panel "Đang xử lý" dưới video */
.live-proc { background: #171a21; border: 1px solid #262b36; border-radius: 8px; padding: 10px 12px; }
.proc-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.proc-imgs { display: flex; flex-wrap: wrap; gap: 10px; }
figure.proc { margin: 0; width: 130px; }
figure.proc img { width: 130px; height: 96px; object-fit: contain; background: #0b0d11;
  border: 1px solid #2c323d; border-radius: 6px; display: block; }
figure.proc figcaption { font-size: 11px; color: #8a93a3; text-align: center; margin-top: 3px; }

.card { background: #171a21; border: 1px solid #262b36; border-radius: 8px; overflow: hidden; cursor: pointer; transition: border-color .15s; }
.card:hover { border-color: #3d8bfd; }
.thumb { height: 110px; background: #0b0d11; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 110px; object-fit: cover; }
.noimg { color: #555; font-size: 12px; }
.info { padding: 8px 10px; }
.plate { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.info .row { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-top: 4px; }
.badge { color: #fff; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-box { background: #141821; border: 1px solid #2c323d; border-radius: 10px; max-width: 1280px; width: 100%; max-height: 90vh; overflow: auto; padding: 18px; position: relative; }
/* Chi tiết: media bên TRÁI, thông tin text bên PHẢI */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: 18px; align-items: start; }
.detail-info table { margin: 0; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }
.close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: #aaa; font-size: 26px; cursor: pointer; }
.modal-box h3 { margin: 0 0 12px; display: flex; gap: 10px; align-items: center; }
/* Gallery chi tiết: viewer lớn ở trên + dải thumbnail ở dưới */
.viewer { background: #000; border: 1px solid #2c323d; border-radius: 8px; min-height: 220px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; }
.viewer img, .viewer video { width: 100%; max-height: 55vh; object-fit: contain; background: #000; display: block; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.thumb { position: relative; width: 96px; height: 70px; border-radius: 6px; overflow: hidden;
  border: 2px solid #2c323d; cursor: pointer; background: #0b0d11; }
.thumb:hover { border-color: #5a6473; }
.thumb.active { border-color: #3d8bfd; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .vthumb { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #fff; background: #1b2330; }
.thumb .tlabel { position: absolute; left: 0; bottom: 0; right: 0; font-size: 10px; padding: 1px 4px;
  background: rgba(0,0,0,.6); color: #cfd6e2; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #232833; vertical-align: top; }
th { color: #8a93a3; width: 130px; font-weight: 600; }

/* Panel phân tích lại video */
.ra-section { margin-top: 16px; border-top: 1px solid #262b36; padding-top: 14px; }
.ra-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.ra-btn-start { background: #1b2a3e; border-color: #3d8bfd; color: #3d8bfd; font-weight: 600; }
.ra-btn-start:hover:not(:disabled) { background: #223450; }
.ra-result { margin-top: 4px; }
.ra-result.hidden { display: none; }

/* Grid danh sách candidate */
.ra-cand-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; max-height: 340px;
  overflow-y: auto; padding: 2px; }
.ra-cand { display: flex; flex-direction: column; width: 110px; border: 2px solid #2c323d;
  border-radius: 8px; overflow: hidden; cursor: pointer; background: #0f1420;
  transition: border-color .15s; }
.ra-cand:hover { border-color: #5a6473; }
.ra-cand-sel { border-color: #3d8bfd !important; background: #131d2e; }
.ra-cand-img { height: 56px; background: #0b0d11; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ra-cand-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ra-noimg { font-size: 10px; color: #555; }
.ra-cand-body { padding: 5px 6px; }
.ra-cand-plate { font-weight: 700; font-size: 13px; letter-spacing: .4px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.ra-cand-meta { display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 12px; }
.ra-badge { font-size: 10px; padding: 1px 5px; border-radius: 8px; font-weight: 600; }
.ra-badge-valid   { background: #1a3d27; color: #2ecc71; }
.ra-badge-invalid { background: #3d1a1a; color: #e74c3c; }
.ra-cand-raw { font-size: 10px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 14px; }
.ra-ocr-btn { width: 100%; border: none; border-top: 1px solid #2c323d; background: #1a1f2a;
  color: #8a93a3; font-size: 11px; padding: 4px 0; cursor: pointer; transition: background .15s, color .15s; }
.ra-ocr-btn:hover:not(:disabled) { background: #1e3450; color: #3d8bfd; }
.ra-ocr-btn:disabled { opacity: .5; cursor: default; }

/* Row nút Cập nhật */
.ra-apply-row { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.ra-btn-apply { background: #1b2a1e; border-color: #27ae60; color: #27ae60; font-weight: 600; white-space: nowrap; }
.ra-btn-apply:hover:not(:disabled) { background: #1e3424; }
.ra-btn-apply:disabled { opacity: .4; }
.ra-no-video { margin-top: 16px; border-top: 1px solid #262b36; padding-top: 12px; font-size: 12px; }
