/* ================================
   Inline Contextual Help Component
   Design Pattern
   ================================ */

/* ================================
   Design Tokens
   ================================ */
:root {
    /* Colors - Calm, Trust-Building Palette */
    --color-primary: #5B8A9F;
    --color-primary-dark: #4A6F82;
    --color-primary-light: #E8F1F5;

    --color-text-primary: #2C3E50;
    --color-text-secondary: #5A6C7D;
    --color-text-muted: #8395A7;

    --color-background: #FFFFFF;
    --color-background-soft: #F7F9FB;
    --color-background-hover: #EEF3F7;

    --color-border: #D4DCE3;
    --color-border-light: #E8EEF3;

    --color-help-trigger: #6B96AC;
    --color-help-trigger-hover: #5B8A9F;
    --color-help-bg: #FFFFFF;
    --color-help-shadow: rgba(43, 62, 80, 0.12);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography */
    --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;

    --line-height-tight: 1.4;
    --line-height-normal: 1.6;
    --line-height-relaxed: 1.7;

    /* Borders & Radius - Standardized */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(43, 62, 80, 0.08);
    --shadow-md: 0 4px 12px rgba(43, 62, 80, 0.1);
    --shadow-lg: 0 8px 24px rgba(43, 62, 80, 0.12);
    --shadow-tooltip: 0 2px 8px rgba(43, 62, 80, 0.1);
    --shadow-popover: 0 8px 32px rgba(43, 62, 80, 0.15);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index */
    --z-tooltip: 1000;
    --z-popover: 1010;
}

/* ================================
   Base Styles
   ================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-background-soft);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ================================
   Skip Link (Accessibility)
   ================================ */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary, #4A7C8C);
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 1000;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
}

.back-to-catalog {
    position: fixed;
    top: 1rem;
    left: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4A7C8C;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #E8E4DD;
    border-radius: 6px;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all 0.2s ease;
}

.back-to-catalog:hover {
    background: #4A7C8C;
    color: white;
    border-color: #4A7C8C;
}

.back-to-catalog:focus {
    outline: 2px solid #4A7C8C;
    outline-offset: 2px;
}

/* ================================
   Component Container
   ================================ */
.component-container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--spacing-xl);
}

.component-header {
    margin-bottom: var(--spacing-xl);
    text-align: center;
}

.component-header h1 {
    font-size: 2rem;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-sm);
}

.subtitle {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-normal);
}

/* ================================
   Example Sections
   ================================ */
.example-section {
    margin-bottom: var(--spacing-xl);
    background: var(--color-background);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

.example-section h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-sm);
}

.description {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-lg);
    line-height: var(--line-height-relaxed);
}

.demo-box {
    background: var(--color-background-soft);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
    position: relative;
}

.demo-box:last-child {
    margin-bottom: 0;
}

/* ================================
   Form Elements
   ================================ */
label {
    display: block;
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-sm);
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    color: var(--color-text-primary);
    background: var(--color-background);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

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

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

.form-group {
    margin-bottom: var(--spacing-md);
}

/* ================================
   Info Card
   ================================ */
.info-card {
    background: var(--color-background);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
}

.info-card:last-child {
    margin-bottom: 0;
}

.info-card h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--spacing-md);
}

.info-card p {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

.info-card p + p {
    margin-top: var(--spacing-md);
}

.info-card ul {
    margin-top: var(--spacing-sm);
    padding-left: var(--spacing-lg);
    color: var(--color-text-secondary);
}

.info-card li {
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height-relaxed);
}

/* ================================
   Help Trigger Styles
   ================================ */
.help-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--color-help-trigger);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    padding: 4px;
    border-radius: var(--radius-sm);
    min-width: 24px;
    min-height: 24px;
}

.help-trigger:hover {
    color: var(--color-help-trigger-hover);
    background: var(--color-primary-light);
}

.help-trigger:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-background), 0 0 0 4px var(--color-primary);
}

.help-trigger:active {
    transform: scale(0.95);
}

/* Icon Styles */
.help-icon {
    display: block;
    flex-shrink: 0;
}

.help-icon--small {
    width: 14px;
    height: 14px;
}

/* Tooltip Trigger */
.help-trigger--tooltip {
    padding: 2px;
}

/* Popover Trigger */
.help-trigger--popover {
    gap: 4px;
    padding: 6px 10px;
    background: var(--color-primary-light);
    border-radius: var(--radius-md);
    font-weight: var(--font-weight-medium);
    min-width: auto;
}

.help-trigger--popover:hover {
    background: var(--color-primary);
    color: var(--color-background);
}

.help-trigger--popover[aria-expanded="true"] {
    background: var(--color-primary);
    color: var(--color-background);
}

.help-trigger__text {
    font-size: var(--font-size-sm);
}

/* Inline Trigger */
.help-trigger--inline {
    color: var(--color-primary);
    border-bottom: 1.5px dotted var(--color-primary);
    padding: 0 2px;
    border-radius: 0;
}

.help-trigger--inline:hover {
    background: var(--color-primary-light);
    border-bottom-style: solid;
}

/* Expandable Trigger */
.help-trigger--expandable {
    padding: 0;
    gap: 4px;
    background: transparent;
    min-width: auto;
}

.help-trigger--expandable:hover {
    background: transparent;
}

.help-trigger__underline {
    border-bottom: 1.5px dotted var(--color-help-trigger);
    transition: border-color var(--transition-fast);
}

.help-trigger--expandable:hover .help-trigger__underline {
    border-bottom-color: var(--color-help-trigger-hover);
    border-bottom-style: solid;
}

.help-trigger--expandable[aria-expanded="true"] .help-icon {
    transform: rotate(45deg);
}

