:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e3e6ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --on: #16a34a;
  --off: #9ca3af;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

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

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Topbar */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 18px;
  font-size: 15px;
}
.nav a:hover { color: var(--primary); }

.content { padding-top: 24px; padding-bottom: 48px; }

/* Headings */
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); margin: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.empty {
  text-align: center;
  color: var(--muted);
}
.empty .btn { margin-top: 12px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f5; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
}
.btn-ghost:hover { background: #eef2ff; }
.btn-danger {
  background: var(--card);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 8px; }

/* Bots grid */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.bot-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bot-name { word-break: break-word; }
.bot-meta { font-size: 14px; margin: 6px 0 14px; }
.bot-card-actions { display: flex; gap: 8px; }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-on { background: #dcfce7; color: var(--on); }
.badge-off { background: #f1f3f5; color: var(--off); }

/* Forms */
.form .field { margin-bottom: 16px; }
.form .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
input[type=text],
input[type=password],
input[type=number],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}
.ta-big { min-height: 400px; }
.ta-mid { min-height: 300px; }
.ta-small { min-height: 100px; }

.field-check { margin-top: 4px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  cursor: pointer;
}
.check input { width: auto; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.delete-form { margin-top: 16px; }

.alert {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 20px; }
.login-card form { margin-top: 16px; text-align: left; }

/* Lists (dialogs) */
.list { padding: 0; overflow: hidden; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #f7f9fc; }
.list-main { font-weight: 500; }
.list-aside { font-size: 13px; white-space: nowrap; }

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble-row { display: flex; }
.bubble-row.left { justify-content: flex-start; }
.bubble-row.right { justify-content: flex-end; }
.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.bubble-bot {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-user {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-role {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  opacity: .7;
  margin-bottom: 4px;
}
.bubble-text { white-space: pre-wrap; word-break: break-word; }

/* Responsive */
@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .form .row { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
}
