/* ============================================
   KTP Penduduk Threads — Modern Liquid Glass
   ============================================ */

:root {
  /* Premium Dark Theme Palette */
  --bg-color: #060608;
  --panel-bg: rgba(18, 18, 24, 0.7);
  --card-bg: rgba(255, 255, 255, 0.03);
  --card-border: rgba(255, 255, 255, 0.12);
  --card-highlight: rgba(255, 255, 255, 0.15);
  
  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-tertiary: rgba(255, 255, 255, 0.35);
  
  --accent-primary: #FFFFFF;
  --accent-dim: rgba(255, 255, 255, 0.7);
  --success-color: #10B981;

  /* Typography Design Tokens */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Outfit', sans-serif; /* Soft, circular numerals look much friendlier than mono */
  
  --transition-smooth: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* --- Base Setup --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Background Glow --- */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Custom background image layer: low-contrast and blurred */
.bg-glow::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('bg.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.06; /* Extremely low contrast */
  filter: blur(6px) brightness(0.4) grayscale(20%);
  z-index: -1;
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.15;
  z-index: 1;
}

.glow-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, transparent 70%);
  top: -10%;
  right: -10%;
}

.glow-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
  bottom: -10%;
  left: -10%;
}

/* --- Container --- */
.container {
  position: relative;
  z-index: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 16px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

/* --- Header & Typography --- */
.header {
  margin-bottom: 36px;
  text-align: center;
}

.header-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.threads-logo-img {
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.15));
  object-fit: contain;
}

.header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #FFFFFF;
  line-height: 1.1;
}

.header-sub {
  font-size: 0.88rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* --- Main Content Grid --- */
.content {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 32px;
  align-items: start;
}

/* --- Form Panel --- */
.glass {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  padding: 24px;
}

.section-title {
  font-size: 0.88rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 20px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Photo Upload (Fix: Hides broken image previews initially) */
.photo-upload {
  width: 100%;
  height: 100px;
  border: 1.5px dashed rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  background: rgba(255, 255, 255, 0.01);
  transition: all var(--transition-smooth);
  margin-bottom: 16px;
}

.photo-upload:hover, .photo-upload:focus-visible {
  border-color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 550;
  color: var(--text-secondary);
}

.photo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none; /* Crucial fix: hidden by default until source load */
}

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

.form-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 450;
  line-height: 1.4;
  outline: none;
  transition: all var(--transition-smooth);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
}

.input-prefix-wrap {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  overflow: hidden;
}

.input-prefix-wrap:focus-within {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
}

.input-prefix-wrap .prefix {
  padding-left: 14px;
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 0.88rem;
  user-select: none;
}

.input-prefix-wrap input {
  border: none !important;
  background: transparent !important;
  padding-left: 4px;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.flex-1 {
  flex: 1;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toggle {
  cursor: pointer;
  margin-top: 4px;
}

.toggle input {
  display: none;
}

.toggle-track {
  display: block;
  width: 40px;
  height: 22px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  position: relative;
  transition: all var(--transition-smooth);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #888888;
  border-radius: 50%;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.toggle input:checked + .toggle-track {
  background: var(--text-primary);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: var(--bg-color);
}

/* --- Preview Panel --- */
.preview-panel {
  display: flex;
  flex-direction: column;
}

.preview-label {
  margin-bottom: 12px;
}

.preview-wrapper {
  width: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 32px 12px;
  margin-bottom: 16px;
  position: relative;
}

.card-scaler {
  width: 100%;
  max-width: 500px;
  height: 310px;
  position: relative;
  flex-shrink: 0;
}

.capture-area {
  width: 500px;
  height: 310px;
  position: absolute;
  top: 0;
  left: 50%;
  transform-origin: center top;
  background: transparent;
}

/* --- Premium ID Card & Typography --- */
.id-card {
  width: 500px;
  height: 310px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.02) 40%,
    rgba(255, 255, 255, 0.04) 70%,
    rgba(255, 255, 255, 0.08) 100%
  );
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.card-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.02) 20%,
    transparent 45%
  );
  pointer-events: none;
}

/* Card Header Typography */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.card-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-logo {
  opacity: 0.9;
}

.card-logo-img {
  opacity: 0.95;
  object-fit: contain;
}

.card-title {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #FFFFFF;
  line-height: 1.1;
}

.card-subtitle {
  font-size: 8px;
  font-weight: 650;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 2px;
}

.card-region {
  text-align: right;
  font-size: 7.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1.4;
}

/* Body */
.card-body {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-grow: 1;
  padding: 10px 0;
}

/* Photo aspect-ratio */
.card-photo {
  width: 90px;
  height: 120px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  flex-shrink: 0;
}

#cardPhotoCanvas {
  width: 100%;
  height: 100%;
  display: none;
}

.card-photo-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.04) 100%);
}

.card-photo-placeholder-img {
  opacity: 0.15;
  object-fit: contain;
}

/* Info Details Typography */
.card-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex-grow: 1;
}

.info-row {
  display: flex;
  align-items: flex-start;
  font-size: 10px;
  line-height: 1.4;
}

.info-label {
  width: 65px;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.info-sep {
  width: 12px;
  color: rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
  font-weight: 600;
}

.info-value {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

.info-value.nik {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 0.08em; /* Slightly wider spaced soft numerals */
}

.info-value.nama {
  font-weight: 800;
  font-size: 11.5px;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.info-value.bio {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: rgba(255, 255, 255, 0.6);
  font-style: italic;
  font-size: 9.5px;
  line-height: 1.4;
}

.info-value.status {
  font-weight: 800;
  font-size: 9px;
  letter-spacing: 0.03em;
}

.info-value.status.verified {
  color: var(--success-color);
}

.info-value.status.not-verified {
  color: var(--text-tertiary);
}

/* Footer Details Typography */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-stats {
  display: flex;
  gap: 18px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat-emoji {
  font-size: 10px;
  opacity: 0.8;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}

.stat-label {
  font-size: 8px;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-brand {
  font-size: 8.5px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.06em;
}

/* Subtle Shimmer foil */
.shimmer-strip {
  height: 3px;
  margin: 12px -24px -22px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.15) 30%,
    rgba(255, 255, 255, 0.03) 60%,
    rgba(255, 255, 255, 0.15) 90%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: shineFoil 10s linear infinite;
  opacity: 0.4;
}

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

/* --- Action Buttons --- */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.btn-download {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  background: #FFFFFF;
  border: none;
  border-radius: 10px;
  color: #000000;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.08);
  transition: all var(--transition-smooth);
}

.btn-download:hover {
  background-color: #E2E2E2;
}

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

.btn-download.loading {
  opacity: 0.6;
  pointer-events: none;
}

.btn-download.success {
  background-color: var(--success-color);
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.2);
}

.btn-share {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.btn-share:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.3);
}

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

.share-logo-icon {
  filter: invert(1);
  display: inline-block;
  vertical-align: middle;
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: 24px 0 0;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: auto;
}

/* ============================================
   Responsive Layout & Scaling
   ============================================ */

@media (max-width: 800px) {
  .content {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  
  .container {
    padding: 24px 12px;
  }

  .header {
    margin-bottom: 24px;
  }

  .glass {
    padding: 20px;
  }
}
