:root {
  --bg: #10141a;
  --surface: #1a212b;
  --elev: #222a35;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f7;
  --muted: #8b98a9;
  --accent: #3b9fd9;
  --accent-dim: rgba(59, 159, 217, 0.14);
  --ok: #47c98a;
  --danger: #d85a5a;
  --warn: #e5b567;
  --radius: 12px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ?? hidden???? display:flex ???????????? */
[hidden] {
  display: none !important;
}

html, body {
  min-height: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(100% 60% at 0% 0%, rgba(59, 159, 217, 0.1), transparent 50%),
    var(--bg);
}

body.view-login {
  overflow: hidden;
  height: 100%;
}

body.view-app {
  overflow: auto;
  height: auto;
  min-height: 100%;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 14px calc(18px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

/* ?? */
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  flex-shrink: 0;
  background: linear-gradient(145deg, #4db3e8, #1f6aa5 60%, #153d5c);
  position: relative;
  box-shadow: 0 6px 16px rgba(31, 106, 165, 0.3);
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 10px 8px 11px 9px;
  background: rgba(255, 255, 255, 0.92);
  clip-path: polygon(0 55%, 48% 0, 100% 40%, 58% 48%, 100% 100%, 40% 62%, 0 100%);
}

.top h1 {
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.2;
}

.sub {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--muted);
}

.status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.status-pill[data-state="running"] .dot,
.status-pill[data-state="online"] .dot { background: var(--ok); }
.status-pill[data-state="running"],
.status-pill[data-state="online"] { color: #b8efd4; }

/* ?? */
.tabs {
  display: flex;
  gap: 3px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: 11px;
  border: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  flex: 1 0 auto;
  white-space: nowrap;
}

.tab.active {
  background: var(--bg);
  color: var(--text);
}

.panels { flex: 1; }
.panel { display: none; }
.panel.active { display: block; animation: fade 0.16s ease; }

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ??? */
.control-card {
  padding: 0;
  margin-bottom: 10px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}

.control-row + .control-row {
  border-top: 1px solid var(--line);
}

.control-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.control-detail {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
  max-width: 220px;
}

.control-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ???? */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 8px;
  text-align: center;
}

.metric span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric b {
  font-size: 0.86rem;
  font-weight: 650;
}

.note {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--accent-dim);
  border-radius: 10px;
}

.note.compact {
  margin-top: -2px;
  margin-bottom: 10px;
  padding: 8px 11px;
  font-size: 0.76rem;
}

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

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

.section-head h2 {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--muted);
}

.quick-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.quick {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.quick:hover { border-color: rgba(59, 159, 217, 0.35); }

/* ???? */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.card-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 650;
}

.chevron {
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-top: -2px;
}

.card.collapsed .chevron {
  transform: rotate(-45deg);
  margin-top: 2px;
}

.card-body {
  padding: 0 14px 14px;
}

.card:not(.collapsed) .card-body {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.card.collapsed .card-body { display: none; }

/* ???? */
.list { display: flex; flex-direction: column; gap: 8px; }

.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.item-head {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

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

.item-title {
  font-size: 0.92rem;
  font-weight: 650;
}

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

.badge {
  font-size: 0.68rem;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  flex-shrink: 0;
}

.badge.ok {
  background: rgba(71, 201, 138, 0.15);
  color: #8fdfb5;
}

.badge.warn {
  background: rgba(229, 181, 103, 0.16);
  color: #e8cf9a;
}

.badge.accent {
  background: var(--accent-dim);
  color: #9fd0f0;
}

.item-head .chevron { margin-left: auto; }

.item-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.item.open .item-body {
  display: block;
  padding-top: 12px;
}

.item.open .item-head .chevron {
  transform: rotate(45deg);
  margin-top: -2px;
}

.item:not(.open) .item-head .chevron {
  transform: rotate(-45deg);
  margin-top: 2px;
}

.empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ?? */
.field-hint {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.mode-pick {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
}

.mode-option:has(input:checked) {
  border-color: rgba(59, 159, 217, 0.55);
  background: var(--accent-dim);
}

.mode-option input {
  margin-top: 3px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.mode-option-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mode-option-body strong {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text);
}

.mode-option-body small {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field input,
.field select {
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 10px 11px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: rgba(59, 159, 217, 0.5);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
}

.switch-row.compact {
  padding: 10px 12px;
  margin-bottom: 10px;
}

.step-label {
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.proto-step[hidden] {
  display: none !important;
}

.proto-step .actions {
  margin-top: 8px;
}

/* ??? */
.kw-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.kw-add-row input {
  flex: 1;
  min-width: 0;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 10px 11px;
  outline: none;
}

.kw-add-row input:focus {
  border-color: rgba(59, 159, 217, 0.5);
}

.kw-add-row .btn {
  flex-shrink: 0;
}

.field textarea {
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  padding: 10px 11px;
  outline: none;
  resize: vertical;
  min-height: 68px;
  line-height: 1.4;
}

.field textarea:focus {
  border-color: rgba(59, 159, 217, 0.5);
}

.kw-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  min-height: 8px;
}

.kw-list:empty::after {
  content: "???????????????";
  color: var(--muted);
  font-size: 0.78rem;
}

.kw-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 159, 217, 0.28);
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.2;
}

.kw-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.kw-chip button {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}

.kw-chip button:hover {
  color: var(--danger);
  background: rgba(216, 90, 90, 0.15);
}

.field-hint.locked-exec b {
  color: #9fd0f0;
}

.switch-row input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.feed {
  list-style: none;
}

.feed li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 0.86rem;
}

.feed li:first-child {
  border-top: 0;
  padding-top: 0;
}

.feed time {
  flex: 0 0 40px;
  color: var(--muted);
  font-size: 0.75rem;
}

/* ?? */
.btn {
  border: 0;
  border-radius: 9px;
  font: inherit;
  font-weight: 600;
  font-size: 0.86rem;
  padding: 10px 14px;
  cursor: pointer;
}

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

.btn.primary {
  background: var(--accent);
  color: #fff;
}

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

.btn.sm {
  padding: 7px 11px;
  font-size: 0.78rem;
}

.btn.block {
  width: 100%;
  margin-top: 4px;
}

.btn.danger-text {
  background: transparent;
  color: #e89090;
  border: 1px solid rgba(216, 90, 90, 0.35);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.log {
  min-height: 320px;
  max-height: 60vh;
  overflow: auto;
  background: #0c1015;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.55;
  color: #a8b8c8;
  white-space: pre-wrap;
  word-break: break-word;
}

.foot {
  margin-top: 14px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-b));
  transform: translateX(-50%) translateY(8px);
  background: #262f3a;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.84rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
  z-index: 40;
  max-width: 88vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ??¼? */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-b));
  overflow: auto;
  background:
    radial-gradient(100% 60% at 0% 0%, rgba(59, 159, 217, 0.12), transparent 50%),
    var(--bg);
}

.login-screen[hidden],
.app[hidden] {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-brand { margin-bottom: 8px; }
.login-card .field { margin: 0; }
.danger-text { color: var(--danger) !important; }

.user-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--elev);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-bottom: 8px;
}

.user-row .user-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.user-row .user-name { font-weight: 600; font-size: 0.95rem; }
.user-row .user-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--accent);
}
.badge.expired { background: rgba(216, 90, 90, 0.18); color: var(--danger); }
.badge.ok { background: rgba(71, 201, 138, 0.16); color: var(--ok); }

select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
