/**
 * Demo Section Styles - Apple Human Interface Guidelines
 * Clean, minimal design with frosted glass effects and smooth animations
 */

/* ==================== Demo Container ==================== */

.demo__container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0;
}

/* ==================== System Selector (Apple HIG Style) ==================== */

.demo__system-selector {
    margin-bottom: 24px;
}

.demo__system-selector .demo__label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #86868b);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.system-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.system-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1.5px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #1d1d1f;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
}

.system-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.1), rgba(88, 86, 214, 0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: 12px;
}

/* Tooltip */
.system-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.system-btn:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.system-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 122, 255, 0.3);
}

.system-btn:hover::before {
    opacity: 1;
}

.system-btn.active {
    background: linear-gradient(135deg, #007aff, #5856d6);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.3);
}

.system-btn.active::before {
    opacity: 0;
}

.system-icon {
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
    position: relative;
    z-index: 1;
}

.system-name {
    font-weight: 500;
    position: relative;
    z-index: 1;
}

/* ==================== Input Form (Apple Style) ==================== */

.demo__form {
    margin-bottom: 20px;
}

.demo__input-wrapper {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1.5px solid rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.demo__input-wrapper:focus-within {
    border-color: #007aff;
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1),
        0 8px 24px rgba(0, 0, 0, 0.08);
}

.demo__input-wrapper textarea {
    width: 100%;
    padding: 16px 20px;
    border: none;
    background: white !important;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: #1d1d1f !important;
    resize: none;
    outline: none;
}

.demo__input-wrapper textarea::placeholder {
    color: #86868b;
}

.demo__input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid rgba(34, 48, 255, 0.08);
    background: #f0f3ff;
}

.demo__counter {
    font-size: 13px;
    font-weight: 500;
    color: #86868b;
    font-variant-numeric: tabular-nums;
}

.demo__counter.warning {
    color: #ff3b30;
}

/* ==================== Submit Button (Apple Style) ==================== */

.demo__submit {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: linear-gradient(135deg, #007aff, #5856d6);
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    color: white;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.demo__submit:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.4);
}

.demo__submit:active {
    transform: scale(0.98);
}

.demo__submit.loading .btn__text {
    opacity: 0;
}

.demo__submit.loading .btn__loader {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    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: translate(-50%, -50%) rotate(360deg);
    }
}

/* ==================== Chat Container (GPT/Grok Style) ==================== */

.demo__result {
    margin-top: 32px;
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.demo__chat-container {
    background: #f0f3ff;
    border: 1px solid rgba(34, 48, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 12px 24px -16px rgba(16, 22, 64, 0.2);
}

/* ==================== Messages ==================== */

.demo__message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.demo__message:last-child {
    margin-bottom: 0;
}

.message__avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.1), rgba(88, 86, 214, 0.1));
    border: 1.5px solid rgba(0, 122, 255, 0.2);
}

.demo__message--ai .message__avatar {
    background: linear-gradient(135deg, #007aff, #5856d6);
    border: none;
}

.message__content {
    flex: 1;
    min-width: 0;
    background: #ffffff;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(16, 22, 64, 0.08);
}

.message__header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.message__author {
    font-size: 14px;
    font-weight: 600;
    color: #0e1633;
}

.message__system {
    font-size: 12px;
    font-weight: 500;
    color: #007aff;
    padding: 2px 8px;
    background: rgba(0, 122, 255, 0.1);
    border-radius: 6px;
}

.message__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #86868b;
}

.status__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #86868b;
}

.status__dot--generating {
    background: #007aff;
    animation: pulse 1.5s ease-in-out infinite;
}

.status__dot--complete {
    background: #34c759;
}

.status__dot--error {
    background: #ff3b30;
}

