/* ============================================================
   1. Custom Properties
   ============================================================ */
:root {
  --color-brand:        #1e3a5f;
  --color-brand-dark:   #122840;
  --color-brand-mid:    #2d5186;
  --color-accent:       #2b7de9;
  --color-accent-light: #e8f2fd;

  --color-surface:      #f8fafc;
  --color-card:         #ffffff;
  --color-border:       #e2e8f0;
  --color-border-dark:  #cbd5e1;

  --color-text:         #1e293b;
  --color-text-muted:   #64748b;
  --color-text-light:   #94a3b8;

  --color-error-bg:     #fef2f2;
  --color-error-text:   #b91c1c;
  --color-success-bg:   #f0fdf4;
  --color-success-text: #166534;

  --color-delete-bg:    #fef2f2;
  --color-delete-text:  #b91c1c;

  --color-tag-bg:       #eff6ff;
  --color-tag-border:   #bfdbfe;
  --color-tag-text:     #1e40af;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Fira Code", Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
}

/* ============================================================
   2. Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0;
  background: var(--color-surface);
  color: var(--color-text);
}

/* ============================================================
   3. Layout
   ============================================================ */

/* Header */
header {
  background: var(--color-brand);
  color: #fff;
  padding: 0 32px;
  height: 56px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-brand {
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-brand:hover {
  color: #e0eeff;
  text-decoration: none;
}

header nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

header nav a,
header nav button {
  color: #c8d9f0;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}
header nav a:hover,
header nav button:hover {
  color: #fff;
  background: rgba(255,255,255,.12);
  text-decoration: none;
}

.header-cv-label {
  color: #94b8e0;
  font-size: 0.8rem;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 10px;
  border-right: 1px solid rgba(255,255,255,.15);
  margin-right: 4px;
}

.nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.nav-dropdown-trigger {
  color: #c8d9f0;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: default;
  transition: color .15s, background .15s;
  user-select: none;
}
.nav-dropdown:hover .nav-dropdown-trigger,
.nav-dropdown:focus-within .nav-dropdown-trigger {
  color: #fff;
  background: rgba(255,255,255,.12);
}
.nav-dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 120px;
  z-index: 100;
}
.nav-dropdown-menu a {
  display: block;
  padding: 0.45rem 0.9rem;
  color: var(--color-text);
  font-size: 0.9rem;
  white-space: nowrap;
  text-decoration: none;
  border-radius: 0;
}
.nav-dropdown-menu a:hover {
  background: var(--color-accent-light);
  color: var(--color-accent);
}
.drag-handle {
  cursor: grab;
  color: #bbb;
  font-size: 1.2rem;
  padding: 0 6px 0 0;
  user-select: none;
  flex-shrink: 0;
}
.sortable-entry.dragging { opacity: 0.4; }
.sortable-entry.drag-over { border-top: 2px solid var(--color-accent); }

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu,
.nav-dropdown.open .nav-dropdown-menu {
  display: block;
}

/* Main content area — default (no sidebar) */
main {
  max-width: 860px;
  margin: 32px auto;
  padding: 0 24px;
}

/* Profile layout override */
.profile-main {
  max-width: none;
  padding: 0;
  margin: 0;
}

/* Profile layout: sidebar + content */
.profile-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 32px;
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 24px;
  align-items: start;
}

/* ============================================================
   4. Cards
   ============================================================ */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.card + .card {
  margin-top: 20px;
}

/* Section heading inside a card */
.card-heading {
  margin: 0 0 20px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Section anchor/id for sidebar links */
.profile-section {
  scroll-margin-top: 72px;
}

/* ============================================================
   5. Typography
   ============================================================ */
h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin: 0 0 16px; }
h2 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; margin: 0 0 14px; }
h3 { font-size: 1rem;    font-weight: 600; line-height: 1.4; margin: 0 0 10px; color: var(--color-text-muted); }

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: var(--font-mono); font-size: 0.875em; }

