:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #fff;
  --border: #dfe3e8;
  --text: #17191c;
  --muted: #707782;
  --blue: #0f7cff;
  --blue-soft: #e8f2ff;
  --green-soft: #eaf7ec;
  --red: #e73b45;
  --shadow: 0 12px 32px rgba(30, 37, 46, .1);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.crm-shell { display: grid; grid-template-columns: 390px 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sidebar-header, .dialog-header { min-height: 74px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); gap: 12px; }
.sidebar-header h1, .dialog-header h2 { margin: 0; font-size: 20px; }
.sync-state { border: 0; background: transparent; color: var(--muted); padding: 4px 0 0; font-size: 12px; }
.header-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.icon-button, .link-button { border: 0; color: #4f5966; background: transparent; padding: 7px; font-size: 12px; }
.chat-tools { padding: 12px; border-bottom: 1px solid var(--border); }
input, textarea, select { width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 11px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(15,124,255,.12); }
.filters { display: flex; gap: 5px; margin-top: 10px; }
.filters button { border: 0; background: #f0f2f5; border-radius: 16px; padding: 7px 11px; color: #555f6b; font-size: 12px; }
.filters button.active { background: var(--blue); color: white; }
.chat-list { min-height: 0; overflow-y: auto; flex: 1; }
.chat-row { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 14px 18px; border-bottom: 1px solid #edf0f3; cursor: pointer; }
.chat-row:hover { background: #f7f9fb; }
.chat-row.active { background: var(--blue-soft); }
.chat-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: 11px; }
.chat-item, .chat-last { grid-column: 1 / 3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-item { color: #49515b; }
.chat-last { color: var(--muted); }
.chat-status { display: inline-flex; align-items: center; gap: 6px; color: #5c6570; font-size: 11px; margin-top: 2px; }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(231,59,69,.13); }
.dialog-column { min-width: 0; min-height: 0; height: 100%; overflow: hidden; background: #eef1f5; }
.empty-chat { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-chat h2 { color: var(--text); margin: 12px 0 0; }
.empty-chat p { margin: 8px 0; }
.empty-chat-icon, .brand-mark { width: 58px; height: 58px; margin: auto; display: grid; place-items: center; border-radius: 18px; background: var(--blue); color: #fff; font-size: 30px; font-weight: 750; }
.dialog { height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.dialog-header { background: #fff; }
.dialog-title { min-width: 0; flex: 1; }
.dialog-title div { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-image { width: 45px; height: 45px; border-radius: 10px; object-fit: cover; }
.item-link { color: var(--blue); text-decoration: none; font-size: 13px; }
.mobile-back { display: none; }
.messages { min-height: 0; overflow-y: auto; padding: 24px 6%; display: flex; flex-direction: column; gap: 8px; }
.chat-loading { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.skeleton-message { width: min(46%, 430px); height: 58px; border-radius: 15px; background: linear-gradient(90deg, #fff 25%, #e5e9ee 50%, #fff 75%); background-size: 220% 100%; animation: skeleton-shimmer 1.2s infinite linear; }
.skeleton-message.wide { width: min(68%, 650px); }
.skeleton-message.out { align-self: flex-end; background-image: linear-gradient(90deg, #dcebff 25%, #c6dcf7 50%, #dcebff 75%); }
.chat-load-error { margin: auto; color: #c72632; background: #fff; border-radius: 12px; padding: 14px 18px; }
.load-older { align-self: center; border: 0; border-radius: 18px; padding: 8px 14px; color: #536170; background: rgba(255,255,255,.9); margin-bottom: 8px; }
@keyframes skeleton-shimmer { to { background-position-x: -220%; } }
.message { max-width: min(72%, 720px); border-radius: 15px; padding: 10px 13px; box-shadow: 0 1px 1px rgba(0,0,0,.03); position: relative; }
.message.in { align-self: flex-start; background: #fff; }
.message.out { align-self: flex-end; background: #dcebff; }
.message.turn-linked { border-left: 4px solid #ffab2e; cursor: pointer; }
.message.turn-linked:hover { box-shadow: 0 0 0 3px rgba(255,171,46,.18); }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { text-align: right; color: var(--muted); font-size: 10px; margin-top: 5px; }
.message img { display: block; max-width: 100%; max-height: 340px; margin: 7px 0; border-radius: 10px; }
.message audio { width: min(340px, 100%); margin-top: 7px; }
.transcript { margin-top: 7px; padding: 8px; background: rgba(0,0,0,.04); border-radius: 8px; font-size: 12px; }
.universal-card { margin-top: 6px; padding: 8px; border: 1px dashed #b9c0c9; border-radius: 8px; color: var(--muted); font-size: 12px; }
.composer { background: #fff; border-top: 1px solid var(--border); padding: 13px 20px 17px; }
.composer label { display: block; color: var(--muted); font-size: 12px; margin: 8px 0 5px; }
.composer textarea { min-height: 66px; resize: vertical; }
.ai-state { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.ai-card { background: var(--green-soft); padding: 11px 13px; border-radius: 12px; margin-bottom: 10px; }
.ai-card textarea { background: transparent; border: 0; padding: 7px 0; min-height: 58px; box-shadow: none; }
.ai-card-head { display: flex; justify-content: space-between; color: #416047; font-weight: 650; font-size: 12px; }
.manager-note { background: #fff1c8; color: #6d5100; padding: 9px; border-radius: 8px; margin-top: 8px; font-size: 13px; }
.button-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.primary, .secondary, .danger, .danger-quiet { border: 0; border-radius: 9px; padding: 10px 14px; font-weight: 600; }
.primary { color: white; background: var(--blue); }
.secondary { background: #edf0f4; color: #313740; }
.danger { color: white; background: var(--red); }
.danger-quiet { background: #fff0f1; color: #b92530; }
button:disabled { opacity: .55; cursor: not-allowed; }
.test-badge { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); top: 8px; background: #c51d28; color: white; border-radius: 20px; padding: 7px 16px; font-weight: 750; font-size: 12px; box-shadow: var(--shadow); }
.modal { width: min(720px, calc(100vw - 30px)); max-height: 86vh; border: 0; border-radius: 16px; padding: 0; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(17, 24, 33, .42); }
.modal > :not(.modal-head) { margin-left: 20px; margin-right: 20px; }
.modal > :last-child { margin-bottom: 20px; }
.modal-head { position: sticky; top: 0; background: white; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head button { border: 0; background: transparent; color: var(--muted); }
.small-modal { width: min(520px, calc(100vw - 30px)); }
.wide-modal { width: min(900px, calc(100vw - 30px)); }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 5px; }
.details-grid { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; padding: 16px 0; font-size: 13px; }
.details-grid dt { color: var(--muted); }
.details-grid dd { margin: 0; overflow-wrap: anywhere; }
.details-grid input[type="checkbox"] { width: auto; }
.details-section { border-top: 1px solid var(--border); padding: 14px 0; }
.details-section h3 { margin: 0 0 8px; font-size: 14px; }
pre.json { max-height: 280px; overflow: auto; background: #f4f6f8; border-radius: 10px; padding: 12px; font-size: 11px; white-space: pre-wrap; }
.preview-text { margin-top: 18px !important; padding: 14px; border-radius: 10px; background: #f4f7fa; white-space: pre-wrap; }
.warning { color: #8b5a00; font-size: 12px; }
.form-error { color: #c72632; font-size: 12px; min-height: 17px; margin-top: 6px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: #1c222a; color: white; border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); z-index: 30; }
.empty { color: var(--muted); padding: 25px; text-align: center; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #e6f1ff, #f4f6f9 55%); }
.login-card { width: min(390px, 100%); background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 35px; text-align: center; }
.login-card h1 { margin: 14px 0 0; }
.login-card p { color: var(--muted); }
.login-card form { text-align: left; margin-top: 25px; }
.login-card label { font-size: 13px; display: block; margin-bottom: 6px; }
.login-card button { width: 100%; margin-top: 12px; }
@media (max-width: 780px) {
  .crm-shell { grid-template-columns: 1fr; }
  .dialog-column { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .dialog-column { display: block; }
  .mobile-back { display: inline-block; border: 0; background: transparent; color: var(--blue); }
  .message { max-width: 88%; }
  .details-grid { grid-template-columns: 1fr; }
}
