:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .textarea, .select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 14px; font-family: inherit;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.textarea { resize: vertical; min-height: 84px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary);
}
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }

/* Portal */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 18px; font-weight: 800; color: var(--text); display: flex; align-items: center; gap: 10px; }
.brand span { color: var(--primary); }
.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px; }
.search-bar { max-width: 440px; margin-bottom: 20px; }
.bot-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px;
}
.bot-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s, border-color .15s; color: inherit;
}
.bot-card:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.bot-card-head { display: flex; align-items: center; gap: 12px; }
.bot-logo {
  width: 46px; height: 46px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border);
  background: var(--primary-soft); display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.bot-title { font-size: 16px; font-weight: 700; margin: 0; }
.bot-slug { font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.bot-intro { font-size: 13px; color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bot-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }

/* Chat Layout */
.chat-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 300px; min-width: 300px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; padding: 16px; gap: 14px;
}
.sidebar-logo { text-align: center; }
.sidebar-logo img { max-width: 170px; max-height: 90px; border-radius: 10px; object-fit: contain; }
.sidebar-section { border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-section h4 { margin: 0 0 8px 0; font-size: 13px; color: var(--muted); font-weight: 700; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.chat-header-center { text-align: center; flex: 1; }
.chat-header-center h1 { margin: 0; font-size: 20px; font-weight: 800; }
.chat-header-center p { margin: 4px 0 0 0; font-size: 13px; color: var(--muted); }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px;
}
.msg-wrap { max-width: 880px; width: 100%; margin: 0 auto; }
.msg-user {
  background: #e2e8f0; color: var(--text); padding: 12px 16px; border-radius: 12px;
  font-size: 14.5px; white-space: pre-wrap; margin-bottom: 10px;
}
.msg-bot {
  background: var(--surface); border: 1px solid var(--border); padding: 16px 20px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14.5px; overflow-x: auto;
}
.msg-bot img { max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0; border: 1px solid var(--border); }
.msg-bot pre { background: #0f172a; color: #f8fafc; padding: 12px; border-radius: 8px; overflow-x: auto; }
.msg-bot table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.msg-bot th, .msg-bot td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13.5px; }
.msg-bot th { background: #f8fafc; }
.chat-composer {
  background: var(--surface); border-top: 1px solid var(--border); padding: 14px 20px;
}
.composer-inner {
  max-width: 880px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
}
.composer-inner textarea {
  flex: 1; min-height: 44px; max-height: 140px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 14.5px; font-family: inherit;
  resize: none;
}
.composer-inner textarea:focus { outline: none; border-color: var(--primary); }

.clue-card {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; margin-bottom: 8px;
}
.clue-score { font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.clue-text { color: #334155; max-height: 110px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }

details summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--text); padding: 4px 0; }

/* Mobile sidebar toggle */
.mobile-toggle { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -320px; top: 0; bottom: 0; z-index: 40; transition: left .2s; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  .sidebar.open { left: 0; }
  .mobile-toggle { display: inline-flex; }
}

/* Admin Layout */
.admin-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
@media (max-width: 960px) { .admin-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.panel h2, .panel h3 { margin-top: 0; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-3col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.bot-list-item {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.bot-list-item:hover, .bot-list-item.active { border-color: var(--primary); background: var(--primary-soft); }
.progress-bar { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--primary); transition: width .3s; }
.login-box { max-width: 380px; margin: 90px auto; }
