:root {
  --primary: #1e3a8a;
  --primary-light: #3b82f6;
  --primary-dark: #0f172a;
  --accent: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --font: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: #0f172a;
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
}

/* Container que emula a tela do smartphone na web desktop, e ocupa 100% no celular */
#app-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

@media (min-width: 481px) {
  #app-container {
    height: 90vh;
    max-height: 840px;
    border-radius: 28px;
    border: 8px solid #334155;
  }
}

/* Header */
.app-header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit-badge {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.2);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

/* Main Content Area */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Bottom Navigation Bar */
.bottom-nav {
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
  z-index: 20;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.nav-item .icon {
  font-size: 20px;
  line-height: 1;
  display: inline-block;
}

.nav-item.active {
  color: var(--primary-light);
  background: rgba(59, 130, 246, 0.08);
}

/* Cards & Sections */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-control {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #f8fafc;
  color: var(--text-primary);
  transition: border-color 0.2s ease;
}

.input-control:focus {
  outline: none;
  border-color: var(--primary-light);
  background: #ffffff;
}

textarea.input-control {
  resize: vertical;
  min-height: 90px;
}

/* Buttons */
.btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, background 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary-light);
  color: white;
}

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

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-secondary);
}

.btn-scan {
  background: linear-gradient(135deg, #2563eb, #1e3a8a);
  color: white;
  padding: 24px;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 800;
  box-shadow: 0 10px 20px -5px rgba(37, 99, 235, 0.4);
  margin: auto 0;
}

/* Button Group (Sim / Não) */
.btn-group-row {
  display: flex;
  gap: 10px;
}

.btn-option {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.btn-option.selected-yes {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.btn-option.selected-no {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-option.selected-blue {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Modal Overlay & QR Code Camera Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: #ffffff !important;
  color: #0f172a !important;
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-card h3,
.modal-card p,
.modal-card span,
.modal-card div,
.modal-card strong,
.modal-card label {
  color: #0f172a;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

/* Scanner Overlay */
#qr-reader-container {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: #000;
}

#qr-reader {
  width: 100% !important;
}

#qr-reader video {
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius);
}

/* Badges & History Cards */
.history-card {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  border-left: 4px solid var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.history-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.history-user {
  font-weight: 700;
  color: var(--text-primary);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  margin-right: 6px;
  margin-top: 6px;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1d4ed8; }

/* Subtabs inside Turno */
.subtabs {
  display: flex;
  background: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}

.subtab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
}

.subtab-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Photo Upload & Preview System */
.photo-upload-box {
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  background: #eff6ff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s ease;
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
}

.photo-upload-box:active {
  background: #dbeafe;
  transform: scale(0.99);
}

.photo-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  width: 100%;
}

.photo-preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

.photo-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  z-index: 5;
}

#qr-reader {
  width: 100% !important;
  border: none !important;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

#qr-reader video {
  width: 100% !important;
  height: auto !important;
  border-radius: 12px;
  object-fit: cover;
}

/* Login Screen Background */
.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #0f172a 0%, #1e3a8a 100%);
  color: white;
}

.login-brand {
  text-align: center;
  margin-bottom: 30px;
}

.login-brand h2 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.login-brand p {
  color: #93c5fd;
  font-size: 14px;
  margin-top: 4px;
}

.login-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 24px;
  color: var(--text-primary);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

/* Spinner */
.spinner {
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 3px solid #ffffff;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
