:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e2e8f2;
  --text: #16203a;
  --text-dim: #6b7893;
  --primary: #2f6bff;
  --primary-weak: #e7efff;
  --danger: #e5484d;
  --warn-bg: #fff6e5;
  --warn-text: #8a5a00;
  --ok: #17a673;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(19, 34, 71, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #141c2e;
    --surface-2: #1c2438;
    --border: #26314a;
    --text: #e8edf7;
    --text-dim: #93a0bb;
    --primary: #5b8cff;
    --primary-weak: #1e2c4d;
    --warn-bg: #3a2c10;
    --warn-text: #ffd08a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

.app {
  max-width: 480px;
  margin: 0 auto;
}

/* 默认（登录页）内边距；二维码页自己单独控制，见 .qr-view */
.view { padding: 20px 16px 48px; }

.hidden { display: none !important; }

/* ---------- 品牌头 ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 4px 22px;
}
.brand-logo {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), #7aa2ff);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand h1 { margin: 0; font-size: 21px; letter-spacing: .5px; }
.brand p { margin: 3px 0 0; font-size: 13px; color: var(--text-dim); }

/* ---------- 步骤条 ---------- */
.steps {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
}
.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.step i {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  font-style: normal;
  font-size: 13px;
  transition: .2s;
}
.step.is-active i, .step.is-done i {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.step.is-active { color: var(--text); font-weight: 600; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 14px; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.crumb { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crumb b { font-size: 15px; }
.crumb small { font-size: 12px; color: var(--text-dim); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.field-inline { display: flex; gap: 8px; }
.field-inline input { flex: 1; }

/* label 与输入控件同一行（设置浮层里的有效期） */
.field.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.field.field-row label { margin-bottom: 0; flex: 0 0 auto; }
.field.field-row .field-inline { flex: 1; min-width: 0; }

input[type="tel"], input[type="text"], input[type="number"], select {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-weak);
}
select { width: auto; min-width: 88px; }

/* ---------- 按钮 ---------- */
.btn {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 11px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-weight: 500;
}
.btn-mini {
  width: auto;
  height: 34px;
  padding: 0 18px;
  font-size: 14px;
  background: var(--primary);
  color: #fff;
  margin-top: 10px;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.hint {
  margin: 10px 2px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  min-height: 0;
}
.hint.is-error { color: var(--danger); }
.hint.is-ok { color: var(--ok); }

/* ---------- 列表（项目） ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: .15s;
}
.list-item:hover { border-color: var(--primary); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-size: 15px; font-weight: 600; }
.list-item .li-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item .li-arrow { color: var(--text-dim); font-size: 18px; }

/* ---------- 楼层选择 ---------- */
.floor-groups { display: flex; flex-direction: column; gap: 16px; }
.floor-group-title {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.floor-group-title b { color: var(--text); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  position: relative;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  transition: .15s;
}
.chip.is-on {
  background: var(--primary-weak);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.chip .order {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  margin-right: 6px;
}
.chip .x { margin-left: 7px; opacity: .6; font-size: 12px; }
.chips .empty { font-size: 13px; color: var(--text-dim); }

.selected-box {
  margin-top: 18px;
  padding: 13px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
}
.selected-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ---------- 二维码页：整屏 flex，二维码垂直居中 ---------- */
.qr-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}

.qr-stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0;
}

/* 常用楼层：跟在过期时间下方，自动换行居中 */
.floor-pick { margin-top: 20px; width: 100%; }

.floor-label {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 9px;
}

/* ---------- 二维码页 ---------- */
.qr-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 0 2px 6px;
}

/* 右上角齿轮 */
.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.icon-btn.is-on { color: var(--primary); border-color: var(--primary); }

/* 设置浮层 */
.settings-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: min(300px, calc(100vw - 44px));
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}
.settings-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0 2px 10px;
}
.settings-pop .btn { width: 100%; margin-top: 8px; }

/* 二维码上方：项目名 + 当前楼层 */
.qr-title {
  text-align: center;
  margin-bottom: 16px;
  padding: 0 12px;
  width: 100%;
}
.qr-project {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qr-floor {
  margin-top: 4px;
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}
.qr-floor .unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 6px;
}

.banner {
  padding: 11px 14px;
  border-radius: 11px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 14px;
}

/* 常用楼层 chips */
.floor-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  padding: 2px 0 4px;
}
.floor-tabs .chip { flex: 0 0 auto; }
.floor-tabs .chip.is-on { background: var(--primary); color: #fff; }

.qr-box {
  position: relative;
  width: 236px;
  height: 236px;
  margin: 0 auto;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.qr-canvas {
  width: 216px;
  height: 216px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-canvas img, .qr-canvas canvas { display: block; }
.qr-mask {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  color: #33415c;
  text-align: center;
  padding: 12px;
}
.qr-mask.is-error { background: rgba(255, 245, 245, .96); color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .qr-mask { background: rgba(20, 28, 46, .94); color: #d5dded; }
  .qr-mask.is-error { background: rgba(48, 22, 24, .95); }
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-tip {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 14px 0 0;
}

.expire { margin-top: 16px; }
.expire-bar {
  height: 5px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.expire-bar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: var(--primary);
  transition: width .3s linear, background .3s;
}
.expire-bar i.is-low { background: var(--danger); }
.expire-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 8px;
}

.settings-body { padding: 4px 2px 2px; }
.code-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  line-height: 1.6;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 16px);
  max-width: 84vw;
  padding: 11px 18px;
  border-radius: 11px;
  background: rgba(20, 28, 46, .94);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.toast-error { background: rgba(190, 45, 50, .96); }
.toast.toast-ok { background: rgba(20, 130, 92, .96); }
