/* 扁平化配色:纯色表面 + 细描边,不用玻璃拟态与阴影堆叠。
   取值与 iOS 版 Design/Theme.swift 一一对应。 */

:root {
  --brand: #0fb981;
  --brand-soft: #e7f8f1;
  --info: #2f6bff;
  --info-soft: #eaf0ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --warn: #c77d14;
  --warn-soft: #fdf3e3;

  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-alt: #f5f7fa;
  --separator: #e7ebf0;

  --text-1: #0f1419;
  --text-2: #69747f;
  --text-3: #9aa3ad;

  --card-radius: 26px;
  --field-radius: 16px;
  --page-pad: 20px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --brand: #2dd4a0;
    --brand-soft: #0f2e26;
    --info: #5b8cff;
    --info-soft: #131e3a;
    --danger: #ff6369;
    --danger-soft: #33191b;
    --warn: #f5b14c;
    --warn-soft: #2e2312;

    --bg: #0a0c10;
    --surface: #151a21;
    --surface-alt: #1d232c;
    --separator: #252c36;

    --text-1: #f3f6f9;
    --text-2: #99a4b0;
    --text-3: #6c7783;

    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --brand: #2dd4a0;
  --brand-soft: #0f2e26;
  --info: #5b8cff;
  --info-soft: #131e3a;
  --danger: #ff6369;
  --danger-soft: #33191b;
  --warn: #f5b14c;
  --warn-soft: #2e2312;

  --bg: #0a0c10;
  --surface: #151a21;
  --surface-alt: #1d232c;
  --separator: #252c36;

  --text-1: #f3f6f9;
  --text-2: #99a4b0;
  --text-3: #6c7783;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

/* dvh 会随移动浏览器工具栏的伸缩动态调整,100% 不会 */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  background: var(--bg);
  color: var(--text-1);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
        'Hiragino Sans GB', 'Microsoft YaHei', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

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

button { cursor: pointer; }

.mono {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  font-variant-ligatures: none;
}

/* —— 骨架 —— */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

.page {
  flex: 1;
  padding: 0 var(--page-pad) calc(140px + env(safe-area-inset-bottom));
  display: none;
}

.page.active { display: block; }

/* 加到主屏独立运行时没有浏览器工具栏,那 140px 的余量就纯属浪费,收回来 */
@media all and (display-mode: standalone), all and (display-mode: fullscreen) {
  .page { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
}

.page-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: calc(16px + env(safe-area-inset-top)) 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stack { display: flex; flex-direction: column; gap: 18px; }

/* 条件渲染的插槽（环境提示、自动获取卡片、中断按钮）在没内容时是个空 div。
   flex 的 gap 照样会算上它,导致相邻卡片之间凭空多出一个间距 —— 直接摘掉。 */
.stack > :empty,
.unlock-wrap > :empty { display: none; }

/* —— 底部 Tab —— */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  max-width: 520px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -6px 16px -12px rgba(0, 0, 0, 0.35);
}

.tabbar button {
  flex: 1;
  border: 0;
  background: none;
  padding: 10px 0 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  transition: color 0.15s;
}

.tabbar button[aria-selected='true'] { color: var(--brand); }
.tabbar svg { width: 22px; height: 22px; }

/* —— 卡片 —— */

.card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--card-radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-header { display: flex; align-items: center; gap: 12px; }

.card-header .glyph {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: none;
}

.card-header .glyph svg { width: 19px; height: 19px; }
.card-header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.card-header p { margin: 2px 0 0; font-size: 12px; color: var(--text-2); }

/* —— 按钮 —— */

.btn {
  border: 0;
  border-radius: var(--field-radius);
  height: 50px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
  transition: opacity 0.15s, transform 0.08s;
}

.btn svg { width: 17px; height: 17px; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.info { background: var(--info); }
.btn.danger { background: var(--danger); }

.btn.quiet {
  background: var(--surface-alt);
  color: var(--text-2);
  border: 1px solid var(--separator);
  height: 44px;
  font-size: 14px;
}

.btn.quiet.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn.block { width: 100%; }

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--surface-alt);
  color: var(--text-2);
  display: grid;
  place-items: center;
}

