/* ---------- Tokens ---------- */
:root {
  --paper: #F3F1EA;
  --panel: #FFFFFF;
  --ink: #201F1B;
  --ink-soft: #55534A;
  --line: #DBD5C6;
  --petrol: #24545A;
  --petrol-dark: #17383C;
  --ochre: #B4802C;
  --ochre-soft: #E9D9B8;
  --danger: #A23B33;
  --radius-s: 3px;
  --radius-m: 6px;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font-family: inherit; font-size: inherit; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--petrol);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Topbar ---------- */
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--petrol-dark);
  color: #F1EFE7;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 30px;
  height: 30px;
  border: 1px solid var(--ochre-soft);
  border-radius: var(--radius-s);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--ochre-soft);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.2px;
}

.topbar-actions { display: flex; align-items: center; gap: 14px; }

.template-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #D8D4C6;
}

.template-picker select {
  background: #1E4448;
  color: #F1EFE7;
  border: 1px solid #366266;
  border-radius: var(--radius-s);
  padding: 6px 10px;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-small { padding: 6px 12px; font-size: 12.5px; }

.btn-primary {
  background: var(--ochre);
  color: #241804;
  border-color: var(--ochre);
}
.btn-primary:hover { background: #C89239; }

.btn-ghost {
  background: transparent;
  color: #E4E0D2;
  border-color: #3E6C70;
}
.btn-ghost:hover { background: #2A5458; }

.btn-secondary {
  background: transparent;
  color: var(--petrol-dark);
  border-color: var(--petrol);
}
.btn-secondary:hover { background: #E7EFEE; }

/* ---------- Workspace layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  min-height: calc(100vh - 60px);
}

.form-pane {
  padding: 28px 28px 80px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  border-right: 1px solid var(--line);
}

.form-section {
  margin-bottom: 30px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.form-section:last-child { border-bottom: none; }

.form-section h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--petrol-dark);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 { margin: 0; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-grid .field { margin-bottom: 0; }

.field label {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}

.field input, .field textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 9px 11px;
  background: var(--panel);
  color: var(--ink);
}
.field input:focus, .field textarea:focus { border-color: var(--petrol); }
.field textarea { resize: vertical; font-family: var(--font-body); }

/* photo uploader */
.photo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }

.photo-preview {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  color: var(--ink-soft);
  overflow: hidden;
  background: var(--panel);
  flex-shrink: 0;
  text-align: center;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.photo-controls { display: flex; flex-direction: column; gap: 8px; }

/* repeatable entries */
.repeat-list { display: flex; flex-direction: column; gap: 16px; }

.repeat-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 14px;
  background: var(--panel);
  position: relative;
}

.repeat-item .field-grid { margin-bottom: 12px; }
.repeat-item .field:last-child { margin-bottom: 0; }

.repeat-item-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.repeat-item-remove:hover { text-decoration: underline; }

.empty-hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-style: italic;
}

/* tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #EDE7D6;
  border: 1px solid var(--ochre-soft);
  color: var(--petrol-dark);
  border-radius: 999px;
  padding: 5px 12px 5px 14px;
  font-size: 12.5px;
  font-weight: 600;
}

.tag button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

/* ---------- Preview pane ---------- */
.preview-pane {
  background: #E7E3D6;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  display: flex;
  justify-content: center;
  padding: 40px 30px;
}

.preview-scale-wrap { width: 100%; max-width: 780px; }

.cv-page {
  width: 100%;
  min-height: 1050px;
  background: #ffffff;
  box-shadow: 0 6px 24px rgba(20, 24, 22, 0.16);
  font-family: var(--font-body);
  color: var(--ink);
}

/* Empty state inside preview */
.cv-empty {
  height: 100%;
  min-height: 1000px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #A6A18E;
  font-family: var(--font-display);
  font-size: 16px;
  text-align: center;
  padding: 60px;
}

/* ===================================================== */
/* Template: Classico                                     */
/* ===================================================== */
.cv-classico { padding: 56px 60px; }

.cv-classico .cv-header {
  text-align: center;
  border-bottom: 2px solid var(--petrol-dark);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.cv-classico .cv-name {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--petrol-dark);
}

.cv-classico .cv-title {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  letter-spacing: 0.3px;
}

.cv-classico .cv-contacts {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 12px;
  color: var(--ink-soft);
}

.cv-classico .cv-section { margin-bottom: 20px; }

.cv-classico .cv-section-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--petrol-dark);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin: 0 0 10px;
}

.cv-classico .cv-summary { font-size: 13px; line-height: 1.65; color: var(--ink); }

.cv-classico .cv-entry { margin-bottom: 14px; }
.cv-classico .cv-entry:last-child { margin-bottom: 0; }

.cv-classico .cv-entry-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
}

