@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --brand: #224887;
    --brand-dark: #0f2744;
    --accent: #10B0CE;
    --accent-hover: #0e9ab5;
    --bg-app: #f0f4f8;
    --bg-sidebar: #ffffff;
    --bg-chat: #e8edf3;
    --bg-header: #ffffff;
    --bg-outgoing-user: #d4f1e8;
    --bg-bot: #ffffff;
    --bg-operator: #fff4e6;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --operator: #c2410c;
    --bot-color: #0369a1;
    --danger: #dc2626;
    --shadow-sm: 0 1px 3px rgba(15, 39, 68, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 39, 68, 0.08);
    --sidebar-width: 360px;
    --header-height: 64px;
    --composer-height: 68px;
}

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

html, body { height: 100%; }

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background: var(--bg-app);
    -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

.fa, .fas, .far, .fab {
    font-family: "Font Awesome 5 Free" !important;
    font-style: normal;
    font-weight: 900;
    -webkit-font-smoothing: antialiased;
}

.fab { font-family: "Font Awesome 5 Brands" !important; font-weight: 400; }
.far { font-weight: 400 !important; }

html:not(.has-session) #app { display: none !important; }
html.has-session #login-screen { display: none !important; }
html.has-session #app { display: flex !important; }
html:not(.has-session) body { overflow: hidden; }

/* ── Layout ── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-app);
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: 0;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
}

.sidebar-brand__logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
    flex-shrink: 0;
}

.sidebar-brand__text {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.sidebar-brand__text h1 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.sidebar-user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.sidebar-user__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.sidebar-user__name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.95);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-bar .logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    flex-shrink: 0;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.sidebar-user-bar .logout-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.search-wrap {
    position: relative;
    padding: 12px 16px 14px;
    background: var(--bg-sidebar);
}

.search-wrap__icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.status-pill {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-pill--online {
    background: rgba(16, 176, 206, 0.35);
    color: #ecfdf5;
}

.status-pill--offline {
    background: rgba(255, 255, 255, 0.15);
    color: #fecaca;
}

.search-wrap input {
    width: 100%;
    padding: 10px 12px 10px 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-app);
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(16, 176, 206, 0.15);
}

/* ── Conversation list ── */
.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-list::-webkit-scrollbar { width: 6px; }
.conversation-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.conversation-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease;
}

.conversation-item:hover { background: #f8fafc; }

.conversation-item.is-active {
    background: #eef6ff;
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

.conversation-item__top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
}

.conversation-item__title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item__time {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.conversation-item__preview {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.conversation-item__meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.tag {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.tag--operator {
    background: #ffedd5;
    color: var(--operator);
}

.tag--bot {
    background: #e0f2fe;
    color: var(--bot-color);
}

.list-empty {
    padding: 32px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ── Chat panel ── */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-chat);
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px 32px;
    color: var(--text-secondary);
    background: var(--bg-chat);
}

.empty-state__icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}

.empty-state h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.empty-state p {
    max-width: 420px;
    line-height: 1.6;
    font-size: 0.9rem;
}

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

.chat-header {
    min-height: var(--header-height);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.chat-header-info h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--brand);
}

.chat-header-info p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.operator-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--operator);
    background: #ffedd5;
    padding: 6px 12px;
    border-radius: 999px;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn--primary {
    background: var(--brand);
    color: #fff;
}

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

.btn--ghost {
    background: #fff;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn--ghost:hover {
    background: var(--bg-app);
    color: var(--text-primary);
}

.btn--small {
    padding: 6px 12px;
    font-size: 0.75rem;
}

/* ── Messages ── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 5%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: var(--bg-chat);
    background-image:
        radial-gradient(circle at 20% 20%, rgba(16, 176, 206, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(34, 72, 135, 0.04) 0%, transparent 50%);
}

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

.message-row {
    display: flex;
    flex-direction: column;
    max-width: min(68%, 480px);
}

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

.message-row.bot,
.message-row.operator,
.message-row.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.message-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding-left: 4px;
}

.message-row.bot .message-label,
.message-row.assistant .message-label {
    color: var(--bot-color);
}

.message-row.operator .message-label {
    color: var(--operator);
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-row.user .message-bubble {
    background: var(--bg-outgoing-user);
    border-bottom-right-radius: 4px;
    color: #134e4a;
}

.message-row.bot .message-bubble,
.message-row.assistant .message-bubble {
    background: var(--bg-bot);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.message-row.operator .message-bubble {
    background: var(--bg-operator);
    border-bottom-left-radius: 4px;
    border: 1px solid #fed7aa;
    color: #7c2d12;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message-attachment {
    display: block;
    max-width: 100%;
    margin-bottom: 6px;
    border-radius: 10px;
}

.message-attachment--image {
    max-height: 240px;
    object-fit: contain;
}

.message-attachment--video {
    max-width: 100%;
}

.message-attachment--document {
    color: var(--brand);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
}

/* ── Task banner ── */
.task-banner {
    margin: 0 20px 8px;
    padding: 14px 16px;
    border-radius: 12px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    box-shadow: var(--shadow-sm);
}

.task-banner__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.task-banner__message {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: #9a3412;
    max-height: 160px;
    overflow-y: auto;
}

/* ── Composer ── */
.composer {
    min-height: var(--composer-height);
    padding: 12px 20px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(15, 39, 68, 0.04);
}

.composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 12px 18px;
    max-height: 120px;
    line-height: 1.45;
    font-size: 0.9rem;
    background: var(--bg-app);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.composer textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(16, 176, 206, 0.12);
    background: #fff;
}

.send-btn {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s, box-shadow 0.15s;
}

.send-btn:hover {
    box-shadow: var(--shadow-md);
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 900px) {
    .app { flex-direction: column; }

    .sidebar {
        width: 100%;
        min-width: 0;
        max-height: 42vh;
    }

    .messages { padding: 16px 12px; }

    .message-row { max-width: 88%; }

    .sidebar-user-bar .logout-btn__label { display: none; }
}