.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.plain { background: none; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* —— 表单 —— */

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.field input, .field textarea, .field select {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--separator);
  border-radius: var(--field-radius);
  padding: 13px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); }
.field textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
.field .hint { font-size: 11px; color: var(--text-3); }

.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

.field-link {
  border: 0;
  background: none;
  padding: 0;
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--info);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* 帮助弹层里的步骤 */
.steps {
  margin: 6px 0 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.steps .step b { font-size: 14px; font-weight: 600; display: block; }

.steps .step p {
  margin: 4px 0 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-2);
  word-break: break-word;
}

.steps .step .btn { margin-top: 10px; }
.field .hint.error { color: var(--danger); }

/* —— 开关行 / 步进行 —— */

.pref {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--separator);
}

.pref:last-child { border-bottom: 0; }
.pref .text { flex: 1; min-width: 0; }
.pref .text b { display: block; font-size: 14px; font-weight: 600; }
.pref .text span { display: block; font-size: 11.5px; color: var(--text-2); margin-top: 2px; }

.switch {
  position: relative;
  width: 48px;
  height: 29px;
  flex: none;
  border: 0;
  border-radius: 15px;
  background: var(--separator);
  transition: background 0.18s;
}

.switch[aria-checked='true'] { background: var(--brand); }

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}

.switch[aria-checked='true']::after { transform: translateX(19px); }

.stepper { display: flex; align-items: center; gap: 4px; flex: none; }

.stepper button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--separator);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text-1);
  font-size: 17px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.stepper button:disabled { opacity: 0.35; }
.stepper .value { min-width: 42px; text-align: center; font-size: 14px; font-weight: 600; }

/* —— 门禁选择条 —— */

.door-bar { display: flex; gap: 12px; }

.door-select {
  flex: 1;
  min-width: 0;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 18px;
  color: var(--text-1);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
}

.door-select .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.door-select svg { width: 17px; height: 17px; flex: none; }
.door-select .lead { color: var(--brand); }
.door-select .tail { color: var(--text-3); width: 13px; height: 13px; }

.door-bar .icon-btn {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  background: var(--info-soft);
  color: var(--info);
}

/* —— 门禁列表项 —— */

.door-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--field-radius);
  background: var(--surface-alt);
  text-align: left;
  border: 0;
  width: 100%;
}

.door-row.current { background: var(--brand-soft); }
.door-row .mark { width: 20px; height: 20px; flex: none; color: var(--text-3); }
.door-row.current .mark { color: var(--brand); }
.door-row .body { flex: 1; min-width: 0; }
.door-row .body b { display: block; font-size: 15px; font-weight: 600; }
.door-row .body span { display: block; font-size: 12px; color: var(--text-2); margin-top: 3px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  flex: none;
  background: var(--warn-soft);
  color: var(--warn);
}

/* —— 开锁按钮 —— */

.unlock-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0 4px;
}

.unlock {
  position: relative;
  width: 208px;
  height: 208px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  gap: 6px;
  align-content: center;
  transition: transform 0.1s, background 0.25s;
}

.unlock svg { width: 54px; height: 54px; }
.unlock .caption { font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }
.unlock:active:not(:disabled) { transform: scale(0.96); }
.unlock:disabled { background: var(--separator); color: var(--text-3); cursor: not-allowed; }
.unlock.busy { background: var(--info); }
.unlock.success { background: var(--brand); }
.unlock.failure { background: var(--danger); }

/* 忙碌时的涟漪 */
.unlock.busy::before,
.unlock.busy::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--info);
  animation: ripple 1.8s ease-out infinite;
}

.unlock.busy::after { animation-delay: 0.9s; }

@keyframes ripple {
  from { transform: scale(1); opacity: 0.55; }
  to { transform: scale(1.35); opacity: 0; }
}

.status {
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  min-height: 44px;
  color: var(--text-2);
  padding: 0 8px;
}

