/* Mean.Coach User Chat Styles - Light Theme */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-message-user: #0f172a;
    --bg-message-admin: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-on-dark: #ffffff;
    --border-color: #e2e8f0;
    --accent: #0f172a;
    --accent-hover: #1e293b;
    --error: #ef4444;
    --success: #22c55e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    height: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* Main Layout - Fixed height handling */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: var(--bg-primary);
}

/* Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    padding: 16px 40px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-header h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.login-btn {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.login-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.login-btn.logged-in {
    background: var(--bg-tertiary);
    border-color: var(--success);
    color: var(--success);
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--success);
    color: var(--success);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.user-menu-btn:hover {
    background: var(--border-color);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 140px;
    z-index: 100;
    overflow: hidden;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

/* Messages Area */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

.messages-inner {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 680px;
    margin: 0 auto;
}

/* Loading indicator */
.loading {
    display: none;
    justify-content: center;
    padding: 40px 20px;
}

.loading.active {
    display: flex;
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Message Bubbles */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 20px;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
    line-height: 1.45;
    font-size: 15px;
}

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

.message.user {
    align-self: flex-end;
    background: var(--bg-message-user);
    color: var(--text-on-dark);
    border-bottom-right-radius: 6px;
}

.message.admin {
    align-self: flex-start;
    background: var(--bg-message-admin);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}

.message-time {
    font-size: 11px;
    margin-top: 6px;
    opacity: 0.7;
}

.message.user .message-time {
    text-align: right;
    color: var(--text-on-dark);
}

.message.admin .message-time {
    color: var(--text-secondary);
}

/* Typing Indicator */
.typing-indicator {
    padding: 16px 20px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

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

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

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

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

/* Media Messages */
.message-media {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 6px;
    overflow: hidden;
}

.message-media img,
.message-media video {
    max-width: 100%;
    max-height: 280px;
    border-radius: 12px;
    display: block;
}

.message-media audio {
    width: 100%;
    min-width: 220px;
}

/* Custom Audio Player */
.audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    min-width: 200px;
}

.audio-player audio {
    display: none;
}

.audio-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.message.admin .audio-play-btn {
    background: rgba(0, 0, 0, 0.1);
}

.audio-play-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message.admin .audio-play-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

.audio-play-btn .pause-icon {
    display: none;
}

.audio-play-btn.playing .play-icon {
    display: none;
}

.audio-play-btn.playing .pause-icon {
    display: block;
}

.audio-progress {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    min-width: 80px;
}

.message.admin .audio-progress {
    background: rgba(0, 0, 0, 0.1);
}

.audio-progress-bar {
    height: 100%;
    background: currentColor;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.audio-time {
    font-size: 12px;
    opacity: 0.8;
    min-width: 35px;
    text-align: right;
}

/* System Messages */
.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 8px 16px;
}

/* Signup Form */
.signup-form {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    max-width: 100%;
    width: 340px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Desktop: wider form with side-by-side fields */
@media (min-width: 601px) {
    .signup-form {
        width: 480px;
    }

    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .form-row .form-group {
        margin-bottom: 16px;
    }
}

.signup-form h3 {
    margin-bottom: 20px;
    font-size: 17px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 15px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.1);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.checkbox-group label {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 0;
}

.checkbox-group a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.checkbox-group a:hover {
    text-decoration: underline;
}

.form-submit {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.15s;
}

.form-submit:hover {
    background: var(--accent-hover);
}

.form-submit:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.form-error {
    color: var(--error);
    font-size: 13px;
    margin-top: 12px;
}

.form-divider {
    display: flex;
    align-items: center;
    margin: 16px 0;
}

.form-divider span {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 0 12px;
    flex-shrink: 0;
}

.form-divider::before,
.form-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.form-submit.secondary {
    background: transparent;
    color: var(--accent);
    border: 2px solid var(--accent);
    margin-top: 0;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
}

.form-submit.secondary:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
}

/* OTP Input */
.otp-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.otp-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* Input Area */
.input-container {
    padding: 16px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    background: transparent;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 600px;
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 14px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.message-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    transition: none;
    overflow-y: hidden;
}

.message-input:focus {
    outline: none;
}

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

.input-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-actions {
    display: flex;
    gap: 8px;
}

.action-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.action-pill:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.action-pill.recording {
    background: var(--error);
    border-color: var(--error);
    color: white;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.send-btn {
    background: var(--accent);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}

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

/* File input hidden */
.file-input {
    display: none;
}

/* Upload progress */
.upload-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.2s;
}

/* Links in messages */
.message a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message.user a {
    color: var(--text-on-dark);
}

.message.admin a {
    color: var(--accent);
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 600px) {
    .chat-header {
        padding: 14px 20px;
    }

    .messages-container {
        padding: 16px;
    }

    .message {
        max-width: 88%;
    }

    .input-container {
        padding: 12px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        max-width: none;
        border-radius: 16px;
        padding: 12px 14px;
    }

    .action-pill span {
        display: none;
    }

    .action-pill {
        padding: 8px;
        border-radius: 50%;
    }
}

/* iOS Safari fixes */
@supports (-webkit-touch-callout: none) {
    .chat-container {
        height: -webkit-fill-available;
    }
}

/* Voice Memo (iMessage style) */
.voice-memo {
    display: flex !important;
    align-items: center;
    gap: 10px;
    min-width: 180px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.15);
    border-radius: 20px;
}

.voice-memo audio,
.voice-memo audio::-webkit-media-controls,
.voice-memo audio::-webkit-media-controls-panel,
.voice-memo audio::-webkit-media-controls-enclosure {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    visibility: hidden !important;
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.message.user .voice-play-btn {
    background: rgba(255, 255, 255, 0.2);
}

.message.admin .voice-play-btn {
    background: rgba(0, 0, 0, 0.1);
}

.voice-play-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message.admin .voice-play-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

.voice-play-btn .pause-icon {
    display: none;
}

.voice-play-btn.playing .play-icon {
    display: none;
}

.voice-play-btn.playing .pause-icon {
    display: block;
}

.voice-waveform {
    flex: 1;
    height: 24px;
    background: linear-gradient(90deg,
        currentColor 2px, transparent 2px,
        transparent 4px, currentColor 4px, currentColor 6px, transparent 6px,
        transparent 8px, currentColor 8px, currentColor 10px, transparent 10px,
        transparent 12px, currentColor 12px, currentColor 14px, transparent 14px
    );
    background-size: 16px 100%;
    opacity: 0.4;
    border-radius: 2px;
    min-width: 80px;
}

.voice-duration {
    font-size: 12px;
    opacity: 0.7;
    flex-shrink: 0;
}

/* Voice Preview */
.voice-preview {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 20px 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 90%;
    width: 340px;
}

.voice-preview-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.voice-preview audio {
    width: 100%;
    height: 44px;
    border-radius: 10px;
}

.voice-preview-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    margin-top: 4px;
}

.voice-preview .action-btn {
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    min-width: 100px;
}

.voice-preview .action-btn.discard {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.voice-preview .action-btn.discard:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.voice-preview .action-btn.send {
    background: var(--accent);
    color: white;
}

.voice-preview .action-btn.send:hover {
    background: var(--accent-hover);
}

/* ToS Prompt */
.tos-prompt {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tos-accept-btn {
    align-self: flex-start;
    padding: 12px 28px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.tos-accept-btn:hover {
    background: var(--accent-hover);
}

/* Hidden utility */
.hidden {
    display: none !important;
}
