/* Firstmate web console — minimal chat-first (Defect 3 redesign). */

:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --captain-bubble: #2563eb;
  --captain-ink: #ffffff;
  --fm-bubble: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --idle: #9ca3af;
  --term-bg: #111418;
  --term-ink: #d6dbe1;
  --radius: 12px;
  --sidebar-w: 240px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.85rem; margin: 0.4rem 0 0; }

button { font: inherit; cursor: pointer; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 1.1rem;
  font-weight: 500;
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.3rem 0.7rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); }

/* ---------- 登录 ---------- */
.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
}
.login-brand { font-size: 1.35rem; font-weight: 600; }
.login-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font: inherit;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.8rem 0.8rem;
  gap: 1rem;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.4rem; }
.brand-dot { color: var(--accent); font-size: 1.1rem; }
.brand-dot::before { content: "◉"; }
.brand-name { font-weight: 700; letter-spacing: 0.02em; }
.working-badge {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

.nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  padding: 0.7rem 0.5rem 0.25rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 0.5rem 0.55rem;
  color: var(--ink);
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item.inactive { color: var(--idle); }
.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.nav-empty { color: var(--idle); font-size: 0.82rem; padding: 0.3rem 0.55rem; }

.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.dot.alive { background: var(--ok); }
.dot.dead { background: transparent; border: 1.5px solid var(--idle); width: 6px; height: 6px; }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 0.7rem; display: flex; flex-direction: column; gap: 0.55rem; }
.fleet-summary { font-size: 0.8rem; color: var(--muted); padding: 0 0.4rem; }
.foot-actions { display: flex; gap: 0.5rem; }

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.35rem 0.6rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  z-index: 25;
}

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; }
.view { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* 聊天 */
.view-chat { max-width: 860px; margin: 0 auto; width: 100%; padding: 0 1.25rem; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 0.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg .who {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  display: flex;
  gap: 0.5rem;
}
.msg .bubble {
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}
.msg .bubble code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 5px;
  padding: 0.08em 0.32em;
}
.msg.captain .bubble code { background: rgba(255, 255, 255, 0.22); }
.msg .bubble a { color: inherit; text-decoration: underline; }
.msg.firstmate .bubble a { color: var(--accent); }
.msg.captain { align-self: flex-end; align-items: flex-end; }
.msg.captain .bubble {
  background: var(--captain-bubble);
  color: var(--captain-ink);
  border-bottom-right-radius: 4px;
}
.msg.firstmate { align-self: flex-start; align-items: flex-start; }
.msg.firstmate .bubble {
  background: var(--fm-bubble);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-empty { margin: auto; color: var(--idle); font-size: 0.9rem; }

/* 输入条 */
.composer {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  padding: 0.9rem 0 1.1rem;
}
.composer textarea, .composer input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font: inherit;
  background: var(--panel);
  max-height: 9rem;
}
.composer textarea:focus, .composer input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.banner-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

/* 工人终端 */
.view-worker { padding: 0 1.25rem; }
.worker-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0.25rem 0.8rem;
  border-bottom: 1px solid var(--line);
}
.worker-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.state-badge {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  flex: 0 0 auto;
}
.inactive-badge { font-size: 0.78rem; color: var(--idle); flex: 0 0 auto; }
.term {
  flex: 1;
  overflow: auto;
  background: var(--term-bg);
  color: var(--term-ink);
  border-radius: 12px;
  margin: 0.9rem 0 0;
  padding: 0.9rem 1rem;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}
.term.dead { opacity: 0.62; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .view-chat, .view-worker { padding: 0 0.8rem; }
  .chat-log { padding-top: 3.2rem; }
  .worker-head { padding-top: 3.2rem; }
  .msg { max-width: 92%; }
}
