/*
 * 全局样式。
 * 设计目标：一套代码同时适配手机、平板、电脑。
 * 做法是移动优先 + 单一断点（720px）向上增强，避免维护多套布局。
 */

:root {
  --primary: #C0502A;
  --primary-dark: #9C3E1F;
  --primary-soft: #FBF0EC;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #1F2937;
  --text-2: #4B5563;
  --muted: #8A9199;
  --border: #E5E7EB;
  --border-strong: #D5D9DF;
  --green: #2F7D5D;
  --green-soft: #EDF6F1;
  --amber: #B7791F;
  --amber-soft: #FDF6E7;
  --gray-soft: #F3F4F6;
  --danger: #B4453A;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* ------------------------------ 布局 ------------------------------ */

.wrap {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.wrap-wide {
  max-width: 1180px;
}

.page-head {
  padding: 20px 0 14px;
}

.page-head h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
}

.page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  flex: none;
}

/* ------------------------------ 卡片 ------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 14px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title small {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------ 表单 ------------------------------ */

.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.label .req {
  color: var(--danger);
  margin-left: 2px;
}

.input,
.select,
.textarea {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  font-size: 16px; /* 16px 可避免 iOS 聚焦时页面自动放大 */
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.select {
  background-image: linear-gradient(45deg, transparent 50%, #6B7280 50%),
    linear-gradient(135deg, #6B7280 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.textarea {
  height: auto;
  min-height: 76px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(192, 80, 42, 0.1);
}

.input::placeholder,
.textarea::placeholder {
  color: #B4B9C0;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 12px;
  margin-bottom: 16px;
}

/*
 * 栅格内的字段不再自带外边距。
 * 否则字段自身的 margin-bottom 会与 grid 的 gap 叠加，
 * 造成同一行内上下留白不一致（手机上尤其明显）。
 */
.row > .field,
.row-3 > .field {
  margin-bottom: 0;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 1px;
}

/* 意愿选择：大块可点区域，避免手机上误触 */
.choice-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 68px;
  padding: 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.choice strong {
  font-size: 16px;
  font-weight: 600;
}

.choice span {
  font-size: 12px;
  color: var(--muted);
}

.choice:active {
  transform: scale(0.99);
}

.choice.on-yes {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.choice.on-yes strong {
  color: var(--primary-dark);
}

.choice.on-yes span {
  color: var(--primary);
}

.choice.on-no {
  border-color: #6B7280;
  background: var(--gray-soft);
}

.choice.on-no strong {
  color: #374151;
}

/* 原因选项：小一号的胶囊按钮 */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.chip.on {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 500;
}

/* ------------------------------ 按钮 ------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 20px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  background: #fff;
  color: var(--text);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-ghost {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text-2);
}

.btn-ghost:hover {
  border-color: #B8BFC8;
}

.btn-danger {
  background: #fff;
  border-color: #E3B5B0;
  color: var(--danger);
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-block + .btn-block {
  margin-top: 10px;
}

.submit-bar {
  margin-top: 22px;
}

/* ------------------------------ 提示 ------------------------------ */

.notice {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid #F0D5C9;
  color: #8A3B1F;
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 16px;
}

.notice-gray {
  background: var(--gray-soft);
  border-color: var(--border);
  color: var(--text-2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(12px);
  max-width: 86vw;
  padding: 11px 18px;
  border-radius: 10px;
  background: #1F2937;
  color: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 200;
  text-align: center;
}

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

.toast.err {
  background: #A33B31;
}

.toast.ok {
  background: #2C6E52;
}

/* ------------------------------ 弹层 ------------------------------ */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  padding: 0;
}

.modal-mask.show {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  animation: slideUp 0.26s ease;
  /* 小屏手机（如 320x568）上弹窗内容可能超过一屏，
     限制高度并允许内部滚动，避免按钮被顶出可视区域点不到 */
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px;
}

.modal p {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.55;
}

.qr-box {
  display: inline-flex;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}

.qr-box img {
  width: 200px;
  height: 200px;
  display: block;
  image-rendering: auto;
}

.qr-tip {
  font-size: 12px;
  color: var(--text-2);
  background: var(--gray-soft);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 16px;
  line-height: 1.55;
  text-align: left;
}

@media (min-width: 720px) {
  .modal-mask {
    align-items: center;
    padding: 20px;
  }
  .modal {
    border-radius: 18px;
    padding: 28px 24px 24px;
  }
}

/* ------------------------------ 成功页 ------------------------------ */

.success-mark {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 14px;
  font-weight: 300;
}

.rank-text {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.rank-text b {
  color: var(--primary);
  font-size: 17px;
  font-weight: 600;
  margin: 0 3px;
}

.detail-list {
  margin: 0;
  border-top: 1px solid var(--border);
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.detail-list dt {
  color: var(--muted);
  flex: none;
}

.detail-list dd {
  margin: 0;
  text-align: right;
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
}

/* ------------------------------ 后台 ------------------------------ */

.topnav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 54px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav-inner::-webkit-scrollbar {
  display: none;
}

.nav-brand {
  font-size: 14px;
  font-weight: 600;
  margin-right: 12px;
  white-space: nowrap;
  flex: none;
}

.nav-brand small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1;
  margin-top: 2px;
}

.nav-link {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-2);
  white-space: nowrap;
  flex: none;
}

.nav-link:hover {
  background: var(--gray-soft);
}

.nav-link.on {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 500;
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding-left: 8px;
}

.nav-user {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* 统计卡片 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.4px;
  /* 用 flex + baseline 对齐，保证数字与单位始终同一行，
     窄屏下不会因为行内空白被挤到第二行 */
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-wrap: nowrap;
}

.stat-value small {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}

.stat.accent .stat-value {
  color: var(--primary);
}

.stat.green .stat-value {
  color: var(--green);
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* 环形图：纯 CSS conic-gradient，避免引入图表库 */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.donut {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  position: relative;
  flex: none;
  background: var(--gray-soft);
}

.donut::after {
  content: "";
  position: absolute;
  inset: 20px;
  background: #fff;
  border-radius: 50%;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  line-height: 1.2;
}

.donut-center b {
  font-size: 21px;
  font-weight: 600;
}

.donut-center span {
  font-size: 11.5px;
  color: var(--muted);
}

.legend {
  flex: 1;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.legend-item b {
  margin-left: auto;
  font-weight: 600;
}

.legend-item em {
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
  min-width: 42px;
  text-align: right;
}

/* 横向条形 */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-name {
  width: 92px;
  flex: none;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  height: 18px;
  background: var(--gray-soft);
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 5px;
  transition: width 0.4s ease;
  min-width: 0;
}

.bar-fill.alt {
  background: #8C9199;
}

.bar-fill.soft {
  background: #E0A48C;
}

.bar-num {
  width: 46px;
  flex: none;
  text-align: right;
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* 趋势：改用柱状，比折线在手机小屏上更易读 */
.trend {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 108px;
  padding-top: 8px;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
  position: relative;
}

.trend-bar {
  width: 100%;
  max-width: 22px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  transition: height 0.4s ease;
  opacity: 0.85;
}

.trend-col span {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  transform: scale(0.92);
}

.trend-col b {
  position: absolute;
  top: -4px;
  font-size: 10.5px;
  color: var(--text-2);
  font-weight: 500;
}

/* 表格 */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 860px;
}

table.data th {
  text-align: left;
  padding: 11px 12px;
  background: #FAFAFB;
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 11px 12px;
  border-bottom: 1px solid #F1F2F4;
  color: var(--text-2);
  vertical-align: middle;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tbody tr:hover {
  background: #FCFCFD;
}

.mono {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-yes {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.badge-no {
  background: var(--gray-soft);
  color: #4B5563;
}

.badge-pending {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-gray {
  background: var(--gray-soft);
  color: var(--muted);
}

.badge-green {
  background: var(--green-soft);
  color: var(--green);
}

/* 工具栏 */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .input,
.toolbar .select {
  height: 38px;
  font-size: 14px;
  width: auto;
  min-width: 110px;
}

.toolbar .input.search {
  min-width: 180px;
  flex: 1;
}

.toolbar .spacer {
  flex: 1;
}

/* 分页 */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pager-info {
  font-size: 13px;
  color: var(--muted);
  margin-right: 6px;
}

/* 移动端把表格转成卡片列表，避免横向滚动难以阅读 */
.mobile-list {
  display: none;
}

@media (max-width: 720px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
  .stat-value {
    font-size: 22px;
  }
  .table-scroll {
    display: none;
  }
  .mobile-list {
    display: block;
  }
  .row,
  .row-3 {
    grid-template-columns: 1fr;
  }
  .row-3 {
    grid-template-columns: 1fr 1fr;
  }
  .row-3 > .field:last-child {
    grid-column: span 2;
  }
  .wrap {
    padding: 0 12px 32px;
  }
  .card {
    padding: 16px;
    border-radius: 14px;
  }
}

.item-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  margin-bottom: 10px;
}

.item-card .row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.item-card .room {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.item-card .meta {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.item-card .acts {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* 日志条目 */
.log-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.log-item:last-child {
  border-bottom: none;
}

.log-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.log-time {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.log-detail {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
  word-break: break-all;
}

/* 二维码列表 */
.qr-item {
  display: flex;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.qr-item img {
  width: 84px;
  height: 84px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex: none;
  object-fit: contain;
  background: #fff;
}

.qr-meta {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.qr-meta strong {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 500;
}

.qr-acts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}

/* 楼栋维护 */
.building-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.building-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.building-head strong {
  font-size: 14px;
  font-weight: 600;
}

.unit-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.unit-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--gray-soft);
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-2);
}

.unit-tag button {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}

.unit-tag button:hover {
  color: var(--danger);
}

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
  font-size: 13.5px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.d-none {
  display: none !important;
}
