/* ============================================
  GASIN - Main Stylesheet
  Theme: Blue & White
  ============================================ */

:root {
  --primary: #1E40AF;
  --primary-light: #3B82F6;
  --primary-dark: #1E3A8A;
  --secondary: #60A5FA;
  --accent: #93C5FD;
  --bg: #FFFFFF;
  --bg-light: #F0F9FF;
  --bg-card: #F8FAFC;
  --border: #DBEAFE;
  --border-dark: #BFDBFE;
  --text: #0F172A;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 6px -1px rgba(30, 64, 175, 0.1), 0 2px 4px -1px rgba(30, 64, 175, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(30, 64, 175, 0.1), 0 4px 6px -2px rgba(30, 64, 175, 0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-light);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== NAVBAR ===== */
.navbar {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.navbar-brand {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-brand-icon {
  width: 32px;
  height: 32px;
  background: white;
  color: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 18px;
}

.navbar-links {
  display: flex;
  gap: 24px;
  align-items: center;
}

.navbar-link {
  color: white;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.navbar-link:hover {
  opacity: 1;
}

/* ===== CONTAINER ===== */
.container {
  max-width: 720px;
  margin: 32px auto;
  padding: 0 16px;
}

.container-wide {
  max-width: 1200px;
}

/* ===== CARD ===== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 4px;
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== PROGRESS STEPS ===== */
.steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 32px;
  position: relative;
}

.steps::before {
  content: '';
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  position: relative;
  z-index: 1;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  transition: all 0.3s;
}

.step.active .step-circle {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.step.completed .step-circle {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.step-label {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
}

.step.active .step-label,
.step.completed .step-label {
  color: var(--text);
  font-weight: 600;
}

/* ===== FORM ===== */
.form-group {
  margin-bottom: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.form-label .required {
  color: var(--error);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  transition: all 0.2s;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input:disabled {
  background: var(--bg-light);
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-error {
  color: var(--error);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

/* ===== BUTTON ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  font-family: inherit;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-primary:disabled {
  background: var(--text-light);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-secondary:hover {
  background: var(--bg-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-light);
  color: var(--text);
}

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

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

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 24px;
}

/* ===== KTP SCANNER ===== */
.ktp-scanner-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0 auto 16px;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 1.586 / 1; /* KTP aspect ratio 85.6:53.98 */
}

#ktpVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ktp-frame-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ktp-frame-overlay svg {
  width: 95%;
  height: 95%;
  filter: drop-shadow(0 0 8px rgba(0,0,0,0.5));
}

.ktp-corner-marker {
  position: absolute;
  width: 36px;
  height: 36px;
  border: 4px solid #00FF80;
  filter: drop-shadow(0 0 8px rgba(0,255,128,0.6));
}
.ktp-corner-tl { top: 4%; left: 4%; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.ktp-corner-tr { top: 4%; right: 4%; border-left: none; border-bottom: none; border-radius: 0 8px 0 0; }
.ktp-corner-bl { bottom: 4%; left: 4%; border-right: none; border-top: none; border-radius: 0 0 0 8px; }
.ktp-corner-br { bottom: 4%; right: 4%; border-left: none; border-top: none; border-radius: 0 0 8px 0; }

.ktp-scanner-container.scanning .ktp-corner-marker {
  animation: corner-pulse 1.2s ease-in-out infinite;
}
.ktp-scanner-container.detected .ktp-corner-marker {
  border-color: #FFD700;
  animation: corner-flash 0.4s ease-out;
}

@keyframes corner-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
@keyframes corner-flash {
  0% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.ktp-result-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: var(--bg-light);
  padding: 12px;
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}

.ktp-result-img {
  width: 100%;
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

.ktp-result-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 640px) {
  .ktp-result-container { grid-template-columns: 1fr; }
}

/* ===== CAMERA ===== */
.camera-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 16px;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 4/3;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Mirror the preview so it feels like a mirror to the user (typical webcam UX) */
  /* The actual capture uses the raw video frame, so the saved image is NOT mirrored */
  transform: scaleX(-1);
  -webkit-transform: scaleX(-1);
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.camera-frame {
  width: 200px;
  height: 240px;
  border: 3px dashed rgba(255, 255, 255, 0.5);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.camera-frame.active {
  border-color: rgba(124, 255, 110, 0.9);
  box-shadow: 0 0 30px rgba(124, 255, 110, 0.5), inset 0 0 20px rgba(124, 255, 110, 0.2);
}

/* Real-time face detection box overlay (drawn on canvas over video) */
#faceOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Counter-mirror so the box follows the actual face position in the mirrored preview */
  transform: scaleX(-1);
  -webkit-transform: scaleX(-1);
}

.camera-captured {
  width: 100%;
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  /* Captured image NOT mirrored - matches actual face for matching */
}

.camera-status {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 20px;
}

.camera-status.success {
  color: var(--success);
  font-weight: 600;
}

.camera-status.error {
  color: var(--error);
  font-weight: 600;
}

/* ===== UPLOAD ===== */
.upload-area {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-light);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--primary);
}

.upload-text {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-hint {
  color: var(--text-muted);
  font-size: 13px;
}

.upload-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  margin-top: 16px;
  border: 1px solid var(--border);
}

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-pending { background: #FEF3C7; color: #92400E; }
.badge-reviewing { background: #DBEAFE; color: #1E40AF; }
.badge-approved { background: #D1FAE5; color: #065F46; }
.badge-rejected { background: #FEE2E2; color: #991B1B; }
.badge-disbursed { background: #E0E7FF; color: #3730A3; }

.badge-grade-A { background: #D1FAE5; color: #065F46; }
.badge-grade-B { background: #DBEAFE; color: #1E40AF; }
.badge-grade-C { background: #FEF3C7; color: #92400E; }
.badge-grade-D { background: #FEE2E2; color: #991B1B; }

/* ===== TABLE ===== */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: var(--bg-light);
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover {
  background: var(--bg-light);
}

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #6EE7B7; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FCD34D; }
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }

/* ===== STATS CARD ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary-dark);
  margin-top: 4px;
}

.stat-card-blue { border-top: 3px solid var(--primary); }
.stat-card-green { border-top: 3px solid var(--success); }
.stat-card-yellow { border-top: 3px solid var(--warning); }
.stat-card-red { border-top: 3px solid var(--error); }

/* ===== FACE COMPARE ===== */
.face-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.face-compare-item {
  text-align: center;
}

.face-compare-item img {
  width: 100%;
  max-width: 200px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  margin-bottom: 8px;
}

.face-compare-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--primary-dark);
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 48px;
}

/* ===== UTILS ===== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 13px; }
.text-bold { font-weight: 700; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .step-label { font-size: 10px; }
  .step-circle { width: 30px; height: 30px; font-size: 13px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 22px; }
}

/* ===== LOADING ===== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 16px auto;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--bg-light) 25%, var(--border) 50%, var(--bg-light) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s ease-in-out infinite;
  border-radius: var(--radius);
  height: 16px;
  margin-bottom: 8px;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* OCR-filled highlight */
.ocr-filled {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%) !important;
  border-color: #10b981 !important;
  animation: ocrFlash 0.6s ease-out;
}
@keyframes ocrFlash {
  0%  { transform: scale(1.02); box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Inline error alert (auto-dismiss) */
.alert-error-inline {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%) !important;
  border: 1px solid #f87171 !important;
  color: #991b1b !important;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideInDown 0.3s ease-out;
}
@keyframes slideInDown {
  from { transform: translateY(-20px); opacity: 0; }
  to  { transform: translateY(0); opacity: 1; }
}