/* MCTV Warehouse Scanner — minimal, mobile-first */

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --accent: #0f3460;
  --primary: #e94560;
  --text: #eaeaea;
  --muted: #a0a0a0;
  --success: #2ecc71;
  --error: #e74c3c;
  --radius: 8px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-box {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
}
.login-box h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}
.login-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.login-box input {
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.login-box button {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.login-box .error { color: var(--error); font-size: 0.9rem; margin-top: 0.5rem; }

/* App layout */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.header h1 { margin: 0; font-size: 1.25rem; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.btn-header {
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-header:hover { background: var(--primary); color: #fff; }
.logout {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}
.logout:hover { color: var(--primary); }

.controls {
  background: var(--surface);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.field {
  margin-bottom: 0.75rem;
}
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.field input, .field select {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.project-row {
  display: flex;
  gap: 0.5rem;
}
.project-row select { flex: 1; }
.project-row button {
  padding: 0.6rem 0.75rem;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.scanner-section {
  margin-bottom: 1rem;
}
.btn-primary {
  width: 100%;
  padding: 1rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  cursor: pointer;
}
.camera-wrap {
  margin-top: 1rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 2px solid var(--accent);
}
.camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--accent);
}
.camera-title {
  font-size: 0.95rem;
  color: var(--text);
}
.camera-close {
  padding: 0.4rem 0.75rem;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
}
.camera-close:hover {
  background: var(--primary);
  color: #fff;
}
.reader-viewport,
#reader {
  width: 100%;
  min-height: 280px;
  max-height: 60vh;
  position: relative;
  display: block;
}
#reader video {
  width: 100%;
  height: auto;
  min-height: 280px;
  max-height: 60vh;
  object-fit: cover;
  display: block;
}
#reader__scan_region {
  width: 100% !important;
}
#reader__dashboard {
  display: none;
}
.camera-hint {
  text-align: center;
  padding: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}
.scan-status {
  min-height: 2rem;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}
.scan-status.success { color: var(--success); }
.scan-status.error { color: var(--error); }

.scan-success-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1.75rem;
  border-radius: 12px;
  background: #27ae60;
  color: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  min-width: 220px;
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
.scan-success-toast:not(.hidden) {
  pointer-events: auto;
  cursor: pointer;
}
.scan-success-toast.hidden { display: none !important; }
.scan-success-toast-icon {
  font-size: 2.5rem;
  line-height: 1;
  font-weight: bold;
}
.scan-success-toast-text {
  font-size: 1.15rem;
  font-weight: 600;
  word-break: break-all;
}
.scan-success-toast-dismiss {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 0.25rem;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.log-section h2 {
  font-size: 1rem;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}
.log-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9rem;
}
.log-section li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--accent);
}
.log-section li:last-child { border-bottom: none; }
#api-error { margin-top: 0.5rem; }

.hidden { display: none !important; }
.error { color: var(--error); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal-content {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
}
.modal-content h2 { margin: 0 0 1rem; font-size: 1.2rem; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.modal-actions button {
  flex: 1;
  padding: 0.6rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 1rem;
}
.modal-actions button[type="submit"] {
  background: var(--primary);
  color: #fff;
}
.modal-actions button[type="button"] {
  background: var(--accent);
  color: var(--text);
}

/* Overview modal */
.overview-modal-content {
  max-width: 96%;
  max-height: 90vh;
  overflow: auto;
}
.overview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.overview-header h2 { margin: 0; font-size: 1.2rem; }
.modal-close {
  padding: 0.35rem 0.5rem;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
}
.modal-close:hover { background: var(--primary); color: #fff; }
.overview-body { min-height: 120px; }
.overview-loading, .overview-empty, .overview-error {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}
.overview-error { color: var(--error); }
.overview-group {
  margin-bottom: 1.25rem;
}
.overview-group-title {
  font-size: 1rem;
  color: var(--primary);
  margin: 0 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--accent);
}
.overview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.overview-table th, .overview-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--accent);
}
.overview-table th {
  color: var(--muted);
  font-weight: 600;
}
.overview-table tbody tr:last-child td { border-bottom: none; }
