/* Chat-Modul - Mobile-first Styles */

:root {
    --primary: #0066cc;
    --primary-dark: #0052a3;
    --success: #28a745;
    --danger: #dc3545;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #adb5bd;
    --gray-700: #495057;
    --gray-900: #212529;
    --white: #ffffff;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-100);
}

/* ===== Kunden-Chat ===== */
.customer-chat {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.chat-container {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--white);
    box-shadow: var(--shadow);
}

@media (min-width: 768px) {
    .chat-container {
        height: 90vh;
        max-height: 800px;
        margin: auto;
        border-radius: var(--radius);
    }
}

.chat-header {
    padding: 16px 20px;
    background: var(--primary);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    opacity: 0.9;
}

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

.status-dot.connected {
    background: var(--success);
}

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

/* Start-Screen */
.start-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.start-content {
    text-align: center;
    max-width: 300px;
}

.logo {
    font-size: 4rem;
    margin-bottom: 20px;
}

.start-content h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.start-content p {
    color: var(--gray-700);
    margin-bottom: 24px;
}

.start-content input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    transition: border-color 0.2s;
}

.start-content input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

/* Chat-Screen */
.chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-screen.hidden {
    display: none;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--gray-100);
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Nachrichten */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius);
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

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

.message.customer {
    align-self: flex-end;
    background: var(--primary);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message.support {
    align-self: flex-start;
    background: var(--white);
    color: var(--gray-900);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

.message.support .message-time {
    color: var(--gray-500);
}

/* Nachricht-Formular */
.message-form {
    padding: 12px 16px;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.message-form textarea {
    flex: 1;
    padding: 12px 16px;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--gray-300);
    border-radius: 24px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.message-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-send {
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

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

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

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

.hidden {
    display: none !important;
}

/* ===== Admin-Panel ===== */
.admin-panel {
    height: 100vh;
    overflow: hidden;
}

/* Login */
.login-container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--white);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-box h1 {
    margin-bottom: 24px;
}

.login-box input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.login-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.error-message {
    color: var(--danger);
    background: #ffeaea;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

/* Admin Layout */
.admin-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.admin-header {
    padding: 16px 20px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.admin-header h1 {
    font-size: 1.3rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: var(--gray-700);
    cursor: pointer;
}

.chat-count {
    font-size: 0.9rem;
    color: var(--gray-500);
}

.btn-logout {
    padding: 8px 16px;
    font-size: 0.9rem;
    color: var(--gray-700);
    text-decoration: none;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.btn-logout:hover {
    background: var(--gray-100);
}

.admin-layout {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Chat-Liste */
.chat-list {
    width: 320px;
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .chat-list {
        width: 100%;
        position: absolute;
        left: 0;
        top: 60px;
        bottom: 0;
        z-index: 10;
    }
    
    .chat-list.hidden-mobile {
        display: none;
    }
}

.chat-list-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--gray-500);
}

.chat-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    transition: background 0.2s;
}

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

.chat-item.active {
    background: var(--gray-100);
    border-left: 3px solid var(--primary);
}

.chat-item.closed {
    opacity: 0.6;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 600;
}

.chat-item-time {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.chat-item-preview {
    font-size: 0.9rem;
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.75rem;
    background: var(--gray-200);
    border-radius: 10px;
    margin-left: 8px;
}

/* Chat-Bereich */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--gray-100);
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.active-chat.hidden {
    display: none;
}

.chat-info {
    padding: 12px 20px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.customer-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-time {
    font-size: 0.85rem;
    color: var(--gray-500);
}

.chat-actions {
    margin-left: auto;
}

.btn-close-chat {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--white);
    background: var(--success);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.btn-close-chat:hover {
    background: #218838;
}

.btn-close-chat.reopen {
    background: var(--gray-500);
}

.btn-close-chat.reopen:hover {
    background: var(--gray-700);
}

#adminMessagesContainer {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

#adminMessages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* System-Nachricht */
.system-message {
    text-align: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--gray-500);
    background: var(--gray-200);
    border-radius: 20px;
    align-self: center;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--white);
    border-radius: var(--radius);
    align-self: flex-start;
    box-shadow: var(--shadow);
}

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

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

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

/* Ticket Export */
.ticket-export {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ticket-input {
    width: 90px;
    padding: 6px 10px;
    font-size: 0.85rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    text-align: center;
}

.ticket-input:focus {
    outline: none;
    border-color: var(--primary);
}

.ticket-input::-webkit-inner-spin-button,
.ticket-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-export-ticket {
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--white);
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-export-ticket:hover {
    background: var(--primary-dark);
}

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--gray-900);
    color: var(--white);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: toastIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Responsive adjustments for ticket export */
@media (max-width: 768px) {
    .chat-info {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .chat-actions {
        width: 100%;
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .ticket-export {
        flex: 1;
    }
    
    .btn-close-chat {
        flex: 1;
    }
}
