* { box-sizing: border-box; font-family: Arial, sans-serif; }
body { margin: 0; background: #f5f7fb; color: #1f2937; }
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #fff; padding: 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.sidebar a { color: #e5e7eb; text-decoration: none; padding: 8px 10px; border-radius: 8px; }
.sidebar a:hover { background: #374151; }
.content { padding: 24px; }
.card { background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.metric { font-size: 28px; font-weight: bold; }
.muted { color: #6b7280; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; }
th, td { padding: 10px; border-bottom: 1px solid #e5e7eb; text-align: left; }
th { background: #f9fafb; }
input, select, textarea, button { width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: 8px; margin-bottom: 10px; }
button { background: #2563eb; color: #fff; border: none; cursor: pointer; }
button:hover { background: #1d4ed8; }
.row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }
.login-wrap { max-width: 420px; margin: 80px auto; background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 6px rgba(0,0,0,.12); }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #e5e7eb; font-size: 12px; }
.log-box {
  background: #0b1020;
  color: #cde3ff;
  border-radius: 10px;
  padding: 14px;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.35;
  font-size: 13px;
}
.metric-ok { color: #166534; }
.metric-error { color: #b91c1c; }

.dialogs-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
}

.dialogs-sidebar {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f9fafb;
  padding: 8px;
  max-height: 72vh;
  overflow: auto;
}

.dialog-item {
  display: block;
  text-decoration: none;
  color: #111827;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
}

.dialog-item:hover { background: #f3f4f6; }

.dialog-item.active {
  border-color: #2563eb;
  background: #eff6ff;
}

.dialog-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.dialog-chat-id { font-weight: 700; }
.dialog-time { color: #6b7280; }

.dialog-last-text {
  font-size: 13px;
  line-height: 1.35;
  color: #374151;
  margin-bottom: 8px;
  word-break: break-word;
}

.dialog-counts {
  display: flex;
  gap: 6px;
}

.badge.in {
  background: #dcfce7;
  color: #166534;
}

.badge.out {
  background: #dbeafe;
  color: #1d4ed8;
}

.dialogs-main {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f8fafc;
  padding: 10px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 10px;
}

.messages-feed {
  max-height: 72vh;
  overflow: auto;
  padding: 6px;
  border-top: 1px solid #e5e7eb;
}

.msg-row {
  display: flex;
  margin: 8px 0;
}

.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }

.msg-bubble {
  max-width: 78%;
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.msg-row.in .msg-bubble {
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.msg-row.out .msg-bubble {
  background: #dbeafe;
  border: 1px solid #bfdbfe;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.msg-meta {
  margin-top: 6px;
  font-size: 11px;
  color: #6b7280;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  .dialogs-layout {
    grid-template-columns: 1fr;
  }
}
