/* Global Styles */
body {
  margin: 0;
  padding: 0;
  font-family: "Inter", sans-serif;
  background-color: #f3f4f6;
  color: #1f2937;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding-top: 40px;
  padding-bottom: 40px;
}

.logo {
  width: 120px;
  height: 120px;
}

.container {
  width: 100%;
  max-width: 600px;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 32px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 24px;
  font-weight: 600;
  color: #b61217;
  margin-bottom: 8px;
  margin-top: 0;
}

header p {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

/* Upload Section */
.upload-section {
  margin-bottom: 24px;
}

.drop-zone {
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  transition: all 0.2s ease;
  background-color: #f9fafb;
}

.drop-zone.dragover {
  border-color: #3b82f6;
  background-color: #eff6ff;
}

.drop-zone p {
  margin: 0 0 16px;
  color: #4b5563;
  font-size: 14px;
}

.drop-zone .or {
  margin: 8px 0;
  color: #9ca3af;
  font-size: 12px;
}

/* Preview Section */
.preview-container {
  position: relative;
  margin-top: 16px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.preview-container img {
  width: 100%;
  display: block;
}

.preview-container .btn.icon {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.9);
  color: #ef4444;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-container .btn.icon:hover {
  background-color: #ffffff;
  color: #dc2626;
}

/* Loading */
.loading {
  text-align: center;
  padding: 20px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

.loading p {
  font-size: 14px;
  color: #6b7280;
}

/* Form Styles */
.ktp-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

label {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}

input,
textarea {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  font-size: 14px;
  color: #111827;
  transition: border-color 0.2s;
  font-family: inherit;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Buttons */
.btn {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn.primary {
  background-color: #3b82f6;
  color: #ffffff;
}

.btn.primary:hover {
  background-color: #2563eb;
}

.btn.secondary {
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  color: #374151;
}

.btn.secondary:hover {
  border-color: #9ca3af;
  background-color: #f9fafb;
}

.form-actions {
  margin-top: 16px;
  text-align: right;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Camera */
.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.camera-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  background: #000;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#camera-stream {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh; /* Dynamic viewport height for mobile */
  display: block;
  object-fit: cover;
}

.camera-controls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let clicks pass through if needed, but buttons need pointer-events: auto */
}

#capture-btn {
  pointer-events: auto;
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-color: transparent;
  border: 4px solid #ffffff;
  padding: 0;
  cursor: pointer;
  z-index: 10;
}

#capture-btn::after {
  content: "";
  display: block;
  width: 52px;
  height: 52px;
  background-color: #ffffff;
  border-radius: 50%;
  margin: 2px auto;
  transition: transform 0.1s;
}

#capture-btn:active::after {
  transform: scale(0.9);
}

#close-camera-btn {
  pointer-events: auto;
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  border: none;
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}

#close-camera-btn:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

#switch-camera-btn {
  pointer-events: auto;
  position: absolute;
  bottom: 32px;
  right: 20%; /* Position it to the right of center */
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  padding: 0;
}

#switch-camera-btn:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

#switch-camera-btn svg {
  width: 24px;
  height: 24px;
}

/* KTP Frame Overlay */
.ktp-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.ktp-frame::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  /* Create a cutout effect using box-shadow */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

/* The actual frame rectangle */
.ktp-frame-rect {
  position: absolute;
  top: 5px;
  left: 5px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  box-sizing: border-box;
  border: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.3);
  pointer-events: none;
}

.ktp-frame-rect * {
  pointer-events: none;
}

/* Corner markers for better visual guidance */
.ktp-frame-rect::before,
.ktp-frame-rect::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  border: 4px solid #3b82f6;
}

.ktp-frame-rect::before {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 12px;
}

.ktp-frame-rect::after {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 12px;
}

/* Bottom corners using pseudo elements on a child div */
.ktp-frame-corners {
  position: absolute;
  width: 100%;
  height: 100%;
}

.ktp-frame-corners::before,
.ktp-frame-corners::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  border: 4px solid #3b82f6;
}

.ktp-frame-corners::before {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 12px;
}

.ktp-frame-corners::after {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 12px;
}

.ktp-instruction {
  position: absolute;
  top: 20px;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  margin: 0;
  padding: 0 16px;
  box-sizing: border-box;
  pointer-events: none;
  user-select: none;
}

/* Responsive Styles */
@media (max-width: 640px) {
  #switch-camera-btn {
    right: 15%; /* Adjust for smaller screens */
    bottom: 32px;
  }

  body {
    padding: 20px 16px; /* Less vertical padding, added horizontal padding for card margin effect */
  }

  .container {
    padding: 20px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0; /* Remove gap between grid columns since they are stacked */
  }

  .form-row .form-group {
    margin-bottom: 16px; /* Add margin-bottom to stacked items */
  }

  .action-buttons {
    flex-direction: column;
    width: 100%;
  }

  .action-buttons .btn {
    width: 100%;
  }

  header h1 {
    font-size: 20px;
  }

  /* KTP Frame responsive adjustments */
  .ktp-frame::after {
    font-size: 14px;
    top: 12%;
    padding: 6px 12px;
  }

  .ktp-frame-rect {
    width: calc(100% - 10px);
    max-width: none;
    height: calc(100% - 10px);
    aspect-ratio: auto;
    top: 5px;
    left: 5px;
    transform: none;
  }

  .ktp-frame-rect::before,
  .ktp-frame-rect::after,
  .ktp-frame-corners::before,
  .ktp-frame-corners::after {
    width: 24px;
    height: 24px;
    border-width: 3px;
  }
}

/* Additional styles for portrait mobile to ensure vertical frame */
@media (max-width: 640px) and (orientation: portrait) {
  .ktp-frame-rect {
    width: calc(100% - 10px);
    max-width: none;
    aspect-ratio: auto;
    height: calc(100% - 10px);
  }

  .ktp-instruction {
    /* Vertical text on the right side */
    width: auto; /* Allow width to fit content */
    top: 50%;
    right: 20px;
    left: auto;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 14px; /* Adjust size if needed */
    padding: 16px 0; /* Vertical padding becomes horizontal in vertical mode but usually padding is relative to box. Use 0 16px if needed, let's stick to safe padding */
    white-space: nowrap; /* Prevent wrapping */
  }
}

/* Instructions Section */
.instructions {
  margin-top: 32px;
  background-color: #fff;
  border-radius: 12px;
  padding: 24px;
  border: 1px solid #e5e7eb;
  text-align: left;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  position: relative;
  overflow: hidden;
}

.instructions::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(to bottom, #d84045, #bd292e);
}

.instructions h3 {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  margin-top: 0;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.instructions h3::before {
  content: "📋";
  font-size: 18px;
}

.instructions ul {
  padding-left: 24px;
  margin-bottom: 24px;
  color: #4b5563;
  font-size: 14px;
  margin-top: 0;
  line-height: 1.6;
}

.instructions li {
  margin-bottom: 8px;
  padding-left: 4px;
}

.instructions-example {
  text-align: center;
  background: #f9fafb;
  padding: 20px;
  border-radius: 10px;
  border: 1px dashed #d1d5db;
  transition: all 0.2s ease;
}

.instructions-example:hover {
  border-color: #b61217;
  background-color: #fff3f4;
}

.instructions-example img {
  max-width: 100%;
  border-radius: 8px;
  border: 4px solid #ffffff;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  height: auto;
  transition: transform 0.3s ease;
}

.instructions-example:hover img {
  transform: scale(1.02);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.instructions-example p {
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  margin-top: 12px;
  margin-bottom: 0;
}
