:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #dce3ef;
  --soft: #eef3fb;
  --strong: #101828;
  --accent: #155eef;
  --ok: #137333;
  --warn: #b45309;
  --bad: #b42318;
  --shadow: 0 16px 45px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Tahoma, Arial, sans-serif;
  background: radial-gradient(circle at top right, #eaf0ff, transparent 34%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 26px clamp(16px, 4vw, 44px) 12px;
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(23px, 4vw, 36px); letter-spacing: -.5px; }
h2 { font-size: 18px; }
.topbar p, .hint, footer, .notice { color: var(--muted); line-height: 1.8; }
.layout {
  display: grid;
  grid-template-columns: minmax(310px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  padding: 16px clamp(16px, 4vw, 44px) 24px;
}
.panel {
  background: rgba(255,255,255,.94);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(10px);
}
.search-panel { grid-column: 1 / -1; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.pill, .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 11px;
  border-radius: 999px;
  background: #e7f7ed;
  color: var(--ok);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}
.badge.muted { background: var(--soft); color: var(--muted); }
.badge.warn { background: #fff7ed; color: var(--warn); }
.badge.bad { background: #fef3f2; color: var(--bad); }
.camera-box {
  position: relative;
  width: 100%;
  background: #101828;
  border-radius: 20px;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border: 1px solid #151f33;
}
video, .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
video {
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
}
body.environment video { transform: none; }
.overlay { pointer-events: none; }
.scan-note {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  color: #fff;
  background: rgba(0,0,0,.58);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  text-align: center;
}
.actions, .upload-row, .search-box {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}
button, .file-label {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--strong);
  border-radius: 13px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s ease;
}
button:hover, .file-label:hover { transform: translateY(-1px); border-color: #b9c4d6; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
input[type="file"] { display: none; }
input[type="text"] {
  flex: 1 1 260px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}
.status {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--soft);
  color: var(--text);
  line-height: 1.7;
  margin: 10px 0 14px;
  border: 1px solid transparent;
}
.status.ok { background: #e7f7ed; color: var(--ok); border-color: #b7e4c7; }
.status.warn { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.status.bad { background: #fef3f2; color: var(--bad); border-color: #fecaca; }
.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.mini-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}
.label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.value { font-size: 16px; font-weight: 800; word-break: break-word; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab { padding: 8px 12px; border-radius: 999px; font-size: 13px; }
.tab.active { background: var(--strong); color: #fff; border-color: var(--strong); }
.tab-content { display: none; margin-top: 12px; }
.tab-content.active { display: block; }
.text-box, .variant pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 16px;
  padding: 14px;
  min-height: 120px;
  direction: rtl;
  text-align: right;
  overflow: auto;
}
.fields-table, .matches-table { width: 100%; border-collapse: collapse; }
.fields-table td, .matches-table td, .matches-table th {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: right;
  vertical-align: top;
}
.fields-table td:first-child { width: 160px; color: var(--muted); font-weight: 700; }
.matches-table th { color: var(--muted); font-size: 12px; background: #f8fafc; }
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--border); border-radius: 16px; margin-top: 12px; }
.match-score { font-weight: 800; color: var(--ok); }
.variant { border: 1px solid var(--border); border-radius: 16px; margin: 10px 0; overflow: hidden; }
.variant-title { padding: 10px 12px; background: #f8fafc; color: var(--muted); font-weight: 700; }
.variant pre { margin: 0; border-radius: 0; }
.notice { margin-top: 14px; padding: 12px 14px; background: #f8fafc; border: 1px solid var(--border); border-radius: 16px; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.preview-grid canvas { width: 100%; min-height: 70px; background: #111827; border: 1px solid var(--border); border-radius: 14px; }
.small-title { color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 6px; }
footer { padding: 0 clamp(16px, 4vw, 44px) 28px; font-size: 13px; }
@media (max-width: 940px) {
  .layout { grid-template-columns: 1fr; }
  .search-panel { grid-column: auto; }
  .cards { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .topbar { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 520px) {
  .cards, .preview-grid { grid-template-columns: 1fr; }
  h1 { font-size: 24px; }
  .panel { padding: 14px; border-radius: 18px; }
}
