/* ─── Reset & Variables ──────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --bg-surface: #1e293b;
  --bg-hover: #334155;
  --bg-active: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-active: #ffffff;
  --border: #334155;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-width: 280px;
  --topbar-height: 56px;
  --bottomnav-height: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 200ms ease;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  /* dynamic viewport height: shrinks when the mobile keyboard opens */
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  padding-top: var(--safe-top);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}

.logo svg {
  color: var(--accent);
}

.sidebar-search {
  padding: 12px 16px 8px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.sidebar-search input:focus {
  border-color: var(--accent);
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.bot-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.bot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
  -webkit-user-select: none;
}

.bot-item:hover {
  background: var(--bg-hover);
}

.bot-item.active {
  background: var(--bg-active);
}

.bot-item.active .bot-name {
  color: var(--text-active);
  font-weight: 600;
}

.bot-item.active .bot-role {
  color: rgba(255, 255, 255, 0.7);
}

.bot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: var(--bg);
}

.bot-info {
  flex: 1;
  min-width: 0;
}

.bot-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-role {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-text {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Overlay ───────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay.visible {
  display: block;
}

/* ─── Main ──────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-width);
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: var(--safe-top);
}

.topbar-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-info h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--success);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ─── Welcome ───────────────────────────────────────────── */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome-content {
  text-align: center;
  max-width: 320px;
}

.welcome-content h2 {
  margin-top: 16px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.welcome-content p {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.welcome-hint {
  margin-top: 16px;
  font-size: 13px;
}

/* ─── Iframe container ──────────────────────────────────── */
.iframe-container {
  flex: 1;
  overflow: hidden;
}

.iframe-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--bg);
}

/* ─── Sidebar toggle (hidden on desktop) ────────────────── */
#sidebar-toggle {
  display: none;
}

#sidebar-close {
  display: none;
}

/* ─── Desktop ───────────────────────────────────────────── */
@media (min-width: 769px) {
  .sidebar {
    transform: none !important;
  }

  #sidebar-close {
    display: none !important;
  }
}

/* ─── Mobile ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  #sidebar-toggle {
    display: flex;
  }

  #sidebar-close {
    display: flex;
  }

  .main {
    margin-left: 0;
  }
}

/* ─── Scrollbar styling ─────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Focus styles ──────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Animations ────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.iframe-container iframe {
  animation: fadeIn 200ms ease;
}
