@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-user: #e8f0fe;
    --bg-bot: #ffffff;
    --bg-operator: #fff7ed;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --user-color: #224887;
    --bot-color: #0369a1;
    --operator-color: #c2410c;
    --sidebar-width: 360px;
    --audit-width: 320px;
    --shadow-sm: 0 1px 3px rgba(15, 39, 68, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 39, 68, 0.08);
}

*, *::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);
}

button, input { font: inherit; }

/* Font Awesome — do not inherit Poppins from body */
.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;
}

/* Boot: avoid login flash when restoring session */
html:not(.has-session) #app { display: none; }
html.has-session #login-screen { display: none; }
html.has-session #app { display: grid; }

.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    background: var(--bg-app);
}

/* ── Sidebar ── */
.sidebar {
    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;
}

.total-count {
    font-size: 0.7rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.15);
    padding: 3px 8px;
    border-radius: 999px;
}

.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-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    -webkit-appearance: none;
    appearance: none;
}

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

.sidebar-user-bar .logout-btn:active {
    transform: scale(0.97);
}

.sidebar-user-bar .logout-btn .fa {
    font-size: 0.9rem;
    opacity: 0.95;
}

.sidebar-user-bar .logout-btn__label {
    letter-spacing: 0.02em;
}

.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;
}

.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 {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-sidebar);
}

.conversation-list::-webkit-scrollbar {
    width: 6px;
}

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

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

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

.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;
    margin-bottom: 4px;
}

.conversation-item__title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.conversation-item__time {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.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 {
    margin-top: 5px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ── Main panel ── */
.main-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
}

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

.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 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    max-width: 420px;
}

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

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

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

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

.detail-body {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr var(--audit-width);
    min-height: 0;
}

.messages-panel {
    background: var(--bg-chat);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    max-width: 92%;
    box-shadow: var(--shadow-sm);
}

.message-card--user {
    align-self: flex-start;
    border-left: 4px solid var(--user-color);
    background: var(--bg-user);
}

.message-card--assistant {
    align-self: flex-start;
    border-left: 4px solid var(--bot-color);
}

.message-card--operator {
    align-self: flex-end;
    border-right: 4px solid var(--operator-color);
    background: var(--bg-operator);
}

.message-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.75rem;
}

.sender-badge {
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-size: 0.65rem;
}

.sender-badge--user { background: #c7d2fe; color: var(--user-color); }
.sender-badge--assistant { background: #bae6fd; color: var(--bot-color); }
.sender-badge--operator { background: #fed7aa; color: var(--operator-color); }

.message-id {
    font-family: ui-monospace, monospace;
    color: var(--text-muted);
    word-break: break-all;
    font-size: 0.68rem;
}

.message-time {
    color: var(--text-muted);
    margin-left: auto;
    font-size: 0.7rem;
}

.message-sender-id {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.message-content {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    font-size: 0.9rem;
}

.message-extracted {
    margin-top: 8px;
    padding: 8px 10px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    border-left: 3px solid var(--accent);
}

.message-attachment { display: block; margin-top: 8px; max-width: 100%; border-radius: 8px; }
.message-attachment--image { max-height: 280px; object-fit: contain; background: #000; }
.message-attachment--video { max-height: 280px; width: 100%; background: #000; }

.message-attachment--document {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #f1f5f9;
    border-radius: 8px;
    color: var(--brand);
    text-decoration: none;
    font-size: 0.875rem;
}

.audit-sidebar {
    background: #fff;
    border-left: 1px solid var(--border);
    padding: 18px 16px;
    overflow-y: auto;
    font-size: 0.8125rem;
}

.audit-sidebar h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 600;
    margin: 18px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.audit-sidebar h3:first-child { margin-top: 0; }

.session-meta dt {
    color: var(--text-muted);
    margin-top: 8px;
    font-size: 0.7rem;
    font-weight: 500;
}

.session-meta dd {
    color: var(--text-primary);
    word-break: break-all;
    margin-left: 0;
    font-size: 0.8125rem;
}

.media-list { list-style: none; }
.media-list li { margin-bottom: 8px; }

.media-list a {
    color: var(--brand);
    text-decoration: none;
    word-break: break-all;
    font-size: 0.8125rem;
}

.media-list a:hover { color: var(--accent); text-decoration: underline; }
.media-list .media-meta { display: block; color: var(--text-muted); font-size: 0.68rem; margin-top: 2px; }

@media (max-width: 1100px) {
    .detail-body { grid-template-columns: 1fr; }
    .audit-sidebar {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 240px;
    }
}

@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { max-height: 45vh; }
    .sidebar-user-bar .logout-btn__label { display: none; }
    .sidebar-user-bar .logout-btn { padding: 8px 11px; }
}
