/**
 * AVW Platform Design System - Lesson Editor (SME)
 * Shared styles for all Lesson Editor pages
 *
 * SYNC NOTE: This file should be kept in sync across all repos (ID, SME, Weave).
 * Only the "Workflow Overrides" section (lines ~27-40) differs per repo.
 * When updating shared patterns, update all three repos.
 *
 * This file contains:
 * - Design tokens (CSS custom properties)
 * - Header component
 * - Layout patterns (container, grid, sidebar, content-area)
 * - Common UI components (buttons, forms, badges, cards, tables, modals)
 *
 * Page-specific styles should be defined in <style> tags within each page.
 */

/* ===== Design Tokens ===== */
:root {
    /* Brand / Primary - Teal */
    --teal-50: #f0f9f8;
    --teal-100: #d4f1ed;
    --teal-200: #a8e3db;
    --teal-300: #6bcec2;
    --teal-400: #3db5a6;
    --teal-500: #1a7a6f;
    --teal-600: #14635a;
    --teal-700: #104d46;
    --teal-800: #0c3a35;
    --teal-900: #082624;

    /* Workflow Color - Teal for Lesson Editor (SME) */
    --workflow-color: #1a7a6f;
    --workflow-light: #f0f9f8;
    --workflow-hover: #14635a;

    /* Also define named workflow tokens for clarity */
    --workflow-id: #3d7a99;
    --workflow-id-light: #e8f4f8;
    --workflow-sme: #1a7a6f;
    --workflow-sme-light: #f0f9f8;
    --workflow-weave: #7a5a99;
    --workflow-weave-light: #f3eef8;
    --workflow-admin: #99713d;
    --workflow-admin-light: #f8f3e8;

    /* Surfaces (warm paper tones) */
    --surface-page: #fafaf8;
    --surface-card: #ffffff;
    --surface-raised: #ffffff;
    --surface-sunken: #f5f5f3;
    --surface-overlay: #ffffff;

    /* Structure (cool gray scaffolding) */
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f4;
    --gray-200: #e8eaed;
    --gray-300: #dadce0;
    --gray-400: #bdc1c6;
    --gray-500: #9aa0a6;
    --gray-600: #80868b;
    --gray-700: #5f6368;
    --gray-800: #3c4043;
    --gray-900: #202124;

    /* Text */
    --text-primary: #1a1a1a;
    --text-secondary: #5f6368;
    --text-tertiary: #9aa0a6;
    --text-inverse: #ffffff;
    --text-link: var(--workflow-color);
    --text-link-hover: var(--workflow-hover);

    /* Borders */
    --border-default: #e8eaed;
    --border-subtle: #f1f3f4;
    --border-strong: #dadce0;
    --border-interactive: var(--teal-300);
    --border-focus: var(--workflow-color);
    padding: 0;
    /* Status / Semantic */
    --status-success-bg: #e8f5e8;
    --status-success-border: #a8d5a8;
    --status-success-text: #2d5a2d;
    --status-warning-bg: #fef7e6;
    --status-warning-border: #f0d78c;
    --status-warning-text: #8a6914;
    --status-error-bg: #fef2f0;
    --status-error-border: #f0b8b0;
    --status-error-text: #a63d2d;
    --status-neutral-bg: #f5f5f3;
    --status-neutral-border: #dadce0;
    --status-neutral-text: #5f6368;

    /* Typography */
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Depth */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-focus: 0 0 0 3px rgba(26, 122, 111, 0.15);

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--surface-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Lists ===== */
ol, ul {
    padding-left: var(--space-6);
    margin: var(--space-3) 0;
}

ol ol, ol ul, ul ol, ul ul {
    margin: var(--space-2) 0;
}

li {
    margin-bottom: var(--space-2);
    line-height: var(--leading-relaxed);
}

li:last-child {
    margin-bottom: 0;
}

/* ===== Content Components ===== */
/* Used in lesson content blocks (text, quiz, activity, etc.) */
.component-header {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    line-height: var(--leading-tight);
}

.component-content {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--text-primary);
}

.component-content p {
    margin-bottom: var(--space-4);
}

.component-content p:last-child {
    margin-bottom: 0;
}

/* ===== Header Component ===== */
.header {
    background: var(--surface-card);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: inherit;
}

