/* ========================================
   Simplex Tech Chat - Styles
   Oliver - Frontend | Simplex Tech Inc
   ======================================== */

:root {
    --primary: #25D366;
    --primary-dark: #1DA851;
    --primary-light: #E8F8EE;
    --bg: #F0F2F5;
    --bg-chat: #EFEAE2;
    --sidebar-bg: #FFFFFF;
    --sidebar-hover: #F5F6F6;
    --sidebar-active: #E8F8EE;
    --header-bg: #FFFFFF;
    --text-primary: #111B21;
    --text-secondary: #667781;
    --text-muted: #8696A0;
    --border: #E9EDEF;
    --msg-sent: #D9FDD3;
    --msg-received: #FFFFFF;
    --input-bg: #FFFFFF;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: all 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* --- Sidebar --- */
.sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--sidebar-bg);
    z-index: 10;
}
.sidebar__logo {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-mark {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary) 0%, #075E54 100%);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
}
.sidebar__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.sidebar__subtitle {
    font-size: 12px;
    color: var(--text-muted);
}
.sidebar__section { padding: 8px 12px; }
.sidebar__label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 8px 4px;
}
.sidebar__footer {
    margin-top: auto;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* --- Agent Card --- */
.agent-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.agent-card:hover { background: var(--sidebar-hover); }
.agent-card.active { background: var(--sidebar-active); }
.agent-card__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}
.agent-card__info { flex: 1; min-width: 0; }
.agent-card__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.agent-card__role {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Connection Status --- */
.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-dot--connected { background: var(--primary); }
.status-dot--disconnected { background: #DC2626; }
.status-dot--connecting { background: #F59E0B; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* --- Conversation Panel --- */
.conv-panel {
    width: 300px;
    min-width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.conv-panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--sidebar-bg);
}
.conv-panel__back,
.conv-panel__new {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.conv-panel__back:hover,
.conv-panel__new:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}
.conv-panel__new { color: var(--primary); }
.conv-panel__new:hover { background: var(--primary-light); color: var(--primary-dark); }
.conv-panel__agent {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.conv-panel__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    color: white;
    flex-shrink: 0;
}
.conv-panel__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-panel__list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-active); }
.conv-item__icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
}
.conv-item.active .conv-item__icon { background: var(--primary-light); color: var(--primary); }
.conv-item__info { flex: 1; min-width: 0; }
.conv-item__title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item__meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}
.conv-item__delete {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: var(--text-muted);
    opacity: 0;
    transition: var(--transition);
    display: flex;
    align-items: center;
}
.conv-item:hover .conv-item__delete { opacity: 1; }
.conv-item__delete:hover { color: #DC2626; background: rgba(220,38,38,0.1); }
.conv-panel__empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* --- Welcome Screen --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.welcome__content {
    text-align: center;
    max-width: 500px;
    padding: 40px;
}
.welcome__icon {
    width: 80px;
    height: 80px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    color: var(--primary);
}
.welcome__content h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.welcome__content p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 32px;
}
.welcome__agents {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.welcome-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.welcome-tag:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.welcome-tag__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* --- Chat Screen --- */
.chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 5;
}
.chat-header__back {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
}
.chat-header__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
}
.chat-header__name {
    font-size: 15px;
    font-weight: 600;
}
.chat-header__role {
    font-size: 12px;
    color: var(--text-secondary);
}
.chat-header__actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: var(--transition);
}
.icon-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-chat);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d5d0c8' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
}
.chat-messages__inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
}

