/* =============================================================
   ResumeCraft — components.css
   Reusable UI components: buttons, inputs, chips, modals, toasts…
   ============================================================= */

/* ---------------------------------------------------------------
   BUTTONS
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-5);
  height: 40px;
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-snug);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background-color var(--t-fast),
    border-color var(--t-fast),
    color var(--t-fast),
    box-shadow var(--t-fast),
    transform var(--t-fast),
    opacity var(--t-fast);
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-md);
}
.btn-primary:active { background: var(--accent-press); }

/* Secondary */
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

/* Destructive */
.btn-destructive {
  background: var(--error);
  color: white;
  border-color: var(--error);
}
.btn-destructive:hover { background: #B91C1C; }

/* Sizes */
.btn-sm {
  height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-13);
  border-radius: var(--r-sm);
}
.btn-lg {
  height: 48px;
  padding: 0 var(--sp-7);
  font-size: var(--fs-15);
  border-radius: var(--r-md);
}
.btn-xl {
  height: 56px;
  padding: 0 var(--sp-8);
  font-size: var(--fs-16);
  border-radius: var(--r-md);
}

/* Arrow button effect */
.btn-arrow {
  display: inline-block;
  transition: transform var(--t-base);
}
.btn:hover .btn-arrow { transform: translateX(3px); }

/* Icon-only */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.btn-icon.btn-sm { width: 28px; height: 28px; }

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

/* Loading state */
.btn.is-loading { pointer-events: none; }
.btn.is-loading .btn-label { opacity: 0; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ---------------------------------------------------------------
   FORM ELEMENTS
   --------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

label, .label {
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.label-required::after {
  content: '*';
  color: var(--error);
  margin-left: 1px;
}

.form-hint {
  font-size: var(--fs-12);
  color: var(--text-3);
  line-height: 1.4;
}

.form-error {
  font-size: var(--fs-12);
  color: var(--error);
  display: flex;
  align-items: center;
  gap: 4px;
}
.form-error::before { content: '⚠'; font-size: 11px; }

/* Input */
.input, .textarea, .select {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-14);
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-3);
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.input.is-error, .textarea.is-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}

.input.is-success { border-color: var(--success); }

.textarea {
  height: auto;
  min-height: 100px;
  padding: var(--sp-3);
  resize: vertical;
  line-height: var(--lh-relaxed);
}

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

/* Character counter */
.char-counter {
  font-size: var(--fs-12);
  color: var(--text-3);
  text-align: right;
  transition: color var(--t-fast);
}
.char-counter.near-limit { color: var(--warning); }
.char-counter.at-limit   { color: var(--error); }

/* ---------------------------------------------------------------
   SKILL CHIPS
   --------------------------------------------------------------- */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  min-height: 40px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  color: var(--accent-text);
  background: var(--accent-subtle);
  border: 1px solid #BFDBFE;
  border-radius: var(--r-full);
  line-height: 1;
  transition: background var(--t-fast);
}

.chip-remove {
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(37,99,235,0.15);
  color: var(--accent-text);
  font-size: 10px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
  border: none;
  padding: 0;
}
.chip-remove:hover {
  background: var(--accent);
  color: white;
}

.chip-input-row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.chip-input-row .input {
  flex: 1;
}

/* ---------------------------------------------------------------
   SECTION CARD (Builder)
   --------------------------------------------------------------- */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}

.section-card.is-open {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08), var(--shadow-sm);
}

.section-card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}
.section-card-header:hover { background: var(--bg-subtle); }
.section-card.is-open .section-card-header { background: var(--accent-subtle); }

.section-card-icon {
  width: 32px; height: 32px;
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--t-base);
}
.section-card.is-open .section-card-icon { background: rgba(37,99,235,0.12); }

.section-card-title {
  flex: 1;
  font-size: var(--fs-14);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.section-card-meta {
  font-size: var(--fs-12);
  color: var(--text-3);
}

.section-card-chevron {
  color: var(--text-3);
  transition: transform var(--t-base);
  flex-shrink: 0;
}
.section-card.is-open .section-card-chevron { transform: rotate(180deg); }

.section-card-body {
  padding: var(--sp-5);
  border-top: 1px solid var(--border);
  display: none;
}
.section-card.is-open .section-card-body { display: block; }

/* ---------------------------------------------------------------
   ENTRY CARD (Experience, Education…)
   --------------------------------------------------------------- */
.entry-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  position: relative;
}
.entry-card:last-child { margin-bottom: 0; }

.entry-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.entry-card-title {
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.entry-card-subtitle {
  font-size: var(--fs-12);
  color: var(--text-2);
  margin-top: 2px;
}

.entry-card-actions {
  display: flex;
  gap: var(--sp-1);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   EMPTY STATE
   --------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-6);
  color: var(--text-3);
}

.empty-state-icon {
  font-size: 28px;
  margin-bottom: var(--sp-3);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  color: var(--text-2);
  margin-bottom: var(--sp-2);
}

.empty-state-text {
  font-size: var(--fs-13);
  color: var(--text-3);
  line-height: var(--lh-relaxed);
  max-width: 28ch;
  margin-inline: auto;
  margin-bottom: var(--sp-4);
}

