/* DSH Remote Control — 移动端样式（暗色主题） */

:root {
  --bg: #14161b;
  --bg-elev: #1d2027;
  --bg-elev2: #262a33;
  --border: #333845;
  --text: #e6e9ef;
  --text-dim: #8b92a3;
  --accent: #4f8cff;
  --accent-dim: #2c4a7c;
  --green: #34c778;
  --red: #e5534b;
  --yellow: #d9a53a;
  --radius: 12px;
  --statusbar-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

#app { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- 状态栏 ---------- */
.statusbar {
  height: var(--statusbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.status-title {
  flex: 1;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  flex: 0 0 auto;
}
.status-indicator.ok { background: var(--green); }
.status-indicator.warn { background: var(--yellow); }
.status-indicator.off { background: var(--red); }

.icon-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: var(--bg-elev2); }

/* ---------- 视图 ---------- */
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 连接页 ---------- */
.connect-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.connect-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--bg-elev2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.connect-title { font-size: 18px; font-weight: 600; }
.connect-msg { color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.btn {
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: 0.85; }
.btn.secondary { background: var(--bg-elev2); color: var(--text); }
.btn.danger { background: var(--red); }

/* ---------- 会话列表 ---------- */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.session-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.session-card:active { background: var(--bg-elev2); }
.session-card .row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.session-card .title {
  flex: 1;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev2);
  color: var(--text-dim);
  flex: 0 0 auto;
}
.tag.local { color: var(--accent); background: rgba(79,140,255,0.12); }
.tag.remote { color: var(--yellow); background: rgba(217,165,58,0.12); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--text-dim); }
.dot.running { background: var(--green); animation: pulse 1.2s ease-in-out infinite; }
.dot.idle { background: var(--text-dim); }
.dot.error { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.4; } }
.session-card .meta { font-size: 12px; color: var(--text-dim); }
.empty-hint {
  color: var(--text-dim);
  text-align: center;
  padding: 48px 16px;
  line-height: 1.8;
  font-size: 14px;
}

/* ---------- 聊天页 ---------- */
.chat-page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 3px; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg .bubble {
  padding: 10px 13px;
  border-radius: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble { background: var(--accent-dim); border-bottom-right-radius: 4px; }
.msg.assistant .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.assistant .bubble code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-elev2);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg.assistant .bubble pre {
  background: #10131a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg.assistant .bubble pre code { background: none; padding: 0; }
.msg .bubble.streaming::after {
  content: '▍';
  color: var(--accent);
  animation: blink 0.9s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg .tool-call {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: ui-monospace, Consolas, monospace;
}
.msg-actions { display: flex; gap: 14px; font-size: 13px; color: var(--text-dim); padding: 0 4px; }
.msg-actions button {
  border: none; background: none; color: var(--text-dim);
  font-size: 14px; cursor: pointer; padding: 2px 4px;
}
.msg-actions button.active { color: var(--accent); }

/* 输入区 */
.chat-input {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
}
.chat-input textarea:focus { outline: none; border-color: var(--accent); }
.send-btn {
  width: 46px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
}
.send-btn:disabled { opacity: 0.4; }
.send-btn.stop { background: var(--red); }

/* 加载指示 */
.typing-hint {
  align-self: flex-start;
  color: var(--text-dim);
  font-size: 13px;
  padding: 2px 6px;
}

/* ---------- 模型栏 ---------- */
.model-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.model-label {
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-caret { font-size: 11px; }

/* ---------- 底部弹出面板 ---------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  max-height: 72vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: slideUp 0.18s ease-out;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.6; } }
.sheet-title {
  font-size: 16px;
  font-weight: 600;
  padding: 4px 4px 12px;
}
.sheet-back {
  color: var(--accent);
  font-size: 14px;
  padding: 2px 4px 10px;
  cursor: pointer;
}
.sheet-group {
  font-size: 12px;
  color: var(--text-dim);
  padding: 10px 4px 4px;
}
.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.sheet-row:active { background: var(--bg-elev2); }
.sheet-row.current { background: rgba(79,140,255,0.12); }
.sheet-row.current .sheet-row-name { color: var(--accent); font-weight: 600; }
.sheet-row-name { font-size: 15px; }
.sheet-row-hint { font-size: 12px; color: var(--text-dim); }

/* ---------- 登录页 ---------- */
.login-logo {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-input {
  width: 100%;
  max-width: 300px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
  text-align: center;
}
.login-input:focus { outline: none; border-color: var(--accent); }

/* ---------- 设置页 ---------- */
.settings-page {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.set-section {
  font-size: 12px;
  color: var(--text-dim);
  padding: 14px 4px 6px;
}
.set-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.set-label { color: var(--text-dim); }
.set-value { color: var(--text); word-break: break-all; }
.set-value.ok { color: var(--green); }
.set-value.err { color: var(--red); }
.set-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 8px;
}
.set-btn.danger { color: var(--red); }
.set-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
  padding: 8px 4px;
}
