/* ============================================
   تصميم أداة السيرة الذاتية (CV Builder)
   ============================================ */

.builder-container {
  display: flex;
  height: calc(100vh - 80px); /* تحت الهيدر */
  overflow: hidden;
  background: var(--bg);
}

/* ============ لوحة التحكم (اليمين) ============ */
.builder-controls {
  width: 400px;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  box-shadow: -5px 0 20px rgba(0,0,0,.05);
  z-index: 10;
}
.controls-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg-2);
  z-index: 5;
}
.controls-header h2 {
  font-size: 1.2rem;
  font-weight: 900;
  margin: 0;
  color: var(--primary);
}
.back-link {
  font-size: .9rem;
  color: var(--text-3);
  text-decoration: none;
  transition: .2s;
}
.back-link:hover {
  color: var(--primary);
}

.control-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.control-section h3 {
  font-size: 1.05rem;
  margin-bottom: 15px;
  color: var(--text);
}
.section-title-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.section-title-flex h3 {
  margin-bottom: 0;
}

.form-group {
  margin-bottom: 15px;
}
.form-group label {
  display: block;
  font-size: .85rem;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 600;
}
.form-group input, 
.form-group textarea,
.dynamic-item input,
.dynamic-item textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: .95rem;
  transition: .2s;
  direction: ltr;
  text-align: left;
}
.form-group input:focus, 
.form-group textarea:focus,
.dynamic-item input:focus,
.dynamic-item textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,255,136,.1);
}

.add-btn {
  background: rgba(0,255,136,.1);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: .8rem;
  cursor: pointer;
  transition: .2s;
}
.add-btn:hover {
  background: var(--primary);
  color: var(--on-primary);
}

/* عناصر الديناميكية (الخبرات / التعليم) */
.dynamic-item {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  position: relative;
  animation: fade-in .3s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
.item-header {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}
.item-header input {
  flex: 1;
  font-weight: bold;
}
.remove-btn {
  background: #f87171;
  color: #fff;
  border: none;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .2s;
}
.remove-btn:hover {
  background: #ef4444;
}
.dynamic-item input {
  margin-bottom: 8px;
}
.dynamic-item textarea {
  margin-bottom: 0;
}

/* ============ المعاينة (اليسار) ============ */
.builder-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #cbd5e1; /* خلفية رمادية دائماً لتبدو الورقة بارزة */
  position: relative;
}
.preview-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(10px);
}
.preview-hint {
  color: #94a3b8;
  font-size: .9rem;
}
.download-btn {
  background: #ef4444;
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: .3s;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}
.download-btn:hover {
  transform: translateY(-2px);
  background: #dc2626;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

.preview-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ============ ورقة الـ CV (A4) ============ */
.cv-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 15px 35px rgba(0,0,0,0.2);
  padding: 40px;
  /* الخط الإنجليزي */
  font-family: 'Inter', sans-serif;
  color: #333;
  box-sizing: border-box;
  text-align: left; /* الإنجليزية هي الافتراضية */
}

/* تنسيقات داخل الورقة (يجب ألا تعتمد على متغيرات الثيم لتكون ثابتة في الطباعة) */
.cv-header {
  border-bottom: 2px solid #333;
  padding-bottom: 15px;
  margin-bottom: 25px;
}
.cv-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0 0 5px 0;
  color: #111;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.cv-header h2 {
  font-size: 1.2rem;
  font-weight: 400;
  color: #555;
  margin: 0 0 12px 0;
}
.cv-contact {
  font-size: .9rem;
  color: #666;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.cv-contact .separator {
  color: #ccc;
}

.cv-section {
  margin-bottom: 25px;
}
.cv-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111;
  border-bottom: 1px solid #eee;
  padding-bottom: 5px;
  margin-bottom: 15px;
  letter-spacing: 1px;
}
.cv-summary {
  font-size: .95rem;
  line-height: 1.6;
  color: #444;
  margin: 0;
}

.cv-item {
  margin-bottom: 15px;
}
.cv-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.cv-item-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: #222;
}
.cv-item-date {
  font-size: .85rem;
  color: #666;
  font-weight: 500;
}
.cv-item-subtitle {
  font-weight: 500;
  font-size: .95rem;
  color: #555;
  margin-bottom: 6px;
}
.cv-item-desc {
  font-size: .9rem;
  line-height: 1.5;
  color: #444;
  white-space: pre-wrap; /* للحفاظ على الأسطر الجديدة */
}

.cv-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cv-skill-badge {
  background: #f1f5f9;
  color: #334155;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: .85rem;
  font-weight: 500;
  border: 1px solid #e2e8f0;
}

/* ============ Scrollbar ============ */
.builder-controls::-webkit-scrollbar,
.preview-wrapper::-webkit-scrollbar {
  width: 8px;
}
.builder-controls::-webkit-scrollbar-track,
.preview-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
.builder-controls::-webkit-scrollbar-thumb,
.preview-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* ============ استجابة ============ */
@media (max-width: 1024px) {
  .builder-container {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .builder-controls {
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }
  .preview-wrapper {
    overflow: visible;
    padding: 20px;
  }
  /* تصغير الورقة لتناسب الشاشات الصغيرة (للعرض فقط) */
  .cv-page {
    transform: scale(0.6);
    transform-origin: top center;
    margin-bottom: -120mm; /* تعويض المسافة المفقودة بالسكيل */
  }
}
@media (max-width: 600px) {
  .cv-page {
    transform: scale(0.45);
    margin-bottom: -160mm;
  }
}
