:root {
  --bg: #f5f7f8;
  --panel: #fff;
  --line: #d8e0e3;
  --text: #182124;
  --muted: #68777d;
  --green: #128c7e;
  --green-dark: #075e54;
  --green-soft: #e5f5f1;
  --amber: #b86200;
  --amber-soft: #fff3df;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
.app { min-height: 100vh; display: grid; grid-template-rows: 56px 1fr; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 18px; color: #fff; background: var(--green-dark); }
.brand, .top-actions { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 7px; background: rgba(255,255,255,.14); font-weight: 800; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { color: rgba(255,255,255,.72); font-size: 12px; }
.agent-switch { display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,.82); font-size: 13px; }
.agent-switch select, .mode-pill { height: 34px; border-radius: 7px; border: 1px solid rgba(255,255,255,.24); background: rgba(255,255,255,.1); color: #fff; padding: 0 10px; }
.agent-switch option { color: var(--text); }
.mode-pill { display: inline-flex; align-items: center; font-size: 13px; font-weight: 800; }
.logout-link { color: #fff; font-size: 13px; font-weight: 800; text-decoration: none; border: 1px solid rgba(255,255,255,.24); border-radius: 7px; padding: 8px 10px; }
.layout { min-height: 0; display: grid; grid-template-columns: 320px minmax(360px, 1fr) 340px; }
.sidebar, .chat, .details { min-height: 0; background: var(--panel); }
.sidebar { border-right: 1px solid var(--line); display: grid; grid-template-rows: auto auto 1fr; }
.pane-head { padding: 14px; border-bottom: 1px solid var(--line); }
.pane-head h1, .pane-head h2 { margin: 0 0 10px; font-size: 16px; }
.search { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 7px; padding: 0 12px; background: #fbfcfc; }
.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fbfcfc; }
.filter { height: 32px; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 800; }
.filter.active { background: var(--green-soft); color: var(--green-dark); }
.conversation-list { overflow: auto; }
.conversation-item { width: 100%; min-height: 86px; display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px 14px; text-align: left; background: #fff; border-bottom: 1px solid #edf1f2; }
.conversation-item.active, .conversation-item:hover { background: #eef8f5; }
.conversation-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 800; font-size: 14px; }
.conversation-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-height: 22px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; color: var(--green-dark); background: var(--green-soft); white-space: nowrap; }
.badge.warn { color: var(--amber); background: var(--amber-soft); }
.badge.closed { color: var(--muted); background: #edf1f2; }
.preview { grid-column: 1 / -1; margin: 6px 0 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; color: var(--muted); font-size: 12px; }
.chat { display: grid; grid-template-rows: auto 1fr auto; border-right: 1px solid var(--line); }
.chat-head { min-height: 72px; padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; }
.contact-title strong, .contact-title span { display: block; }
.contact-title span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.chat-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.icon-button, .primary-button, .secondary-button { height: 36px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 12px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.icon-button { width: 36px; padding: 0; color: var(--green-dark); background: var(--green-soft); }
.primary-button { color: #fff; background: var(--green); }
.secondary-button { color: var(--green-dark); background: #fff; border: 1px solid var(--line); }
.message-area { overflow: auto; padding: 18px; background: #f4f8f7; }
.message-row { display: flex; margin: 9px 0; }
.message-row.out { justify-content: flex-end; }
.bubble { max-width: min(72%, 620px); padding: 9px 10px 7px; border-radius: 7px; background: #fff; box-shadow: 0 1px 2px rgba(24,33,36,.08); line-height: 1.38; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.out .bubble { background: #dcf8c6; }
.bubble-meta { display: flex; justify-content: flex-end; gap: 6px; margin-top: 4px; color: #607177; font-size: 11px; }
.composer { border-top: 1px solid var(--line); background: #fff; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.composer textarea { width: 100%; min-height: 44px; max-height: 118px; resize: vertical; border: 1px solid var(--line); border-radius: 7px; padding: 11px 12px; background: #fbfcfc; }
.composer-note { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.composer-tools { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.details { display: grid; grid-template-rows: auto 1fr; }
.details-scroll { overflow: auto; padding: 14px; }
.section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.section:first-child { padding-top: 0; }
.section h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
label { display: grid; gap: 6px; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 800; }
label input, label select { width: 100%; min-height: 36px; border-radius: 7px; border: 1px solid var(--line); background: #fbfcfc; color: var(--text); padding: 8px 10px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px; margin: 8px 0; font-size: 13px; }
.kv span { color: var(--muted); font-weight: 800; }
.preview-box { padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfc; color: var(--text); font-size: 12px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.activity-log { display: grid; gap: 8px; }
.log-item { padding: 9px 10px; border-radius: 7px; background: #fbfcfc; border: 1px solid var(--line); font-size: 12px; line-height: 1.35; color: var(--muted); }
.log-item strong { display: block; color: var(--text); font-size: 13px; margin-bottom: 2px; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(420px, calc(100vw - 36px)); padding: 12px 14px; border-radius: 8px; color: #fff; background: #182124; box-shadow: 0 12px 28px rgba(24,33,36,.12); font-size: 14px; transform: translateY(20px); opacity: 0; pointer-events: none; transition: transform .18s ease, opacity .18s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: var(--bg); }
.login-panel { width: min(420px, 100%); padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 12px 28px rgba(24,33,36,.08); }
.login-brand { color: var(--text); margin-bottom: 18px; }
.login-brand .brand-mark { color: #fff; background: var(--green-dark); }
.login-brand span { color: var(--muted); }
.login-form .primary-button { width: 100%; }
.login-error { margin-bottom: 14px; padding: 10px 12px; border-radius: 7px; color: #b3261e; background: #fdecea; font-size: 14px; font-weight: 800; }
.login-success { margin-bottom: 14px; padding: 10px 12px; border-radius: 7px; color: var(--green-dark); background: var(--green-soft); font-size: 14px; font-weight: 800; }
.account-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.account-actions .secondary-button { text-decoration: none; }
.desk-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: #fff; box-shadow: 0 20px 50px rgba(24,33,36,.22); }
.desk-dialog::backdrop { background: rgba(24,33,36,.48); }
.desk-dialog-wide { width: min(980px, calc(100vw - 32px)); }
.dialog-form { padding: 18px; overflow: auto; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-head h2, .library-grid h3 { margin: 0; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.library-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.compact-form { padding: 12px; margin: 12px 0; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfc; }
.compact-form textarea { min-height: 90px; resize: vertical; border: 1px solid var(--line); border-radius: 7px; padding: 9px; }
.library-list { display: grid; gap: 8px; margin-top: 12px; max-height: 360px; overflow: auto; }
.library-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; text-align: left; }
.library-item:hover { background: #eef8f5; }
.library-item strong, .library-item span { display: block; }
.library-item span { margin-top: 3px; color: var(--muted); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.library-actions { display: flex; gap: 6px; align-items: start; }
.small-button { min-height: 30px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--green-dark); background: #fff; font-size: 12px; font-weight: 800; }
@media (max-width: 1120px) { .layout { grid-template-columns: 300px 1fr; } .details { display: none; } }
@media (max-width: 760px) { .app { grid-template-rows: auto 1fr; } .topbar { align-items: flex-start; flex-direction: column; padding: 12px; } .layout { grid-template-columns: 1fr; } .sidebar { min-height: 280px; max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); } .chat { min-height: 62vh; border-right: 0; } .composer { grid-template-columns: 1fr; } .bubble { max-width: 88%; } .library-grid { grid-template-columns: 1fr; } }
