/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Navbar ────────────────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}

.navbar-brand a {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gray-900);
    text-decoration: none;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: var(--gray-600);
    text-decoration: none;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary);
    background: var(--gray-100);
}

.nav-user {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.nav-logout-form {
    display: inline;
}

.nav-logout {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

/* ─── Container ─────────────────────────────────────────────── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ─── Login ─────────────────────────────────────────────────── */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 56px);
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    text-align: center;
}

.login-subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* ─── Forms ─────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-800);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* ─── Alerts ────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* ─── Generator Layout ──────────────────────────────────────── */
.generator-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* ─── Generator Form Panel ──────────────────────────────────── */
.form-panel {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    position: sticky;
    top: 1rem;
}

.form-panel h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.form-section {
    margin-bottom: 1.25rem;
}

.form-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    margin-bottom: 0.75rem;
}

/* ─── Toggle switch (language) ──────────────────────────────── */
.toggle-group {
    display: flex;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    overflow: hidden;
}

.toggle-group input[type="radio"] {
    display: none;
}

.toggle-group label {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    background: white;
    color: var(--gray-600);
    transition: background 0.15s, color 0.15s;
}

.toggle-group input[type="radio"]:checked + label {
    background: var(--primary);
    color: white;
}

/* ─── Quantity selector ─────────────────────────────────────── */
.quantity-selector {
    display: flex;
    gap: 0.5rem;
}

.quantity-selector input[type="radio"] {
    display: none;
}

.quantity-selector label {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.quantity-selector input[type="radio"]:checked + label {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.quantity-selector label:hover {
    border-color: var(--primary);
}

/* ─── Collapsible section ───────────────────────────────────── */
.collapsible-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--gray-600);
    user-select: none;
    margin-bottom: 0.75rem;
}

.collapsible-toggle input[type="checkbox"] {
    accent-color: var(--primary);
}

.collapsible-content {
    display: none;
}

.collapsible-content.open {
    display: block;
}

/* ─── Results Panel ─────────────────────────────────────────── */
.results-panel {
    min-height: 300px;
}

.results-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--gray-400);
    text-align: center;
}

.results-empty p {
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* ─── Email cards ───────────────────────────────────────────── */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.results-header h2 {
    font-size: 1.1rem;
}

.email-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    overflow: hidden;
}

.email-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.email-card-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-functional {
    background: #dbeafe;
    color: #1e40af;
}

.badge-contextual {
    background: #d1fae5;
    color: #065f46;
}

.badge-relational {
    background: #fce7f3;
    color: #9d174d;
}

.email-card-body {
    padding: 1rem;
}

.email-subject {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.email-subject strong {
    font-size: 0.95rem;
}

.email-body-content {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    white-space: pre-wrap;
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

.email-signature {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.85rem;
    color: var(--gray-600);
    white-space: pre-wrap;
}

.email-strategy {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-100);
    font-size: 0.8rem;
    color: var(--gray-500);
}

.email-strategy summary {
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.strategy-detail {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.75rem;
    margin-top: 0.5rem;
}

.strategy-label {
    font-weight: 500;
    color: var(--gray-600);
}

.email-card-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-100);
}

/* ─── Copy feedback ─────────────────────────────────────────── */
.copy-btn {
    position: relative;
}

.copy-btn.copied {
    color: var(--success);
}

/* ─── Loading indicator ─────────────────────────────────────── */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-flex;
}

.htmx-request .htmx-hide-on-request {
    display: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Profile page ──────────────────────────────────────────── */
.profile-container {
    max-width: 500px;
    margin: 0 auto;
}

.profile-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.profile-card h1 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.profile-card .subtitle {
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* ─── Mobile ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .generator-layout {
        grid-template-columns: 1fr;
    }

    .form-panel {
        position: static;
    }

    .navbar {
        flex-direction: column;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .navbar-menu {
        flex-wrap: wrap;
        justify-content: center;
    }
}