/* ---------------------------------------------------------------
   TOAST
   --------------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--text);
  color: var(--text-inverse);
  border-radius: var(--r-lg);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 200ms ease both;
  min-width: 200px;
  max-width: 360px;
}
.toast.toast-success { background: #14532D; }
.toast.toast-error   { background: #7F1D1D; }
.toast.toast-info    { background: var(--accent-press); }
.toast.is-exiting    { animation: toastOut 200ms ease forwards; }

/* ---------------------------------------------------------------
   MODAL
   --------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  animation: fadeInFast var(--t-fast) ease;
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2xl);
  max-width: 440px;
  width: 100%;
  padding: var(--sp-8);
  animation: fadeIn var(--t-base) ease;
}

.modal-title {
  font-size: var(--fs-18);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-2);
}

.modal-text {
  font-size: var(--fs-14);
  color: var(--text-2);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--sp-6);
}

.modal-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
}

/* ---------------------------------------------------------------
   FAQ ACCORDION
   --------------------------------------------------------------- */
.faq-list { display: flex; flex-direction: column; gap: var(--sp-1); }

.faq-item {
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.faq-question {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  font-size: var(--fs-15);
  font-weight: var(--fw-medium);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast);
  background: none;
  border: none;
}
.faq-question:hover { background: var(--bg-subtle); }
.faq-question[aria-expanded="true"] { color: var(--accent); }

.faq-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: transform var(--t-base), color var(--t-base);
}
.faq-question[aria-expanded="true"] .faq-icon {
  transform: rotate(45deg);
  color: var(--accent);
}

.faq-answer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--t-slow) ease;
}
.faq-answer.is-open { grid-template-rows: 1fr; }

.faq-answer-inner {
  overflow: hidden;
  font-size: var(--fs-14);
  color: var(--text-2);
  line-height: var(--lh-relaxed);
}

.faq-answer-content {
  padding: 0 var(--sp-6) var(--sp-5);
}

/* ---------------------------------------------------------------
   TABS
   --------------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
}

.tab-btn {
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast);
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------------------------------------------------------------
   TEMPLATE SELECTOR CARDS (in builder)
   --------------------------------------------------------------- */
.template-card {
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  cursor: pointer;
  transition: border-color var(--t-base), box-shadow var(--t-base);
  background: var(--surface);
  text-align: center;
}
.template-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.template-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.template-card-preview {
  aspect-ratio: 210 / 297;
  background: var(--bg-subtle);
  border-radius: var(--r-sm);
  margin-bottom: var(--sp-2);
  overflow: hidden;
  position: relative;
}

.template-card-name {
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  color: var(--text-2);
}
.template-card.is-active .template-card-name { color: var(--accent-text); }

/* ---------------------------------------------------------------
   SAVE STATUS INDICATOR
   --------------------------------------------------------------- */
.save-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-12);
  color: var(--text-3);
  transition: color var(--t-slow);
}

.save-status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  transition: background var(--t-slow);
  flex-shrink: 0;
}
.save-status.is-saving .save-status-dot {
  background: var(--warning);
  animation: pulse 1s ease infinite;
}
.save-status.is-saved .save-status-dot { background: var(--success); }
.save-status.is-saved { color: var(--success); }

/* ---------------------------------------------------------------
   COLOUR PICKER (customisation)
   --------------------------------------------------------------- */
.color-swatch {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast);
  flex-shrink: 0;
  outline-offset: 2px;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.is-active {
  border-color: var(--text);
  transform: scale(1.15);
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* ---------------------------------------------------------------
   CONTACT CATEGORY CHIPS
   --------------------------------------------------------------- */
.category-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-2);
}

.category-option {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    border-color var(--t-fast),
    background var(--t-fast),
    color var(--t-fast);
  background: var(--surface);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  color: var(--text-2);
  user-select: none;
}
.category-option:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-subtle);
}
.category-option.is-selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--accent-text);
}
.category-option-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   CHECKBOX
   --------------------------------------------------------------- */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-label {
  font-size: var(--fs-13);
  color: var(--text-2);
}

/* ---------------------------------------------------------------
   DIVIDER
   --------------------------------------------------------------- */
.divider {
  height: 1px;
  background: var(--border);
  border: none;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  font-size: var(--fs-12);
  color: var(--text-3);
}
.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------------------------------------------------------------
   RANGE INPUT
   --------------------------------------------------------------- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--t-fast);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* ---------------------------------------------------------------
   BADGE
   --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
}
.badge-default  { background: var(--bg-subtle); color: var(--text-2); }
.badge-accent   { background: var(--accent-subtle); color: var(--accent-text); }
.badge-success  { background: var(--success-subtle); color: var(--success); }
.badge-error    { background: var(--error-subtle); color: var(--error); }

/* ---------------------------------------------------------------
   STEP INDICATOR (Home page "How it works")
   --------------------------------------------------------------- */
.step-number {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-text);
  font-size: var(--fs-16);
  font-weight: var(--fw-bold);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   SCROLL TO TOP
   --------------------------------------------------------------- */
.scroll-top {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  width: 40px; height: 40px;
  background: var(--text);
  color: white;
  border-radius: var(--r-full);
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--t-base), transform var(--t-base);
  z-index: var(--z-float);
}
.scroll-top.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.scroll-top:hover { background: var(--accent); }
