/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
    text-decoration: none;
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn {
    transition: transform var(--transition-base), background var(--transition-base),
        border-color var(--transition-base), color var(--transition-base), box-shadow var(--transition-base);
}
.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
    background: var(--gradient-primary);
    color: var(--color-white);
    box-shadow: var(--shadow-primary);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 16px 34px -8px rgba(79, 70, 229, 0.55); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-ink-50); border-color: var(--color-ink-300); transform: translateY(-1px); }

.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-ink-100); color: var(--color-text); }

.btn-danger { background: var(--color-surface); color: var(--color-danger); border-color: var(--color-border); }
.btn-danger:hover { background: var(--color-danger-bg); border-color: var(--color-danger); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: var(--text-xs); }
.btn-lg { padding: 0.875rem 1.75rem; font-size: var(--text-base); }
.btn-block { width: 100%; }

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: var(--space-6); }

/* Hover-lift utility for interactive cards */
.lift { transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base); }
.lift:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary-200);
}

/* Forms */
.field { margin-bottom: var(--space-5); }
.field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}
.field .hint { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="tel"],
input[type="date"], input[type="search"], textarea, select {
    width: 100%;
    font-family: inherit;
    font-size: var(--text-sm);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.75rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
textarea { resize: vertical; min-height: 5.5rem; font-family: inherit; }

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--color-text-muted); opacity: 0.7; }

/* Password show/hide toggle */
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 2.75rem; }
.password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: color var(--transition-fast);
}
.password-toggle:hover { color: var(--color-text); }
.password-toggle:focus-visible { outline: none; color: var(--color-primary-500); }
.password-toggle svg { width: 18px; height: 18px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle.is-visible .icon-eye { display: none; }
.password-toggle.is-visible .icon-eye-off { display: inline-block; }

.checkbox-row { display: flex; align-items: center; gap: var(--space-2); }
.checkbox-row label { margin: 0; font-weight: 500; }

/* Alerts / flash */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    margin-bottom: var(--space-5);
}
.alert-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid var(--color-success-border); }
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid var(--color-danger-border); }
.alert-info { background: var(--color-primary-50); color: var(--color-primary-700); border: 1px solid var(--color-primary-200); }
.alert-warning { background: #fff4e5; color: #8a4b00; border: 1px solid rgba(138, 75, 0, .22); }
[data-theme="dark"] .alert-warning { background: rgba(234, 140, 40, .12); color: #f6b26b; border-color: rgba(246, 178, 107, .28); }
.alert-warning a { color: inherit; font-weight: 700; text-decoration: underline; }

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    background: var(--color-ink-100);
    color: var(--color-ink-700);
}
.badge-primary { background: var(--color-primary-50); color: var(--color-primary-700); }

/* App top nav (dashboard / builder) */
.app-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--color-surface) 82%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}
/* JS adds .is-scrolled once the page moves, for a subtle elevation */
.app-nav.is-scrolled {
    border-bottom-color: var(--color-border);
    box-shadow: var(--shadow-sm);
}
.app-nav-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--space-6);
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--color-text);
}
.brand-mark {
    width: 30px; height: 30px;
    border-radius: var(--radius-sm);
    background: var(--color-primary-600);
    color: var(--color-white);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: var(--text-sm);
}
.nav-links { display: flex; align-items: center; gap: var(--space-4); }
.nav-user { display: flex; align-items: center; gap: var(--space-3); }
.avatar-circle {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--color-primary-100);
    color: var(--color-primary-700);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: var(--text-sm);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--color-text-muted);
}
.empty-state h3 { color: var(--color-text); }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: var(--space-4);
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 420px;
    width: 100%;
    padding: var(--space-6);
}
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-6); }

/* Live CV/template preview: the real template rendered (with sample or the user's
   own data), scaled to fit. The iframe renders at a fixed "page" width (794px);
   cv-preview.js scales it to its frame, which clips to a window showing the top of
   the CV. Shared by the gallery, dashboard, and landing page. */
.tpl-preview-frame {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background: #ffffff;
}
.tpl-preview-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 794px;
    height: 1400px;
    border: 0;
    transform-origin: top left;
    transform: scale(0.28); /* sensible default before cv-preview.js runs */
    pointer-events: none;
    background: #ffffff;
}

/* Theme toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
    flex-shrink: 0;
}
.theme-toggle:hover { color: var(--color-text); border-color: var(--color-ink-300); transform: rotate(-15deg); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Toasts */
.toast-stack {
    position: fixed;
    top: calc(64px + var(--space-4));
    right: var(--space-6);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: min(360px, calc(100vw - 2 * var(--space-4)));
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-ink-300);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    color: var(--color-text);
    transform: translateX(120%);
    opacity: 0;
    transition: transform var(--transition-spring), opacity var(--transition-base);
}
.toast.is-visible { transform: translateX(0); opacity: 1; }
.toast.is-leaving { transform: translateX(120%); opacity: 0; }
.toast-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.toast-message { flex: 1; }
.toast-success { border-left-color: var(--color-success); }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error { border-left-color: var(--color-danger); }
.toast-error .toast-icon { color: var(--color-danger); }
.toast-info { border-left-color: var(--color-primary-500); }
.toast-info .toast-icon { color: var(--color-primary-500); }

@media (max-width: 640px) {
    .toast-stack { right: var(--space-4); left: var(--space-4); max-width: none; }
}
