* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Grupo Gopar brand colors */
  --green:        #5cb035;
  --green-dark:   #4a9029;
  --green-light:  #e8f5e0;
  --gray:         #404040;
  --gray-mid:     #6c6c6c;
  --gray-light:   #e8e8e8;

  /* Light theme surfaces */
  --bg:           #f0f2f0;
  --surface:      #ffffff;
  --surface-alt:  #f7f8f7;
  --border:       #dde3dd;

  /* Text */
  --text:         #242424;
  --text-muted:   #6a6a6a;
  --text-on-dark: #ffffff;

  /* Status */
  --red:          #d93025;
  --yellow:       #c8920a;
  --blue:         #2563eb;

  /* Overlays */
  --overlay-success: rgba(55, 130, 20, 0.93);
  --overlay-warn:    rgba(90, 90, 90, 0.88);
  --overlay-error:   rgba(185, 28, 28, 0.88);
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none;
}

/* ─── Screens ───────────────────────────────────────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

.screen.hidden {
  display: none !important;
}

/* ─── Loading Screen ─────────────────────────────────────────────────────── */

#loading-screen {
  background: var(--surface);
  gap: 18px;
}

.loading-logo-img {
  height: 52px;
  width: auto;
  object-fit: contain;
}

.loading-app-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: -6px;
}

.loading-status {
  color: var(--text-muted);
  font-size: 14px;
  min-height: 20px;
}

.loading-sub {
  color: #aaa;
  font-size: 12px;
  min-height: 16px;
  margin-top: -8px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-light);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Setup Screen ───────────────────────────────────────────────────────── */

#setup-screen {
  background: var(--bg);
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 40px 48px;
  width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.setup-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
  align-self: center;
  margin-bottom: 4px;
}

.setup-card h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.setup-card p {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group input {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(92, 176, 53, 0.12);
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.setup-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.setup-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ─── Main App Screen ────────────────────────────────────────────────────── */

#app-screen {
  background: var(--bg);
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch; /* override .screen align-items:center — critical for browser */
}

/* Ensure content row fills full width in browser */
.content-row {
  width: 100%;
}

/* Top Bar */
.top-bar {
  width: 100%;
  height: 56px;
  background: var(--gray);
  border-bottom: none;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.top-bar-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.top-bar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.top-bar .branch-name {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar .clock {
  font-size: 18px;
  font-weight: 500;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  transition: background 0.3s;
  flex-shrink: 0;
}

.status-dot.online  { background: var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.warning { background: var(--yellow); }

.pending-badge {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.65);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 100px;
}

.pending-badge.has-pending {
  background: rgba(200, 146, 10, 0.25);
  color: #f4c34a;
}

/* Camera Container */
.camera-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
  min-height: 0;
}

.camera-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 960px;
  max-height: 720px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #000;
  transition: border-color 0.3s, box-shadow 0.3s;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
}

.camera-wrapper.detecting {
  border-color: var(--green);
  box-shadow: 0 4px 24px rgba(0,0,0,0.10), 0 0 0 2px rgba(92, 176, 53, 0.18);
}

.camera-wrapper.no-face {
  border-color: var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
}

.camera-wrapper.error {
  border-color: var(--red);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
}

/* Overlay message */
.overlay-message {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.overlay-message.visible {
  transform: translateY(0);
}

.overlay-message.success { background: var(--overlay-success); }
.overlay-message.neutral { background: var(--overlay-warn); }
.overlay-message.error   { background: var(--overlay-error); }

.overlay-name {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.overlay-status {
  font-size: 15px;
  color: rgba(255,255,255,0.9);
}

/* Camera error state */
.camera-error-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 16px;
  text-align: center;
  padding: 32px;
}

.camera-error-msg button {
  background: var(--gray-light);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.camera-error-msg button:hover {
  background: #d8d8d8;
}

/* Bottom bar */
.bottom-bar {
  width: 100%;
  height: 36px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
}

.bottom-bar .info {
  font-size: 12px;
  color: var(--text-muted);
}

.bottom-bar .info span {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Face detection box */
#canvas-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.9;
}

/* ─── Recognition Bar ───────────────────────────────────────────────────── */

.recognition-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 5;
  background: rgba(255, 255, 255, 0.97);
  border-top: 3px solid var(--green);
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.10);
}

.recognition-bar.visible {
  transform: translateY(0);
  pointer-events: auto;
}

.recognition-bar.already-registered {
  border-top-color: var(--yellow);
}

.rec-bar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.rec-bar-name {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-bar-sub {
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.recognition-bar.already-registered .rec-bar-sub {
  color: var(--yellow);
}

.rec-bar-btn {
  flex-shrink: 0;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 26px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.rec-bar-btn:hover {
  background: var(--green-dark);
}

.rec-bar-btn:active {
  transform: scale(0.97);
}

.recognition-bar.already-registered .rec-bar-btn {
  background: var(--yellow);
  color: #fff;
}

.recognition-bar.already-registered .rec-bar-btn:hover {
  background: #a87608;
}

/* ─── Success Confirmation Modal ─────────────────────────────────────────── */

.success-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  animation: success-backdrop-in 0.2s ease;
}

.success-modal.hidden {
  display: none;
}

@keyframes success-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.success-modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 52px 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.22);
  animation: success-card-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes success-card-pop {
  from { opacity: 0; transform: scale(0.82) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.success-check-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--green-light);
  border: 2.5px solid var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--green);
  animation: success-check-pop 0.45s 0.1s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes success-check-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.success-modal-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--green);
  margin-top: 6px;
}

.success-modal-name {
  font-size: 34px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  line-height: 1.1;
}

.success-modal-time {
  font-size: 20px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

/* ─── Content Row (camera + sidebar) ──────────────────────────────────────── */

.content-row {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

/* ─── Attendance Sidebar ─────────────────────────────────────────────────── */

.attendance-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-count {
  font-size: 11px;
  background: var(--green-light);
  color: var(--green-dark);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  font-variant-numeric: tabular-nums;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 6px 0;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--gray-light); border-radius: 2px; }

.sidebar-entry {
  display: flex;
  flex-direction: column;
  padding: 10px 16px;
  gap: 2px;
  border-bottom: 1px solid rgba(221, 227, 221, 0.6);
  animation: sidebar-slide-in 0.25s ease;
}

.sidebar-entry-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-entry-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@keyframes sidebar-slide-in {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Duplicate Attendance Modal ─────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 36px;
  max-width: 380px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

.modal-message {
  font-size: 16px;
  color: var(--text);
  text-align: center;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.btn-modal-yes,
.btn-modal-no {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-modal-yes { background: var(--green); color: #fff; }
.btn-modal-no  { background: var(--gray-light); color: var(--text); }
.btn-modal-yes:hover { background: var(--green-dark); }
.btn-modal-no:hover  { opacity: 0.75; }