.status.success { color: var(--brand); }
.status.failure { color: var(--danger); }
.status.busy { color: var(--info); }

/* —— 参数 / 日志 —— */

.kv { display: flex; flex-direction: column; gap: 10px; }

.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  font-size: 13px;
}

.kv-row .k { color: var(--text-2); flex: none; }
.kv-row .v { text-align: right; word-break: break-all; font-size: 12.5px; }

.logs {
  background: var(--surface-alt);
  border-radius: var(--field-radius);
  padding: 12px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 11.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-all;
}

.logs .line { display: flex; gap: 7px; }
.logs .t { color: var(--text-3); flex: none; }
.logs .lv { flex: none; font-weight: 700; width: 38px; }
.logs .lv.info { color: var(--brand); }
.logs .lv.warn { color: var(--warn); }
.logs .lv.error { color: var(--danger); }
.logs .lv.debug { color: var(--text-3); }
.logs .msg { color: var(--text-1); flex: 1; min-width: 0; }

.empty {
  text-align: center;
  padding: 26px 10px;
  color: var(--text-2);
}

.empty svg { width: 30px; height: 30px; color: var(--text-3); }
.empty b { display: block; font-size: 15px; margin-top: 10px; color: var(--text-1); }
.empty span { display: block; font-size: 12.5px; margin-top: 5px; }

.note {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-2);
}

.note.warn {
  background: var(--warn-soft);
  color: var(--warn);
  padding: 11px 13px;
  border-radius: 14px;
  font-weight: 500;
}

/* —— 弹层 —— */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.18s ease;
}

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

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  padding: 8px var(--page-pad) calc(24px + env(safe-area-inset-bottom));
  animation: rise 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rise { from { transform: translateY(18px); } to { transform: translateY(0); } }

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--separator);
  margin: 8px auto 12px;
}

.sheet h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.sheet .sub { margin: 0 0 16px; font-size: 12.5px; color: var(--text-2); }
.sheet .fields { display: flex; flex-direction: column; gap: 14px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet .actions > * { flex: 1; }

/* —— 菜单 —— */

.menu-backdrop { position: fixed; inset: 0; z-index: 45; }

.menu {
  position: fixed;
  z-index: 46;
  min-width: 168px;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
}

.menu button {
  border: 0;
  background: none;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-1);
  text-align: left;
}

.menu button svg { width: 16px; height: 16px; color: var(--text-2); }
.menu button:hover { background: var(--surface-alt); }
.menu button.danger, .menu button.danger svg { color: var(--danger); }
.menu button .check { margin-left: auto; color: var(--brand); }

/* —— Toast —— */

.toast-host {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text-1);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 600;
  max-width: calc(100% - 40px);
  animation: drop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.error { background: var(--danger); color: #fff; }

@keyframes drop { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* —— 锁屏 —— */

.lockscreen {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px;
}

.lockscreen .glyph {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
}

.lockscreen .glyph svg { width: 30px; height: 30px; }
.lockscreen h1 { margin: 0; font-size: 20px; font-weight: 700; }
.lockscreen .field, .lockscreen .btn { width: 100%; max-width: 320px; }

/* —— iOS 引导页 —— */

.gate {
  justify-content: flex-start;
  padding-top: calc(40px + env(safe-area-inset-top));
  overflow-y: auto;
  gap: 14px;
}

.gate h1 { text-align: center; }

.gate .gate-lead {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-2);
  text-align: center;
  max-width: 340px;
}

.gate .gate-url {
  width: 100%;
  max-width: 340px;
  background: var(--surface-alt);
  border: 1px solid var(--separator);
  border-radius: var(--field-radius);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-1);
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}

.gate .btn, .gate a.btn { max-width: 340px; }

.gate .gate-steps {
  margin: 4px 0 0;
  padding-left: 20px;
  max-width: 340px;
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--text-2);
  align-self: center;
}

.gate .gate-skip {
  margin-top: 4px;
  border: 0;
  background: none;
  color: var(--text-3);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 10px;
}

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