/* ===========================================================
   OpenClaw Control Center — ChatGPT-style layout
   =========================================================== */

/* --- RESET --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* --- BASE --- */
html { height: 100%; background: #0a0a0f; }
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px; line-height: 1.5; color: #ececf1;
  background: #0a0a0f;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ===========================================================
   APP SHELL
   =========================================================== */
#app {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; overflow: hidden;
}

/* ===========================================================
   SIDEBAR — ChatGPT style
   =========================================================== */
.sidebar {
  width: 260px; min-width: 260px; max-width: 260px;
  height: 100%;
  display: flex; flex-direction: column;
  background: #111117;
  border-right: 1px solid rgba(255,255,255,0.06);
  transition: width 0.25s ease, min-width 0.25s ease, max-width 0.25s ease;
  flex-shrink: 0; overflow: hidden;
}
.sidebar.collapsed { width: 0; min-width: 0; max-width: 0; }

/* Brand */
.sb-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0; height: 56px;
}
.sb-logo {
  width: 32px; height: 32px; min-width: 32px;
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 14px rgba(124,58,237,0.3);
}
.sb-name { flex: 1; font-size: 14px; font-weight: 700; color: #ececf1; white-space: nowrap; }

/* Icon button */
.icon-btn {
  width: 28px; height: 28px; flex-shrink: 0;
  background: transparent; border: none; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #565678; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: #1e1e2a; color: #ececf1; }

/* New Chat section */
.sb-new-section {
  padding: 12px 10px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
  display: flex; flex-direction: column; gap: 8px;
}

.btn-new-chat {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 9px 14px;
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  border: none; border-radius: 9px;
  color: #fff; font-size: 13px; font-weight: 600;
  transition: opacity 0.15s, transform 0.12s;
  box-shadow: 0 2px 10px rgba(124,58,237,0.25);
}
.btn-new-chat:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-new-chat:active { transform: translateY(0); }

/* Agent picker */
.agent-picker-wrap { display: flex; flex-direction: column; gap: 4px; }
.picker-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: #444455; padding-left: 2px; }

.select-wrap {
  position: relative;
  display: flex; align-items: center;
}
.agent-select {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.09);
  border-radius: 8px; padding: 8px 30px 8px 10px;
  color: #ececf1; font-size: 12px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.agent-select:focus { border-color: rgba(124,58,237,0.45); box-shadow: 0 0 0 2px rgba(124,58,237,0.12); }
.agent-select option { background: #1a1a24; color: #ececf1; }
.select-arrow {
  position: absolute; right: 9px;
  color: #555566; pointer-events: none;
}

/* Status row */
.sb-status-row {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  flex-shrink: 0;
}
.status-dot {
  width: 6px; height: 6px; min-width: 6px; border-radius: 50%;
  background: #555566; transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.connected { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-dot.error     { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.status-dot.loading   { background: #f59e0b; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.status-txt { flex: 1; font-size: 11px; color: #666677; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Session history */
.sb-sessions {
  flex: 1; min-height: 0;
  padding: 8px 6px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}

.sb-section-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: #333344; padding: 4px 6px 6px; white-space: nowrap;
}

.sess-empty-hint {
  font-size: 12px; color: #333344;
  padding: 12px 6px; line-height: 1.7; text-align: center;
}
.sess-empty-hint strong { color: #555566; }

/* Session item */
.session-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
  group: true;
}
.session-item:hover { background: #1a1a24; border-color: rgba(255,255,255,0.07); }
.session-item.active { background: rgba(124,58,237,0.13); border-color: rgba(124,58,237,0.25); }

.session-emoji {
  font-size: 16px; flex-shrink: 0;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: #1a1a24; border-radius: 6px;
}
.session-item.active .session-emoji { background: rgba(124,58,237,0.15); }

.session-info { flex: 1; min-width: 0; }
.session-title {
  font-size: 12px; font-weight: 500; color: #ccccd8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 1px;
}
.session-item.active .session-title { color: #a06ef8; }
.session-meta { font-size: 10px; color: #444455; white-space: nowrap; }

.session-del {
  opacity: 0; flex-shrink: 0;
  width: 20px; height: 20px;
  background: transparent; border: none; border-radius: 4px;
  color: #555566; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { background: rgba(239,68,68,0.15); color: #ef4444; }

/* Footer */
.sb-footer {
  padding: 8px 8px 10px;
  border-top: 1px solid rgba(255,255,255,0.05);
  flex-shrink: 0;
}
.footer-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: none; border-radius: 7px;
  color: #666677; font-size: 12px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.footer-btn:hover { background: #1a1a24; color: #ececf1; }

/* ===========================================================
   MAIN
   =========================================================== */
#main {
  flex: 1; min-width: 0; height: 100%;
  background: #0d0d14;
  display: flex; flex-direction: column; overflow: hidden;
}

/* --- Collapse toggle (shown when sidebar collapsed) --- */
.sidebar-toggle-btn {
  position: fixed; top: 14px; left: 8px; z-index: 20;
  width: 32px; height: 32px;
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px;
  display: none; align-items: center; justify-content: center;
  color: #888899; transition: background 0.15s, color 0.15s;
}
.sidebar.collapsed ~ #main .sidebar-toggle-btn { display: flex; }

/* --- Empty / Welcome state --- */
.empty-state {
  flex: 1; display: flex;
  align-items: center; justify-content: center;
  padding: 40px;
}

.welcome-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center; max-width: 420px;
}

.welcome-logo {
  width: 72px; height: 72px;
  background: linear-gradient(145deg, rgba(139,71,245,0.15), rgba(92,32,200,0.08));
  border: 1px solid rgba(124,58,237,0.2);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  color: #7c3aed;
  box-shadow: 0 0 30px rgba(124,58,237,0.1);
}

.welcome-wrap h2 { font-size: 22px; font-weight: 700; color: #ececf1; }
.welcome-wrap p  { font-size: 13px; color: #666677; line-height: 1.7; }

.welcome-start {
  display: flex; gap: 8px; width: 100%;
  margin-top: 8px;
}

.welcome-select-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.welcome-select {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 9px; padding: 11px 34px 11px 14px;
  color: #ececf1; font-size: 13px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.welcome-select:focus { border-color: rgba(124,58,237,0.45); box-shadow: 0 0 0 3px rgba(124,58,237,0.12); }
.welcome-select option { background: #1a1a24; }

.btn-welcome-start {
  display: flex; align-items: center; gap: 7px;
  padding: 11px 18px;
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  border: none; border-radius: 9px;
  color: #fff; font-size: 13px; font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(124,58,237,0.25);
  transition: opacity 0.15s;
}
.btn-welcome-start:hover:not(:disabled) { opacity: 0.88; }
.btn-welcome-start:disabled { opacity: 0.35; cursor: not-allowed; }

/* --- Chat Panel --- */
.chat { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.chat.hidden { display: none; }

/* Chat header */
.chat-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; height: 58px;
  background: rgba(11,11,18,0.98);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0; gap: 12px;
}
.chat-hd-left { display: flex; align-items: center; gap: 11px; min-width: 0; }
.chat-av {
  width: 36px; height: 36px; min-width: 36px;
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.chat-agent-name { font-size: 15px; font-weight: 700; color: #ececf1; }
.chat-session-info { font-size: 10px; color: #444455; margin-top: 1px; }
.chat-session-info code {
  font-family: 'Courier New', monospace;
  background: #1a1a24; padding: 1px 5px; border-radius: 3px; color: #666677;
}

.chat-hd-right { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.hd-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px; color: #888899;
  font-size: 11px; font-weight: 500;
  transition: all 0.15s; white-space: nowrap;
}
.hd-btn:hover { background: #1e1e28; color: #ececf1; border-color: rgba(255,255,255,0.14); }
.hd-btn.danger:hover { background: rgba(239,68,68,0.1); color: #ef4444; border-color: rgba(239,68,68,0.3); }

/* --- Messages --- */
.msg-scroll { flex: 1; overflow-y: auto; padding: 18px 0; min-height: 0; }
.msgs { max-width: 820px; margin: 0 auto; padding: 0 22px; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; gap: 10px; animation: msg-in 0.2s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

.msg.user { flex-direction: row-reverse; }
.msg-av {
  width: 30px; height: 30px; min-width: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; margin-top: 2px;
}
.msg.user .msg-av  { background: linear-gradient(145deg, #8b47f5, #5c20c8); color: #fff; font-size: 10px; font-weight: 700; }
.msg.agent .msg-av { background: #1a1a24; border: 1px solid rgba(255,255,255,0.08); }

.msg-body { flex: 1; min-width: 0; max-width: 78%; }
.msg.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }

.msg-meta { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; font-size: 10px; color: #444455; }
.msg.user .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-weight: 600; color: #666677; }

.msg-bubble {
  padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.7;
  word-wrap: break-word; overflow-wrap: anywhere;
  position: relative;
}
.msg.user .msg-bubble {
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  color: #fff; border-bottom-right-radius: 3px;
  box-shadow: 0 2px 10px rgba(124,58,237,0.2);
}
.msg.agent .msg-bubble {
  background: #16161e; border: 1px solid rgba(255,255,255,0.07);
  color: #e0e0eb; border-bottom-left-radius: 3px;
}
.msg.sys .msg-bubble {
  background: transparent; border: 1px dashed rgba(255,255,255,0.08);
  color: #444455; font-size: 11px;
  padding: 6px 16px; border-radius: 99px;
}
.msg.sys { justify-content: center; }

/* Copy btn */
.copy-btn {
  position: absolute; top: 7px; right: 7px;
  background: #252535; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px; padding: 2px 8px;
  font-size: 10px; color: #888899; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
}
.msg.agent .msg-bubble:hover .copy-btn { opacity: 1; pointer-events: auto; }
.copy-btn:hover { color: #ececf1; }
.copy-btn.ok { color: #22c55e; opacity: 1; }

/* Typing indicator */
.typing { display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: #555566; animation: bounce 1.3s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

.cur { display: inline-block; width: 2px; height: 14px; background: #a06ef8; margin-left: 2px; vertical-align: middle; border-radius: 1px; animation: blink 0.75s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Markdown */
.msg.agent .msg-bubble p              { margin-bottom: 8px; }
.msg.agent .msg-bubble p:last-child   { margin-bottom: 0; }
.msg.agent .msg-bubble h1,.msg.agent .msg-bubble h2,.msg.agent .msg-bubble h3 { font-weight: 700; margin: 11px 0 5px; }
.msg.agent .msg-bubble h1 { font-size: 1.1em; }
.msg.agent .msg-bubble h2 { font-size: 1.0em; }
.msg.agent .msg-bubble h3 { font-size: 0.95em; }
.msg.agent .msg-bubble h1:first-child,.msg.agent .msg-bubble h2:first-child,.msg.agent .msg-bubble h3:first-child { margin-top: 0; }
.msg.agent .msg-bubble ul,.msg.agent .msg-bubble ol { padding-left: 18px; margin-bottom: 8px; }
.msg.agent .msg-bubble li { margin-bottom: 3px; }
.msg.agent .msg-bubble code { font-family: 'Courier New', monospace; font-size: 0.84em; background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 3px; }
.msg.agent .msg-bubble pre { background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 8px 0; }
.msg.agent .msg-bubble pre code { background: transparent; padding: 0; font-size: 12px; }
.msg.agent .msg-bubble blockquote { border-left: 3px solid #7c3aed; padding-left: 12px; color: #888899; margin: 8px 0; }
.msg.agent .msg-bubble strong { font-weight: 700; }
.msg.agent .msg-bubble em { font-style: italic; }
.msg.agent .msg-bubble a { color: #a06ef8; text-decoration: none; }
.msg.agent .msg-bubble a:hover { text-decoration: underline; }
.msg.agent .msg-bubble table { border-collapse: collapse; width: 100%; font-size: 12px; margin: 8px 0; }
.msg.agent .msg-bubble th,.msg.agent .msg-bubble td { border: 1px solid rgba(255,255,255,0.1); padding: 6px 10px; text-align: left; }
.msg.agent .msg-bubble th { background: #1e1e28; font-weight: 600; }

/* --- Input --- */
.input-area {
  padding: 12px 22px 16px;
  background: rgba(10,10,18,0.98);
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.input-wrap {
  background: #16161e; border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px; overflow: hidden;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.input-wrap:focus-within {
  border-color: rgba(124,58,237,0.45);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
#msg-input {
  display: block; width: 100%; background: transparent; border: none; outline: none;
  padding: 12px 14px 4px;
  font-size: 13px; color: #ececf1;
  resize: none; max-height: 190px; overflow-y: auto; line-height: 1.6;
}
#msg-input::placeholder { color: #333344; }
.input-ft { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 5px 8px 7px; }
.char-ct { font-size: 10px; color: #2a2a3a; font-family: 'Courier New', monospace; }
.btn-send {
  width: 32px; height: 32px;
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  border: none; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: 0 2px 8px rgba(124,58,237,0.25);
  transition: opacity 0.15s, transform 0.12s;
}
.btn-send:hover:not(:disabled) { opacity: 0.88; transform: scale(1.05); }
.btn-send:disabled { opacity: 0.22; cursor: not-allowed; transform: none; box-shadow: none; }
.input-hint { font-size: 10px; color: #2a2a3a; text-align: center; margin-top: 8px; }
.input-hint kbd {
  background: #1a1a24; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 3px; padding: 1px 5px;
  font-family: 'Courier New', monospace; font-size: 9px; color: #555566;
}

/* ===========================================================
   MODAL
   =========================================================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  animation: fade-in 0.2s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #16161e; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; width: 420px; max-width: calc(100vw - 40px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  animation: modal-in 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.94) translateY(-10px); } to { opacity: 1; transform: scale(1); } }
.modal-hd { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 14px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.modal-hd h2 { font-size: 15px; font-weight: 700; color: #ececf1; }
.modal-bd { padding: 18px 22px; display: flex; flex-direction: column; gap: 18px; }
.modal-ft { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid rgba(255,255,255,0.07); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: #ececf1; }
.field input {
  background: #0f0f16; border: 1px solid rgba(255,255,255,0.09);
  border-radius: 8px; padding: 9px 12px;
  font-size: 13px; color: #ececf1; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: rgba(124,58,237,0.45); box-shadow: 0 0 0 3px rgba(124,58,237,0.1); }
.field input::placeholder { color: #2a2a3a; }
.field small { font-size: 11px; color: #444455; }
.field-row { position: relative; display: flex; align-items: center; }
.field-row input { flex: 1; padding-right: 40px; }
.field-row .icon-btn { position: absolute; right: 6px; }
.btn-primary {
  padding: 8px 18px; border-radius: 8px;
  background: linear-gradient(145deg, #8b47f5, #5c20c8);
  color: #fff; border: none; font-size: 13px; font-weight: 600;
  transition: opacity 0.15s; box-shadow: 0 2px 10px rgba(124,58,237,0.25);
}
.btn-primary:hover { opacity: 0.88; }
.btn-secondary {
  padding: 8px 18px; border-radius: 8px;
  background: #1a1a24; color: #888899;
  border: 1px solid rgba(255,255,255,0.09);
  font-size: 13px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover { background: #1e1e28; color: #ececf1; }

/* ===========================================================
   UTILITY
   =========================================================== */
.hidden { display: none !important; }

