:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2027;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --code: #0f766e;
  --code-bg: #e3f5f2;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --warn-bg: #fff4e0;
  --fresh: #fff6cc;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2b303a;
    --text: #e7e9ee;
    --muted: #98a1b0;
    --accent: #5b9bff;
    --accent-text: #0e1014;
    --code: #5eead4;
    --code-bg: #10302b;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
    --warn-bg: #33270f;
    --fresh: #3a3313;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.icon { font-size: 20px; line-height: 1; padding: 4px 10px; border-color: transparent; }

input, select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible, .device:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
.actions { display: flex; gap: 8px; }
.actions { align-items: center; }
.badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 28px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 12px;
}
h2 { font-size: 15px; margin: 0; }
h2 .count { font-weight: 400; font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type="search"] { width: 220px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

/* 手机卡片 */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.device {
  display: grid;
  gap: 6px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  min-width: 0;
}
.device:hover { border-color: var(--accent); }
.device.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.device.flash { animation: flash 6s ease-out; }
.device-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.device-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-note { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-big {
  justify-self: start;
  font: 600 28px/1.15 var(--mono);
  letter-spacing: 0.06em;
  color: var(--code);
  background: none;
  border: 0;
  padding: 2px 0;
}
.code-big:hover { text-decoration: underline; text-underline-offset: 4px; }
.code-big.stale, .code-pill.stale { color: var(--muted); }
.code-none { color: var(--muted); padding: 8px 0; }
.device-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: 12px; }

/* 短信列表 */
.messages { display: grid; gap: 8px; }
.msg {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) auto;
  gap: 6px 16px;
  align-items: start;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.msg.fresh { animation: flash 6s ease-out; }
.msg-meta { display: grid; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.msg-meta .clock { color: var(--text); font-family: var(--mono); font-size: 13px; }
.chip {
  justify-self: start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 1px 8px;
}
.sim { overflow-wrap: anywhere; }
.msg-main { min-width: 0; display: grid; gap: 2px; }
.msg-from { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.code-pill {
  font: 600 17px/1.2 var(--mono);
  letter-spacing: 0.05em;
  color: var(--code);
  background: var(--code-bg);
  border: 0;
  border-radius: 6px;
  padding: 6px 12px;
}

@keyframes flash {
  from { background: var(--fresh); }
  to { background: var(--surface); }
}

/* 管理面板 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  background: rgba(10, 12, 16, 0.45);
}
.sheet {
  width: min(640px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sheet-body { padding: 4px 20px 32px; }
.block { padding: 16px 0; border-bottom: 1px solid var(--border); }
.block:last-child { border-bottom: 0; }
.block h3 { font-size: 14px; margin: 0 0 8px; }
.block p { margin: 0 0 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1 1 160px; }
.row.end { justify-content: flex-end; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.template-box { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; }
.template-box pre, pre.api {
  flex: 1;
  margin: 0;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
pre.api { margin-bottom: 8px; }
.device-admin { display: grid; gap: 12px; }
.admin-device {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-device .label { font-size: 12px; color: var(--muted); }
.url {
  flex: 1 1 260px;
  display: block;
  padding: 6px 8px;
  overflow-wrap: anywhere;
}
.warn { color: var(--warn); }
.url.warn { background: var(--warn-bg); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--danger); color: #fff; }
.clipboard-helper { position: fixed; top: 0; left: -9999px; opacity: 0; }

/* 登录页 */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 0; }
.login-card p { margin: 0; }
.login-card form { display: grid; gap: 10px; }
.login-card input, .login-card button { padding: 10px 12px; }
.login-error { color: var(--danger); font-size: 13px; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  main { padding: 16px; gap: 22px; }
  .msg { grid-template-columns: minmax(0, 1fr) auto; }
  .msg-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; }
  .filters, .filters input[type="search"] { width: 100%; }
  .filters input[type="search"] { flex: 1 1 140px; }
  .sheet-body { padding: 4px 16px 28px; }
  .template-box { flex-direction: column; }
}
