:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --border: #e2e8f0;
  --visitor: #e0ecff;
  --agent: #e8f7e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px;
  gap: 10px;
}

.header {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.title {
  font-size: 16px;
  font-weight: 600;
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.conn-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.conn-item {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: #334155;
}

.conn-item.ok {
  border-color: #16a34a;
  color: #166534;
  background: #f0fdf4;
}

.conn-item.warn {
  border-color: #d97706;
  color: #92400e;
  background: #fffbeb;
}

.conn-item.err {
  border-color: #dc2626;
  color: #991b1b;
  background: #fef2f2;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.messages {
  flex: 1;
  min-height: 45vh;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: #fafcff;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.conversation-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  background: #fff;
}

.conversation-item.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.conversation-title {
  font-size: 13px;
  font-weight: 600;
}

.conversation-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message {
  max-width: 80%;
  padding: 8px 10px;
  border-radius: 10px;
  line-height: 1.35;
  word-break: break-word;
}

.message-status {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.message-meta {
  margin-top: 4px;
  font-size: 11px;
  color: #475569;
}

.message.failed .message-status {
  color: #dc2626;
}

.message.visitor {
  align-self: flex-end;
  background: var(--visitor);
}

.message.agent {
  align-self: flex-start;
  background: var(--agent);
}

.message img {
  max-width: 220px;
  border-radius: 8px;
}

.input-area {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

textarea {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px;
  font-size: 14px;
}

button {
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

button.secondary {
  background: #475569;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-replies button {
  background: #e2e8f0;
  color: #0f172a;
  font-size: 12px;
}

.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.emoji-panel.hidden {
  display: none;
}

.emoji-item {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: #0f172a;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.admin-kv {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  background: #fff;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-item {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  background: #fff;
}
.admin-item:hover {
  border-color: #cbd5e1;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
}

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}

.drawer.hidden {
  display: none;
}

.drawer-body {
  width: min(780px, 94vw);
  height: 100%;
  background: #fff;
  padding: 12px;
  overflow: auto;
}

.drawer-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-message {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  background: #fff;
}

@media (min-width: 768px) {
  .page {
    padding: 20px;
  }

  .layout {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }

  .conversation-list {
    max-height: 58vh;
  }

  .messages {
    min-height: 56vh;
    max-height: 62vh;
  }

  .title {
    font-size: 18px;
  }
}