.cv-classico .cv-entry-role { font-weight: 700; }
.cv-classico .cv-entry-org { font-style: italic; color: var(--ink-soft); }
.cv-classico .cv-entry-period { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.cv-classico .cv-entry-desc { font-size: 12.5px; line-height: 1.6; margin-top: 4px; color: var(--ink); }

.cv-classico .cv-tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cv-classico .cv-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 4px 10px;
  font-size: 11.5px;
  color: var(--petrol-dark);
}

.cv-classico .cv-lang-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.cv-classico .cv-lang-row:last-child { margin-bottom: 0; }

/* ===================================================== */
/* Template: Moderno                                      */
/* ===================================================== */
.cv-moderno { padding: 0; }

.cv-moderno .cv-header {
  background: var(--petrol-dark);
  color: #F4F1E8;
  padding: 40px 56px 32px;
  display: flex;
  align-items: center;
  gap: 22px;
}

.cv-moderno .cv-photo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2px solid var(--ochre);
  object-fit: cover;
  flex-shrink: 0;
}

.cv-moderno .cv-name {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px;
}

.cv-moderno .cv-title {
  font-size: 13.5px;
  color: var(--ochre-soft);
  margin: 0 0 10px;
}

.cv-moderno .cv-contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 11.5px;
  color: #CFCBBB;
}

.cv-moderno .cv-body { padding: 30px 56px 50px; }

.cv-moderno .cv-section { margin-bottom: 22px; }

.cv-moderno .cv-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--ochre);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.cv-moderno .cv-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.cv-moderno .cv-summary { font-size: 13px; line-height: 1.65; }

.cv-moderno .cv-entry { margin-bottom: 16px; }
.cv-moderno .cv-entry:last-child { margin-bottom: 0; }

.cv-moderno .cv-entry-top { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.cv-moderno .cv-entry-role { font-weight: 700; color: var(--petrol-dark); }
.cv-moderno .cv-entry-org { color: var(--ink-soft); }
.cv-moderno .cv-entry-period {
  font-size: 11px;
  color: var(--panel);
  background: var(--petrol);
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  height: fit-content;
}
.cv-moderno .cv-entry-desc { font-size: 12.5px; line-height: 1.6; margin-top: 4px; }

.cv-moderno .cv-tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cv-moderno .cv-chip {
  background: #EDE7D6;
  border-radius: var(--radius-s);
  padding: 5px 11px;
  font-size: 11.5px;
  color: var(--petrol-dark);
  font-weight: 600;
}

.cv-moderno .cv-lang-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.cv-moderno .cv-lang-row:last-child { margin-bottom: 0; }

/* ===================================================== */
/* Template: Executivo                                    */
/* ===================================================== */
.cv-executivo {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 1050px;
}

.cv-executivo .cv-sidebar {
  background: var(--paper);
  padding: 44px 26px;
  border-right: 3px solid var(--ochre);
}

.cv-executivo .cv-photo {
  width: 100px;
  height: 100px;
  border-radius: 6px;
  object-fit: cover;
  margin-bottom: 18px;
}

.cv-executivo .cv-name {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--petrol-dark);
  line-height: 1.25;
}

.cv-executivo .cv-title { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 20px; }

.cv-executivo .cv-side-block { margin-bottom: 22px; }

.cv-executivo .cv-side-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ochre);
  margin: 0 0 8px;
}

.cv-executivo .cv-contacts { display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; color: var(--ink-soft); word-break: break-word; }

.cv-executivo .cv-tag-row { display: flex; flex-direction: column; gap: 6px; }
.cv-executivo .cv-chip { font-size: 11.5px; color: var(--ink); }
.cv-executivo .cv-chip::before { content: "-- "; color: var(--ochre); }

.cv-executivo .cv-lang-row { font-size: 11.5px; margin-bottom: 5px; color: var(--ink); }

.cv-executivo .cv-main { padding: 44px 46px; }

.cv-executivo .cv-section { margin-bottom: 22px; }

.cv-executivo .cv-section-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--petrol-dark);
  margin: 0 0 12px;
}

.cv-executivo .cv-summary { font-size: 13px; line-height: 1.65; }

.cv-executivo .cv-entry { margin-bottom: 16px; }
.cv-executivo .cv-entry:last-child { margin-bottom: 0; }
.cv-executivo .cv-entry-top { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.cv-executivo .cv-entry-role { font-weight: 700; }
.cv-executivo .cv-entry-org { color: var(--ink-soft); }
.cv-executivo .cv-entry-period { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; }
.cv-executivo .cv-entry-desc { font-size: 12.5px; line-height: 1.6; margin-top: 4px; }

/* ---------- Print ---------- */
@media print {
  .topbar, .form-pane { display: none !important; }
  .preview-pane {
    background: #fff;
    padding: 0;
    display: block;
    max-height: none;
    overflow: visible;
  }
  .preview-scale-wrap { max-width: none; }
  .cv-page { box-shadow: none; min-height: 0; }
  @page { margin: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .form-pane, .preview-pane { max-height: none; }
  .field-grid { grid-template-columns: 1fr; }
}
