/* MacControl — 深色主题，移动优先 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #16161e;
  --bg2: #1f2029;
  --bg3: #2a2b38;
  --fg: #c8cad4;
  --dim: #6b6e7f;
  --accent: #7ee787;
  --danger: #f47067;
  --vvh: 100dvh;
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
button {
  font: inherit;
  color: var(--fg);
  background: var(--bg3);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:active { filter: brightness(1.3); }
button.primary { background: #2b5735; color: #d3f9d8; }
input {
  font: inherit;
  color: var(--fg);
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------- 登录 ---------- */
#login-view {
  height: var(--vvh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#login-form { width: 100%; max-width: 320px; text-align: center; }
.login-logo {
  font: 700 40px/1 ui-monospace, Menlo, monospace;
  color: var(--accent);
  margin-bottom: 8px;
}
#login-form h1 { font-size: 22px; margin-bottom: 4px; }
#login-hint { color: var(--dim); font-size: 13px; margin-bottom: 20px; }
#login-form input { width: 100%; padding: 12px 14px; margin-bottom: 12px; font-size: 16px; }
#login-form button { width: 100%; padding: 12px; background: #2b5735; color: #d3f9d8; font-size: 16px; }
.err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 1.5em; }

/* ---------- 主界面 ---------- */
#app-view {
  height: var(--vvh);
  display: flex;
  flex-direction: column;
}
#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bg2);
  flex: none;
}
#conn-dot {
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--dim);
  margin-left: 2px;
}
#conn-dot.ok { background: var(--accent); }
#conn-dot.bad { background: #e5a54b; }
#tabs {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--dim);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.tab.active { background: var(--bg3); color: var(--fg); }
.tab .tab-close {
  background: none;
  color: var(--dim);
  font-size: 14px;
  padding: 0 2px;
  border-radius: 4px;
}
.tab .tab-close:active { color: var(--danger); }
.icon-btn {
  flex: none;
  width: 34px; height: 34px;
  font-size: 17px;
  line-height: 1;
  background: none;
}
#btn-new-tab { font-size: 20px; color: var(--accent); }

#term-wrap { flex: 1; position: relative; min-height: 0; background: var(--bg); }
#terminal { position: absolute; inset: 0; padding: 4px 0 0 6px; }
.xterm-viewport { overscroll-behavior: contain; }
#conn-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(22,22,30,.72);
  z-index: 5;
}
#conn-overlay-text {
  padding: 10px 20px;
  background: var(--bg3);
  border-radius: 10px;
  font-size: 14px;
}

/* ---------- 撰写栏 ---------- */
#compose-bar {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg2);
}
#compose-input { flex: 1; padding: 9px 12px; font-size: 16px; min-width: 0; }
#compose-bar button { flex: none; padding: 0 14px; font-size: 14px; }
#compose-send { background: #2b5735; color: #d3f9d8; }

/* ---------- 按键工具条 ---------- */
#toolbar {
  flex: none;
  display: flex;
  gap: 5px;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--bg2);
  overflow-x: auto;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar button {
  flex: none;
  min-width: 44px;
  height: 38px;
  padding: 0 10px;
  font-size: 14px;
  font-family: ui-monospace, Menlo, monospace;
}
#toolbar button.on { background: #2b5735; color: var(--accent); }

/* ---------- 文件抽屉 ---------- */
#files-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 20;
}
#files-drawer {
  position: fixed;
  z-index: 21;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  /* 手机：底部抽屉 */
  left: 0; right: 0; bottom: 0;
  height: min(72vh, 560px);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 700px) {
  /* 桌面/iPad：左侧面板 */
  #files-drawer {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 360px;
    height: auto;
    border-radius: 0 16px 16px 0;
  }
}
#files-drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  font-size: 16px;
}
#files-crumbs {
  padding: 0 16px 8px;
  font-size: 13px;
  color: var(--dim);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
#files-crumbs::-webkit-scrollbar { display: none; }
#files-crumbs a { color: var(--accent); text-decoration: none; cursor: pointer; }
#files-crumbs .sep { margin: 0 3px; color: var(--dim); }
#files-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0 8px;
  -webkit-overflow-scrolling: touch;
}
#files-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
#files-list li:active { background: var(--bg3); }
#files-list li .f-icon { flex: none; }
#files-list li .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#files-list li .f-meta { flex: none; color: var(--dim); font-size: 12px; }
#files-list li.dotfile .f-name { color: var(--dim); }
#files-drawer footer {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
}
#files-drawer footer button { flex: 1; padding: 11px; font-size: 14px; }

/* ---------- 菜单 ---------- */
#menu-pop {
  position: fixed;
  top: 48px; right: 8px;
  z-index: 30;
  background: var(--bg3);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  min-width: 160px;
}
#menu-pop button { background: none; text-align: left; padding: 10px 14px; font-size: 14px; border-radius: 7px; }
#menu-pop button:active { background: var(--bg2); }
#menu-pop hr { border: none; border-top: 1px solid var(--bg2); margin: 4px 0; }

/* ---------- 小对话框 ---------- */
#dlg-mask {
  position: fixed; inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#dlg {
  width: 100%;
  max-width: 320px;
  background: var(--bg2);
  border-radius: 14px;
  padding: 20px;
}
#dlg-text { font-size: 15px; margin-bottom: 14px; }
#dlg-input { width: 100%; padding: 10px 12px; font-size: 16px; margin-bottom: 14px; }
.dlg-btns { display: flex; gap: 10px; }
.dlg-btns button { flex: 1; padding: 10px; }
