/* ============================================================
   设备地址管理 · 移动端优先样式
   - 跟随系统暗色模式（prefers-color-scheme）
   - 刘海屏 / Dynamic Island 安全区（viewport-fit=cover + env()）
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #16181d;
  --text-dim: #6b7280;
  --primary: #0b6cff;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  /* 安全区：不支持 env() 的浏览器回落到 0 */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #141b2b;
    --surface-2: #1c2436;
    --border: #263149;
    --text: #e8ecf4;
    --text-dim: #94a3b8;
    --primary: #4c8dff;
    --primary-ink: #08101f;
    --danger: #f87171;
    --danger-soft: #3b1a1c;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  /* 弹层打开时锁滚动由 .no-scroll 负责，这里保留 overscroll 阻断回弹白边 */
  overscroll-behavior-y: contain;
}

body.no-scroll { overflow: hidden; }

[hidden] { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }

/* ==================== 通用控件 ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;              /* 移动端可点区域下限 */
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .06s ease, opacity .15s ease, background-color .15s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }

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

.btn-mini { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
/* 顶栏里的小按钮，别占太多横向空间 */
.btn-sm { min-height: 34px; padding: 0 14px; font-size: 14px; border-radius: 10px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--surface-2); }

.text-btn {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.text-btn:active { background: var(--surface-2); }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-dim); }
.field-label .req { color: var(--danger); font-style: normal; }

.field-input {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* 16px 以下 iOS Safari 聚焦时会自动放大页面 */
  font-size: 16px;
}
.field-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field-input::placeholder { color: var(--text-dim); opacity: .75; }
.field-textarea { resize: vertical; line-height: 1.55; }

.form-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* ==================== 登录屏 ==================== */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r))
           calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--primary);
  color: var(--primary-ink);
}
.login-logo svg { width: 26px; height: 26px; }
.login-title { margin: 0 0 24px; font-size: 20px; font-weight: 700; }
/* 登录页只有一个密码框，左对齐更好读 */
.login-card .field { text-align: left; }
.login-card .field { margin-bottom: 18px; }

/* ==================== 主屏骨架 ==================== */

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 12px calc(14px + var(--safe-l));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar-main { min-width: 0; }
.appbar-title { margin: 0; font-size: 17px; font-weight: 700; }
.appbar-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }
.appbar-actions { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }

.toolbar { padding: 12px calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l)); }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--text-dim);
  pointer-events: none;
}
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0 40px 0 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.search-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* ==================== 列表：卡片内字段横向排开 ==================== */

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l));
}

.state {
  margin: 40px 0;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}
.state-error { color: var(--danger); }
.state .btn { margin-top: 14px; }

/* 一张卡片 = 一条记录；四个字段块在卡内从左到右排，不再竖着堆 */
.card {
  display: flex;
  align-items: stretch;          /* 行高随最高的单元格拉伸，换行后整卡不歪 */
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* 字段块：小标签 + 值，块内也是横向 */
.cell {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  line-height: 1.5;              /* 长文本块内换行，行距舒服 */
  overflow-wrap: anywhere;
}
.cell-label {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}
.cell-value { min-width: 0; font-weight: 600; }

/* 宽度分配：前三个字段保底宽度足够长文本，块内自行换行不挤压别人；
   地址、备注弹性伸展填满剩余空间 */
.cell .col-tenant { flex: 1 1 12%; min-width: 110px; }
.cell .col-alias  { flex: 1 1 15%; min-width: 130px; }
.col-url    { flex: 2 1 22%; min-width: 180px; }
.col-remark { flex: 1 1 12%; min-width: 110px; color: var(--text-dim); }
.col-remark .cell-value { font-weight: 400; }

.cell-link { color: var(--primary); text-decoration: none; }
.col-url-text {
  min-width: 0;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
}

.cell-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

/* 窄屏放不下时字段块换行，但每块本身仍保持横向 */
@media (max-width: 620px) {
  .card { flex-wrap: wrap; row-gap: 6px; }
  .col-url, .col-remark { flex: 1 1 45%; }
  .cell-actions { margin-left: auto; }
}

/* ==================== 分页 ==================== */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 4px calc(14px + var(--safe-r)) calc(20px + var(--safe-b)) calc(14px + var(--safe-l));
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.pager-info { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ==================== 编辑弹层 ==================== */

.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 12, 22, .5);
  animation: fade .16s ease;
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 92dvh;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  animation: rise .2s ease;
}
@media (min-width: 640px) {
  .sheet-mask { align-items: center; }
  .sheet { max-width: 460px; border-radius: 20px; max-height: 88dvh; }
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) {
  .sheet-mask, .sheet { animation: none; }
}

.sheet-grabber {
  width: 40px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: 999px;
  background: var(--border);
  flex: 0 0 auto;
}
@media (min-width: 640px) { .sheet-grabber { display: none; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 10px 18px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.sheet-title { margin: 0; font-size: 16px; font-weight: 700; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px 4px;
  flex: 1 1 auto;
}

.sheet-foot {
  display: flex;
  gap: 10px;
  padding: 12px 18px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.sheet-foot .btn { flex: 1 1 0; }
@media (min-width: 640px) {
  .sheet-foot { padding-bottom: 12px; }
  .sheet-foot .btn-ghost { flex: 0 0 96px; }
}

/* ==================== 提示条 ==================== */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: min(88vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 12px;
  background: #16181d;
  color: #fff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
  animation: fade .16s ease;
}
.toast-ok { background: #14532d; }
.toast-error { background: #7f1d1d; }

/* ==================== 确认弹窗 ==================== */

/* 居中小卡片，和底部弹层区分开 */
.confirm-mask { align-items: center; z-index: 60; }
.confirm {
  width: calc(100% - 48px);
  max-width: 340px;
  padding: 20px 18px 16px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .35);
}
.confirm-title { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.confirm-text { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; line-height: 1.55; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1 1 0; }