/* ============================================================
   6. Forms
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 5px;
  color: var(--color-text);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 3px 0 0;
}

input[type=text],
input[type=password],
input[type=email],
input[type=url],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--color-border-dark);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}

input[type=text]::placeholder,
input[type=password]::placeholder,
input[type=email]::placeholder,
input[type=url]::placeholder,
textarea::placeholder {
  color: var(--color-text-light);
}

input[type=text]:focus,
input[type=password]:focus,
input[type=email]:focus,
input[type=url]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(43,125,233,.18);
}

input[type=text]:invalid:not(:placeholder-shown),
input[type=email]:invalid:not(:placeholder-shown),
input[type=url]:invalid:not(:placeholder-shown) {
  border-color: var(--color-error-text);
  box-shadow: 0 0 0 3px rgba(185,28,28,.12);
}

/* Select custom arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

/* Monospaced textarea for templates and bibtex */
textarea.code-editor {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Checkbox row */
.form-check {
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-check input[type=checkbox] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--color-accent);
}
.form-check label {
  margin: 0;
  font-weight: normal;
  cursor: pointer;
}

/* Inline divider ("or") */
.form-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
}
.form-divider hr {
  flex: 1;
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 0;
}
.form-divider span {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

/* File input */
input[type=file] {
  padding: 8px 0;
  border: none;
  background: transparent;
  width: 100%;
}

/* ============================================================
   7. Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font-sans);
  text-decoration: none;
  line-height: 1.2;
  transition: background .15s, box-shadow .15s, border-color .15s, transform .1s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}
.btn-primary:hover {
  background: var(--color-brand-dark);
  border-color: var(--color-brand-dark);
  box-shadow: 0 2px 8px rgba(30,58,95,.3);
  color: #fff;
}

.btn-secondary {
  background: #fff;
  color: var(--color-text);
  border-color: var(--color-border-dark);
}
.btn-secondary:hover {
  background: var(--color-surface);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-danger {
  background: var(--color-delete-bg);
  color: var(--color-delete-text);
  border-color: #fecaca;
}
.btn-danger:hover {
  background: #fee2e2;
  border-color: var(--color-delete-text);
  color: var(--color-delete-text);
}

/* Small variant */
.btn-sm {
  padding: 5px 12px;
  font-size: 0.8125rem;
}

/* Full-width */
.btn-full {
  width: 100%;
  justify-content: center;
}

/* Google OAuth button */
.btn-google {
  background: #fff;
  color: #374151;
  border-color: var(--color-border-dark);
  justify-content: center;
}
.btn-google:hover {
  background: #f9fafb;
  border-color: var(--color-accent);
  color: var(--color-text);
}

/* ============================================================
   8. Messages / Alerts
   ============================================================ */
.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
}
.messages li {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 4px solid;
}
.messages .error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-color: var(--color-error-text);
}
.messages .success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-color: var(--color-success-text);
}

/* ============================================================
   9. Profile-specific components
   ============================================================ */

/* Section block */
.section {
  margin-top: 24px;
}
.section h2 {
  font-size: 1.0625rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 8px;
  margin-bottom: 14px;
}

/* Subsection within a card */
.subsection {
  margin-top: 16px;
  border-top: 1px solid #f0f4f8;
  padding-top: 14px;
}
.subsection h3 {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--color-text-light);
}

/* Entry row */
.entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9375rem;
}
.entry:last-of-type {
  border-bottom: none;
}

/* Tags */
.tag {
  display: inline-block;
  background: var(--color-tag-bg);
  border: 1px solid var(--color-tag-border);
  color: var(--color-tag-text);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 0.78rem;
  font-weight: 500;
  margin: 1px 2px;
}

/* Hints / secondary text */
.hint {
  color: var(--color-text-muted);
  font-size: 0.84rem;
  margin: 2px 0 5px;
  line-height: 1.5;
}

/* Empty state */
.empty {
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.9rem;
  padding: 8px 0;
}

/* "Add ..." details/summary disclosure */
details.sub-add {
  margin-top: 12px;
}
details summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
}
details summary::-webkit-details-marker {
  display: none;
}
details.sub-add > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-accent);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 4px 0;
}
details.sub-add > summary::before {
  content: "+";
  font-size: 1.1em;
  font-weight: 700;
}
details.sub-add[open] > summary::before {
  content: "−";
}
details.sub-add > summary:hover {
  color: var(--color-brand);
}

/* Edit panel inside a details */
.edit-panel {
  margin-top: 10px;
  padding: 16px;
  background: #f8faff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

/* ============================================================
   10. Profile sidebar nav
   ============================================================ */
.profile-sidebar {
  position: sticky;
  top: 72px;
}

.profile-sidebar nav {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px 0;
  box-shadow: var(--shadow-sm);
}

.profile-sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-heading {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-light);
  padding: 8px 16px 4px;
  margin-top: 4px;
}

