:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2f6fed;
  --primary-hover: #1f56c9;
  --danger: #d64545;
  --ok: #1f9d55;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.header-actions { display: flex; flex-wrap: wrap; gap: 10px; }

button {
  font: inherit;
  padding: 8px 16px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

button:hover { background: #f0f1f3; }

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover { background: var(--primary-hover); }

.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

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

@media (max-width: 480px) {
  .main-grid { padding: 12px; gap: 14px; }
}

.full-width { grid-column: 1 / -1; }

.mock-panel p { margin: 0 0 12px; font-size: 0.88rem; }

.mock-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mock-controls select {
  flex: 1;
  min-width: 220px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font: inherit;
  background: #fff;
}

.mock-controls .file-picker { flex: 1; min-width: 260px; }

.mock-block { margin-bottom: 4px; }

/* Кастомная кнопка выбора файла поверх спрятанного нативного input[type=file] */

.file-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.file-picker-btn svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--primary); }

.file-picker-btn:hover { background: #f0f1f3; border-color: var(--primary); }

.file-picker-input:focus-visible + .file-picker-btn {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.file-picker-name {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  min-width: 0;
  flex: 1 1 auto;
}

.file-picker-name.has-file { color: var(--text); font-weight: 500; }

.mock-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.video-wrap {
  background: #111;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

.video-wrap.small { aspect-ratio: 4 / 3; max-width: min(320px, 100%); }

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-controls {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.checkbox-row input[type="number"] {
  width: 56px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.result-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.result-warning { color: var(--danger); border-color: #f3caca; background: #fdf2f2; }

.result-matched {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.result-matched img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.result-name { font-size: 1.2rem; font-weight: 600; }

.result-confidence { color: var(--ok); margin-top: 6px; }

.error-text { color: var(--danger); font-size: 0.9rem; }

.muted { color: var(--muted); }

/* Модалки */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--panel-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.05rem; }

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 8px;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.field input[type="text"],
.field textarea {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font: inherit;
  resize: vertical;
}

.settings-hint {
  font-size: 0.83rem;
  color: var(--muted);
  line-height: 1.6;
  margin: 0 0 14px;
}

.settings-hint code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.82em;
  color: var(--text);
}

#btn-save-settings { width: 100%; }

.tabs { display: flex; gap: 8px; margin: 16px 0 12px; }

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.tab-content { display: none; margin-bottom: 12px; }

.tab-content.active { display: block; }

#btn-capture-photo { margin-top: 10px; }

#add-capture-preview {
  margin-top: 10px;
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

#btn-submit-employee { width: 100%; margin-top: 8px; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.logs-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.logs-table th, .logs-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.logs-table img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}

.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-small { padding: 5px 10px; min-height: 0; font-size: 0.82rem; }

.photos-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.photo-card {
  position: relative;
  width: 96px;
}

.photo-card img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

.photo-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(31, 36, 48, 0.75);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.photo-card .btn-remove-photo {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-card .btn-remove-photo:hover { background: #b93838; }

.photo-card .btn-remove-photo:disabled {
  background: var(--muted);
  border-color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.status-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-matched { background: #e5f7ea; color: var(--ok); }
.status-not_matched { background: #fdf2f2; color: var(--danger); }
.status-error { background: #f0f1f3; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2430;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  z-index: 200;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.error { background: var(--danger); }

[hidden] { display: none !important; }

/* ---------- Мобильные экраны ---------- */

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px;
  }

  .app-header h1 { text-align: center; }

  .header-actions { justify-content: stretch; }
  .header-actions button { flex: 1; }

  .modal-overlay { padding: 0; align-items: flex-end; }

  .modal {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .modal-header { padding: 12px 14px; flex-wrap: wrap; }
  .modal-header h2 { font-size: 0.95rem; white-space: nowrap; }

  .modal-body { padding: 14px; }

  .modal-header-actions { flex-wrap: wrap; justify-content: flex-end; }

  .camera-controls { flex-direction: column; align-items: stretch; }
  .camera-controls button { width: 100%; }
  .checkbox-row { flex-wrap: wrap; }

  .mock-controls { flex-direction: column; align-items: stretch; }
  .mock-controls select,
  .mock-controls .file-picker { min-width: 0; }
  .mock-controls button { width: 100%; }

  .file-picker { width: 100%; }
  .file-picker-btn { flex: 1; justify-content: center; }
  .file-picker-name { max-width: none; }

  .result-matched { justify-content: center; text-align: center; }
  .result-matched img { width: 96px; height: 96px; }

  .tabs { gap: 6px; }
  .tab-btn { flex: 1; text-align: center; }

  #add-capture-preview { width: 100%; max-width: 220px; height: auto; aspect-ratio: 1 / 1; }

  button { min-height: 44px; }
}
