:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-soft: #12151d;
  --panel: rgba(22, 27, 38, 0.88);
  --panel-2: #1b2230;
  --panel-3: #242c3d;
  --text: #eef2fb;
  --muted: #97a3ba;
  --accent: #6ea8ff;
  --accent-2: #8b5cf6;
  --danger: #ff7b7b;
  --border: rgba(255, 255, 255, 0.08);
  --user: linear-gradient(145deg, #1f4f96 0%, #173b73 100%);
  --assistant: linear-gradient(145deg, #2a3142 0%, #1e2433 100%);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 20%, rgba(110, 168, 255, 0.16), transparent 28%),
    radial-gradient(circle at 85% 0%, rgba(139, 92, 246, 0.14), transparent 24%),
    linear-gradient(180deg, #0b0d12 0%, #10141d 100%);
  z-index: 0;
}

.screen {
  position: relative;
  z-index: 1;
  min-height: 100%;
}

.hidden {
  display: none !important;
}

.login-card {
  width: min(440px, calc(100% - 32px));
  margin: 12vh auto 0;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(110, 168, 255, 0.25);
  margin-bottom: 18px;
}

.logo-mark.small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 0.82rem;
  margin-bottom: 0;
}

.brand {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.card input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(10, 12, 18, 0.72);
  color: var(--text);
  font: inherit;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card input:focus {
  outline: none;
  border-color: rgba(110, 168, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(110, 168, 255, 0.12);
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 18px;
  font: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #4f7cff);
  color: white;
  box-shadow: 0 10px 24px rgba(79, 124, 255, 0.28);
}

.primary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.login-card .primary-btn {
  width: 100%;
  margin-top: 16px;
}

.ghost-btn,
.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
}

.error {
  color: var(--danger);
  margin-top: 14px;
  font-size: 0.92rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 17, 24, 0.95);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  min-height: 44px;
}

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

.topbar-title {
  min-width: 0;
  line-height: 1.2;
}

.topbar-main {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.topbar-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.topbar-icon-btn:active {
  background: rgba(255, 255, 255, 0.14);
}

.topbar-icon-btn.active {
  background: rgba(110, 168, 255, 0.18);
  color: #9ec1ff;
}

.mobile-back {
  font-size: 1.25rem;
  font-weight: 300;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #6b7a90;
  box-shadow: 0 0 0 2px rgba(107, 122, 144, 0.25);
}

.status-dot.idle {
  background: #6b7a90;
  box-shadow: 0 0 0 2px rgba(107, 122, 144, 0.25);
}

.status-dot.running {
  background: #4caf50;
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
  animation: pulse-dot 1.4s ease-in-out infinite;
}

.status-dot.error {
  background: #ff6b6b;
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.mode-banner {
  padding: 6px 10px;
  background: rgba(110, 168, 255, 0.06);
  color: #a8b8d4;
  border-bottom: 1px solid rgba(110, 168, 255, 0.1);
  font-size: 0.75rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.session-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 19, 27, 0.85);
  min-height: 36px;
}

.project-badge {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  color: white;
  background: #4f8cff;
  white-space: nowrap;
  flex-shrink: 0;
}

.session-meta {
  min-width: 0;
  flex: 1;
}

.session-project-name {
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-project-path {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 280px) 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(12, 15, 22, 0.92);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-weight: 600;
  font-size: 0.84rem;
}

.sidebar-count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.session-groups {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.sidebar-empty {
  padding: 16px 12px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.group-card {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.03);
  min-height: 32px;
}

.group-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.group-badge.project { background: #4f8cff; }
.group-badge.temp { background: #d9822b; }
.group-badge.workspace { background: #8b5cf6; }
.group-badge.empty { background: #667085; }
.group-badge.unknown { background: #546072; }

.group-count {
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
}

.group-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.8rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-chats {
  display: flex;
  flex-direction: column;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  min-height: 44px;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-item-main {
  flex: 1;
  min-width: 0;
}

.chat-item-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.chat-item-unread {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #ffc107;
  box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.28);
}

.chat-item.unread .chat-item-title {
  color: #fff7da;
}

.chat-item.unread:not(.active) {
  background: rgba(255, 193, 7, 0.05);
}

.chat-item-title {
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-sub {
  margin-top: 2px;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-chevron {
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.28);
  font-size: 1rem;
  line-height: 1;
  padding-left: 2px;
}

.chat-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-item.active {
  background: rgba(110, 168, 255, 0.1);
  box-shadow: inset 2px 0 0 var(--accent);
}

.main-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.tabs-bar,
.tabs,
.tab {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-anchor: none;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.message-row {
  display: flex;
  gap: 8px;
  max-width: min(880px, 100%);
  width: 100%;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 92%;
}

.message-row.assistant,
.message-row.system,
.message-row.tool,
.message-row.interaction {
  align-self: flex-start;
  max-width: 96%;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  flex: 0 0 auto;
}

.message-row.user .message-avatar {
  background: rgba(110, 168, 255, 0.18);
  color: #9ec1ff;
}

.message-row.assistant .message-avatar {
  background: rgba(139, 92, 246, 0.18);
  color: #cdb6ff;
}

.message-row.system .message-avatar,
.message-row.tool .message-avatar {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.message-row.interaction .message-avatar {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.message {
  padding: 9px 11px 6px;
  border-radius: 12px;
  line-height: 1.5;
  border: 1px solid transparent;
  flex: 1;
  min-width: 0;
  font-size: 0.86rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.message-sender-label {
  font-size: 0.68rem;
  line-height: 1;
  color: var(--muted);
  opacity: 0.82;
  letter-spacing: 0.02em;
  user-select: none;
}

.message-copy-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0.72;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.message-copy-btn:hover,
.message-copy-btn:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.06);
}

.message-copy-btn:active {
  transform: scale(0.97);
}

.message-copy-btn.copied {
  opacity: 1;
  color: #86efac;
}

.message-row.user .message-copy-btn:hover,
.message-row.user .message-copy-btn:focus-visible {
  background: rgba(110, 168, 255, 0.12);
}

.message-copy-icon {
  flex: 0 0 auto;
}

.message-copy-label {
  font-size: 0.72rem;
}

.message-row.user .message {
  background: var(--user);
  border-color: rgba(110, 168, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.message-row.user .message-sender-label {
  color: rgba(174, 206, 255, 0.88);
}

.message-row.assistant .message {
  background: var(--assistant);
  border-color: rgba(139, 92, 246, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.message-row.assistant .message-sender-label {
  color: rgba(205, 182, 255, 0.82);
}

.message-row.system .message,
.message-row.tool .message {
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.78rem;
}

.message-row.interaction .message {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.28);
}

.message-row.interaction .message-sender-label {
  color: rgba(251, 191, 36, 0.88);
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.action-btn {
  appearance: none;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}

.action-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.action-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.action-btn.action-approve {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}

.action-btn.action-deny {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.action-btn.action-skip {
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
  color: #cbd5e1;
}

.composer {
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: rgba(14, 17, 24, 0.98);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-stop {
  flex-shrink: 0;
  width: 44px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(255, 107, 107, 0.22);
  background: rgba(255, 107, 107, 0.08);
  color: #ff9a9a;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.composer-stop.running {
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.16);
  color: #ffb4b4;
}

.composer-stop:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.composer-field {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  padding: 0 10px;
  box-sizing: border-box;
}

.composer-field textarea {
  width: 100%;
  min-height: 22px;
  max-height: 100px;
  padding: 7px 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.4;
  resize: none;
  box-shadow: none;
}

.composer-field textarea:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

.composer-send {
  flex-shrink: 0;
  width: 52px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #07c160;
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.composer-send:hover {
  opacity: 0.92;
}

.composer-send:active {
  transform: scale(0.97);
}

.composer-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

#app-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar-empty {
  padding: 28px 16px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
  text-align: center;
}

.sidebar-empty p {
  margin: 8px 0 4px;
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    min-height: 0;
    overflow: hidden;
  }

  .layout.view-list .panel-chat {
    display: none;
  }

  .layout.view-chat .panel-list {
    display: none;
  }

  .layout.view-list .sidebar,
  .layout.view-chat .main-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    max-height: none;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 0;
  }

  .session-groups {
    padding: 6px 8px 12px;
  }

  .group-card {
    border-radius: 10px;
  }

  .session-header {
    display: none;
  }

  .layout.view-chat .session-header {
    display: flex;
  }

  .messages {
    padding: 8px 10px;
  }

  .mode-banner {
    display: none;
  }

  .mobile-back.hidden {
    display: none !important;
  }

  .layout.view-chat .mobile-back:not(.hidden) {
    display: grid;
    place-items: center;
  }

  .layout.view-list .mobile-back {
    display: none;
  }

  .layout.view-list #refresh-btn {
    display: grid;
  }

  .layout.view-chat #refresh-btn {
    display: none;
  }

  .layout.view-chat #notify-btn {
    display: none;
  }
}

.group-empty-chats {
  padding: 10px 12px 12px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

@media (min-width: 769px) {
  .mobile-back {
    display: none !important;
  }

  .layout.view-list,
  .layout.view-chat {
    grid-template-columns: minmax(280px, 340px) 1fr;
  }

  .layout.view-list .panel-chat,
  .layout.view-chat .panel-list {
    display: flex;
  }

  .topbar-icon-btn {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
  }

  .composer-send,
  .composer-stop {
    min-height: 44px;
    padding: 0 18px;
  }

  #prompt {
    font-size: 1rem;
    line-height: 1.45;
  }
}

@media (max-width: 640px) {
  .login-card {
    margin-top: 8vh;
    padding: 22px 18px;
  }
}

.notify-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
}

.notify-sheet.hidden {
  display: none !important;
}

.notify-sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.notify-sheet-panel {
  position: relative;
  width: min(420px, calc(100% - 20px));
  margin-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(18, 22, 31, 0.98);
  box-shadow: var(--shadow);
}

.notify-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.notify-sheet-title {
  font-size: 0.95rem;
  font-weight: 700;
}

.notify-sheet-tip {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.notify-sheet-panel input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(10, 12, 18, 0.72);
  color: var(--text);
  font: inherit;
}

.notify-sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.notify-sheet-actions .primary-btn,
.notify-sheet-actions .ghost-btn {
  flex: 1;
  min-height: 40px;
}

.notify-sheet-status {
  margin: 10px 0 0;
  font-size: 0.74rem;
  color: #9be7a0;
}

.notify-sheet-tip-sub {
  margin-top: 0;
  font-size: 0.82rem;
  opacity: 0.85;
}
  margin: 14px 0 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
}

.notify-sheet-wide {
  width: 100%;
  min-height: 40px;
}