.profile-sidebar nav li a {
  display: block;
  padding: 7px 16px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color .12s, background .12s, border-color .12s;
}
.profile-sidebar nav li a:hover {
  color: var(--color-accent);
  background: var(--color-accent-light);
  border-left-color: var(--color-accent);
  text-decoration: none;
}

.sidebar-tools {
  padding: 12px 14px 8px;
  border-top: 1px solid var(--color-border);
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-tools .btn {
  font-size: 0.8125rem;
  padding: 6px 10px;
  width: 100%;
  justify-content: center;
}

/* ============================================================
   11. CV list
   ============================================================ */
.cv-item {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 12px;
  background: var(--color-card);
  transition: box-shadow .15s;
}
.cv-item:hover {
  box-shadow: var(--shadow-sm);
}
.cv-item--active {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}
.cv-item-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.cv-item-label {
  font-weight: 600;
  font-size: 1.0625rem;
  flex: 1;
}
.cv-item-badge {
  color: var(--color-accent);
  font-size: 0.78rem;
  font-weight: 600;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  border-radius: 20px;
  padding: 1px 8px;
}
.cv-item-date {
  color: var(--color-text-muted);
  font-size: 0.84rem;
}
.cv-item-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.cv-item-actions input[type=text] {
  width: 200px;
  padding: 6px 10px;
  font-size: 0.875rem;
}

/* Create CV form at bottom of cv_list */
.cv-create-form {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}
.cv-create-form h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}
.cv-create-form .form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.cv-create-form .form-row input[type=text] {
  flex: 1;
  max-width: 280px;
}

/* ============================================================
   12. Templates table
   ============================================================ */
.templates-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.templates-table thead th {
  text-align: left;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
}
.templates-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
}
.templates-table tbody tr:last-child {
  border-bottom: none;
}
.templates-table tbody tr:hover {
  background: var(--color-surface);
}
.templates-table td {
  padding: 12px 14px;
  vertical-align: middle;
}
.templates-table .actions-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ============================================================
   13. Landing page
   ============================================================ */
.hero {
  text-align: center;
  padding: 56px 32px 48px;
}
.hero-eyebrow {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: 12px;
}
.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--color-text);
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}
.hero-subtitle {
  font-size: 1.0625rem;
  color: var(--color-text-muted);
  max-width: 480px;
  margin: 0 auto 36px;
  line-height: 1.6;
}
.hero-ctas {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 24px;
}
.feature-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.feature-icon {
  font-size: 1.75rem;
  margin-bottom: 10px;
}
.feature-title {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.feature-desc {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.55;
  margin: 0;
}

/* ============================================================
   14. Utilities (preserve existing class names)
   ============================================================ */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.full  { grid-column: 1 / -1; }

.sub-add { margin-top: 10px; }

.text-muted  { color: var(--color-text-muted); }
.text-sm     { font-size: 0.875rem; }
.text-center { text-align: center; }

/* Auth card constraint */
.auth-card {
  max-width: 420px;
  margin: 0 auto;
}

/* ============================================================
   15. Responsive
   ============================================================ */
@media (max-width: 900px) {
  .profile-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .profile-sidebar {
    position: static;
  }
  .profile-sidebar nav {
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    gap: 4px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
  }
  .profile-sidebar nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .profile-sidebar nav li a {
    padding: 5px 10px;
    border-left: none;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 0.8rem;
  }
  .sidebar-heading { display: none; }
  .sidebar-tools {
    flex-direction: row;
    border-top: none;
    margin-top: 0;
    padding: 0;
  }
  .sidebar-tools .btn {
    width: auto;
  }
}

@media (max-width: 640px) {
  main { padding: 0 16px; margin: 20px auto; }
  .card { padding: 20px 18px; }
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
  .full  { grid-column: 1; }
  header { padding: 0 16px; }
  .hero-title { font-size: 1.75rem; }
  .features-grid { grid-template-columns: 1fr; }
  .cv-item-actions { flex-direction: column; align-items: flex-start; }
  .cv-item-actions input[type=text] { width: 100%; }
  .cv-create-form .form-row { flex-direction: column; }
  .cv-create-form .form-row input[type=text] { max-width: 100%; }
}
