/* ==========================================================================
   DSH Remote · 移动优先深色主题（无外部字体/资源）
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-elev: #111823;
  --bg-elev-2: #16202d;
  --bg-input: #0f1722;
  --border: #22303f;
  --border-strong: #2f4257;
  --text: #e6edf3;
  --text-dim: #c3cfdb;
  --muted: #8b9bb0;
  --accent: #4d9dff;
  --accent-ink: #06101d;
  --accent-2: #3ee0b0;
  --danger: #ff6b6b;
  --warn: #f5b942;
  --ok: #3ee0b0;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

body.session-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}

img {
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 启动占位 ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
}

.boot-logo {
  border-radius: 14px;
}

.boot-text {
  font-size: 14px;
  letter-spacing: 0.06em;
}

/* ---------- 登录页 ---------- */

.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: calc(24px + var(--safe-top)) calc(18px + var(--safe-right))
    calc(24px + var(--safe-bottom)) calc(18px + var(--safe-left));
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(77, 157, 255, 0.14), transparent 60%),
    radial-gradient(900px 480px at 105% 105%, rgba(62, 224, 176, 0.1), transparent 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 22px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(22, 32, 45, 0.96), rgba(17, 24, 35, 0.96));
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-brand img {
  border-radius: 12px;
  flex: 0 0 auto;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.login-form {
  display: block;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.pin-row {
  display: flex;
  gap: 8px;
}

.pin-row .input {
  flex: 1 1 auto;
  min-width: 0;
}

.pin-toggle {
  flex: 0 0 auto;
  min-width: 64px;
}

.form-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: var(--radius-sm);
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
}

.login-form .btn-block {
  margin-top: 14px;
}

.login-foot {
  margin-top: 16px;
  text-align: center;
}

/* ---------- 基础控件 ---------- */

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px; /* iOS 聚焦时避免自动缩放 */
  line-height: 1.4;
  appearance: none;
}

.input::placeholder {
  color: #64748b;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.99);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn-primary:not(:disabled):active {
  background: #6cb0ff;
}

.btn-secondary {
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-dim);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(255, 107, 107, 0.45);
  color: var(--danger);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  min-height: 38px;
  padding: 0 14px;
  font-size: 13px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
}

.icon-btn:active {
  background: var(--bg-elev-2);
}

.text-btn {
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.text-btn:active {
  background: rgba(77, 157, 255, 0.12);
}

/* ---------- 应用骨架 ---------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: calc(6px + var(--safe-top)) calc(14px + var(--safe-right)) 6px
    calc(14px + var(--safe-left));
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: saturate(150%) blur(12px);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-name {
  font-size: 16px;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot.is-ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(62, 224, 176, 0.18);
}

.dot.is-bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.16);
}

.dot.is-unknown {
  background: var(--muted);
}

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px calc(12px + var(--safe-right)) 9px calc(12px + var(--safe-left));
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}

.banner-text {
  flex: 1 1 auto;
  min-width: 0;
}

.banner-warn {
  background: #2a1f10;
  border-bottom-color: #5a4520;
  color: #f0c987;
}

.banner-info {
  background: #101f33;
  border-bottom-color: #24476e;
  color: #b9d6ff;
}

.banner .icon-btn {
  width: 36px;
  height: 36px;
  color: inherit;
}

.app-main {
  flex: 1 0 auto;
  padding: 12px calc(14px + var(--safe-right)) calc(96px + var(--safe-bottom))
    calc(14px + var(--safe-left));
}

.page-inner {
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- 卡片 / 区块 ---------- */

.card,
.status-card {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.section {
  margin: 18px 0 2px;
}

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

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- 状态卡 ---------- */

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev-2);
  font-size: 13px;
  color: var(--text-dim);
}

.chip .dot {
  width: 8px;
  height: 8px;
}

.chip.is-ok {
  border-color: rgba(62, 224, 176, 0.35);
}

.chip.is-bad {
  border-color: rgba(255, 107, 107, 0.4);
  color: #ffc9c9;
}

.chip.is-unknown {
  border-color: var(--border);
  color: var(--muted);
}

.status-meta {
  margin-top: 10px;
}

.tunnel-slot {
  margin-top: 10px;
}

.tunnel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 6px 6px 6px 12px;
  color: var(--muted);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.tunnel-row .tunnel-label {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}

