:root {
  --bg: #0b0e14;
  --bg-soft: #10141c;
  --panel: #121722;
  --panel-2: #171d29;
  --border: #1f2735;
  --border-soft: #18202c;
  --text: #e8eef7;
  --text-dim: #aab6c8;
  --muted: #7d8a9d;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --inbound: #34d399;
  --inbound-soft: rgba(52, 211, 153, 0.13);
  --outbound: #6aa1ff;
  --outbound-soft: rgba(106, 161, 255, 0.13);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(79, 140, 255, 0.13), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(52, 211, 153, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: 0.2px; }
p { margin: 0; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.82);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #4f8cff, #2f6ede);
  color: #fff;
  font-size: 17px;
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35);
  flex: 0 0 auto;
}
.brand-text p { color: var(--muted); font-size: 11.5px; margin-top: -1px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: 0.16s ease;
  white-space: nowrap;
}
.chip:hover { border-color: #2b3a52; color: var(--text); }
.chip.active {
  border-color: rgba(79, 140, 255, 0.55);
  background: var(--accent-soft);
  color: #cfe0ff;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.chip.active .dot { background: var(--accent); opacity: 1; }
.chip .chip-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; opacity: 0.6; }

.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------------- buttons ---------------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  cursor: pointer;
  transition: 0.16s ease;
  font-family: inherit;
}
.btn:hover { color: var(--text); border-color: #2e3d55; background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(145deg, #4f8cff, #3b74e0); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ---------------- banner ---------------- */
.banner {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 16px 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
  font-size: 12.5px;
}
.banner-close {
  margin-left: auto; border: 0; background: transparent; color: inherit;
  font-size: 16px; cursor: pointer; line-height: 1; padding: 0 2px;
}

/* ---------------- layout ---------------- */
body:not(.login-body) {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.layout {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(18, 23, 34, 0.6), rgba(11, 14, 20, 0.4));
}

/* ---------------- toolbar ---------------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 12px 6px;
}
.search {
  position: relative; flex: 1 1 100%;
  display: flex; align-items: center;
}
.search svg {
  position: absolute; left: 11px; width: 15px; height: 15px;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
.search input {
  width: 100%;
  padding: 8px 12px 8px 33px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: 0.16s ease;
}
.search input::placeholder { color: #5f6b7d; }
.search input:focus { border-color: rgba(79, 140, 255, 0.6); box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.12); }

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
}
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 10px; border-radius: 8px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: 0.16s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent-soft); color: #cfe0ff; }

.select {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px; cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--accent); width: 13px; height: 13px; cursor: pointer; }

.meta-right { display: inline-flex; align-items: center; gap: 10px; }
.meta-right .select { max-width: 190px; padding: 3px 6px; font-size: 11.5px; }

.list-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  flex-wrap: wrap;
  padding: 4px 14px 8px;
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------------- list ---------------- */
.list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: #253046 transparent;
}
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-thumb { background: #253046; border-radius: 8px; }

.row {
  display: flex; gap: 10px; align-items: flex-start;
  width: 100%;
  padding: 10px 10px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.14s ease;
}
.row:hover { background: rgba(23, 29, 41, 0.75); }
.row.selected { background: rgba(79, 140, 255, 0.1); border-color: rgba(79, 140, 255, 0.35); }

.avatar {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
  background: var(--panel-2);
  color: var(--text-dim);
  margin-top: 1px;
}
.avatar.inbound { background: var(--inbound-soft); color: var(--inbound); }
.avatar.outbound { background: var(--outbound-soft); color: var(--outbound); }

.row-main { min-width: 0; flex: 1 1 auto; }
.row-top { display: flex; align-items: baseline; gap: 6px; }
.phone {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 60%;
}
.row-time { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}
.row-sub.error { color: #f0a3a3; }
.unread-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; margin-top: 13px; }

.tag {
  display: inline-flex; align-items: center;
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.tag.acc { color: #9db5dd; border-color: #28374f; background: rgba(40, 55, 79, 0.35); }
.tag.mine { color: #c4b5fd; border-color: rgba(167, 139, 250, 0.3); background: rgba(167, 139, 250, 0.1); }
.tag.delivered { color: var(--inbound); border-color: rgba(52, 211, 153, 0.3); background: var(--inbound-soft); }
.tag.failed, .tag.undelivered, .tag.delivery_failed { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); background: rgba(248, 113, 113, 0.1); }
.tag.received { color: var(--inbound); border-color: rgba(52, 211, 153, 0.3); background: var(--inbound-soft); }
.tag.queued, .tag.sending, .tag.sent { color: var(--warn); border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.09); }

.list-foot { padding: 8px 14px 14px; display: flex; justify-content: center; }
.list-foot .btn { width: 100%; }

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty strong { display: block; color: var(--text-dim); font-size: 14px; margin-bottom: 6px; font-weight: 600; }
.empty code {
  display: inline-block; margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 8px; color: var(--text-dim);
  word-break: break-all;
}
.spinner {
  width: 18px; height: 18px; margin: 0 auto 10px;
  border: 2px solid #253046; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-row { display: flex; gap: 10px; padding: 12px 10px; }
.skeleton {
  height: 10px; border-radius: 6px;
  background: linear-gradient(90deg, #1a2130, #232c3d, #1a2130);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------------- detail ---------------- */
.detail-pane {
  min-width: 0;
  overflow-y: auto;
  padding: 20px clamp(16px, 3vw, 36px) 40px;
  scrollbar-width: thin;
  scrollbar-color: #253046 transparent;
}
.detail-pane::-webkit-scrollbar { width: 8px; }
.detail-pane::-webkit-scrollbar-thumb { background: #253046; border-radius: 8px; }

.detail-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.detail-avatar { width: 44px; height: 44px; border-radius: 14px; font-size: 18px; }
.detail-title { font-size: 18px; font-weight: 650; letter-spacing: 0.2px; }
.detail-sub { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.detail-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.bubble {
  margin-top: 22px;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.7;
  max-width: 760px;
  box-shadow: var(--shadow);
}
.bubble.inbound { border-left: 3px solid var(--inbound); }
.bubble.outbound { border-left: 3px solid var(--outbound); }
.bubble .body-text { margin: 0; font-family: inherit; white-space: pre-wrap; word-break: break-word; }
.bubble .body-loading { color: var(--muted); font-size: 13px; }
.bubble .body-error { color: #f0a3a3; font-size: 13px; }

.detail-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  max-width: 760px;
}
.field {
  background: rgba(18, 23, 34, 0.7);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 9px 12px;
}
.field .k { color: var(--muted); font-size: 11px; }
.field .v { font-size: 12.5px; word-break: break-all; }

.media-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; max-width: 760px; }
.media-list a { color: var(--outbound); font-size: 12.5px; word-break: break-all; }

.raw { margin-top: 22px; max-width: 760px; }
.raw summary {
  cursor: pointer; color: var(--muted); font-size: 12px; padding: 6px 0; user-select: none;
}
.raw pre {
  margin: 8px 0 0;
  padding: 12px;
  border-radius: 12px;
  background: #0d1119;
  border: 1px solid var(--border-soft);
  font-size: 11.5px;
  line-height: 1.6;
  overflow: auto;
  max-height: 420px;
  color: #b9c6da;
}

.back-btn { display: none; }
@media (max-width: 900px) {
  .detail-pane { display: none; position: fixed; inset: 0; z-index: 30; background: var(--bg); padding-top: 14px; }
  .detail-pane.open { display: block; padding-bottom: 40px; }
  .back-btn { display: inline-flex; }
  .bubble { max-width: none; }
}

/* ---------------- login ---------------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 30px 26px 26px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(18, 23, 34, 0.85);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  text-align: center;
}
.login-logo {
  width: 50px; height: 50px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, #4f8cff, #2f6ede);
  font-size: 24px; color: #fff;
  box-shadow: 0 10px 26px rgba(79, 140, 255, 0.4);
}
.login-card h1 { font-size: 17px; }
.login-sub { color: var(--muted); font-size: 12.5px; margin: 6px 0 20px; }
.login-card input {
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.login-card input:focus { border-color: rgba(79, 140, 255, 0.6); box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.12); }
.login-card .btn { width: 100%; padding: 10px; font-size: 13.5px; }
.login-error { min-height: 18px; margin-top: 12px; color: #f0a3a3; font-size: 12px; }
