:root {
  --glass-bg: rgba(255,255,255,.45);
  --glass-border: rgba(255,255,255,.5);
  --radius: 1.25rem;
  --accent: #6366f1;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  overflow: hidden;
  overscroll-behavior-y: none;
}

/* Layout */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* Desktop: hide-preview expands editor to full width */
.app.hide-preview .editor-panel {
  width: 100%;
}
.app.hide-preview .preview-panel {
  display: none;
}

.editor-panel {
  width: 66.666%;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 6rem;
  -webkit-overflow-scrolling: touch;
}

.preview-panel {
  width: 33.333%;
  background: #e2e8f0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Glass cards */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0,0,0,.08);
  padding: 1rem;
  transition: transform .3s, box-shadow .3s;
}
.glass:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,.12);
}

/* Form elements - 16px prevents iOS auto-zoom */
input[type="text"], input[type="email"], input[type="month"], input[type="number"], textarea, select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  min-height: 44px;
  background: rgba(255,255,255,0.7);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
  background: white;
}
textarea { resize: vertical; font-size: 1rem; }

/* ==========================================
   MODERN BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1.25rem;
  border-radius: 0.625rem;
  border: 1px solid rgba(99,102,241,0.25);
  background: linear-gradient(135deg, rgba(99,102,241,0.9), rgba(79,70,229,0.95));
  color: white;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(99,102,241,0.25), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.08);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover {
  background: linear-gradient(135deg, rgba(99,102,241,1), rgba(67,56,202,0.95));
  box-shadow: 0 6px 20px rgba(99,102,241,0.35), inset 0 1px 0 rgba(255,255,255,0.25);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(99,102,241,0.2);
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.375rem 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(99,102,241,0.2);
  background: linear-gradient(135deg, rgba(99,102,241,0.88), rgba(79,70,229,0.92));
  color: white;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  min-width: 36px;
  backdrop-filter: blur(8px);
  box-shadow: 0 3px 10px rgba(99,102,241,0.2), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.06);
  -webkit-tap-highlight-color: transparent;
}
.btn-sm:hover {
  background: linear-gradient(135deg, rgba(99,102,241,1), rgba(67,56,202,0.95));
  box-shadow: 0 5px 16px rgba(99,102,241,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
  transform: translateY(-1px);
}
.btn-sm:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(99,102,241,0.15);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1.25rem;
  border-radius: 0.625rem;
  border: 1.5px solid rgba(99,102,241,0.4);
  background: rgba(255,255,255,0.5);
  color: #4f46e5;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(99,102,241,0.08);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
}
.btn-outline:hover {
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.6);
  box-shadow: 0 4px 12px rgba(99,102,241,0.15);
  transform: translateY(-1px);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
  border: none;
  background: rgba(239,68,68,0.1);
  color: #dc2626;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 32px;
  transition: all 0.2s;
}
.btn-danger:hover {
  background: rgba(239,68,68,0.18);
  color: #b91c1c;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 0.375rem;
  border: none;
  background: rgba(0,0,0,0.06);
  color: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover {
  background: rgba(0,0,0,0.12);
  transform: scale(1.08);
}

/* Preview close button - hidden by default, shown on mobile */
.preview-close-btn {
  display: none;
}

/* Drag & Drop */
.sortable-list { display: flex; flex-direction: column; gap: 0.5rem; }
.sortable-item {
  background: rgba(255,255,255,0.7);
  border-radius: 0.5rem;
  padding: 0.75rem;
  cursor: grab;
  border: 1px solid transparent;
  transition: opacity 0.2s, transform 0.2s, border-color 0.2s;
}
.sortable-item:hover { border-color: #cbd5e1; }
.sortable-item.dragging {
  opacity: 0.5;
  transform: scale(0.98);
  border-color: #6366f1;
}
.sortable-item:active { cursor: grabbing; }

/* Drop zone */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 0.75rem;
  padding: 1.25rem;
  text-align: center;
  background: rgba(255,255,255,0.3);
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: #6366f1;
  background: rgba(99,102,241,0.06);
}
.profile-preview {
  width: 6rem; height: 6rem; object-fit: cover; border-radius: 9999px;
  margin: 0 auto 0.5rem; display: block;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* A4 Preview */
.preview-scale-wrapper {
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  background: white;
}

.preview-resume {
  width: 210mm;
  min-height: 297mm;
  padding: 15mm;
  font-size: 10pt;
  line-height: 1.4;
  box-sizing: border-box;
  background-color: white;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(297mm - 2px),
    #94a3b8 calc(297mm - 2px),
    #94a3b8 297mm
  );
}

