/* Smart HAI Professional Styling - v2.5.1 */

:root {
    /* Atriensis Color System */
    --hai-primary: #2c3e50;
    --hai-secondary: #7f8c8d;
    --hai-accent: #27ae60;
    --hai-accent-secondary: #3498db;
    --hai-success: #27ae60;
    --hai-warning: #f39c12;
    --hai-danger: #e74c3c;
    --hai-background: #ecf0f1;
    --hai-surface: rgba(255, 255, 255, 0.95);
    --hai-border: rgba(149, 165, 166, 0.3);
    --hai-shadow: 0 25px 50px 0 rgba(44, 62, 80, 0.12);
    --hai-shadow-hover: 0 30px 60px 0 rgba(44, 62, 80, 0.15);

    /* Typography */
    --hai-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;

    /* Apple Easing */
    --hai-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--hai-font-family);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, #fefefe 0%, #f8f9fa 50%, #f5f6f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hai-primary);
    line-height: 1.6;
    position: relative;
    overflow: hidden;
}

/* Manus-style elegant floating dots */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(0, 0, 0, 0.15) 2px, transparent 2px),
        radial-gradient(circle at 80% 20%, rgba(0, 0, 0, 0.12) 2px, transparent 2px),
        radial-gradient(circle at 40% 40%, rgba(0, 0, 0, 0.08) 1px, transparent 1px),
        radial-gradient(circle at 60% 60%, rgba(0, 0, 0, 0.15) 2px, transparent 2px),
        radial-gradient(circle at 90% 90%, rgba(0, 0, 0, 0.12) 2px, transparent 2px);
    background-size:
        120px 120px,
        80px 80px,
        60px 60px,
        100px 100px,
        140px 140px;
    background-position:
        0 0,
        40px 40px,
        80px 80px,
        20px 20px,
        60px 60px;
    animation: appleFloat 35s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 10% 30%, rgba(0, 0, 0, 0.10) 1px, transparent 1px),
        radial-gradient(circle at 70% 10%, rgba(0, 0, 0, 0.12) 2px, transparent 2px),
        radial-gradient(circle at 30% 70%, rgba(0, 0, 0, 0.08) 1px, transparent 1px);
    background-size:
        90px 90px,
        110px 110px,
        70px 70px;
    background-position:
        30px 30px,
        10px 10px,
        50px 50px;
    animation: appleFloat 42s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite reverse;
    pointer-events: none;
    z-index: 0;
}

@keyframes appleFloat {

    0%,
    100% {
        transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
        opacity: 0.8;
    }

    16.66% {
        transform: translate3d(8px, -12px, 0) rotate(0.8deg) scale(1.02);
        opacity: 0.9;
    }

    33.33% {
        transform: translate3d(-6px, -18px, 0) rotate(-0.6deg) scale(0.98);
        opacity: 1;
    }

    50% {
        transform: translate3d(-12px, -8px, 0) rotate(-1deg) scale(1.01);
        opacity: 0.85;
    }

    66.66% {
        transform: translate3d(-8px, 10px, 0) rotate(0.4deg) scale(0.99);
        opacity: 0.95;
    }

    83.33% {
        transform: translate3d(6px, 14px, 0) rotate(0.7deg) scale(1.02);
        opacity: 0.75;
    }
}

/* Ensure main content is above the pattern */
.auth-container,
.hai-app {
    position: relative;
    z-index: 10;
    background: transparent !important;
}

/* Auth Container */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
}

/* Main HAI App Container */
.hai-app {
    display: none;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    height: 90vh;
    margin: 2rem;
    border-radius: 24px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    border: none;
    box-shadow: var(--hai-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    animation: keynoteSlideIn 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes keynoteSlideIn {
    0% {
        opacity: 0;
        transform: translate3d(0, 80px, 0) scale(0.9);
        filter: blur(8px);
    }

    60% {
        opacity: 0.8;
        transform: translate3d(0, -10px, 0) scale(1.02);
        filter: blur(2px);
    }

    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
        filter: blur(0px);
    }
}

/* Enhanced depth overlay */
.hai-app::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.01) 0%, rgba(0, 0, 0, 0.06) 100%);
    border-radius: 24px;
    pointer-events: none;
}

/* HAI Header */
.hai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2rem 2rem 1rem;
    position: relative;
    z-index: 10;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.avatar-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar-circle {
    width: 120px;
    height: 48px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 2px solid rgba(39, 174, 96, 0.3);
    box-shadow: 0 8px 25px rgba(44, 62, 80, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.6);
    transition: all 0.3s var(--hai-ease);
}

.avatar-circle:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.avatar-initial {
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
}

.avatar-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.active-indicator {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, var(--hai-success) 0%, #30D158 100%);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 4px 15px rgba(52, 199, 89, 0.4);
    animation: pulse 2s infinite var(--hai-ease);
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

.avatar-info h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--hai-primary);
}

.avatar-info p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--hai-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Message Footer Usage Monitor Styles */
.message-usage-monitor {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--hai-secondary);
}

.usage-label {
    color: var(--hai-secondary);
    font-size: 0.75rem;
    font-weight: 400;
}

