:root{
  --bg:#f4f8fb;
  --card:#ffffff;
  --accent:#155eff;
  --muted:#6b7280;
  --shadow: 0 10px 30px rgba(16,24,40,0.08);
  --radius:12px;
  --toolbar-w:200px;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0;font-family:Inter,system-ui,-apple-system,"Segoe UI",Roboto,Arial}
.app{min-height:100%;background:linear-gradient(180deg,var(--bg),#eef6ff);display:flex;flex-direction:column}

/* topbar */
.topbar{display:flex;justify-content:space-between;align-items:center;padding:14px 22px;background:linear-gradient(90deg,#ffffffaa,#eaf6ff);border-bottom:1px solid #eef6ff}
.brand{font-weight:800;color:var(--accent);font-size:20px}
.subtitle{color:var(--muted);font-size:13px}

/* layout */
.container{display:flex;gap:20px;align-items:flex-start;max-width:1200px;margin:22px auto;padding:0 16px;width:100%}

.left-panel h3{margin:0 0 10px}
.thumb-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.thumb{border-radius:10px;overflow:hidden;border:1px solid #e8f6ff;cursor:pointer;transition:transform .22s,box-shadow .22s}
.thumb img{width:100%;height:96px;object-fit:cover;display:block}
.thumb .tmeta{padding:8px;font-size:13px;color:#0f172a}
.thumb:hover{transform:translateY(-6px);box-shadow:0 14px 36px rgba(16,24,40,0.12)}

/* editor */
.card{background:var(--card);border-radius:12px;box-shadow:var(--shadow);padding:14px;flex:1;min-height:680px}
.editor-area{position:relative;display:flex;flex-direction:column}
.editor-top{display:flex;justify-content:space-between;align-items:center;padding-bottom:10px;border-bottom:1px solid #f0f6ff;margin-bottom:12px}
.controls{display:flex;gap:8px;align-items:center}
.file-label input{display:none}
.file-label{padding:8px 12px;border-radius:8px;border:1px solid #e6f0ff;cursor:pointer;background:#fff}

/* Enhanced left toolbar with new sections */
.left-toolbar {
  position: sticky;
  top: 40px;
  align-self: flex-start;
  margin-left:-9px;
  width: var(--toolbar-w);
  background: linear-gradient(180deg, #fff, #fbfdff);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 26px rgba(12,24,40,0.06);
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 10;
  max-height: 80vh;
  overflow-y: auto;
}

.left-toolbar.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Tool sections */
.tool-section {
  border-bottom: 1px solid #f0f6ff;
  padding-bottom: 12px;
}

.tool-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Enhanced heading buttons */
.headings-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.heading-btn {
  flex: 1;
  padding: 8px 4px;
  border-radius: 6px;
  border: 1px solid #e6eefb;
  background: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
  min-width: 0;
}

.heading-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Text button */
.btn-text {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #e6eefb;
  background: linear-gradient(180deg, #fff, #f8fbff);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.btn-text:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* toolbar rows and elements */
.tool-row {
  display: flex;
  gap: 8px;
  flex-direction: column;
}

.left-toolbar button {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #e6eefb;
  background: white;
  cursor: pointer;
  transition: all 0.15s ease;
}

.left-toolbar button:hover {
  background: #f8fbff;
  border-color: var(--accent);
}

.left-toolbar input[type=color] {
  width: 36px;
  height: 36px;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 6px;
}

.left-toolbar select {
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #e6eefb;
  background: #fff;
}

/* Editor background */
#editor-container {
  background: #2b2b2b;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 0;
  min-height: 100vh;
  overflow: auto;
}

/* Actual CV Page (A4) */
.template-root {
  width: 794px;
  min-height: 1123px;
  height: auto;
  max-height: none;
  overflow: hidden; /* Prevent content from spilling outside */
  box-sizing: border-box;
  background: #fff;
  margin: 0 auto;
  padding: 24px;
  position: relative;
}

/* editable content inside template-root */
.template-root [data-editable] {
  display: block;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

/* Enhanced draggable elements */
.draggable {
  cursor: move;
  transition: box-shadow .12s ease, transform .12s ease;
  border: 2px dashed transparent;
}

.draggable:hover {
  border-color: rgba(21,94,255,0.3);
}

.draggable.dragging {
  box-shadow: 0 18px 40px rgba(16,24,40,0.18);
  transform: scale(1.02);
  z-index: 1000;
  border-color: var(--accent);
}

/* Enhanced editable elements */
.editable {
  outline: 1px dashed transparent;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.editable:focus {
  outline: 2px solid rgba(21,94,255,0.5);
  background: rgba(21,94,255,0.05);
}

.editable:hover:not(:focus) {
  outline: 1px dashed rgba(21,94,255,0.3);
  background: rgba(21,94,255,0.02);
}

/* selected element */
.selected {
  outline: 3px solid rgba(21,94,255,0.4);
  box-shadow: 0 8px 20px rgba(21,94,255,0.1);
}

/* Enhanced heading styles */
.heading-element {
  font-family: Inter, sans-serif;
  line-height: 1.2;
  color: #1a1a1a;
  margin: 0;
}

.text-element {
  font-family: Inter, sans-serif;
  line-height: 1.5;
  color: #333;
  margin: 0;
}

.template-root * {
  max-width: 100%;
  box-sizing: border-box;
}

.template-root h1,
.template-root h2,
.template-root h3,
.template-root h4,
.template-root h5,
.template-root h6,
.template-root p {
  overflow-wrap: break-word;
  word-break: break-word;
  word-wrap: break-word;
  hyphens: auto;
  margin: 0 0 10px 0;
  max-width: 100%;
}

/* Enhanced text wrapping for all editable elements */
.template-root [data-editable] {
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  word-wrap: break-word !important;
  hyphens: auto;
  white-space: pre-wrap;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* copy paste helper */
.muted{color:var(--muted);font-size:13px;margin-top:8px}
.small{font-size:12px}

/* Button styles */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #e6eefb;
  background: white;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: #f8fbff;
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: #0d4ed1;
}

.btn.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.subtle:hover {
  background: #f8fbff;
  color: var(--accent);
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
  /* Mobile layout adjustments */
  .app {
    min-height: 100vh;
  }
  
  .topbar {
    padding: 12px 16px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
  
  .brand {
    font-size: 18px;
  }
  
  .subtitle {
    font-size: 12px;
  }
  
  .container {
    flex-direction: column;
    padding: 8px;
    gap: 15px;
    margin: 8px auto;
  }
  
  /* Mobile template gallery */
  .left-panel {
    width: 100%;
    order: 1;
  }
  
  #templates-list {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 8px;
  }
  
  #templates-list .thumb {
    max-width: none;
  }
  
  /* Mobile editor area */
  .editor-area {
    order: 2;
    min-height: auto;
  }
  
  .editor-top {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  
  .controls {
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }
  
  .controls button,
  .controls .file-label {
    flex: 1;
    min-width: 80px;
    font-size: 12px;
    padding: 6px 8px;
  }
  
  /* Mobile toolbar */
  .left-toolbar {
    position: relative !important;
    order: 3;
    width: 100%;
    margin-left: 0;
    top: auto;
    max-height: none;
    overflow-y: visible;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    margin-bottom: 15px;
  }
  
  .left-toolbar.visible {
    transform: none;
  }
  
  /* Mobile editor container */
  #editor-container {
    padding: 20px 0;
    min-height: 60vh;
  }
  
  .template-root {
    width: 100%;
    min-width: 280px;
    max-width: 100%;
    min-height: auto;
    padding: 16px;
    margin: 0;
    box-sizing: border-box;
  }
  
  /* Mobile-specific template adjustments */
  .template-root div[style*="display: flex"] {
    flex-direction: column !important;
    gap: 15px !important;
  }
  
  .template-root [style*="flex: 2"],
  .template-root [style*="flex: 1"] {
    flex: 1 !important;
  }
  
  /* Mobile photo adjustments */
  .template-photo {
    width: 60px !important;
    height: 60px !important;
    font-size: 9px !important;
  }
  
  /* Mobile text sizing */
  .template-root [data-editable] {
    font-size: 12px !important;
    line-height: 1.4 !important;
    padding: 4px !important;
  }
  
  .template-root [style*="font-size: 36px"],
  .template-root [style*="font-size: 42px"] {
    font-size: 24px !important;
  }
  
  .template-root [style*="font-size: 28px"] {
    font-size: 20px !important;
  }
  
  .template-root [style*="font-size: 20px"],
  .template-root [style*="font-size: 22px"] {
    font-size: 16px !important;
  }
  
  .template-root [style*="font-size: 18px"] {
    font-size: 14px !important;
  }
  
  .template-root [style*="font-size: 16px"] {
    font-size: 13px !important;
  }
  
  .template-root [style*="font-size: 14px"] {
    font-size: 12px !important;
  }
  
  /* Mobile toolbar sections */
  .tool-section {
    padding-bottom: 10px;
  }
  
  .headings-row {
    gap: 4px;
  }
  
  .heading-btn {
    padding: 6px 2px;
    font-size: 11px;
  }
  
  .btn-text {
    padding: 8px;
    font-size: 12px;
  }
  
  /* Mobile touch targets */
  .draggable {
    min-height: 44px;
    min-width: 44px;
  }
  
  .editable:focus {
    outline: 3px solid rgba(21,94,255,0.5);
    outline-offset: 2px;
  }
  
  /* Mobile-specific template overrides */
  .template-root [style*="background: linear-gradient"] {
    padding: 15px !important;
  }
  
  .template-root [style*="margin-bottom: 30px"] {
    margin-bottom: 20px !important;
  }
  
  .template-root [style*="margin-bottom: 25px"] {
    margin-bottom: 15px !important;
  }
  
  .template-root [style*="margin-bottom: 20px"] {
    margin-bottom: 12px !important;
  }
}

/* Tablet responsive design */
@media (max-width: 1024px) and (min-width: 769px) {
  .container {
    max-width: 100%;
    padding: 16px;
  }
  
  .left-toolbar {
    width: 160px;
  }
  
  .template-root {
    width: 90%;
    max-width: 700px;
  }
  
  #templates-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

.hidden {
  display: none !important;
}

/* Templates gallery center layout */
#templates-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 24px;
  justify-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px;
}

#templates-list .thumb {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
}

#templates-list .thumb:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.12);
}

#templates-list .thumb img {
  width: 100%;
  height: auto;
  display: block;
}

#templates-list .tmeta {
  padding: 14px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  color: #0a2540;
  background: linear-gradient(90deg, #f8fbff, #ffffff);
  border-top: 1px solid #e6eefb;
}
/* Accent Color Options */
.accent-color-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.accent-color-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.accent-color-option:hover {
  transform: scale(1.1);
  border-color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.accent-color-option.accent-active {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 3px rgba(21,94,255,0.3);
}

.accent-remove-btn {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 12px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s ease;
}

.accent-remove-btn:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.accent-remove-btn.accent-active {
  background: #ef4444;
  color: white;
  border-color: #dc2626;
}
