/* ─── OpenClaw Hub v2 — Styles ────────────────────────────── */

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

:root {
  --bg:         #0f172a;
  --bg-surface: #1e293b;
  --bg-hover:   #334155;
  --bg-input:   #1e293b;
  --border:     #334155;
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim:   #64748b;
  --accent:     #3b82f6;
  --accent-hover: #2563eb;
  --user-bg:    #1e40af;
  --user-text:  #dbeafe;
  --asst-bg:    #1e293b;
  --asst-text:  #e2e8f0;
  --error:      #ef4444;
  --success:    #22c55e;
  --radius:     12px;
  --radius-sm:  8px;
  --sidebar-w:  280px;
  --topbar-h:   56px;
  --safe-top:   env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 700; color: var(--text);
}
.logo svg { color: var(--accent); }

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

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

.bot-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s;
}
.bot-item:hover { background: var(--bg-hover); }
.bot-item.active { background: var(--accent)22; }

.bot-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.bot-name { font-weight: 600; font-size: 14px; }
.bot-role { font-size: 12px; color: var(--text-muted); }

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

/* ── Overlay ───────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99; opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.overlay.visible { opacity: 1; pointer-events: auto; }

/* ── Main ──────────────────────────────────────────────── */
.main {
  display: flex; flex-direction: column;
  height: 100%; width: 100%;
}

/* ── Topbar ────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: var(--topbar-h);
  padding-top: var(--safe-top);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-info { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-info h1 {
  font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 4px; }

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

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

/* ── 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: 16px 0 8px; font-size: 22px; }
.welcome-content p { color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.welcome-content svg { opacity: 0.3; }
.welcome-hint { margin-top: 12px; font-size: 13px; color: var(--text-dim); }

/* ── Chat Container ────────────────────────────────────── */
.chat-container {
  flex: 1; display: none; flex-direction: column;
  overflow: hidden;
}

/* ── Chat Area ─────────────────────────────────────────── */
.chat-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.empty-chat {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%;
  color: var(--text-dim);
}
.empty-chat-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-chat p { font-size: 14px; }

/* ── Messages ──────────────────────────────────────────── */
.msg {
  display: flex; margin-bottom: 12px;
  animation: msgIn 0.2s ease;
}
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }

.msg-bubble {
  max-width: 85%; padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14.5px; line-height: 1.6;
  word-wrap: break-word; overflow-wrap: break-word;
}
.msg-user .msg-bubble {
  background: var(--user-bg); color: var(--user-text);
  border-bottom-right-radius: 4px;
}
.msg-assistant .msg-bubble {
  background: var(--asst-bg); color: var(--asst-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.msg-error { color: var(--error); font-size: 13px; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Markdown inside messages ──────────────────────────── */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
  background: rgba(0,0,0,0.3); padding: 2px 5px;
  border-radius: 4px; font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}
.msg-bubble pre {
  margin: 8px 0; padding: 12px;
  background: #0d1117; border-radius: var(--radius-sm);
  overflow-x: auto; border: 1px solid #21262d;
}
.msg-bubble pre code {
  background: none; padding: 0; font-size: 13px;
  line-height: 1.5;
}
.msg-bubble a { color: #58a6ff; text-decoration: none; }
.msg-bubble a:hover { text-decoration: underline; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px; margin: 8px 0;
  color: var(--text-muted);
}
.msg-bubble table {
  border-collapse: collapse; margin: 8px 0; width: 100%;
  font-size: 13px;
}
.msg-bubble th, .msg-bubble td {
  border: 1px solid var(--border); padding: 6px 10px;
  text-align: left;
}
.msg-bubble th { background: rgba(0,0,0,0.2); font-weight: 600; }

/* ── Typing indicator ──────────────────────────────────── */
.typing {
  display: none; align-items: center; gap: 8px;
  padding: 8px 16px; color: var(--text-dim);
  font-size: 13px;
}
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim);
  animation: typingDot 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* ── Input Area ────────────────────────────────────────── */
.input-area {
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s;
}
.input-row:focus-within { border-color: var(--accent); }

#chat-input {
  flex: 1; border: none; background: none;
  color: var(--text); font-size: 15px;
  font-family: inherit; line-height: 1.5;
  resize: none; outline: none;
  max-height: 150px; min-height: 24px;
  padding: 6px 0;
}
#chat-input::placeholder { color: var(--text-dim); }

.send-btn, .stop-btn {
  width: 36px; height: 36px;
  border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn {
  background: var(--accent); color: white;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-dim); cursor: default; }
.stop-btn {
  background: var(--error); color: white;
  display: none;
}
.stop-btn:hover { background: #dc2626; }

/* ── Update banner ─────────────────────────────────────── */
#update-banner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 20px; border-radius: var(--radius);
  z-index: 9999; display: flex; align-items: center; gap: 12px;
  font-size: 14px; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  max-width: calc(100vw - 32px);
}
#btn-update {
  background: var(--accent); color: white; border: none;
  padding: 6px 14px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 600;
}
#btn-update-dismiss {
  background: transparent; color: var(--text-muted);
  border: none; padding: 6px; cursor: pointer;
  font-size: 18px; line-height: 1;
}