.status__dot--stopped {
    background: #ff9500;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.message__text {
    font-size: 15px;
    line-height: 1.6;
    color: #0e1633;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ==================== Message Body & Output ==================== */

.message__body {
    font-size: 15px;
    line-height: 1.7;
    color: #0e1633 !important;
    max-height: 500px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

#demo-stream-output {
    color: #0e1633 !important;
}

/* Make sure ALL text inside is dark */
.message__body *,
#demo-stream-output * {
    color: inherit;
}

/* Custom scrollbar (Apple style) */
.message__body::-webkit-scrollbar {
    width: 6px;
}

.message__body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 3px;
}

.message__body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.message__body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ==================== Markdown Styles ==================== */

/* Paragraphs */
.message__body .md-p,
#demo-stream-output .md-p,
.message__body p {
    margin: 0 0 16px 0;
    color: #0e1633 !important;
    line-height: 1.7;
}

/* Headers */
.message__body .md-h2,
.message__body .md-h3,
.message__body .md-h4,
#demo-stream-output .md-h2,
#demo-stream-output .md-h3,
#demo-stream-output .md-h4 {
    margin: 24px 0 12px 0;
    font-weight: 600;
    color: #0f172a !important;
    line-height: 1.3;
}

.message__body .md-h2:first-child,
.message__body .md-h3:first-child,
.message__body .md-h4:first-child {
    margin-top: 0;
}

.message__body .md-h2,
#demo-stream-output .md-h2 {
    font-size: 20px;
}

.message__body .md-h3,
#demo-stream-output .md-h3 {
    font-size: 18px;
}

.message__body .md-h4,
#demo-stream-output .md-h4 {
    font-size: 16px;
}

/* Lists */
.message__body .md-ul,
#demo-stream-output .md-ul {
    margin: 16px 0;
    padding-left: 24px;
    color: #0e1633 !important;
}

.message__body .md-li,
#demo-stream-output .md-li {
    margin: 8px 0;
    line-height: 1.6;
    color: #0e1633 !important;
}

/* Inline code */
.message__body .inline-code,
#demo-stream-output .inline-code {
    padding: 2px 6px;
    background: rgba(34, 48, 255, 0.08);
    border: 1px solid rgba(34, 48, 255, 0.15);
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    color: #2230ff !important;
}

/* Bold and italic */
.message__body strong,
#demo-stream-output strong {
    font-weight: 600;
    color: #0e1633 !important;
}

.message__body em,
#demo-stream-output em {
    font-style: italic;
    color: rgba(14, 22, 51, 0.68) !important;
}

/* ==================== Code Blocks (Light Apple Style) ==================== */

.code-block {
    margin: 16px 0;
    border-radius: 12px;
    overflow: hidden;
    background: #f0f3ff;
    border: 1px solid rgba(34, 48, 255, 0.12);
}

.code-block__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.code-block__lang {
    font-size: 11px;
    font-weight: 600;
    color: #007aff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-block__copy {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(0, 122, 255, 0.1);
    border: none;
    border-radius: 6px;
    color: #007aff;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.code-block__copy:hover {
    background: rgba(0, 122, 255, 0.15);
}

.code-block__copy svg {
    width: 12px;
    height: 12px;
}

.code-block__content {
    padding: 12px;
    margin: 0;
    overflow-x: auto;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #1d1d1f;
    background: white;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-block__content::-webkit-scrollbar {
    height: 6px;
}

.code-block__content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
}

.code-block__content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* ==================== Typing Cursor ==================== */

