:root {
  --blue: #8a7cd8;
  --blue-deep: #6d5fc2;
  --teal: #7a6cc9;
  --ink: #332f45;
  --muted: #8b86a3;
  --line: #e6e1f0;
  --bg: #efedf6;
  --red: #c03535;
  --green: #12805c;
  --amber: #b66a00;
  --radius: 20px;
  --shadow-sm: 0 2px 10px rgba(90, 78, 140, .09);
  --shadow-md: 0 12px 34px rgba(90, 78, 140, .14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(170deg, var(--bg) 0%, #faf9ff 60%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus, .tab:focus, .btn:focus, .link:focus { outline: none; -webkit-tap-highlight-color: transparent; }

/* ============ 登录页 ============ */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(155deg, var(--blue-deep) 0%, var(--blue) 48%, var(--teal) 100%);
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 28px;
  padding: 36px 28px 30px;
  box-shadow: 0 24px 70px rgba(76, 62, 140, .26);
  text-align: center;
}
.logo {
  width: 76px; height: 76px;
  margin: 0 auto 20px;
  border-radius: 24px;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; letter-spacing: 2px; font-size: 26px;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  box-shadow: 0 12px 26px rgba(109, 95, 194, .30);
}
.login-card h1 { font-size: 23px; letter-spacing: .5px; }
.login-card p { color: var(--muted); font-size: 13px; margin: 10px 0 26px; line-height: 1.75; }
.login-card input {
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #f7f5fc;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(138, 124, 216, .16);
}
.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 15px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  box-shadow: 0 10px 22px rgba(109, 95, 194, .28);
  transition: transform .12s, box-shadow .15s;
}
.login-card button:active { transform: scale(.98); }
.error { color: var(--red); font-size: 13px; margin-top: 12px; }

/* ============ 主界面 ============ */
#appView { width: min(720px, 100%); margin: 0 auto; padding: 18px 16px 64px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 18px 18px;
  border-radius: 22px;
  color: var(--ink);
  background: #f4f2fb;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar h1 { font-size: 20px; letter-spacing: .5px; color: var(--ink); }
.topbar p { color: var(--muted); font-size: 12px; margin-top: 4px; }
.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.device-bar { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 12px; scrollbar-width: none; }
.device-bar::-webkit-scrollbar { display: none; }
.gate-bar { margin-top: -6px; }
.gate-chip { border-left: 3px solid var(--green); }
.device-chip {
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 12px;
  min-width: 158px;
  box-shadow: var(--shadow-sm);
}
.device-chip b { display: block; font-size: 13px; }
.device-chip span { color: var(--muted); }
.device-chip.on { border-color: #dcd5f2; background: #f3f1fb; }
.device-chip.off { border-color: #f0d4d4; background: #fdf8f8; }
.door-actions { display: flex; gap: 8px; margin-top: 10px; }
.door-actions button { flex: 1; border: 1px solid transparent; font-size: 13px; font-weight: 700; padding: 7px 10px; border-radius: 10px; }
.door-actions .door-open { background: var(--green); color: #fff; }
.door-actions .door-close { background: #fff; color: var(--red); border-color: #f3c4c2; }
.door-actions button:active { transform: scale(.97); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #b9c6d4; margin-right: 6px; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(18, 128, 92, .14); }
.dot.off { background: var(--red); }

.tabs {
  display: flex;
  gap: 4px;
  background: #e9e5f3;
  padding: 4px;
  border-radius: 16px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: #6b6684;
  padding: 11px 4px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab.active { background: linear-gradient(135deg, var(--blue), var(--blue-deep)); color: #fff; box-shadow: 0 6px 16px rgba(109, 95, 194, .25); }

/* ============ 设备时间栏（三等分，尺寸同 tabs，浅蓝加深） ============ */
.time-bar {
  display: flex;
  gap: 4px;
  background: #d8e8f8;
  border: 1px solid #b9d6f0;
  padding: 4px;
  border-radius: 16px;
  margin-bottom: 14px;
}
.time-bar-clock,
.time-bar button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: #243b53;
  padding: 11px 4px;
  border-radius: 12px;
  font-size: clamp(14px, 3.8vw, 16px);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
}
.time-bar-clock {
  font-weight: 700;
  font-size: clamp(15px, 4.2vw, 18px);
  letter-spacing: .5px;
  font-variant-numeric: tabular-nums;
}
.time-bar button { color: #2f6db3; }
.time-bar button:active { background: #c2dcf3; }

.panel {
  background: #fdfcff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px 18px;
  box-shadow: var(--shadow-sm);
}
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-title h2 { font-size: 17px; }
.badge { background: #fff4e3; color: var(--amber); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.apply-entry { margin-top: 10px; font-size: 12px; color: var(--muted); background: #f3f1fb; border: 1px dashed #dcd5f2; border-radius: 12px; padding: 10px 12px; }
.apply-entry a { color: var(--blue); font-weight: 700; text-decoration: none; }
.qr-card { margin-top: 12px; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px 12px; }
.qr-card img { width: 200px; height: 200px; display: block; margin: 0 auto; }
.qr-card p { color: var(--muted); font-size: 12px; margin-top: 10px; }

/* ============ 照片 ============ */
.photo-row { display: flex; gap: 16px; margin: 20px 0; }
.panel .photo-row { justify-content: center; }
.photo-box {
  width: 132px; height: 176px;
  flex: 0 0 132px;
  border: 1.5px dashed #d6cfe8;
  border-radius: 18px;
  overflow: hidden;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #f6f4fc, #efecf9);
  transition: border-color .15s, background .15s;
}
.photo-box:active { border-color: var(--blue); }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-hint { text-align: center; color: #6a6480; font-size: 12px; padding: 0 8px; }
.photo-hint b { display: block; color: #3d3757; margin-top: 6px; }
.photo-hint span { font-size: 10px; color: #948fae; }
.plus { font-size: 34px; color: var(--blue); font-weight: 300; line-height: 1; }
.photo-side { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 9px; }
.muted { color: var(--muted); font-size: 12px; }
.tiny { font-size: 11px; }

/* ============ 按钮 ============ */
.btn {
  border: 1px solid var(--line);
  background: #efecf7;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--ink);
  transition: transform .12s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.small { padding: 9px 12px; font-size: 12px; }
.btn.primary { border: 0; color: #fff; background: linear-gradient(135deg, var(--blue), var(--blue-deep)); box-shadow: 0 10px 22px rgba(109, 95, 194, .24); }
.btn.big { width: 100%; padding: 15px; border-radius: 15px; font-size: 16px; margin-top: 10px; letter-spacing: .5px; }
.btn:disabled { opacity: .55; }

/* ============ 表单 ============ */
label { display: block; margin-bottom: 14px; color: #45405c; font-size: 13px; font-weight: 600; }
label input, .search-row input, .search-row select {
  width: 100%;
  margin-top: 6px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f7f5fc;
  color: var(--ink);
  outline: none;
  font-weight: 400;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
label input:focus, .search-row input:focus, .search-row select:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(138, 124, 216, .14);
}
.two { display: flex; gap: 12px; }
.two label { flex: 1; min-width: 0; }
.date-field { flex: 1 1 0%; min-width: 0; text-align: center; margin-bottom: 14px; }
.date-label { display: block; color: #45405c; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.date-box { position: relative; width: 100%; }
.date-text { width: 100%; box-sizing: border-box; padding: 12px 8px; border: 1px solid var(--line); border-radius: 13px; background: #f7f5fc; color: var(--ink); text-align: center; font-size: 13px; font-weight: 400; outline: none; }
.date-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; background: transparent; cursor: pointer; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.link { border: 0; background: none; color: var(--blue); font-size: 12px; font-weight: 700; white-space: nowrap; padding: 0 2px; }
.field > span { display: block; color: #45405c; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.checks { display: flex; flex-direction: column; gap: 9px; }
.check {
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 13px;
  background: #f7f5fc;
  font-size: 13px;
  font-weight: 500;
  margin: 0;
}
.check input { width: 18px; height: 18px; accent-color: var(--blue); margin: 0; }
.check.on { border-color: #dcd5f2; background: #f3f1fb; }
.check.disabled { opacity: .5; }

/* ============ 结果 / 记录 ============ */
.result { margin-top: 18px; border-radius: 16px; padding: 15px; background: #f5fcf9; border: 1px solid #bfe8d8; font-size: 13px; }
.result.bad { background: #fff7f7; border-color: #f3caca; }
.result .line { padding: 6px 0; border-top: 1px solid rgba(15, 39, 66, .06); }
.result .line:first-child { border-top: 0; }

.records { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.record { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: #fff; box-shadow: var(--shadow-sm); }
.record-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.record-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.record-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.45; }
.record-actions { display: flex; gap: 10px; margin-top: 12px; }
.app-main { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.app-thumb { width: 52px; height: 64px; border-radius: 12px; object-fit: cover; flex: 0 0 52px; background: #efecf7; }
.record-actions button { border: 1px solid transparent; background: none; color: var(--blue); font-size: 13px; font-weight: 700; padding: 8px 18px; border-radius: 10px; }
.record-actions button.ok { background: var(--green); border-color: var(--green); color: #fff; }
.record-actions .del { color: var(--red); background: #fff; border-color: #f3c4c2; }
.tag { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.tag.ok { background: #e7f7f0; color: var(--green); }
.tag.bad { background: #fdecec; color: var(--red); }
.tag.warn { background: #fff4e3; color: var(--amber); }
.tag.gray { background: #eef1f5; color: #6b7b8d; }
.empty { text-align: center; color: #948fae; padding: 42px 16px; font-size: 13px; }

.search-row { display: flex; gap: 10px; margin-top: 14px; }
.search-row select { width: 42%; }
.search-row input { flex: 1; }

/* ============ 浮层 ============ */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: #2b2740;
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 13px;
  z-index: 80;
  max-width: calc(100% - 32px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .25);
}
.toast.bad { background: #8f2424; }
.busy { position: fixed; inset: 0; background: rgba(239, 237, 246, .85); z-index: 70; display: grid; place-items: center; text-align: center; backdrop-filter: blur(2px); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #e3dff2; border-top-color: var(--blue); animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy p { color: #3d3757; font-size: 13px; font-weight: 600; }

/* ============ 修改密码弹层 ============ */
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.modal {
  position: fixed; inset: 0; z-index: 75;
  display: grid; place-items: center; padding: 22px;
  background: rgba(40, 32, 70, .5); backdrop-filter: blur(3px);
}
.modal-card {
  width: min(420px, 100%); background: #fdfcff; border-radius: 24px;
  padding: 26px 22px; box-shadow: var(--shadow-md);
}
.modal-card h2 { font-size: 18px; letter-spacing: .5px; }
.modal-card .sub { margin-top: 4px; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.modal-card .btn.ghost { background: #efecf7; color: var(--ink); border: 1px solid var(--line); }

/* ============ 响应式 ============ */
@media (max-width: 380px) {
  .photo-row { gap: 12px; }
  .photo-box { width: 114px; height: 152px; flex-basis: 114px; }
  .tab { font-size: 12px; }
}
@media (max-width: 360px) {
  .two { flex-direction: column; gap: 0; }
}