/* ── Model bar ──────────────────────────────────────────── */
.model-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}
.model-bar select {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px;
  color: var(--text); font-size: 13px; outline: none;
  max-width: 300px; cursor: pointer;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.model-bar select:focus { border-color: var(--accent); }
.model-bar select option { background: var(--bg-surface); color: var(--text); }
.model-bar select optgroup { color: var(--text-muted); font-weight: 600; }
.model-hint { font-size: 11px; color: var(--text-dim); }

/* ── Usage bar ──────────────────────────────────────────── */
.usage-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 16px;
  background: rgba(59,130,246,0.08);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  flex-shrink: 0;
}
.usage-model { color: var(--accent); font-weight: 600; }
.usage-total { color: var(--text); font-weight: 500; }
.ctx-pct { font-weight: 700; font-size: 12px; white-space: nowrap; }
.ctx-bar-wrap {
  flex: 1; max-width: 80px; height: 4px;
  background: var(--border); border-radius: 2px; overflow: hidden;
}
.ctx-bar-fill { height: 100%; border-radius: 2px; transition: width 0.4s ease; }

/* ── Message metadata ──────────────────────────────────── */
.msg-footer {
  font-size: 11px; color: var(--text-dim);
  margin-top: 6px; padding: 0 4px;
}

/* ── Reasoning block ───────────────────────────────────── */
.msg-reasoning {
  margin-bottom: 6px;
}
.msg-reasoning summary {
  cursor: pointer; font-size: 12px;
  color: var(--text-dim); padding: 4px 8px;
  display: flex; align-items: center; gap: 6px;
  user-select: none;
}
.msg-reasoning summary:hover { color: var(--text-muted); }
.reasoning-content {
  font-size: 13px; color: var(--text-muted);
  padding: 8px 12px; margin: 4px 0;
  background: rgba(251,191,36,0.06);
  border-left: 3px solid #fbbf24;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-wrap; line-height: 1.5;
}

/* ── Tool calls ─────────────────────────────────────────── */
.msg-tools {
  margin-top: 6px;
}
.tool-call {
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tool-call-header {
  font-size: 12px; font-weight: 600;
  padding: 6px 10px;
  background: rgba(16,185,129,0.1);
  color: #10b981;
}
.tool-call-args {
  font-size: 12px; color: var(--text-muted);
  padding: 6px 10px; margin: 0;
  background: rgba(0,0,0,0.2);
  max-height: 120px; overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Code highlight (dark) ─────────────────────────────── */
.hljs { background: transparent !important; padding: 0 !important; }

/* ── Scrollbar ─────────────────────────────────────────── */
::-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-dim); }

/* ── Desktop ───────────────────────────────────────────── */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
    position: relative;
    flex-shrink: 0;
  }
  .overlay { display: none; }
  .sidebar-close { display: none; }
  #sidebar-toggle { display: none; }
  .main { flex: 1; }
  .msg-bubble { max-width: 70%; }
}

/* ── Keyboard open (mobile) ────────────────────────────── */
body.keyboard-open .topbar { display: none; }
body.keyboard-open .main { height: 100dvh; }
body.keyboard-open .chat-container { height: 100%; }