.tunnel-url {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--accent-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 任务输入 ---------- */

.compose-card .textarea {
  margin-top: 2px;
}

.compose-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.compose-row .count-over,
.compose-row .is-over {
  color: var(--danger);
}

.compose-row .btn {
  min-width: 96px;
}

.compose-hint {
  margin-top: 8px;
}

/* ---------- 列表 ---------- */

.list {
  display: block;
}

.item {
  display: block;
  width: 100%;
  min-height: 64px;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  color: inherit;
  text-align: left;
}

.item:active {
  background: var(--bg-elev-2);
}

.item-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.item-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.item-sub {
  display: -webkit-box;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid rgba(77, 157, 255, 0.35);
  border-radius: 999px;
  background: rgba(77, 157, 255, 0.14);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.is-running::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.badge.is-ok {
  border-color: rgba(62, 224, 176, 0.35);
  background: rgba(62, 224, 176, 0.12);
  color: var(--accent-2);
}

.badge.is-bad {
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

.empty {
  padding: 22px 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  word-break: break-word;
}

.empty.small {
  padding: 16px 12px;
}

.home-meta {
  margin-top: 16px;
  text-align: center;
}

/* ---------- 截图 ---------- */

.shot-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #05080c;
}

.shot-frame .empty {
  border: 0;
}

.shot-img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- 诊断 ---------- */

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 56px;
  margin-bottom: 8px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
}

.check-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.check.is-ok .check-dot {
  background: var(--ok);
}

.check.is-bad .check-dot {
  background: var(--danger);
}

.check.is-unknown .check-dot {
  background: var(--muted);
}

.check-body {
  flex: 1 1 auto;
  min-width: 0;
}

.check-name {
  font-size: 14px;
  font-weight: 600;
}

.check-detail {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.check-hint {
  margin-top: 4px;
  color: var(--warn);
  font-size: 12px;
  word-break: break-word;
}

.pre {
  max-height: 280px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #0a121b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.page-actions .btn {
  flex: 1 1 160px;
}

/* ---------- 底部 Tab ---------- */

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0 calc(8px + var(--safe-right)) var(--safe-bottom) calc(8px + var(--safe-left));
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.94);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.tab-btn.is-active {
  color: var(--accent);
}

.tab-icon {
  width: 23px;
  height: 23px;
}

/* ---------- 会话覆盖层 ---------- */

.session-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.session-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.session-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.session-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-status {
  overflow: hidden;
  margin-top: 1px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-status.is-ok {
  color: var(--ok);
}

.session-status.is-warn {
  color: var(--warn);
}

.session-status.is-bad {
  color: var(--danger);
}

.session-output {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 14px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.out-line {
  margin: 0 0 8px;
  padding-left: 10px;
  border-left: 2px solid transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
}

.out-line.out-user {
  border-left-color: var(--warn);
  color: #e8d9b6;
}

.out-line.out-message {
  border-left-color: var(--accent);
  color: var(--text);
}

.out-line.out-tool {
  border-left-color: var(--accent-2);
  color: #c8e6da;
}

.out-line.out-system {
  padding-left: 0;
  border-left: 0;
  color: var(--muted);
  font-style: italic;
}

.out-line.out-warn {
  border-left-color: var(--warn);
  color: #f0c987;
}

.out-line.out-error {
  border-left-color: var(--danger);
  color: #ffb4b4;
}

.out-line.out-stream {
  border-left-color: var(--accent);
  color: var(--text);
}

.out-line.out-json {
  border-left-color: var(--border-strong);
  color: var(--muted);
  font-size: 12px;
}

.session-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}

/* ---------- Toast ---------- */

.toast-root {
  position: fixed;
  right: 0;
  bottom: calc(84px + var(--safe-bottom));
  left: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}

.toast {
  width: min(92vw, 440px);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #1b2634;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  word-break: break-word;
  animation: toast-in 0.18s ease-out;
}

.toast.is-success {
  border-color: rgba(62, 224, 176, 0.5);
}

.toast.is-error {
  border-color: rgba(255, 107, 107, 0.55);
  color: #ffd1d1;
}

.toast.is-leaving {
  opacity: 0;
  transition: opacity 0.22s ease;
}

.copy-helper {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---------- 动画 ---------- */

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---------- 平板/桌面增强 ---------- */

@media (min-width: 700px) {
  .app-main {
    padding-top: 16px;
  }

  .status-card,
  .card {
    padding: 16px;
  }

  .login-card {
    padding: 26px 24px;
  }

  .page-inner {
    max-width: 760px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
