:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #0b69c7;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
}
[data-theme="dark"] {
  --bg: #0b0d12;
  --card: #12161c;
  --text: #e5e7eb;
  --muted: #98a2b3;
  --primary: #4aa3ff;
  --border: #1f2937;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
}

/* Sidebar */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}
.sb-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.brand img {
  height: 28px;
}
.new-chat {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}
.new-chat:hover {
  border-color: var(--primary);
}
.sb-list {
  padding: 10px;
  overflow: auto;
  height: 100%;
}
.chat-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-item:hover {
  background: rgba(0, 0, 0, 0.03);
  border-color: var(--border);
}
[data-theme="dark"] .chat-item:hover {
  background: rgba(255, 255, 255, 0.03);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}
.sb-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* Chat area */
.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 5;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--primary);
}
.icon {
  width: 18px;
  height: 18px;
}
.title {
  font-weight: 700;
  margin-right: auto;
}
.topbar .logo {
  height: 28px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  margin-right: 10px;
}
.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.tab.active,
.tab:hover {
  border-color: var(--primary);
}

/* Views */
.view.hidden {
  display: none;
}
.view-chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
}
.view-agents {
  padding: 14px;
  overflow: auto;
  height: calc(100vh - 56px);
}
.agents-header {
  max-width: 1100px;
  margin: 0 auto 10px;
}
.agents-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
.agents-header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* Chatbase Container */
.chatbase-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card);
}

.chatbase-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--card);
}

/* Stories (Ẩn đi) */
.stories {
  display: none;
}

/* Grid Agents - Image Card Layout với đầy đủ thông tin */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  max-width: 1100px;
  margin: 12px auto 50px;
}
.agent-card {
  background: var(--card);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  height: 540px;
  display: flex;
  flex-direction: column;
}
.agent-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
.agent-image {
  flex: 1;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
}
.agent-image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.1) 50%,
    rgba(0, 0, 0, 0.7) 100%
  );
}
.agent-content {
  background: var(--card);
  padding: 16px;
  height: 35%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.agent-name {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
  line-height: 1.3;
}
.agent-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.last-trained {
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 6px;
}
[data-theme="dark"] .last-trained {
  background: rgba(255, 255, 255, 0.1);
}
.created-by {
  font-size: 12px;
  color: var(--muted);
}
.agent-description {
  font-size: 12px;
  color: var(--text);
  opacity: 0.8;
  line-height: 1.4;
  margin: 6px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.agent-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.trainer-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, #10b981, #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.trainer-avatar span {
  font-weight: 700;
  font-size: 10px;
  color: white;
}
.trainer-info {
  font-size: 11px;
  color: var(--muted);
}

/* Loading indicator for lazy loading */
.loading-indicator {
  text-align: center;
  padding: 15px;
  color: var(--muted);
  font-size: 14px;
  grid-column: 1 / -1;
}

/* Watermark */
.wm {
  position: fixed;
  right: 16px;
  bottom: 10px;
  opacity: 0.25;
  pointer-events: none;
}
.wm img {
  height: 34px;
}

/* Mobile sidebar */
.sb-toggle {
  display: none;
}
@media (max-width: 1024px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 80%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 20;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sb-overlay {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: none;
    z-index: 15;
  }
  .sb-overlay.show {
    display: block;
  }
  .sb-toggle {
    display: inline-flex;
  }

  /* Mobile responsive for agents grid */
  .agents-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
}

@media (max-width: 640px) {
  .agents-grid {
    grid-template-columns: 1fr;
  }
  .agent-card {
    height: 360px;
  }
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

