*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #f3efe6;
  --ink: #1c1916;
  --muted: #6f685e;
  --line: #e3dcd0;
  --paper: #fffdf9;
  --rail: #1e2a24;
  --lime: #d6f25c;
  --danger: #a33b32;
}

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid #1f7a4d; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

.boot { padding: 48px 20px; text-align: center; color: var(--muted); }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(40, 32, 20, 0.08);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand strong { display: block; font-size: 18px; }
.brand p, .lead { color: var(--muted); font-size: 14px; }
.gate h1 { font-size: 28px; line-height: 1.25; margin-bottom: 8px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 232px 1fr; }
.rail {
  background: var(--rail);
  color: #d7e2da;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.rail .brand { margin: 0; }
.rail .brand strong { color: #f4f1ea; }
.rail .brand p { color: #9aab9f; }
.nav { display: grid; gap: 4px; }
.nav button, .text-btn {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.nav button.on { background: var(--lime); color: #1c2414; }
.rail-foot { margin-top: auto; }
.rail-foot button { color: #c5d2c9; width: 100%; }

.main { padding: 28px 32px 64px; min-width: 0; }
.page-head, .label-row, .card-title-row, .filters, .pager, .dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-head { align-items: flex-end; margin-bottom: 18px; }
.page-head h1, .gate h1 { font-weight: 600; }
.page-head h1 { font-size: 28px; }
.page-head p, .hint-copy { color: var(--muted); font-size: 14px; margin-top: 4px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn.primary { background: var(--ink); color: #f6f1e7; border-color: var(--ink); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger, .text-btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }

.banner {
  background: #fff4d8;
  border: 1px solid #ead7a2;
  color: #5c4314;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.banner.soft { background: #f7f4ee; border-color: var(--line); color: #4e493f; }

.search, .stack { display: grid; gap: 8px; }
.search { margin-bottom: 14px; }
input[type="text"], input[type="password"], input[type="url"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; }
label { display: grid; gap: 6px; font-size: 14px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }
.field-help, .count { color: var(--muted); font-size: 12px; }
.form-error { color: var(--danger); min-height: 1.2em; font-size: 14px; }
.stack { margin-top: 8px; }
.stack > .btn, .stack > .text-btn { width: auto; justify-self: start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card-list, .rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card-row, .rank-row, .panel, .stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.card-row, .rank-row { display: flex; gap: 14px; align-items: center; padding: 12px; }
.card-row.off { opacity: 0.62; }
.thumb, .thumb-fallback {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: #ece7dc;
  flex: none;
}
.card-main, .rank-copy { min-width: 0; flex: 1; }
.card-title-row strong, .rank-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag {
  flex: none;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ece7dc;
}
.tag.link { background: #e5ecfa; color: #2457c5; }
.tag.image { background: #e5f4ec; color: #0f7a53; }
.tag.audio { background: #f8ecdf; color: #8a4b12; }
.tag.video { background: #f8e6ef; color: #7a2456; }
.tag.file { background: #e8ebe4; color: #3d4a3a; }
.sid { color: var(--muted); font-size: 13px; margin-top: 4px; }
.sid code { font-family: Consolas, "SFMono-Regular", monospace; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.empty { padding: 28px 8px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.stat { padding: 16px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; margin-top: 6px; font-size: 28px; font-weight: 600; }
.panels { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 12px; margin-bottom: 14px; }
.panel { padding: 16px; }
.panel h2 { font-size: 16px; margin-bottom: 12px; }
.trend { height: 140px; display: flex; align-items: flex-end; gap: 8px; }
.trend div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; }
.trend i {
  display: block;
  width: 22px;
  max-width: 100%;
  background: #1f7a4d;
  border-radius: 6px 6px 2px 2px;
  min-height: 0;
}
.trend em { font-style: normal; color: var(--muted); font-size: 12px; }
.env { display: grid; gap: 8px; }
.env div { display: grid; grid-template-columns: 92px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.env i { display: block; height: 8px; background: #efeae2; border-radius: 99px; }
.env b { display: block; height: 8px; background: #1f7a4d; border-radius: 99px; }
.filters { margin-bottom: 12px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 0; }
.filters input { flex: 1; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ua { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.pager { margin-top: 12px; color: var(--muted); font-size: 13px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 22, 0.46);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.dialog {
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--paper);
  border-radius: 20px;
  padding: 20px;
}
.dialog.narrow { width: min(420px, 100%); }
.dialog h2 { font-size: 20px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 22px; margin-top: 16px; }
.preview-col { min-width: 0; }
.mock-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.mock-switch button { border: 0; background: transparent; border-radius: 999px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.mock-switch button.on { background: var(--ink); color: #f6f1e7; }
.bubble {
  width: 260px;
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(28, 25, 22, 0.08);
}
.bubble strong, .bubble p, .moment b {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bubble strong { font-size: 14px; }
.bubble p { margin-top: 4px; color: #8a847a; font-size: 12px; line-height: 1.4; }
.bubble img, .bubble .thumb-fallback { width: 52px; height: 52px; object-fit: cover; border-radius: 2px; background: #ece7dc; }
.moment { width: 260px; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 10px 28px rgba(28, 25, 22, 0.08); }
.moment b { padding: 10px 12px 0; font-size: 14px; }
.moment img { display: block; width: 100%; height: 140px; object-fit: cover; background: #ece7dc; }
.moment small, .qr-url { display: block; color: var(--muted); font-size: 12px; }
.moment small { padding: 8px 12px 12px; }
.preview-label { margin: 16px 0 8px; color: var(--muted); font-size: 12px; }
.phone {
  width: min(360px, 100%);
  height: 640px;
  max-height: 70vh;
  padding: 10px;
  border-radius: 28px;
  background: #1c1916;
}
.phone-screen { height: 100%; overflow: auto; border-radius: 20px; background: #ebe4d8; position: relative; }
.qr-url { margin: 8px 0 12px; word-break: break-all; }
.qr-img { width: min(240px, 100%); height: auto; display: block; margin: 0 auto 12px; }
.detail { display: grid; grid-template-columns: 72px 1fr; gap: 8px 12px; margin: 16px 0; }
.detail dt { color: var(--muted); white-space: nowrap; }
.detail dd { margin: 0; word-break: break-word; }
.guide { margin: 0 0 16px; padding-left: 18px; color: #3f3a33; }
.guide li + li { margin-top: 6px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: #1c1916;
  color: #f6f1e7;
  border-radius: 999px;
  padding: 10px 16px;
  z-index: 40;
  font-size: 14px;
}

@media (max-width: 980px) {
  .stats, .panels, .editor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .shell { display: block; }
  .rail { width: auto; position: sticky; top: 0; z-index: 5; flex-direction: row; align-items: center; gap: 12px; padding: 12px; }
  .rail .brand p, .rail .brand svg { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav button { width: auto; padding: 8px 10px; }
  .rail-foot { margin-top: 0; margin-left: auto; }
  .rail-foot button { width: auto; }
  .main { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .page-head, .card-row { flex-wrap: wrap; }
  .card-actions { width: 100%; justify-content: flex-start; }
  .phone { height: 560px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
