/* ============================================================================
   CareAI Chat Interface - Mobile-First Styles
   WeChat-inspired design for optimal mobile experience
   ============================================================================ */

/* CSS Variables */
:root {
    /* Colors - WeChat inspired */
    --primary-color: #07C160;
    --primary-dark: #06AD56;
    --secondary-color: #576B95;
    --background-color: #EDEDED;
    --chat-bg: #EDEDED;
    --white: #FFFFFF;
    --black: #000000;
    --gray-100: #F7F7F7;
    --gray-200: #EBEBEB;
    --gray-300: #D9D9D9;
    --gray-400: #B2B2B2;
    --gray-500: #888888;
    --gray-600: #666666;
    --gray-700: #444444;
    --text-primary: #191919;
    --text-secondary: #666666;
    --text-hint: #B2B2B2;
    --danger-color: #FA5151;
    --warning-color: #FFC300;
    
    /* User message - green bubble */
    --user-bubble-bg: #95EC69;
    --user-bubble-text: #000000;
    
    /* Assistant message - white bubble */
    --assistant-bubble-bg: #FFFFFF;
    --assistant-bubble-text: #191919;
    
    /* System message */
    --system-bubble-bg: rgba(0, 0, 0, 0.05);
    --system-bubble-text: #888888;
    
    /* Spacing */
    --header-height: 56px;
    --input-area-height: 60px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    
    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", 
                 "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--chat-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Desktop max-width */
@media (min-width: 768px) {
    #app {
        max-width: 480px;
        box-shadow: var(--shadow-lg);
    }
}

/* ============================================================================
   Header
   ============================================================================ */

.chat-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    z-index: 100;
}

@media (min-width: 768px) {
    .chat-header {
        left: 50%;
        transform: translateX(-50%);
        max-width: 480px;
    }
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 16px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    font-size: 24px;
}

.header-text {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-menu {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--gray-600);
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.header-menu:hover {
    background-color: var(--gray-100);
}

/* Menu Dropdown */
.menu-dropdown {
    position: fixed;
    top: calc(var(--header-height) - 4px);
    right: 8px;
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 200;
}

.menu-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    font-size: 15px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s;
}

.menu-item:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.menu-item:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.menu-item:hover {
    background-color: var(--gray-100);
}

.menu-icon {
    font-size: 16px;
}

/* ============================================================================
   Chat Container
   ============================================================================ */

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(var(--header-height) + 16px) 12px calc(var(--input-area-height) + var(--safe-area-bottom) + 16px);
    background: var(--chat-bg);
    -webkit-overflow-scrolling: touch;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100%;
}

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

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message */
.user-message {
    align-self: flex-end;
}

.user-message .message-content {
    background: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
    padding: 10px 14px;
    word-wrap: break-word;
    position: relative;
}

/* Assistant Message */
.assistant-message {
    align-self: flex-start;
}

.assistant-message .message-content {
    background: var(--assistant-bubble-bg);
    color: var(--assistant-bubble-text);
    border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
}

/* System Message */
.system-message {
    align-self: center;
    max-width: 90%;
}

.system-message .message-content {
    background: var(--system-bubble-bg);
    color: var(--system-bubble-text);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    font-size: 14px;
    text-align: center;
}

/* Message Content Formatting */
.message-content p {
    margin: 0 0 8px 0;
}

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

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content h2, .message-content h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 12px 0 8px 0;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 12px 0;
}

/* Code blocks */
.message-content code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: "SF Mono", Monaco, monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: var(--gray-100);
    padding: 12px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

/* Audio Button in Message */
.audio-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 12px;
    background: var(--gray-100);
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.2s;
}

.audio-btn:hover {
    background: var(--gray-200);
}

.audio-btn.playing {
    color: var(--primary-color);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

/* Mode Change Notification */
.mode-notification {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(7, 193, 96, 0.1);
    color: var(--primary-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================================================
   Input Area
   ============================================================================ */

.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    z-index: 100;
}

@media (min-width: 768px) {
    .input-area {
        left: 50%;
        transform: translateX(-50%);
        max-width: 480px;
    }
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Voice Button */
.voice-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--gray-100);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-btn:hover {
    background: var(--gray-200);
}

.voice-btn:active {
    background: var(--primary-color);
    color: var(--white);
    transform: scale(0.95);
}

.voice-btn.recording {
    background: var(--danger-color);
    color: var(--white);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.voice-icon {
    width: 22px;
    height: 22px;
}

.voice-text {
    display: none;
}

/* Show text on larger screens */
@media (min-width: 768px) {
    .voice-btn {
        width: auto;
        padding: 10px 16px;
        border-radius: var(--radius-lg);
        flex-direction: row;
        gap: 6px;
    }
    
    .voice-text {
        display: inline;
        font-size: 14px;
    }
}

/* Text Input */
.text-input-wrapper {
    flex: 1;
    min-width: 0;
}

.text-input {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    background: var(--gray-100);
    border: none;
    border-radius: var(--radius-xl);
    font-size: 16px;
    line-height: 1.4;
    color: var(--text-primary);
    resize: none;
    outline: none;
    transition: background-color 0.2s;
}

.text-input:focus {
    background: var(--white);
    box-shadow: 0 0 0 2px var(--primary-color);
}

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

/* Send Button */
.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

/* ============================================================================
   Recording Overlay
   ============================================================================ */

.recording-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 300;
}

.recording-overlay.active {
    opacity: 1;
    visibility: visible;
}

.recording-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: var(--radius-lg);
    color: var(--white);
}

.recording-pulse {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--danger-color);
    animation: recordingPulse 1.5s ease-in-out infinite;
    opacity: 0.5;
}

@keyframes recordingPulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 0.3; }
}

.recording-mic {
    position: relative;
    z-index: 1;
    color: var(--white);
}

.recording-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

.recording-overlay.cancel .recording-indicator {
    background: rgba(250, 81, 81, 0.9);
}

.recording-overlay.cancel .recording-text::before {
    content: "松开取消";
}

/* ============================================================================
   Loading Overlay
   ============================================================================ */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 400;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 500;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 320px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.2s;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal-content ul {
    font-size: 14px;
    color: var(--text-secondary);
    padding-left: 20px;
    margin-bottom: 16px;
}

.modal-content .version {
    font-size: 12px;
    color: var(--text-hint);
    margin-bottom: 16px;
}

.modal-close {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-md);
    color: var(--white);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background: var(--primary-dark);
}

/* ============================================================================
   Utilities
   ============================================================================ */

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Disable text selection on buttons */
button {
    user-select: none;
    -webkit-user-select: none;
}

/* Smooth scrolling */
@media (prefers-reduced-motion: no-preference) {
    .chat-container {
        scroll-behavior: smooth;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1A1A1A;
        --chat-bg: #111111;
        --white: #1A1A1A;
        --gray-100: #2A2A2A;
        --gray-200: #3A3A3A;
        --gray-300: #4A4A4A;
        --text-primary: #FFFFFF;
        --text-secondary: #B0B0B0;
        --text-hint: #707070;
        --user-bubble-bg: #07C160;
        --assistant-bubble-bg: #2A2A2A;
        --assistant-bubble-text: #FFFFFF;
    }
}
