/* style.css - 小虾网页版 v2 - 纯 CSS(无框架)
 * 配色:以深色为主,跟 OpenClaw 默认风格靠近
 * 状态色:绿/灰/黄(对齐 8/7 18:27 老大定)
 */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: #e6e6e6;
  background: #0f1419;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, button { font: inherit; }
.hidden { display: none !important; }
.muted { color: #8a8f99; }
.muted.small { font-size: 12px; }
.err { color: #ff6b6b; font-size: 13px; min-height: 18px; }
code { background: #1c1f26; padding: 1px 5px; border-radius: 3px; font-size: 12px; color: #c0c5d0; }

/* ===== 登录层 ===== */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f1419 0%, #1a1f2e 100%);
  z-index: 100;
}
.login-box {
  background: #161b22;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 32px;
  width: 360px;
  max-width: 92vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.login-box h1 { font-size: 22px; margin-bottom: 8px; }
.login-box label { display: block; margin-top: 16px; margin-bottom: 4px; font-size: 12px; color: #8a8f99; }
.login-box input {
  width: 100%;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e6e6e6;
  outline: none;
}
.login-box input:focus { border-color: #4a9eff; }
.login-box button {
  width: 100%;
  margin-top: 20px;
  padding: 10px;
  background: #4a9eff;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 500;
}
.login-box button:hover { background: #5ba8ff; }
.login-box button:disabled { background: #2a3a55; cursor: not-allowed; }

/* ===== 主界面布局 ===== */
.app {
  display: flex; flex-direction: column;
  height: 100vh;
}

/* ===== 顶栏 ===== */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 52px;
  padding: 0 16px;
  background: #161b22;
  border-bottom: 1px solid #2a2f3a;
  position: relative;
  z-index: 50;
}
.topbar-left { justify-self: start; }
.topbar-right { justify-self: end; display: flex; gap: 8px; }
.topbar-center { justify-self: center; position: relative; }

.logo { font-size: 16px; font-weight: 500; color: #e6e6e6; }

.subject-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: #1c2128;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e6e6e6;
  font-size: 14px;
  min-width: 120px;
  justify-content: space-between;
}
.subject-toggle:hover { background: #232830; }
.subject-toggle .caret { font-size: 10px; color: #8a8f99; }

.subject-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c2128;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  padding: 4px 0;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 100;
}
.subject-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
}
.subject-item:hover { background: #232830; }
.subject-item.disabled { cursor: not-allowed; opacity: 0.45; }
.subject-item .dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.subject-item .dot.green { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.subject-item .dot.gray { background: #6b7280; }
.subject-item .dot.yellow { background: #facc15; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.subject-item .name { flex: 1; }
.subject-item .check { color: #4a9eff; font-size: 14px; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 16px;
  color: #c0c5d0;
}
.icon-btn:hover { background: #232830; border-color: #2a2f3a; }

/* ===== 主体 main ===== */
.main {
  display: flex;
  flex: 1;
  min-height: 0;
}
.friends {
  width: 280px;
  background: #11151c;
  border-right: 1px solid #2a2f3a;
  display: flex; flex-direction: column;
  min-width: 0;
}
.friends-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2f3a;
  font-size: 12px;
  color: #8a8f99;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.relay-status { font-size: 12px; }
.relay-status.online { color: #4ade80; }
.relay-status.offline { color: #6b7280; }

.friend-list { list-style: none; overflow-y: auto; flex: 1; }
.friend-item {
  padding: 12px 16px;
  border-bottom: 1px solid #1c2128;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 56px;
  position: relative;
}
.friend-item:hover { background: #1a1f28; }
.friend-item.active { background: #1f2730; border-left: 3px solid #4a9eff; padding-left: 13px; }
.friend-item .row1 { display: flex; align-items: center; justify-content: space-between; }
.friend-item .name { font-weight: 500; }
.friend-item .ts { font-size: 11px; color: #6b7280; }
.friend-item .last { font-size: 12px; color: #8a8f99; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-item .badge {
  position: absolute; right: 12px; top: 12px;
  background: #ef4444; color: white; font-size: 10px;
  border-radius: 8px; padding: 1px 6px; min-width: 16px; text-align: center;
}
.friend-item .actions {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: none; gap: 4px;
}
.friend-item:hover .actions { display: flex; }
.friend-item .actions button {
  background: #2a2f3a; border: none; color: #c0c5d0;
  border-radius: 4px; padding: 2px 6px; font-size: 11px;
}
.friend-item .actions button:hover { background: #ef4444; color: white; }

/* ===== 聊天页 ===== */
.chat {
  flex: 1;
  display: flex; flex-direction: column;
  min-width: 0;
  background: #0f1419;
}
.chat-header {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid #2a2f3a;
  font-size: 15px;
  font-weight: 500;
  min-height: 48px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.messages .empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #6b7280; font-size: 14px;
}

.msg { display: flex; flex-direction: column; max-width: 70%; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
}
.msg .meta { font-size: 10px; color: #6b7280; margin-top: 4px; }
.msg.me { align-self: flex-end; }
.msg.me .bubble { background: #4a9eff; color: white; border-bottom-right-radius: 4px; }
.msg.me .meta { text-align: right; }
.msg.agent { align-self: flex-start; }
.msg.agent .bubble { background: #1c2128; color: #e6e6e6; border-bottom-left-radius: 4px; }
.msg .status { font-size: 10px; color: #6b7280; margin-top: 2px; }
.msg .status.sending { color: #facc15; }
/* 8-30 14:37 载铁案 28: typing 状态闪烁 */
.msg.typing .bubble { opacity: 0.7; }
.msg.typing .bubble::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg .status.sent { color: #8a8f99; }
.msg .status.failed { color: #ef4444; }

.composer {
  display: flex; gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #2a2f3a;
  background: #11151c;
}
.composer textarea {
  flex: 1;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e6e6e6;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 200px;
}
.composer textarea:focus { border-color: #4a9eff; }
.composer button {
  padding: 10px 20px;
  background: #4a9eff;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 500;
}
.composer button:hover { background: #5ba8ff; }
.composer button:disabled { background: #2a3a55; cursor: not-allowed; }

/* ===== 搜索浮层 ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #161b22;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  width: 600px; max-width: 92vw; max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; gap: 8px; padding: 12px;
  border-bottom: 1px solid #2a2f3a;
}
.modal-head input {
  flex: 1;
  padding: 8px 12px;
  background: #0d1117;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e6e6e6;
  outline: none;
}
.search-results { overflow-y: auto; flex: 1; padding: 8px 0; }
.search-results .result {
  padding: 10px 16px;
  border-bottom: 1px solid #1c2128;
  cursor: pointer;
}
.search-results .result:hover { background: #1a1f28; }
.search-results .result .sender { color: #8a8f99; font-size: 11px; }
.search-results .result .friend { color: #4a9eff; font-size: 11px; }
.search-results .result .content mark { background: #facc15; color: #0f1419; padding: 0 2px; border-radius: 2px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  background: #1c2128;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 10px 18px;
  border-radius: 6px;
  z-index: 300;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease;
}
.toast.err { border-color: #ef4444; color: #ff8a8a; }
.toast.ok { border-color: #4ade80; color: #4ade80; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 响应式:窄屏 = 隐藏好友列表 ===== */
@media (max-width: 720px) {
  .friends { display: none; }
  .main { display: block; }
}

/* ===== v3 新增: 聊天页头部右侧按钮 (📜 聊天记录) ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2f3a;
}
.chat-header #chat-friend-name { font-weight: 600; flex-shrink: 0; }
.chat-header #chat-subject-label { flex-shrink: 0; }
.chat-header .icon-btn-right {
  margin-left: auto;
  background: #1a1f28;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.chat-header .icon-btn-right:hover { background: #232830; }

/* ===== v3 新增: 聊天记录页 (从聊天页右上角进) ===== */
.history-screen {
  position: fixed;
  inset: 0;
  background: #0f1419;
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.history-box {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}
.history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2f3a;
}
.history-head h2 { font-size: 16px; font-weight: 600; flex-shrink: 0; }
.history-head #history-search {
  flex: 1;
  background: #1a1f28;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.history-cal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid #2a2f3a;
  font-size: 13px;
}
.history-cal #cal-label { font-weight: 600; min-width: 100px; text-align: center; }
.history-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.history-messages .empty { text-align: center; color: #6b7280; padding: 60px 20px; }
.history-messages .msg {
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: #1a1f28;
  font-size: 13px;
  line-height: 1.5;
}
.history-messages .msg.me { background: #1f3a5c; }
.history-messages .msg .meta { color: #8a8f99; font-size: 11px; margin-bottom: 4px; }
.history-messages .msg .content mark { background: #facc15; color: #0f1419; padding: 0 2px; border-radius: 2px; }
.history-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid #2a2f3a;
  font-size: 12px;
}
.history-pager #pager-label { min-width: 120px; text-align: center; color: #8a8f99; }