.typing-cursor {
    display: inline-block;
    margin-left: 2px;
    color: #007aff;
    animation: blink 1s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* ==================== Action Buttons ==================== */

.demo__actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.demo__actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.demo__actions .btn--secondary {
    background: rgba(0, 122, 255, 0.1);
    color: #007aff;
    border: 1.5px solid rgba(0, 122, 255, 0.2);
}

.demo__actions .btn--secondary:hover {
    background: rgba(0, 122, 255, 0.15);
    border-color: rgba(0, 122, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}

.demo__actions .btn--ghost {
    background: transparent;
    color: #86868b;
    border: 1.5px solid rgba(0, 0, 0, 0.1);
}

.demo__actions .btn--ghost:hover {
    background: rgba(0, 0, 0, 0.03);
    color: #1d1d1f;
}

.demo__actions .btn--danger {
    color: #ff3b30;
    border-color: rgba(255, 59, 48, 0.2);
}

.demo__actions .btn--danger:hover {
    background: rgba(255, 59, 48, 0.1);
    border-color: rgba(255, 59, 48, 0.3);
}

.btn__icon {
    font-size: 16px;
    line-height: 1;
}

/* ==================== Privacy Note ==================== */

.demo__note {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(0, 122, 255, 0.05);
    border-left: 3px solid #007aff;
    border-radius: 8px;
    font-size: 13px;
    color: #515154;
    line-height: 1.5;
}

.note__icon {
    flex-shrink: 0;
    color: #007aff;
}

#demo-rate-limit {
    font-weight: 600;
    transition: color 0.3s ease;
}

.inline-ext-btn {
    display: inline;
    padding: 2px 8px;
    background: linear-gradient(135deg, #007aff, #5856d6);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.inline-ext-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

/* ==================== Toast Notifications ==================== */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast--show {
    transform: translateX(-50%) translateY(0);
}

.toast--success {
    background: rgba(52, 199, 89, 0.95);
}

.toast--error {
    background: rgba(255, 59, 48, 0.95);
}

.toast--info {
    background: rgba(0, 122, 255, 0.95);
}

/* ==================== Responsive Design ==================== */

@media (max-width: 768px) {
    .demo__container {
        padding: 0 16px;
    }

    .system-buttons {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 0;
        margin: 0;
        overflow: visible;
    }

    .system-btn {
        flex: 1 1 auto;
        justify-content: center;
        padding: 10px 14px;
        font-size: 13px;
        min-width: 80px;
    }

    .system-buttons::-webkit-scrollbar {
        display: none;
    }

    .demo__input-footer {
        flex-wrap: wrap;
        gap: 12px;
    }

    .demo__counter {
        order: 1;
    }

    .demo__submit {
        width: 100%;
        justify-content: center;
        order: 2;
    }

    .demo__chat-container {
        padding: 16px;
    }

    .demo__message {
        gap: 10px;
    }

    .message__avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .demo__actions {
        flex-direction: column;
    }

    .demo__actions .btn {
        width: 100%;
        justify-content: center;
    }

    .code-block__content {
        font-size: 12px;
    }
}

/* ==================== Dark Mode Support ==================== */

@media (prefers-color-scheme: dark) {

    .demo__input-wrapper,
    .demo__chat-container {
        background: #f0f3ff !important;
        border-color: rgba(34, 48, 255, 0.1) !important;
    }

    .demo__input-wrapper textarea {
        color: #0e1633 !important;
        background: white !important;
    }

    .demo__input-wrapper textarea::placeholder {
        color: #86868b;
    }

    .demo__input-footer {
        background: #f0f3ff;
        border-color: rgba(34, 48, 255, 0.08);
    }

    .system-btn {
        background: rgba(255, 255, 255, 0.7);
        border-color: rgba(0, 0, 0, 0.06);
        color: #1d1d1f;
    }

    .message__content {
        background: #ffffff !important;
    }

    .message__author,
    .message__text,
    .md-h2,
    .md-h3,
    .md-h4,
    strong {
        color: #0e1633 !important;
    }

    .inline-code {
        background: rgba(34, 48, 255, 0.08);
        color: #2230ff;
    }

    .demo__note {
        background: rgba(0, 122, 255, 0.1);
        color: #0e1633;
    }
}

/* ==================== Accessibility ==================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .typing-cursor {
        animation: none;
        opacity: 1;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {

    .system-btn,
    .demo__input-wrapper,
    .demo__chat-container {
        border-width: 2px;
    }

    .demo__actions .btn {
        border-width: 2px;
    }
}