:root {
    --ink: #17202a;
    --muted: #697586;
    --line: #e6e9ef;
    --surface: #ffffff;
    --soft: #f5f7fb;
    --brand: #246bfe;
    --brand-dark: #174fc4;
    --success: #17a673;
    --danger: #c53a47;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--soft); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.primary {
    border: 0; border-radius: 10px; padding: 11px 18px; background: var(--brand);
    color: white; font-weight: 700;
}
.primary:hover { background: var(--brand-dark); }
.stack { display: grid; gap: 15px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; color: #3d4856; }
input, textarea, select {
    width: 100%; border: 1px solid #ced5df; border-radius: 9px; padding: 10px 12px;
    background: white; color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #246bfe1c; }
textarea { resize: vertical; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
    width: min(420px, 100%); padding: 36px; background: white; border: 1px solid var(--line);
    border-radius: 18px; box-shadow: 0 20px 50px #23314a12;
}
.brand-mark {
    display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
    background: var(--brand); color: white; font-weight: 800;
}
.login-card h1 { margin: 22px 0 6px; font-size: 26px; }
.login-card .muted { margin: 0 0 24px; }
.alert { padding: 11px 13px; margin-bottom: 18px; border-radius: 9px; background: #fff0f1; color: var(--danger); font-size: 14px; }
.topbar {
    height: 64px; padding: 0 22px; display: flex; align-items: center; justify-content: space-between;
    background: white; border-bottom: 1px solid var(--line);
}
.business-name { margin-left: 14px; color: var(--muted); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.topbar-actions form { margin: 0; }
.presence-label { display: flex; align-items: center; gap: 8px; }
.presence-label select { width: 105px; padding: 7px; }
.link-button, .icon-button { border: 0; background: none; color: var(--brand); }
.desk-layout { height: calc(100vh - 64px); display: grid; grid-template-columns: 370px 1fr; }
.conversation-panel { display: flex; flex-direction: column; min-width: 0; background: white; border-right: 1px solid var(--line); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 10px; }
.panel-heading h1 { margin: 0; font-size: 20px; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.icon-button { font-size: 24px; }
.filters { display: flex; gap: 7px; padding: 8px 18px 14px; }
.filter { border: 0; border-radius: 20px; padding: 7px 12px; background: var(--soft); color: var(--muted); font-size: 12px; }
.filter.active { background: #e8f0ff; color: var(--brand); font-weight: 700; }
.conversation-list { overflow: auto; border-top: 1px solid var(--line); }
.conversation-row {
    width: 100%; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px;
    padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: white; text-align: left;
}
.conversation-row:hover, .conversation-row.selected { background: #f2f6ff; }
.avatar {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
    background: #e7edfa; color: var(--brand); font-weight: 800;
}
.conversation-copy { min-width: 0; display: grid; gap: 5px; }
.row-title { display: flex; justify-content: space-between; gap: 8px; }
.row-title time { color: var(--muted); font-size: 11px; }
.preview { color: var(--muted); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.status { text-transform: capitalize; padding: 2px 6px; border-radius: 10px; background: #edf0f5; }
.status.waiting { background: #fff2d8; color: #8c5d00; }
.status.open { background: #dcf7ed; color: #08724c; }
.unread { place-self: start end; min-width: 20px; padding: 3px 6px; border-radius: 10px; background: var(--brand); color: white; text-align: center; font-size: 11px; }
.list-empty { padding: 30px; color: var(--muted); text-align: center; }
.chat-panel { min-width: 0; background: #f7f8fb; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 30px; }
.empty-state h1, .empty-state h2 { color: var(--ink); margin-bottom: 4px; }
.empty-icon { font-size: 44px; }
.active-chat { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.chat-header { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; background: white; border-bottom: 1px solid var(--line); }
.chat-header h2 { margin: 0 0 4px; font-size: 18px; }
.chat-header p { margin: 0; color: var(--muted); font-size: 13px; }
.chat-actions select { width: 125px; padding: 8px; }
.messages { overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.message { max-width: min(72%, 620px); padding: 10px 13px; border-radius: 13px; background: white; box-shadow: 0 1px 2px #18243b14; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.agent, .message.ai { align-self: flex-end; background: var(--brand); color: white; }
.message.system { align-self: center; background: #edf0f5; color: var(--muted); font-size: 12px; }
.message small { display: block; margin-top: 5px; opacity: .7; font-size: 10px; }
.reply-form { display: flex; align-items: end; gap: 10px; padding: 14px 18px; background: white; border-top: 1px solid var(--line); }
.reply-form textarea { min-height: 45px; }
.widget-page { min-height: 100vh; background: transparent; }
.widget-shell { height: 100vh; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; background: white; }
.widget-header { display: flex; align-items: center; gap: 11px; padding: 16px; background: var(--brand); color: white; }
.widget-header small { display: block; opacity: .8; margin-top: 3px; }
.agent-dot { width: 11px; height: 11px; border-radius: 50%; background: #b7c0cf; box-shadow: 0 0 0 4px #ffffff20; }
.agent-dot.online { background: #4ee1a8; }
.widget-content { overflow: auto; padding: 18px; }
.widget-content > p { margin-top: 0; color: var(--muted); line-height: 1.5; }
.widget-chat { min-height: 0; display: grid; grid-template-rows: 1fr auto; }
.widget-chat .messages { padding: 14px; }
.widget-chat .message { max-width: 85%; }
.widget-shell footer { padding: 7px; border-top: 1px solid var(--line); color: #8b94a3; text-align: center; font-size: 10px; }
.error-text { min-height: 18px; color: var(--danger) !important; font-size: 12px; }
@media (max-width: 720px) {
    .desk-layout { grid-template-columns: 1fr; }
    .chat-panel { position: fixed; inset: 64px 0 0; transform: translateX(100%); transition: transform .2s; }
    .chat-panel:has(.active-chat:not(.hidden)) { transform: translateX(0); }
    .business-name { display: none; }
}
