:root {
  --bg: #f1efea;
  --surface: #f8f7f4;
  --surface-strong: #e6e2dc;
  --border: #d8d3ca;
  --ink: #1c2532;
  --muted: #56585d;
  --nav: #b2d9db;
  --blue: #0b2f70;
  --accent: #cfa07a;
  --green: #2b855a;
  --red: #ba3d47;
  --red-bg: #fff3f3;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-family: "Segoe UI", "Microsoft YaHei UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { min-width: 320px; }
button, input, select { font: inherit; letter-spacing: 0; }
button {
  height: 38px;
  padding: 0 14px;
  border: 2px solid var(--blue);
  border-radius: 4px;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
button:hover { color: #fff; background: var(--blue); }
button:disabled { opacity: .55; cursor: wait; }
button.primary { color: white; border-color: var(--blue); background: var(--blue); }
button.primary:hover { color: white; background: #061f4c; }
button.danger { color: var(--red); border-color: #ebc8ca; background: var(--red-bg); }
button.danger:hover { color: #fff; border-color: var(--red); background: var(--red); }
button.quiet { color: var(--muted); }
button.wide { width: 100%; }
input, select {
  height: 38px;
  min-width: 0;
  padding: 0 11px;
  border: 0;
  border-bottom: 2px solid var(--blue);
  border-radius: 0;
  background: transparent;
  color: var(--blue);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid rgba(11, 47, 112, .25); outline-offset: 1px; }
h1, h2, p { margin: 0; letter-spacing: 0; }
h2 { font-size: 17px; font-weight: 600; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}
.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-panel h1 { font-size: 24px; margin-bottom: 8px; }
.login-panel label { font-size: 13px; color: var(--muted); }
.language-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.language-control.inline {
  grid-template-columns: auto minmax(112px, 140px);
  align-items: center;
  gap: 8px;
}
.login-error { height: 20px; color: var(--red); font-size: 13px; }
.brand-logo {
  display: block;
  width: 78px;
  height: 58px;
  object-fit: contain;
}
.brand-logo.compact {
  width: 72px;
  height: 54px;
}
.login-logo { margin: 0 auto 6px 0; }
.login-subtitle { color: var(--muted); font-size: 13px; }

.console { min-height: 100vh; }
.topbar {
  min-height: 84px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(16px, 3vw, 32px);
  border-bottom: 1px solid rgba(86, 88, 93, .18);
  background: var(--nav);
}
.identity { display: flex; align-items: center; gap: 13px; }
.identity h1 { font-size: 19px; font-weight: 800; color: var(--muted); }
.identity p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.device-tools { display: flex; gap: 8px; align-items: center; }
.device-tools label { font-size: 13px; color: var(--muted); }
.device-tools input { width: 264px; }
.statusbar {
  min-height: 52px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 7px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.pill {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #adb8b6; }
.pill.up i { background: var(--green); }
.pill.up { color: var(--green); }
.pill.down i { background: var(--red); }
.pill.down { color: var(--red); }
.status-detail { font-size: 13px; color: var(--muted); }
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 58px;
  padding: 8px clamp(16px, 3vw, 32px) 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tabs button {
  height: 50px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
}
.tabs button:hover { color: var(--blue); background: transparent; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 800; }
.view { display: none; padding: 22px clamp(16px, 3vw, 32px) 32px; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metrics article {
  height: 106px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metrics span { display: block; margin-bottom: 9px; font-size: 13px; color: var(--muted); }
.metrics strong { font-size: 34px; font-weight: 800; color: var(--blue); }
.metrics small { margin-left: 6px; color: var(--muted); }
.overview-grid, .records-grid {
  display: grid;
  grid-template-columns: 1fr 1.28fr;
  gap: 16px;
}
.surface {
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.surface-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.surface-head span { color: var(--muted); font-size: 13px; }
.summary-list { display: grid; gap: 0; margin: 0; }
.summary-list div {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #ecf0ef;
  font-size: 14px;
}
.summary-list dt { color: var(--muted); }
.summary-list dd { margin: 0; font-weight: 500; }
.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 10px;
}
.preview-grid img, .gallery img {
  display: block;
  width: 100%;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ecf0ef;
}
.clickable-image {
  cursor: zoom-in;
}
.clickable-image:focus {
  outline: 3px solid #ff6f61;
  outline-offset: 3px;
}
.preview-grid img { aspect-ratio: 4 / 3; }
.section-toolbar {
  min-height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 18px;
}
.section-toolbar div { display: flex; gap: 8px; }
.valve-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(182px, 1fr));
  gap: 12px;
}
.valve {
  min-height: 125px;
  display: grid;
  gap: 13px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.valve header { display: flex; align-items: center; justify-content: space-between; }
.valve header strong { font-size: 15px; }
.state {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.state.open { color: var(--green); }
.valve footer { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.valve footer button { padding: 0 8px; }
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.workflow {
  min-height: 98px;
  padding: 15px;
  display: grid;
  gap: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.workflow strong { font-size: 15px; }
.workflow span { color: var(--muted); font-size: 13px; }
.dht-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.dht-panel p { margin-top: 8px; font-size: 13px; color: var(--muted); }
.inline-actions { display: flex; gap: 8px; }
.camera-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
  margin-bottom: 26px;
}
.batch-form {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.batch-form label { font-size: 13px; color: var(--muted); }
.batch-form input { width: 72px; }
.gallery-head {
  display: flex;
  gap: 16px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.gallery-head span { font-size: 13px; color: var(--muted); }
.gallery-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  gap: 13px;
}
.gallery figure { margin: 0; }
.gallery .gallery-item {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.gallery img {
  aspect-ratio: 4 / 3;
  user-drag: none;
  -webkit-user-drag: none;
  pointer-events: auto;
}
.gallery figcaption {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

/* Enlarge button overlay for gallery items */
.gallery-enlarge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(11,47,112,0.12);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.gallery-enlarge:active { transform: scale(0.98); }
.gallery-enlarge svg {
  width: 16px;
  height: 16px;
  color: #0b2f70; /* icon color */
}
.gallery-enlarge {
  padding: 4px; /* give breathing room around the icon */
}

/* Make selection highly visible on mobile: outline + shadow - apply to container for browser compatibility */
.gallery-item.selected,
.analysis-image.selected {
  outline: 3px solid #ff6f61;
  outline-offset: 3px;
  -webkit-outline-offset: 3px;
  box-shadow: 0 6px 18px rgba(255,111,97,0.18);
  z-index: 2;
  border-radius: 6px;
}
.gallery-item.selected img,
.analysis-image.selected img {
  /* keep image itself free of outline so the container outline is visible */
  outline: none;
}
.gallery-pagination {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}
.gallery-pagination span {
  min-width: 96px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.gallery-pagination button {
  min-width: 82px;
}
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 31, 45, .72);
}
.image-lightbox-panel {
  width: min(1120px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}
.lightbox-close {
  justify-self: end;
  background: #fff;
}
.image-lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 145px);
  justify-self: center;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}
.lightbox-caption {
  justify-self: center;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  color: #fff;
  background: rgba(14, 31, 45, .72);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.chart-panel canvas {
  width: 100%;
  height: 260px;
  display: block;
}
.table-wrap { max-height: 330px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  position: sticky;
  top: 0;
  padding: 10px 8px;
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 8px; border-bottom: 1px solid #edf1f0; vertical-align: top; }
td:last-child { word-break: break-word; }
.log-panel { margin-top: 16px; }
.console-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px clamp(16px, 3vw, 32px) 10px;
  background: var(--bg);
}
.console-hero h2 {
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
}
.console-hero p { color: var(--muted); }
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.platform-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.platform-facts span {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.section-note {
  color: var(--muted);
  font-size: 13px;
}
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .75fr);
  gap: 16px;
}
.analysis-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
  gap: 13px;
}
.analysis-image {
  height: auto;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.analysis-image:hover {
  color: var(--blue);
  background: transparent;
}
.analysis-image img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.analysis-image span {
  display: block;
  margin-top: 7px;
  font-size: 12px;
}
/* unified selection rules applied above */
.analysis-lang {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.result-grid article {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.result-grid strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
}
.analysis-report {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.analysis-report p {
  line-height: 1.9;
  color: var(--ink);
  font-size: 14px;
}
.analysis-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.analysis-summary article {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.analysis-summary span,
.analysis-detections-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.analysis-summary strong {
  display: block;
  margin-top: 7px;
  color: var(--ink);
  font-size: 18px;
}
.analysis-detections {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.analysis-detections-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.analysis-detections-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
}
.analysis-detection-list {
  display: grid;
  gap: 12px;
}
.analysis-detection-card {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.analysis-detection-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.analysis-detection-card > div {
  min-width: 0;
  overflow-x: auto;
}
.analysis-detection-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.analysis-detection-card header strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
}
.analysis-detection-card header span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}
.analysis-detection-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.analysis-detection-card th,
.analysis-detection-card td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.analysis-detection-card th {
  color: var(--muted);
  font-weight: 700;
}
.analysis-detection-card td {
  color: var(--ink);
}
.analysis-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 16px;
  border-radius: 6px;
  color: white;
  background: var(--blue);
  box-shadow: 0 5px 18px rgba(0, 0, 0, .18);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); }

@media (max-width: 880px) {
  .topbar { height: auto; flex-direction: column; align-items: stretch; padding-top: 12px; padding-bottom: 12px; }
  .device-tools { flex-wrap: wrap; }
  .device-tools input { flex: 1; width: 100px; }
  .console-hero { flex-direction: column; }
  .platform-facts { justify-content: flex-start; }
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .overview-grid, .records-grid { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .tabs { overflow-x: auto; }
  .statusbar { flex-wrap: wrap; }
  .brand-logo.compact { width: 58px; height: 44px; }
  .console-hero h2 { font-size: 24px; }
  .metrics { gap: 10px; }
  .metrics article { height: 94px; padding: 13px; }
  .metrics strong { font-size: 28px; }
  .section-toolbar, .dht-panel { flex-direction: column; align-items: stretch; }
  .camera-controls { align-items: stretch; }
  .camera-controls > button { flex: 1 1 calc(50% - 9px); }
  .batch-form { width: 100%; padding: 10px 0 0; border: 0; border-top: 1px solid var(--border); }
  .analysis-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analysis-detection-card { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: 1fr; }
}