.logo-mark {
    width: 36px;
    height: 36px;
    background: var(--workflow-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-mark svg {
    width: 20px;
    height: 20px;
    color: var(--text-inverse);
}

.logo-text h1 {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    margin: 0;
}

.logo-text p {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
    margin: 0;
}

.header-divider {
    width: 1px;
    height: 32px;
    background: var(--border-default);
}

.page-title {
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--workflow-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.user-details {
    text-align: right;
}

.user-name {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.user-role {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--workflow-color);
}

/* ===== Breadcrumbs ===== */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb a:hover {
    color: var(--text-primary);
}

.breadcrumb-separator {
    color: var(--text-tertiary);
}

.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-card);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:hover {
    background: var(--surface-sunken);
}

.btn:focus {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--workflow-color);
    color: var(--text-inverse);
    border-color: var(--workflow-color);
}

.btn-primary:hover {
    background: var(--workflow-hover);
    border-color: var(--workflow-hover);
}

.btn-secondary {
    background: var(--surface-card);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-sunken);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-base);
}

.btn-full {
    width: 100%;
}

/* ===== Form Elements ===== */
.form-input,
.form-select,
.form-textarea {
    width: 100%;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-base);
    font-family: inherit;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--workflow-color);
    box-shadow: var(--shadow-focus);
    outline: none;
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.form-label .required {
    color: var(--status-error-text);
    margin-left: var(--space-1);
}

/* ===== Status Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.badge-success {
    background: var(--status-success-bg);
    color: var(--status-success-text);
    border: 1px solid var(--status-success-border);
}

.badge-warning {
    background: var(--status-warning-bg);
    color: var(--status-warning-text);
    border: 1px solid var(--status-warning-border);
}

.badge-error {
    background: var(--status-error-bg);
    color: var(--status-error-text);
    border: 1px solid var(--status-error-border);
}

.badge-neutral {
    background: var(--status-neutral-bg);
    color: var(--status-neutral-text);
    border: 1px solid var(--status-neutral-border);
}

/* ===== Cards ===== */
.card {
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-5);
}

.card-interactive {
    cursor: pointer;
    transition: all var(--transition-base);
}

.card-interactive:hover {
    background: linear-gradient(135deg, rgba(26, 122, 111, 0.04) 0%, rgba(26, 122, 111, 0.08) 100%);
    border-color: rgba(26, 122, 111, 0.3);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.card-interactive:focus {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* ===== Tables ===== */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}

.table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--border-default);
}

.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.table tr:hover td {
    background: var(--gray-50);
}

.table tr.clickable {
    cursor: pointer;
    transition: background var(--transition-fast);
}

.table tr.clickable:hover td {
    background: var(--workflow-light);
}

/* ===== Loading States ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-default);
    border-top-color: var(--workflow-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    border-radius: 0;
    box-shadow: none;
    max-height: 85vh;
    overflow: auto;
}

.modal-header {
    padding: var(--space-5) 0;
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    padding: var(--space-1);
    cursor: pointer;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--surface-sunken);
    color: var(--text-secondary);
}

.modal-body {
    padding: 0;
}

.modal-footer {
    padding: var(--space-4) 0;
    border-top: 1px solid var(--border-default);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* ===== Empty States ===== */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-tertiary);
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4);
    color: var(--gray-400);
}

.empty-state-title {
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    max-width: 300px;
    margin: 0 auto;
}

/* ===== Layout: Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-5);
}

.container-wide {
    max-width: 1400px;
}

/* ===== Layout: Two-Column Grid ===== */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: var(--space-5);
}

/* ===== Layout: Content Area ===== */
.content-area {
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.content-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.content-header h3 {
    font-size: var(--text-md);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0;
}

.content-body {
    padding: var(--space-5);
}

/* ===== Layout: Sidebar ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.sidebar-panel {
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.panel-header {
    background: var(--surface-sunken);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
    color: var(--text-primary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.panel-content {
    padding: var(--space-4);
}

/* ===== Layout: Page Header ===== */
.page-header {
    margin-bottom: var(--space-6);
}

.page-header h2 {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0 0 var(--space-1) 0;
}

.page-header p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin: 0;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr 220px;
        gap: var(--space-4);
    }
}

@media (max-width: 768px) {
    .header {
        padding: var(--space-3) var(--space-4);
    }

    .header-left {
        gap: var(--space-3);
    }

    .header-divider {
        display: none;
    }

    .page-title {
        display: none;
    }

    .container {
        padding: var(--space-4);
    }

    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        order: -1; /* Actions above content on mobile */
    }
}
