/* ── Robokod Coach — светлая тема, desktop ≥1280px ── */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --border-strong: #d2d7dd;
  --text: #1f2933;
  --muted: #6b7280;
  --muted-2: #9aa3ad;
  --accent: #2563eb;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ── buttons ── */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: #f0f2f5; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #128a3e; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #1d4ed8; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eceef1; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* ── overlays / modals ── */
.overlay {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.login-card, .modal {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.18); padding: 28px; width: 360px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input, .modal textarea, .reply-text, .search, #escalate-note, .draft-editor {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px;
  font-size: 14px; font-family: inherit; width: 100%; resize: vertical;
}
.login-card input:focus, .modal textarea:focus, .reply-text:focus, .search:focus, .draft-editor:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.login-error { color: var(--red); font-size: 13px; }
.modal { width: 440px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ── topbar ── */
.topbar {
  height: 52px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 16px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-label { color: var(--muted); font-size: 13px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  background: #f0f2f5; border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; cursor: default;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }
.dot-gray { background: var(--muted-2); }

/* ── layout ── */
.columns { display: grid; grid-template-columns: 300px 1fr 420px; height: calc(100vh - 52px); }
.col { overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }
.col-left { border-right: 1px solid var(--border); background: var(--panel); }
.col-center { background: var(--bg); }
.col-right { border-left: 1px solid var(--border); background: var(--panel); }

/* ── left: chat list ── */
.inbox-tabs { display: flex; gap: 4px; padding: 10px 10px 6px; }
.tab {
  flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600;
}
.tab-active { background: #eef2ff; color: var(--accent); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.badge-muted { background: var(--muted-2); }
.search { margin: 0 10px 8px; width: calc(100% - 20px); }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item {
  padding: 11px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 9px; align-items: flex-start;
}
.chat-item:hover { background: #f7f9fb; }
.chat-item.active { background: #eef2ff; }
.chat-icon { font-size: 13px; line-height: 20px; }
.chat-main { flex: 1; min-width: 0; }
.chat-name { font-size: 14px; }
.chat-item.unread .chat-name { font-weight: 700; }
.chat-item.read .chat-name { color: var(--muted); }
.chat-preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.chat-time { color: var(--muted-2); font-size: 11px; }
.chat-unread-badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--muted); }

/* ── center: dialog ── */
.placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.dialog { display: flex; flex-direction: column; height: 100%; }
.dialog-header { padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.dialog-title { font-size: 15px; font-weight: 700; }
.dialog-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.crm-link { color: var(--accent); text-decoration: none; font-size: 13px; }
.crm-link:hover { text-decoration: underline; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 76%; padding: 9px 12px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg-in { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-out { align-self: flex-end; background: #dcf5e3; border: 1px solid #bce8cc; border-bottom-right-radius: 4px; }
.msg-time { display: block; font-size: 11px; color: var(--muted-2); margin-top: 4px; }
.msg-coach-tag { font-size: 10px; color: var(--green); font-weight: 700; }
.reply-area { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--panel); align-items: flex-end; }
.reply-text { flex: 1; max-height: 140px; }

/* ── right: coach panel ── */
.coach-head { padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--border); }
.coach-panel { flex: 1; overflow-y: auto; padding: 16px; }
.coach-cta { text-align: center; padding: 24px 8px; }
.coach-cta .btn { width: 100%; margin-bottom: 10px; }
.coach-hint { color: var(--muted); font-size: 13px; }

.coach-loading { text-align: center; padding: 30px 8px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 14px auto 0; max-width: 220px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); animation: fill 40s ease-out forwards; }
@keyframes fill { to { width: 100%; } }

.coach-card { animation: fadein .2s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600; margin-bottom: 12px; width: 100%;
}
.card-badge .intent { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.badge-green { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; }
.badge-amber { background: var(--amber-bg); color: var(--amber); border: 1px solid #fde68a; }
.badge-red { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }

.customer-block { background: #f7f9fb; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.customer-block .child { font-weight: 700; font-size: 14px; }
.customer-block .row { color: var(--muted); margin-top: 2px; }

.section-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 14px 0 6px; }
.draft-box { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 8px; padding: 12px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; position: relative; }
.draft-editor { min-height: 120px; }
.draft-copy { position: absolute; top: 6px; right: 6px; border: none; background: transparent; cursor: pointer; font-size: 14px; opacity: .6; }
.draft-copy:hover { opacity: 1; }

.warnings { list-style: none; margin: 0; padding: 0; }
.warning { background: var(--amber-bg); border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; font-size: 13px; }
.next-step { color: var(--muted); font-size: 13px; background: #f7f9fb; border-radius: 8px; padding: 8px 10px; }

.sources details { font-size: 13px; }
.sources summary { cursor: pointer; color: var(--accent); }
.sources ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); }

.coach-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.coach-actions .send-btn { grid-column: 1 / -1; }
.coach-error { background: var(--red-bg); border: 1px solid #fecaca; color: var(--red); border-radius: 8px; padding: 14px; text-align: center; }
.coach-error .btn { margin-top: 10px; }

/* ── toasts ── */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: #1f2933; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); animation: slidein .2s ease; max-width: 340px;
  display: flex; align-items: center; gap: 10px;
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast button { background: rgba(255,255,255,.2); border: none; color: #fff; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.pulse { animation: pulse 1s ease 2; }
@keyframes pulse { 0%,100% { background: inherit; } 50% { background: #fef9c3; } }