/* Question Mark Trigger */
.help-trigger--question {
    padding: 4px;
    border-radius: var(--radius-full);
}

/* ================================
   Help Content Base
   ================================ */
.help-content {
    position: absolute;
    background: var(--color-help-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    z-index: var(--z-tooltip);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base),
                visibility var(--transition-base),
                transform var(--transition-base);
    pointer-events: none;
}

.help-content[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.help-content__inner {
    padding: var(--spacing-md);
}

/* ================================
   Tooltip Content
   ================================ */
.help-content--tooltip {
    max-width: 280px;
    box-shadow: var(--shadow-tooltip);
    margin-top: 8px;
    transform: translateY(-4px);
}

.help-content--tooltip[aria-hidden="false"] {
    transform: translateY(0);
}

.help-content--tooltip .help-content__inner {
    padding: 12px 14px;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

/* Tooltip Arrow (Optional Enhancement) */
.help-content--tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 16px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--color-border);
}

.help-content--tooltip::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 17px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid var(--color-help-bg);
}

/* ================================
   Popover Content
   ================================ */
.help-content--popover {
    max-width: 400px;
    box-shadow: var(--shadow-popover);
    z-index: var(--z-popover);
    margin-top: 8px;
    transform: scale(0.95) translateY(-4px);
}

.help-content--popover[aria-hidden="false"] {
    transform: scale(1) translateY(0);
}

.help-content--popover .help-content__inner {
    padding: 0;
}

.help-content__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-md) var(--spacing-sm);
    border-bottom: 1px solid var(--color-border-light);
}

.help-content__title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin: 0;
}

.help-content__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.help-content__close:hover {
    background: var(--color-background-hover);
    color: var(--color-text-primary);
}

.help-content__close:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-primary);
}

.help-content__body {
    padding: var(--spacing-md);
}

.help-content__body p {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--spacing-sm);
}

.help-content__body p:last-child {
    margin-bottom: 0;
}

.help-content__body strong {
    color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold);
}

.help-content__body ul {
    margin: var(--spacing-sm) 0;
    padding-left: var(--spacing-lg);
}

.help-content__body li {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height-relaxed);
}

/* ================================
   Expandable Content
   ================================ */
.help-content--expandable {
    position: relative;
    max-width: 100%;
    margin-top: var(--spacing-md);
    background: var(--color-primary-light);
    border: 1px solid var(--color-primary);
    border-left-width: 3px;
    box-shadow: none;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: none;
    transition: max-height var(--transition-slow),
                opacity var(--transition-base),
                margin var(--transition-slow);
}

.help-content--expandable[aria-hidden="false"] {
    max-height: 1000px;
    opacity: 1;
}

.help-content--expandable[aria-hidden="true"] {
    margin-top: 0;
}

.help-content--expandable .help-content__inner {
    padding: var(--spacing-md);
}

.help-content--expandable p {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--spacing-sm);
}

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

.help-content--expandable strong {
    color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold);
}

.help-content--expandable ul {
    margin: var(--spacing-sm) 0;
    padding-left: var(--spacing-lg);
}

.help-content--expandable li {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
    line-height: var(--line-height-relaxed);
}

/* ================================
   Notes Section
   ================================ */
.notes-section {
    background: var(--color-primary-light);
    border: 1px solid var(--color-primary);
}

.notes-section h2 {
    color: var(--color-primary-dark);
    margin-top: var(--spacing-lg);
}

.notes-section h2:first-child {
    margin-top: 0;
}

.feature-list {
    list-style: none;
    padding: 0;
}

.feature-list li {
    padding: var(--spacing-sm) 0;
    padding-left: var(--spacing-lg);
    position: relative;
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

.feature-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

/* ================================
   Positioning Utilities
   ================================ */
/* These classes are applied dynamically by JavaScript */
.help-content--positioned-top {
    bottom: 100%;
    margin-bottom: 8px;
    margin-top: 0;
}

.help-content--positioned-bottom {
    top: 100%;
    margin-top: 8px;
}

.help-content--positioned-left {
    right: 0;
}

.help-content--positioned-right {
    left: 0;
}

.help-content--positioned-center {
    left: 50%;
    transform: translateX(-50%);
}

.help-content--positioned-center.help-content--tooltip[aria-hidden="false"] {
    transform: translateX(-50%) translateY(0);
}

.help-content--positioned-center.help-content--tooltip {
    transform: translateX(-50%) translateY(-4px);
}

/* ================================
   Reduced Motion Support
   ================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .help-content {
        transition: opacity 0.01ms, visibility 0.01ms;
    }

    .help-trigger:active {
        transform: none;
    }

    .help-trigger--expandable[aria-expanded="true"] .help-icon {
        transform: none;
    }
}

/* ================================
   High Contrast Mode
   ================================ */
@media (prefers-contrast: high) {
    .help-content {
        border-width: 2px;
    }

    .help-trigger {
        outline: 1px solid currentColor;
    }
}

/* ================================
   Print Styles
   ================================ */
@media print {
    .help-trigger {
        display: none;
    }

    .help-content--expandable[aria-hidden="false"] {
        display: block;
        position: relative;
        max-height: none;
        page-break-inside: avoid;
    }
}

/* ================================
   Responsive Design
   ================================ */
@media (max-width: 768px) {
    .component-container {
        padding: var(--spacing-md);
    }

    .help-content--popover {
        max-width: calc(100vw - 32px);
        left: 16px !important;
        right: 16px !important;
    }

    .help-content--tooltip {
        max-width: 240px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .help-trigger {
        min-width: 44px;
        min-height: 44px;
    }

    .help-trigger--tooltip {
        /* Convert hover tooltips to click on touch devices */
        pointer-events: auto;
    }
}
