/* ============================================================================
   PortACourse Platform - Unified Stylesheet
   Combines Marketing Design System with Platform Layouts
   ============================================================================ */

/* 1. Design System & Variables (Imported from Marketing Site) */
:root {
    /* Brand Colors */
    --deep-indigo: #4F46E5;
    --electric-mint: #10B981;
    --warm-slate: #64748B;
    --paper-bg: #F8FAFC;
    --white: #FFFFFF;

    /* Contextual Colors */
    --dark-indigo: #3730A3;
    --light-indigo: #818CF8;
    --mint-hover: #059669;
    --slate-dark: #475569;
    --slate-light: #94A3B8;

    /* Semantic Colors */
    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;
    --danger: #DC2626;
    --info: #3b82f6;

    /* Shadows */
    --glass-shadow: 0 8px 32px 0 rgba(79, 70, 229, 0.1);
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
    
    /* Spacing & Radius (Platform Specific) */
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 2rem;
    --radius: 0.5rem;
}

/* 2. Base Reset & Typography */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--warm-slate);
    background-color: var(--paper-bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Space Grotesk', 'Helvetica Neue', Arial, sans-serif;
    font-weight: 600;
    color: var(--slate-dark);
    margin-bottom: 1rem;
}

a {
    text-decoration: none;
    color: var(--deep-indigo);
    transition: color 0.2s;
}

a:hover {
    color: var(--dark-indigo);
}

/* 3. Layout & Container */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.main-content {
    flex: 1;
    padding: var(--spacing-lg) 0;
}

/* 4. Navbar (Platform Implementation) */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--slate-light);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-logo {
    display: flex;
    align-items: center;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--deep-indigo);
    gap: 0.5rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem; /* Ensure space between items to prevent overlap */
}

.nav-links a:not(.btn) {
    color: var(--slate-dark);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-links a:not(.btn):hover, 
.nav-links a.active {
    color: var(--deep-indigo);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding-left: var(--spacing-md);
    border-left: 1px solid var(--slate-light);
}

.user-email {
    font-size: 0.875rem;
    color: var(--slate-dark);
    font-weight: 500;
}

.btn-logout {
    color: var(--warm-slate);
}
.btn-logout:hover {
    color: var(--error);
}

/* Mobile Menu */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--slate-dark);
}

.mobile-menu {
    display: none;
    background: var(--white);
    border-bottom: 1px solid var(--slate-light);
    padding: var(--spacing-md);
}

.mobile-menu.active {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* 5. Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    gap: 0.5rem;
    font-family: 'Space Grotesk', sans-serif;
}

.btn-primary {
    background-color: var(--electric-mint);
    border-color: var(--electric-mint);
    color: var(--deep-indigo);
}
.btn-primary:hover {
    background-color: var(--mint-hover);
    color: white;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    border-color: var(--slate-light);
    color: var(--slate-dark);
}
.btn-secondary:hover {
    background-color: #f1f5f9;
}

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

.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    width: 100%;
}

.log-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 2000;
}

.log-modal-card {
    background: #0f172a;
    color: #e2e8f0;
    width: min(900px, 95vw);
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.4);
    display: flex;
    flex-direction: column;
}

.log-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.log-modal-header h4 {
    margin: 0;
    font-size: 1rem;
    color: #e2e8f0;
}

.log-modal-close {
    background: transparent;
    border: none;
    color: #e2e8f0;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.log-modal-body {
    margin: 0;
    padding: 1rem 1.25rem;
    overflow: auto;
    font-size: 0.85rem;
    line-height: 1.4;
    background: #0b1220;
}

/* 6. Components: Cards & Dashboard */
.card {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid rgba(79, 70, 229, 0.1);
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    margin-bottom: var(--spacing-md);
}