.resume-layout {
  display: grid;
  grid-template-columns: 35% 1fr;
  gap: 1.5rem;
  height: 100%;
}
.resume-left, .resume-right { display: flex; flex-direction: column; gap: 1rem; }
.resume-header { display: flex; flex-direction: column; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.resume-photo { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; }
.resume-section h3 {
  font-size: 11pt;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.25rem;
}
.resume-rule { height: 2px; margin-bottom: 0.5rem; }
.experience-item, .education-item { margin-bottom: 0.75rem; }
.experience-meta { font-style: italic; font-size: 9pt; margin: 0.1rem 0; opacity: 0.8; }
.skill-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    /* Prevent flex children from overflowing */
    min-width: 0;
}

.skill-item span {
    /* Prevent the name from pushing the bar away */
    flex-shrink: 0;
    font-size: 9pt;
    min-width: 80px;
}

.skill-item svg {
    /* Let the SVG grow to fill remaining space */
    flex: 1 1 auto;
    min-width: 0;
    height: 6px;
    display: block;
}
/* Visibility grid */
.visibility-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; font-size: 0.875rem; }
.visibility-row label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; min-height: 44px; }

/* Footer */
.app-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #1e293b; color: white;
  padding: 0.75rem 1rem; text-align: center; font-size: 0.875rem;
  z-index: 50;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

/* Action bar */
.action-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ==========================================
   FLOATING PREVIEW BUTTON
   ========================================== */
.floating-preview-btn {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  right: 1rem;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.625rem 1.125rem;
  border-radius: 9999px;
  border: none;
  background: linear-gradient(135deg, rgba(99,102,241,0.95), rgba(79,70,229,0.98));
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(99,102,241,0.35), 0 0 0 1px rgba(255,255,255,0.1) inset;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.08);
  -webkit-tap-highlight-color: transparent;
}

.floating-preview-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 30px rgba(99,102,241,0.45), 0 0 0 1px rgba(255,255,255,0.15) inset;
}

.floating-preview-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 10px rgba(99,102,241,0.25);
}

/* Hide floating button when preview is open on mobile (close button is shown instead) */
.app.show-preview .floating-preview-btn {
  display: none;
}

/* On desktop: show floating button only when preview is hidden */
@media (min-width: 901px) {
  .app.show-preview .floating-preview-btn {
    display: inline-flex;
  }
  .app.show-preview .floating-preview-btn span::after {
    content: " Preview";
  }
}

/* ===========================
   RESPONSIVE: Tablet / Mobile
   =========================== */
@media (max-width: 900px) {
  body {
    overflow: auto;
    overscroll-behavior-y: auto;
  }

  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .editor-panel {
    width: 100%;
    padding: 0.75rem;
    padding-bottom: 1rem;
    gap: 0.75rem;
  }

  .preview-panel {
    width: 100%;
    min-height: auto;
    padding: 0.75rem;
  }

  .glass {
    border-radius: 0.75rem;
    padding: 0.875rem;
  }

  .app-footer {
    position: static;
    margin-top: auto;
    font-size: 0.8125rem;
    padding: 0.625rem 1rem;
  }

  .visibility-row {
    gap: 0.5rem 1rem;
  }

  /* Mobile full-page preview mode */
  .app.show-preview .editor-panel {
    display: none;
  }
  .app.show-preview .preview-panel {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    width: 100%;
    height: 100%;
    padding: 0.75rem;
    background: #e2e8f0;
  }

  .preview-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 101;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    background: linear-gradient(135deg, rgba(99,102,241,0.9), rgba(79,70,229,0.95));
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99,102,241,0.25);
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  /* Floating button on mobile */
  .floating-preview-btn {
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
    right: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
  }

  /* Hide floating button when preview panel is open on mobile */
  .app.show-preview .floating-preview-btn {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .editor-panel {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .preview-panel {
    padding: 0.5rem;
  }

  input, select, textarea {
    padding: 0.625rem 0.5rem;
  }

  .btn, .btn-outline {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }

  .resume-layout {
    gap: 1rem;
  }

  .resume-header {
    flex-direction: column;
    text-align: center;
  }

  .resume-photo {
    width: 80px;
    height: 80px;
  }
}

/* ---------- Print / PDF ---------- */
@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html, body, .app, .preview-panel, .preview-scale-wrapper {
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }

  .app {
    display: block !important;
    height: auto !important;
  }

  .editor-panel,
  .app-footer,
  .action-bar,
  .floating-preview-btn {
    display: none !important;
  }

  .preview-panel {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  .preview-scale-wrapper {
    width: auto !important;
    height: auto !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  .preview-resume {
    transform: none !important;
    width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 15mm !important;
    box-shadow: none !important;
    background: white !important;
    page-break-inside: avoid;
  }

  .resume-layout {
    grid-template-columns: 35% 1fr !important;
  }
}