* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px;
  font-size: 1.25rem; font-weight: 700; color: white;
  border-bottom: 1px solid #1e293b;
}
.logo-icon { font-size: 1.5rem; }
.nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 8px;
  color: #94a3b8; text-decoration: none;
  font-size: 0.95rem; font-weight: 500; transition: all 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: white; }
.nav-item.active { background: var(--primary); color: white; }
.nav-item .icon { font-size: 1.1rem; }
.sidebar-footer {
  padding: 16px; border-top: 1px solid #1e293b;
  display: flex; flex-direction: column; gap: 8px;
}
.btn-download {
  display: block; text-align: center;
  background: var(--primary); color: white;
  padding: 12px; border-radius: 8px;
  text-decoration: none; font-weight: 600; font-size: 0.9rem;
}
.btn-download:hover { background: var(--primary-dark); }
.btn-reset {
  display: block; text-align: center;
  color: #94a3b8; font-size: 0.85rem; text-decoration: none; padding: 6px;
}
.btn-reset:hover { color: #f87171; }

/* Main */
.main { margin-left: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  background: white; padding: 20px 32px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.5rem; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }

.content-area {
  display: flex; flex: 1; gap: 0; padding: 24px; overflow: auto;
}
.form-panel {
  flex: 1; max-width: 560px;
  background: white; border-radius: var(--radius);
  padding: 28px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  height: fit-content;
}
.form-panel.hidden { display: none; }
.preview-panel {
  flex: 1; display: flex; justify-content: center; padding-left: 24px;
  overflow: visible;
}

/* Form */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.85rem; font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}
.form-group input, .form-group textarea {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 0.95rem; font-family: inherit; background: #fafafa;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15); background: white;
}
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.form-actions {
  display: flex; gap: 12px; margin-top: 24px;
  padding-top: 20px; border-top: 1px solid var(--border);
}
.btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 12px 24px; border-radius: 8px; font-weight: 600;
  font-size: 0.95rem; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: white; color: var(--text); border: 1px solid var(--border);
  padding: 12px 20px; border-radius: 8px; font-weight: 500;
  text-decoration: none; font-size: 0.95rem; display: inline-flex; align-items: center;
}
.btn-secondary:hover { background: #f8fafc; }
.btn-add {
  background: #f0f9ff; color: var(--primary);
  border: 1px dashed #93c5fd; padding: 10px 16px;
  border-radius: 8px; font-weight: 500; cursor: pointer;
  width: 100%; margin-bottom: 16px;
}
.btn-add:hover { background: #e0f2fe; }
.btn-remove {
  background: none; border: none; color: #ef4444;
  font-size: 0.85rem; cursor: pointer; margin-top: 4px; padding: 4px 0;
}
.btn-remove:hover { text-decoration: underline; }
.repeatable-block {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; margin-bottom: 16px;
}

/* Photo upload */
.photo-upload { margin-bottom: 8px; }
.photo-preview {
  width: 96px; height: 96px; border-radius: 50%;
  object-fit: cover; border: 3px solid var(--primary);
  display: block; margin-bottom: 8px;
}
.upload-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 28px; cursor: pointer; background: #fafafa; transition: all 0.15s;
}
.upload-box:hover { border-color: var(--primary); background: #f0f9ff; }
.upload-box span { font-weight: 600; color: var(--text); }
.upload-box small { color: var(--muted); margin-top: 4px; }

/* Template grid */
.template-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.template-card {
  border: 2px solid var(--border); border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: all 0.15s;
  background: white; display: block; position: relative;
}
.template-card:hover { border-color: #93c5fd; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.template-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.25);
  background: #f0f7ff;
}
.template-card.selected::after {
  content: "✓ Selected";
  position: absolute; top: 8px; left: 8px;
  background: var(--primary); color: white;
  font-size: 0.7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px; z-index: 2;
}
.template-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.tpl-preview {
  height: 90px; background: #f8fafc; position: relative;
  padding: 12px; display: flex; gap: 8px;
}
.tpl-bar {
  width: 8px; background: var(--tpl-color); border-radius: 4px;
}
.tpl-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.tpl-line { height: 6px; background: #cbd5e1; border-radius: 3px; width: 100%; }
.tpl-line.short { width: 60%; }
.tpl-line.mid { width: 80%; }
.tpl-photo-badge {
  position: absolute; top: 6px; right: 6px;
  background: white; font-size: 0.7rem; padding: 2px 6px;
  border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.tpl-info { padding: 10px 12px; }
.tpl-info strong { display: block; font-size: 0.9rem; }
.tpl-info span { font-size: 0.75rem; color: var(--muted); }

/* CV Preview paper */
.cv-paper {
  width: 100%; max-width: 620px;
  background: white; border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
  padding: 0; min-height: 600px; height: auto; overflow: visible;
  font-size: 0.9rem; line-height: 1.5; overflow: hidden;
}

/* Single column header */
.cv-header {
  padding: 36px 40px 16px; display: flex; gap: 20px; align-items: flex-start;
}
.cv-photo-inline {
  width: 72px; height: 72px; border-radius: 50%;
  object-fit: cover; border: 2px solid #e2e8f0; flex-shrink: 0;
}
.cv-name { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.cv-title { font-size: 1.05rem; font-weight: 500; margin-top: 4px; }
.cv-contact-line { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }
.cv-divider { height: 3px; margin: 0 40px 20px; }

.cv-section { padding: 0 40px 18px; }
.cv-section h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 700; margin-bottom: 10px; padding-bottom: 4px;
  border-bottom: 1px solid #e2e8f0;
}
.cv-item { margin-bottom: 12px; }
.cv-item-header { display: flex; justify-content: space-between; gap: 12px; }
.cv-item-header strong { font-size: 0.95rem; }
.cv-item-header .dates { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.cv-item-sub { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.cv-desc { margin-top: 6px; font-size: 0.88rem; white-space: pre-line; color: #334155; }
.cv-tags { color: #334155; }

/* Sidebar layout preview */
.cv-sidebar-layout { display: flex; min-height: 600px; height: auto; overflow: visible; }
.cv-left {
  width: 200px; padding: 28px 18px; color: white; flex-shrink: 0;
}
.cv-photo {
  width: 100px; height: 100px; border-radius: 50%;
  object-fit: cover; display: block; margin: 0 auto 16px;
  border: 3px solid rgba(255,255,255,0.3);
}
.cv-name-side { font-size: 1.1rem; font-weight: 700; text-align: center; color: white; }
.cv-title-side { font-size: 0.8rem; text-align: center; color: rgba(255,255,255,0.75); margin-top: 4px; margin-bottom: 20px; }
.side-section { margin-top: 20px; }
.side-section h3 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px; color: rgba(255,255,255,0.9); border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 4px;
}
.side-section p { font-size: 0.75rem; color: rgba(255,255,255,0.8); margin-bottom: 3px; line-height: 1.4; }
.cv-right { flex: 1; padding: 28px 28px 28px 24px; }
.cv-right .cv-section { padding: 0 0 16px; }

/* Accent bar */
.accent-bar { position: relative; }
.accent-bar::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 6px; background: currentColor;
}

/* Responsive */
@media (max-width: 1100px) {
  .content-area { flex-direction: column; }
  .preview-panel { padding-left: 0; margin-top: 24px; }
  .form-panel { max-width: 100%; }
  .template-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .logo span:last-child, .nav-item span:not(.icon), .sidebar-footer .btn-reset { display: none; }
  .logo { justify-content: center; padding: 20px 0; }
  .nav-item { justify-content: center; padding: 14px; }
  .main { margin-left: 64px; }
  .btn-download { font-size: 0.75rem; padding: 10px 4px; }
  .form-row { flex-direction: column; gap: 0; }
  .template-grid { grid-template-columns: 1fr; }
}

/* Justified text for profile & declaration */
.justified {
  text-align: justify;
  text-justify: inter-word;
}

/* Ensure form panel and actions are fully visible */
.content-area {
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}
.form-panel {
  max-height: none;
  overflow: visible;
}
.form-actions {
  position: sticky;
  bottom: 0;
  background: white;
  z-index: 5;
  padding-bottom: 8px;
}
.sidebar {
  overflow-y: auto;
}
.nav {
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

.btn-docx {
  background: #0f766e !important;
  margin-top: 6px;
}
.btn-docx:hover {
  background: #0d9488 !important;
}
.cv-paper {
  height: auto !important;
  overflow: visible !important;
}
.preview-panel {
  align-items: flex-start;
}