.card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(79, 70, 229, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.module-card {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.module-card .card-body {
    flex: 1;
}

.module-desc {
    color: var(--warm-slate);
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 1rem;
}

.module-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}
.badge-draft { background-color: #e2e8f0; color: #475569; }
.badge-queued { background-color: #fef3c7; color: #d97706; }
.badge-processing { background-color: #dbeafe; color: #1e40af; animation: pulse 2s infinite; }
.badge-ready { background-color: #d1fae5; color: #047857; }
.badge-failed { background-color: #fee2e2; color: #b91c1c; }

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* 7. Forms */
.form-group {
    margin-bottom: 1.25rem;
}

label, .form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--slate-dark);
    font-size: 0.95rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--slate-light);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--deep-indigo);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Compact input helpers */
.refine-choice-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.refine-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.refine-subsection {
    margin-top: 12px;
}

.refine-number {
    max-width: 140px;
}

.refine-grid {
    display: grid;
    gap: 10px;
}

.refine-type-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.form-control.is-invalid {
    border-color: var(--error);
}

.invalid-feedback {
    display: block;
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 0.4rem;
}

/* Refine/Create modal layout */
.refine-shell {
    background: linear-gradient(135deg, #0f172a 0%, #111827 100%);
    min-height: calc(100vh - 80px);
    padding: 2rem 1.5rem 3rem;
}

.refine-overlay {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.refine-modal {
    width: min(1100px, 96vw);
    max-height: 88vh;
    background: #f8fafc;
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.35);
    padding: 1.5rem 1.75rem 1.75rem;
    overflow-y: auto;
    border: 1px solid rgba(148, 163, 184, 0.35);
}

.refine-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
}

.refine-modal-header h2 {
    margin: 0.2rem 0 0.25rem;
    font-size: 1.6rem;
    color: #0f172a;
}

.refine-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 700;
}

.refine-subtitle {
    margin: 0;
    color: #475569;
    font-size: 0.95rem;
}

.refine-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #0f172a;
    text-decoration: none;
    font-size: 1.2rem;
    line-height: 1;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

.refine-modal-body {
    display: grid;
    gap: 1rem;
}

.refine-section {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}

.refine-section-title {
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    color: #1e293b;
}

.refine-collapsible summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-weight: 600;
    color: #1f2937;
}

.refine-collapsible summary::-webkit-details-marker {
    display: none;
}

.refine-collapsible .refine-section-body {
    margin-top: 1rem;
}

.refine-hint {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

@media (max-width: 900px) {
    .refine-shell {
        padding: 1rem;
    }

    .refine-modal {
        width: 100%;
        max-height: 92vh;
        border-radius: 12px;
        padding: 1.25rem;
    }
}

@media (max-width: 640px) {
    .refine-modal {
        max-height: 96vh;
        padding: 1rem;
    }
}

/* 8. Authentication Pages (New Design) */
.auth-container {
    min-height: 100vh; /* fallback */
    min-height: calc(100vh - 80px); /* minus nav/footer estimate */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--paper-bg) 0%, #E0E7FF 100%);
}

.auth-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 500px;
    padding: 2.5rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    height: 48px;
    width: auto;
    margin-bottom: 1rem;
}

.auth-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark-indigo);
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    color: var(--warm-slate);
    font-size: 1rem;
}

.btn-google {
    background-color: white;
    border: 1px solid var(--slate-light);
    color: var(--slate-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 500;
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-google:hover {
    background-color: #F8FAFC;
    border-color: var(--deep-indigo);
}

.btn-google img {
    height: 20px;
    margin-right: 12px;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--slate-light);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #E2E8F0;
}

.divider span {
    padding: 0 10px;
    font-size: 0.875rem;
    font-weight: 500;
}

.captcha-container {
    background: #F8FAFC;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #E2E8F0;
}

.captcha-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.captcha-image {
    height: 44px;
    border-radius: 6px;
    border: 1px solid #E2E8F0;
}

.refresh-captcha {
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--slate-dark);
    transition: all 0.2s;
}

.refresh-captcha:hover {
    background: #F1F5F9;
    color: var(--deep-indigo);
}

/* 9. Footer */
.footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--warm-slate);
    font-size: 0.9rem;
    border-top: 1px solid var(--slate-light);
    background: var(--white);
    margin-top: auto;
}

/* 10. Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--warm-slate); }
.mt-4 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.d-none { display: none; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }

/* 11. Conversation Timeline Styles */
/* Version Timeline Container */
.version-timeline {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1rem 0;
}

/* Conversation Cards */
.conversation-card {
    position: relative;
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    max-width: 85%;
}