/* Message Bubble */
.message {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    animation: msgIn 0.25s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.message--user {
    align-self: flex-end;
}
.message--assistant {
    align-self: flex-start;
}
.message__bubble {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.message--user .message__bubble {
    background: var(--msg-sent);
    border-top-right-radius: 2px;
}
.message--assistant .message__bubble {
    background: var(--msg-received);
    border-top-left-radius: 2px;
}
.message__time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    text-align: right;
}
.message--assistant .message__time { text-align: left; }

/* Markdown styling inside messages */
.message__bubble h1, .message__bubble h2, .message__bubble h3 {
    margin: 8px 0 4px;
    font-size: 15px;
    font-weight: 700;
}
.message__bubble h1 { font-size: 17px; }
.message__bubble p { margin: 4px 0; }
.message__bubble ul, .message__bubble ol {
    margin: 4px 0;
    padding-left: 20px;
}
.message__bubble li { margin: 2px 0; }
.message__bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Consolas', 'Fira Code', monospace;
    font-size: 13px;
}
.message__bubble pre {
    background: #1E1E1E;
    color: #D4D4D4;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}
.message__bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.message__bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}
.message__bubble th, .message__bubble td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    text-align: left;
}
.message__bubble th {
    background: rgba(0,0,0,0.04);
    font-weight: 600;
}
.message__bubble strong { font-weight: 700; }
.message__bubble blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 10px;
    margin: 8px 0;
    color: var(--text-secondary);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    color: var(--text-muted);
    font-size: 13px;
}
.typing-indicator__dots {
    display: flex;
    gap: 3px;
}
.typing-indicator__dots span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: dotBounce 1.4s infinite ease-in-out;
}
.typing-indicator__dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator__dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.chat-input {
    padding: 12px 20px;
    background: var(--bg-chat);
    transition: var(--transition);
}
.chat-input.drag-over {
    background: var(--primary-light);
}
.chat-input__attach {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}
.chat-input__attach:hover {
    color: var(--primary);
    background: var(--primary-light);
}
.chat-input__attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.chat-input__attachments:empty {
    display: none;
    margin-bottom: 0;
}
.attachment-preview {
    position: relative;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: white;
    display: flex;
    flex-direction: column;
    max-width: 220px;
}
.attachment-preview__top {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 28px 6px 6px;
}
.attachment-preview__img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
}
.attachment-preview__file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 4px;
}
.attachment-preview__file-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
}
.attachment-preview__file-icon--pdf { background: #FEE2E2; color: #DC2626; }
.attachment-preview__file-icon--txt { background: #DBEAFE; color: #2563EB; }
.attachment-preview__file-icon--csv { background: #D1FAE5; color: #059669; }
.attachment-preview__file-icon--json { background: #FEF3C7; color: #D97706; }
.attachment-preview__details {
    min-width: 0;
}
.attachment-preview__name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    max-width: 120px;
}
.attachment-preview__size {
    font-size: 11px;
    color: var(--text-muted);
}
.attachment-preview__comment {
    width: 100%;
    border: none;
    border-top: 1px solid var(--border);
    padding: 5px 8px;
    font-size: 11px;
    outline: none;
    color: var(--text-secondary);
    background: transparent;
    font-family: var(--font);
    box-sizing: border-box;
}
.attachment-preview__comment::placeholder {
    color: var(--text-muted);
}
.attachment-preview__remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.5);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    transition: var(--transition);
}
.attachment-preview:hover .attachment-preview__remove {
    opacity: 1;
}
.attachment-preview__remove:hover {
    background: #DC2626;
}

/* Message attachments */
.message__attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
.message__image {
    max-width: 300px;
    max-height: 250px;
    border-radius: 6px;
    cursor: pointer;
    object-fit: contain;
    display: block;
}
.message__image:hover {
    opacity: 0.9;
}
.message__file-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.04);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}
.message__file-icon {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 9px;
    flex-shrink: 0;
}
.message__file-icon--pdf { background: #FEE2E2; color: #DC2626; }
.message__file-icon--txt { background: #DBEAFE; color: #2563EB; }
.message__file-icon--csv { background: #D1FAE5; color: #059669; }
.message__file-icon--json { background: #FEF3C7; color: #D97706; }
.message__attachment-comment {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
}
.message__attachment-item {
    display: flex;
    flex-direction: column;
}

/* Image modal */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
    padding: 20px;
}
.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.chat-input__container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--input-bg);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}
.chat-input__container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,211,102,0.15);
}
.chat-input__field {
    flex: 1;
    border: none;
    outline: none;
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 4px 0;
    color: var(--text-primary);
    background: transparent;
}
.chat-input__field::placeholder { color: var(--text-muted); }
.chat-input__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}
.chat-input__send:hover { background: var(--primary-dark); transform: scale(1.05); }
.chat-input__send:disabled { background: var(--text-muted); cursor: not-allowed; transform: none; }
.chat-input__hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(0);
        transition: transform 0.3s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.hidden { transform: translateX(-100%); }
    .conv-panel {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 99;
        width: 100%;
        min-width: 0;
        box-shadow: var(--shadow-lg);
    }
    .chat-header__back { display: block; }
    .message { max-width: 85%; }
}
