:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c2434;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --danger: #dc2626;
  --ai-bg: #f0fdfa;
  --ai-border: #99f6e4;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column;
}

.topbar {
  height: 56px; background: #0f172a; color: #fff; padding: 0 18px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; background: var(--primary);
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
}
.brand small { display: block; font-size: 11px; color: #94a3b8; }

.topbar-controls { display: flex; align-items: center; gap: 10px; }
.ctrl { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #cbd5e1; }
.ctrl select {
  background: #1e293b; color: #fff; border: 1px solid #334155; border-radius: 6px;
  padding: 5px 8px; font-size: 12.5px;
}

.workspace {
  flex: 1; display: grid; grid-template-columns: 290px 1fr 370px; min-height: 0;
}

/* Inbox */
.inbox {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.inbox-header { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.inbox-header h3 { margin: 0 0 8px; font-size: 14px; }
.filters { display: flex; gap: 6px; }
.pill {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
}
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.conversation-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 12px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: #ecfdf5; border-left: 3px solid var(--primary); }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 4px; }
.conv-title { font-weight: 600; font-size: 13px; }
.conv-preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 6px; margin-top: 6px; font-size: 11px; color: var(--muted); }

/* Thread */
.thread-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread-header {
  padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.thread-header small { display: block; color: var(--muted); font-size: 12px; }

.message-thread {
  flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 72%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.45;
  white-space: pre-wrap;
}
.msg.customer { align-self: flex-start; background: #fff; border: 1px solid var(--border); }
.msg.operator, .msg.agent { align-self: flex-end; background: var(--primary); color: #fff; }
.msg-meta { font-size: 10.5px; opacity: 0.72; margin-top: 4px; }

/* Copilot card */
.copilot-card {
  margin: 0 18px 12px; padding: 12px 14px; background: var(--ai-bg);
  border: 1px solid var(--ai-border); border-radius: 12px;
}
.copilot-card.hidden { display: none; }
.copilot-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.badge-ai { font-weight: 700; font-size: 12px; color: var(--primary); }
.badge-risk {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: #fef3c7; color: #92400e; margin-left: 6px;
}
.badge-conf { font-size: 11px; color: var(--muted); margin-left: 6px; }
.copilot-summary { margin: 4px 0 8px; font-size: 12.5px; color: #334155; }
.copilot-card textarea {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px; font-family: inherit; font-size: 13px;
}
.copilot-actions { display: flex; gap: 8px; margin-top: 8px; }

.composer {
  display: flex; gap: 10px; padding: 12px 18px; background: var(--surface); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 10px;
  font-family: inherit; font-size: 13.5px; resize: none;
}

/* Right inspector */
.inspector {
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: transparent; padding: 11px 8px; font-size: 12.5px;
  font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; padding: 14px; overflow-y: auto; flex: 1; }
.tab-panel.active { display: block; }

.info-box { margin-bottom: 16px; }
.info-box h4, .mini-form h4 { margin: 0 0 8px; font-size: 13px; }
.kv-list { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.code-box {
  display: block; background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 8px;
  font-size: 11.5px; word-break: break-all; margin-bottom: 8px;
}

.mini-form { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.mini-form input, .mini-form textarea {
  border: 1px solid #cbd5e1; border-radius: 6px; padding: 7px 9px; font-size: 12.5px; font-family: inherit;
}
.card-list { display: flex; flex-direction: column; gap: 8px; }
.mini-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px; font-size: 12px; background: #f8fafc;
}
.mini-card strong { display: block; margin-bottom: 3px; }
.mini-card p { margin: 2px 0; color: #475569; }

/* Buttons */
.btn-primary {
  background: var(--primary); color: #fff; border: none; border-radius: 7px;
  padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
  background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; border-radius: 7px;
  padding: 8px 12px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn-outline {
  border: 1px solid #334155; color: #fff; background: transparent; border-radius: 6px;
  padding: 6px 10px; font-size: 12px; text-decoration: none; cursor: pointer;
}
.inspector .btn-outline { border-color: var(--border); color: var(--text); }
.btn-ghost {
  background: rgba(255,255,255,0.08); color: inherit; border: 1px solid rgba(148,163,184,0.3);
  border-radius: 6px; padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.full { width: 100%; }
.hidden { display: none !important; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 32px 16px; }
.tag-pending { background: #fef3c7; color: #92400e; padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.dark-btn { color: var(--text); border-color: var(--border); background: #fff; }

/* Overlays: Login & Admin Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.72); z-index: 9999;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: #fff; width: 380px; max-width: 100%; padding: 28px; border-radius: 14px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-card label { font-size: 12.5px; font-weight: 600; color: #334155; }
.login-card input {
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px; font-size: 13.5px;
}
.brand.dark { color: var(--text); margin-bottom: 8px; }
.error-msg {
  background: #fee2e2; color: #b91c1c; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
}

.modal-card {
  background: #fff; width: 780px; max-width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 14px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.mini-form select {
  border: 1px solid #cbd5e1; border-radius: 6px; padding: 7px 9px; font-size: 12.5px; background: #fff;
}
.status-banner {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  padding: 8px 10px; border-radius: 8px; font-size: 12px; margin-bottom: 10px;
}
.btn-sm {
  padding: 5px 9px; font-size: 11.5px; margin-top: 6px;
}
