:root {
  --cream: #f6f2e9;
  --card: #ffffff;
  --ink: #22302b;
  --muted: #6d7a74;
  --line: #e7e0d3;
  --green: #2f7d5d;
  --green-deep: #1f4a3b;
  --green-soft: #e8f2ec;
  --amber: #b7791f;
  --amber-soft: #fdf3e0;
  --red: #b3413b;
  --red-soft: #fbe9e7;
  --shadow: 0 10px 30px rgba(31, 74, 59, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* 启动 / 跳转 */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  z-index: 50;
}
.boot-inner { text-align: center; padding: 24px; }
.boot-dot {
  width: 34px;
  height: 34px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-text { font-size: 17px; font-weight: 600; }
.boot-sub { color: var(--muted); margin-top: 6px; font-size: 13px; }

/* 登录 */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 10% -10%, #e9f2ec 0%, transparent 60%),
    radial-gradient(700px 400px at 110% 10%, #fbf1df 0%, transparent 55%),
    var(--cream);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: 1px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--green), #3f9a73);
  color: #fff;
  font-size: 25px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(47, 125, 93, .25);
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 19px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fdfcf8;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 93, .12);
}
.field textarea { min-height: 96px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 600;
  transition: transform .08s, background .15s, border-color .15s;
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn:hover { border-color: #d3cbba; }
.btn.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.btn.primary:hover { background: #276b4f; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #eccac7; background: #fff; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.btn[disabled] { opacity: .55; cursor: default; }
.link-btn {
  background: none;
  border: 0;
  color: inherit;
  opacity: .75;
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.login-hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; text-align: center; }
.login-hint b { color: var(--amber); }
.login-foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: #9aa39e; word-break: break-all; }

/* 布局 */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--green-deep);
  color: #eaf3ee;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 22px; }
.side-title { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.side-sub { font-size: 12px; opacity: .6; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  border: 0;
  background: transparent;
  color: #dbe9e2;
  text-align: left;
  font-size: 14.5px;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); }
.nav-item.active { background: #ffffff; color: var(--green-deep); font-weight: 700; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; opacity: .85; }
.side-foot {
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, .12);
}
.side-domain { font-size: 12px; opacity: .55; word-break: break-all; margin-bottom: 8px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 30px 34px 60px;
  max-width: 1180px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 25px; letter-spacing: .5px; }
.page-head p { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(31, 74, 59, .045);
}
.card.pad { padding: 22px; }
.card + .card { margin-top: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16.5px; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: .5px; margin-top: 4px; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--amber-soft);
  border: 1px solid #f0dcb4;
  color: #7a5313;
  border-radius: 13px;
  padding: 13px 16px;
  margin-bottom: 18px;
  font-size: 13.5px;
}
.banner.warn { background: var(--red-soft); border-color: #efc9c5; color: #7d2a26; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1eee6;
  color: var(--muted);
  font-weight: 600;
}
.pill.green { background: var(--green-soft); color: #24634a; }
.pill.amber { background: var(--amber-soft); color: #8c5c12; }
.pill.red { background: var(--red-soft); color: #8f302b; }

.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* 列表 */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
  border-top: 1px solid #f0ece2;
}
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-row .desc { color: var(--muted); font-size: 12.5px; margin-top: 3px; word-break: break-word; }
.list-row .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* 设备 */
.device-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.device-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.device-name { font-size: 17px; font-weight: 700; }
.device-meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.code-box {
  background: #f5f8f5;
  border: 1px dashed #c9dccf;
  border-radius: 13px;
  padding: 14px;
  text-align: center;
}
.code-box .code {
  font-size: 30px;
  letter-spacing: 9px;
  font-weight: 700;
  color: var(--green-deep);
  font-family: "SFMono-Regular", Consolas, monospace;
  margin: 2px 0 6px 6px;
}
.device-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 名片 */
.contacts-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.contact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.contact-card {
  display: flex;
  gap: 13px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
}
.avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 13px;
  overflow: hidden;
  background: var(--green-soft);
  color: #2a6b4f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  line-height: 1.15;
  padding: 4px;
  word-break: break-all;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.contact-main { flex: 1; min-width: 0; }
.contact-main .name { font-weight: 700; font-size: 15.5px; }
.contact-main .line { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-tools { display: flex; flex-direction: column; gap: 6px; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
}
.icon-btn:hover { color: var(--ink); border-color: #cfc6b4; }
.icon-btn.danger:hover { color: var(--red); border-color: #eccac7; }

/* 空状态 */
.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--muted);
}
.empty .big { font-size: 38px; opacity: .35; margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* 表单布局 */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* 上传 */
.drop {
  border: 1.5px dashed #cfd8ce;
  border-radius: 14px;
  padding: 22px;
  text-align: center;
  background: #faf9f3;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--green); background: var(--green-soft); }
.drop .drop-title { font-weight: 600; }
.drop .drop-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.drop input[type=file] { display: none; }
.file-picked { margin-top: 10px; font-size: 13px; color: var(--green); font-weight: 600; word-break: break-all; }

.photo-row { display: flex; align-items: center; gap: 13px; margin: 4px 0 16px; }
.photo-preview {
  width: 74px;
  height: 74px;
  border-radius: 14px;
  background: var(--green-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #2a6b4f;
  font-weight: 700;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(26, 38, 33, .42);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border-radius: 19px;
  box-shadow: 0 24px 70px rgba(20, 40, 30, .25);
  padding: 24px;
  max-height: 88vh;
  overflow: auto;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.985); opacity: .6; } }
.modal h3 { margin: 0 0 4px; font-size: 19px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.modal .field { margin-bottom: 12px; }
.modal .photo-row { margin: 2px 0 12px; }
.modal .form-actions { margin-top: 18px; }
.modal .btn { min-width: 84px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: #22302b;
  color: #fff;
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f302b; }

/* 移动端 */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    padding: 14px 14px 10px;
  }
  .side-brand { padding-bottom: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; }
  .nav-item { width: auto; white-space: nowrap; padding: 8px 12px; font-size: 13.5px; }
  .side-foot { display: none; }
  .main { padding: 20px 16px 50px; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .page-head h2 { font-size: 21px; }
}