.usage-value {
    color: #7f8c8d;
    font-weight: 400;
    font-size: 0.75rem;
    text-decoration: none;
    cursor: default;
    margin-right: 0.5rem;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* Usage Alert Styles */
.usage-alert {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--hai-surface);
    border: 1px solid var(--hai-warning);
    border-radius: 12px;
    box-shadow: var(--hai-shadow);
    padding: 1rem;
    max-width: 300px;
    animation: slideIn 0.3s ease-out;
}

.alert-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-icon {
    font-size: 1.2rem;
}

.alert-message {
    flex: 1;
    color: var(--hai-primary);
    font-weight: 500;
    font-size: 0.9rem;
}

.alert-close {
    background: none;
    border: none;
    color: var(--hai-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s var(--hai-ease);
}

.alert-close:hover {
    background: var(--hai-background);
    color: var(--hai-primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(52, 199, 89, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(52, 199, 89, 0.2);
}

.logout-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: var(--hai-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s var(--hai-ease);
    font-family: var(--hai-font-family);
}

.logout-button:hover {
    opacity: 0.7;
    transform: translateY(-1px);
}

.logout-button:active {
    transform: translateY(0);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--hai-success);
    border-radius: 50%;
    animation: pulse 2s infinite var(--hai-ease);
}

.status-text {
    font-size: 0.75rem;
    color: var(--hai-success);
    font-weight: 500;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.chat-messages {
    height: 100%;
    overflow-y: auto;
    padding: 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Message Styling */
.message {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    animation: appleMessageSlide 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes appleMessageSlide {
    0% {
        opacity: 0;
        transform: translate3d(0, 30px, 0) scale(0.95);
        filter: blur(4px);
    }

    50% {
        opacity: 0.7;
        transform: translate3d(0, -5px, 0) scale(1.01);
        filter: blur(1px);
    }

    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
        filter: blur(0px);
    }
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 1rem 1.25rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.message.user .message-content {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.message.assistant .message-content {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: #495057;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 0.25rem;
}

.message-sender {
    font-size: 0.75rem;
    color: var(--hai-primary);
    font-weight: 500;
    opacity: 0.8;
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--hai-secondary);
    opacity: 0.7;
}

.copy-button {
    font-size: 0.65rem;
    color: var(--hai-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: all 0.2s var(--hai-ease);
    font-family: var(--hai-font-family);
    font-weight: 400;
    margin-left: 0.75rem;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.copy-button:hover {
    opacity: 0.8;
    color: var(--hai-accent);
    text-decoration: none;
}

.copy-button:active {
    opacity: 1;
    transform: scale(0.95);
}

.message.user .message-footer {
    flex-direction: row-reverse;
}

.message.user .message-sender {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    max-width: 60px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.7) 100%);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--hai-secondary);
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDots {

    0%,
    60%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    30% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.input-container {
    padding: 1.5rem 2rem 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 1rem 1.25rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    font-size: 1rem;
    font-family: var(--hai-font-family);
    background: white;
    color: var(--hai-primary);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s var(--hai-ease);
    resize: vertical;
    outline: none;
    min-height: 48px;
    max-height: 200px;
    line-height: 1.5;
}

.message-input:focus {
    border-color: #6c757d;
    box-shadow: 0 0 0 4px rgba(108, 117, 125, 0.15), 0 8px 25px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.98);
    transform: translateY(-2px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.send-button {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s var(--hai-ease);
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
    position: relative;
    overflow: hidden;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 8px 25px rgba(108, 117, 125, 0.5);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.send-button:active {
    transform: scale(0.92) translateY(1px);
    transition: all 0.1s cubic-bezier(0.16, 1, 0.3, 1);
}

.send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.send-button.sending {
    animation: sendingPulse 1s infinite var(--hai-ease);
}

@keyframes sendingPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* Powered By Footer */
.powered-by {
    text-align: center;
    font-size: 0.75rem;
    color: var(--hai-secondary);
    opacity: 0.7;
    margin-top: 1rem;
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 768px) {
    .hai-app {
        margin: 1rem;
        height: calc(100vh - 2rem);
        border-radius: 20px;
    }

    .hai-header {
        padding: 1.5rem 1.5rem 1rem;
    }

    .chat-messages {
        padding: 1rem 1.5rem;
    }

    .input-container {
        padding: 1rem 1.5rem 1.5rem;
    }

    .message {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .hai-app {
        margin: 0.5rem;
        height: calc(100vh - 1rem);
        border-radius: 16px;
    }

    .avatar-circle {
        width: 40px;
        height: 40px;
    }

    .avatar-info h2 {
        font-size: 1rem;
    }

    .connection-status {
        padding: 0.375rem 0.75rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --hai-primary: #f5f5f7;
        --hai-secondary: #a1a1a6;
        --hai-background: #1d1d1f;
        --hai-surface: rgba(26, 26, 29, 0.95);
        --hai-border: rgba(255, 255, 255, 0.1);
    }

    body {
        background: linear-gradient(135deg, #1d1d1f 0%, #2c2c2e 100%);
    }

    .message.assistant .message-content {
        background: linear-gradient(135deg, rgba(26, 26, 29, 0.9) 0%, rgba(26, 26, 29, 0.7) 100%);
        color: var(--hai-primary);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .message-input {
        background: rgba(26, 26, 29, 0.8);
        border-color: rgba(255, 255, 255, 0.1);
        color: var(--hai-primary);
    }

    .typing-dots {
        background: linear-gradient(135deg, rgba(26, 26, 29, 0.9) 0%, rgba(26, 26, 29, 0.7) 100%);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
}