.conversation-card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Instructor cards on the RIGHT */
.conversation-card.instructor {
    margin-left: auto;
    margin-right: 0;
    border: 2px solid var(--deep-indigo);
    background: linear-gradient(to left, #EEF2FF 0%, white 100%);
}

/* Add pointer on top-right for instructor */
.conversation-card.instructor::before {
    content: '';
    position: absolute;
    top: 15px;
    right: -10px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 0 10px 10px;
    border-color: transparent transparent transparent var(--deep-indigo);
}

.conversation-card.instructor::after {
    content: '';
    position: absolute;
    top: 16px;
    right: -7px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 9px 0 9px 9px;
    border-color: transparent transparent transparent #EEF2FF;
}

/* AI cards on the LEFT */
.conversation-card.ai {
    margin-left: 0;
    margin-right: auto;
    border: 2px solid var(--electric-mint);
    background: linear-gradient(to right, #D1FAE5 0%, white 100%);
}

/* Processing state for AI cards */
.conversation-card.ai.processing {
    opacity: 0.85;
    border-color: #A7F3D0;
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        border-color: #A7F3D0;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        border-color: var(--electric-mint);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }
}

/* Add pointer on top-left for AI */
.conversation-card.ai::before {
    content: '';
    position: absolute;
    top: 15px;
    left: -10px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 10px 10px 0;
    border-color: transparent var(--electric-mint) transparent transparent;
}

.conversation-card.ai::after {
    content: '';
    position: absolute;
    top: 16px;
    left: -7px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 9px 9px 9px 0;
    border-color: transparent #D1FAE5 transparent transparent;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--sage-border);
}

.conversation-icon {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--deep-indigo);
}

.conversation-timestamp {
    color: var(--warm-slate);
    font-size: 0.85rem;
}

.conversation-body {
    margin-top: 0.75rem;
}

.instruction-text {
    line-height: 1.5;
    color: var(--slate-dark);
}

.btn-text-toggle {
    background: none;
    border: none;
    color: var(--deep-indigo);
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font-size: inherit;
}

.btn-text-toggle:hover {
    color: #4338CA;
}

/* Settings Summary Grid */
.settings-summary {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--paper-bg);
    border-radius: 4px;
    border: 1px solid var(--sage-border);
}

.settings-summary strong {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--deep-indigo);
    font-size: 0.9rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.setting-item {
    font-size: 0.85rem;
    line-height: 1.4;
}

.setting-key {
    font-weight: 500;
    color: var(--warm-slate);
}

.setting-value {
    color: var(--slate-dark);
    margin-left: 0.25rem;
}

/* Settings Diff Display */
.settings-diff {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #FEF3C7;
    border-left: 3px solid #F59E0B;
    border-radius: 4px;
}

.settings-diff strong {
    display: block;
    margin-bottom: 0.35rem;
    color: #92400E;
    font-size: 0.9rem;
}

.diff-items {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.diff-item {
    font-size: 0.85rem;
    line-height: 1.4;
}

.diff-key {
    font-weight: 500;
    color: #78350F;
}

.diff-old {
    color: #DC2626;
    text-decoration: line-through;
}

.diff-new {
    color: #059669;
    font-weight: 600;
}

/* Feedback Badges */
.feedback-badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.feedback-badge.success {
    background: #D1FAE5;
    color: #065F46;
}

.feedback-badge.warning {
    background: #FEF3C7;
    color: #92400E;
}

.feedback-badge.error {
    background: #FEE2E2;
    color: #991B1B;
}

/* Branch Indicator */
.branch-indicator {
    padding: 0.5rem;
    background: #FEF3C7;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid #F59E0B;
    color: #92400E;
}

.branch-indicator i {
    margin-right: 0.25rem;
}

/* Processing Indicator */
.processing-indicator {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: #F0FDF4;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    color: #065F46;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-links, .user-menu { display: none; }
    .mobile-menu-btn { display: block; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .btn-large { width: 100%; }

    /* Conversation timeline responsive */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .version-actions {
        flex-direction: column;
    }

    .version-actions a,
    .version-actions button {
        width: 100%;
    }

    .conversation-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Make conversation cards wider on mobile */
    .conversation-card {
        max-width: 95%;
    }

    /* Adjust pointer sizes on mobile */
    .conversation-card.instructor::before,
    .conversation-card.ai::before {
        border-width: 8px;
    }

    .conversation-card.instructor::after,
    .conversation-card.ai::after {
        border-width: 7px;
    }
}
