:root {
  --brand: #8B1515;
  --brand-ink: #ffffff;
  --accent: #E8661A;
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #000000;
  --muted: #333333;
  --line: #e4e4e4;
  --soft: #f3f3f3;
  --in: #1a7f4b;
  --out: #8B1515;
  --chip: #f2f2f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 24px 16px; }
.error { color: #c0392b; min-height: 1.2em; font-size: 14px; margin: 10px 0 0; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.block { display: block; width: 100%; }
.btn.danger-outline { color: #c0392b; margin-top: 28px; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px;
  display: inline-grid; place-items: center; color: inherit;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:active { background: #f0f0f0; }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 6px 4px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 18px;
  padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { margin: 0 0 2px; font-size: 20px; color: #000; }
.login { background: #f6f6f6; }
.login-card { border: 1px solid var(--line); }
.login-card p.muted { margin: 0 0 22px; font-size: 14px; }
.brand-logo { display: block; width: 190px; height: auto; margin: -10px auto 0; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: #ffffff; color: #000000; border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 8px 0 16px;
}
.topbar-row { display: flex; align-items: center; gap: 4px; height: 56px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -.01em; display: flex; align-items: center; gap: 9px; color: #000; }
.topbar h1 img { width: 34px; height: 34px; object-fit: contain; }
.topbar h1 small { display: block; font-size: 11px; font-weight: 600; color: var(--brand); letter-spacing: .04em; }
.live {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  background: #f1f8f4; color: #000; border: 1px solid #d6eadf; padding: 4px 9px; border-radius: 99px; margin-right: 4px;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: #1fa463; box-shadow: 0 0 0 0 rgba(31, 164, 99, .6); animation: pulse 2s infinite; }
.live.off { background: #fff6e8; border-color: #f3dcb5; }
.live.off i { background: #e39a1c; animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(31, 164, 99, 0); } 100% { box-shadow: 0 0 0 0 rgba(31, 164, 99, 0); } }
.searchbar { display: flex; gap: 8px; align-items: center; padding: 0 0 10px; }
.searchbar input {
  flex: 1; font: inherit; font-size: 16px; border: 0; border-radius: 10px; padding: 10px 12px;
  background: #f3f3f3; color: #000; border: 1px solid var(--line);
}

/* ---------- people strip ---------- */
.strip-label { font-size: 12px; color: var(--muted); padding: 12px 16px 0; font-weight: 600; }
.strip-label + .people { padding-top: 6px; }
.people {
  display: flex; gap: 6px;
  overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none;
}
.people::-webkit-scrollbar { display: none; }
.person {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; flex: 1 0 auto; min-width: 84px;
  background: var(--card); border: 1.5px solid transparent; border-radius: 12px;
  padding: 9px 9px; box-shadow: var(--shadow); text-align: left;
}
.person.on { border-color: var(--brand); }
.person .who { display: flex; align-items: center; gap: 7px; min-width: 0; width: 100%; }
.person .who { gap: 6px; }
.person .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.person .nm { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .ct { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.person .ct .i { color: var(--in); }
.person .ct .o { color: var(--out); }

.av {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-weight: 700; font-size: 15px; position: relative;
}
.av.all { background: #000; color: #fff; }

/* ---------- direction filter ---------- */
.dirbar { padding: 10px 16px 6px; }
.segmented { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 7px 0; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.banner {
  margin: 6px 16px 0; padding: 10px 12px; border-radius: 10px; background: var(--chip);
  font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}

/* ---------- feed ---------- */
.feed { padding: 4px 0 calc(96px + env(safe-area-inset-bottom)); }
.day {
  font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  padding: 16px 16px 6px;
}
.item {
  display: flex; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--card);
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.day + .item { border-top: 1px solid var(--line); }
.item:active { background: var(--soft); }
.item.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { 0% { background: color-mix(in srgb, var(--brand) 16%, var(--card)); } 100% { background: var(--card); } }
.dir-badge {
  position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; border: 2px solid var(--card); background: var(--card);
}
.dir-badge svg { width: 12px; height: 12px; }
.dir-badge.in svg { fill: var(--in); }
.dir-badge.out svg { fill: var(--out); }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; gap: 8px; align-items: baseline; }
.route { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route b { color: var(--ink); font-weight: 600; }
.route .arrow { margin: 0 3px; }
.time { font-size: 12px; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.subj { font-weight: 650; font-size: 15px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snip { font-size: 13.5px; color: var(--muted); margin-top: 1px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tag {
  font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--chip); color: var(--muted);
  display: inline-flex; align-items: center; gap: 3px;
}
.tag svg { width: 12px; height: 12px; fill: currentColor; }
.tag.in { color: var(--in); }
.tag.out { color: var(--out); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.sentinel { height: 1px; }
.loading-more { text-align: center; color: var(--muted); font-size: 13px; padding: 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 30; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0;
}

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column;
  animation: slide .22s ease-out;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; gap: 4px; padding: env(safe-area-inset-top) 8px 0; height: calc(56px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); flex: none;
}
.sheet-title { font-weight: 700; font-size: 17px; }
.detail-scroll { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.detail-meta { padding: 16px; background: var(--card); }
.detail-meta h2 { margin: 0 0 12px; font-size: 19px; line-height: 1.3; }
.meta-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; overflow-wrap: anywhere; }
.copies { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.att-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.att-list:empty { display: none; }
.att {
  flex: none; display: flex; align-items: center; gap: 8px; max-width: 240px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg);
}
.att svg { width: 20px; height: 20px; fill: var(--brand); flex: none; }
.att span { min-width: 0; }
.att b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att small { color: var(--muted); font-size: 11.5px; }
.img-notice { display: flex; justify-content: space-between; align-items: center; padding: 6px 16px; font-size: 13px; color: var(--muted); background: var(--chip); }
.body-wrap { flex: 1; min-height: 60vh; display: flex; flex-direction: column; background: #fff; border-top: 1px solid var(--line); }
.body-wrap iframe { flex: 1; width: 100%; min-height: 60vh; border: 0; background: #fff; }

.settings-body { padding: 8px 16px 40px; overflow-y: auto; }
.settings-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sync-list { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.sync-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.sync-row:last-child { border-bottom: 0; }
.sync-row .dot { width: 9px; height: 9px; border-radius: 50%; background: #2fae6a; flex: none; }
.sync-row .dot.bad { background: #d9534f; }
.sync-row .info { flex: 1; min-width: 0; }
.sync-row .info small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

@media (min-width: 720px) {
  .app, .sheet > * { max-width: 760px; margin-left: auto; margin-right: auto; width: 100%; }
  .sheet { background: var(--bg); }
  
}

/* ---------- actions ---------- */
.copies .tag { cursor: pointer; border: 1.5px solid transparent; }
.copies .tag.sel { border-color: currentColor; }
.copies .tag.spam, .copies .tag.trash { color: var(--muted); }
.actions {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 14px; background: var(--card);
}
.actions::-webkit-scrollbar { display: none; }
.act {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg);
  border-radius: 99px; padding: 7px 13px; font-size: 13.5px; font-weight: 600;
}
.act svg { width: 16px; height: 16px; fill: currentColor; }
.act.danger { color: #c0392b; }
.act:disabled { opacity: .5; }
.act-scope { flex: none; align-self: center; font-size: 12px; color: var(--muted); padding-right: 2px; }

/* ---------- compose ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 16px;
  background: var(--brand); color: #fff; padding: 14px 18px; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 20px rgba(139, 21, 21, .35);
}
.fab svg { width: 20px; height: 20px; fill: currentColor; }
.send-btn { margin-left: auto; margin-right: 6px; padding: 8px 18px; }
.compose-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; background: var(--card); padding-bottom: 30px; }
.cf { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 0 16px; min-height: 50px; }
.cf span { width: 58px; flex: none; color: var(--muted); font-size: 14px; }
.cf input, .cf select {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 16px; padding: 12px 0; outline: none;
}
.cf select { appearance: none; font-weight: 600; }
.cf-toggle { padding: 2px 12px; border-bottom: 1px solid var(--line); }
.c-text {
  min-height: 42vh; border: 0; resize: vertical; padding: 14px 16px; font: inherit; font-size: 16px; line-height: 1.5;
  background: transparent; color: var(--ink); outline: none;
}
.fwd-note { padding: 0 16px 8px; }
.compose-files { background: transparent; border: 0; padding-top: 4px; }
.compose-files .att button { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 0 0 0 4px; }
.attach-btn { align-self: flex-start; margin: 4px 16px; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.attach-btn svg { width: 18px; height: 18px; fill: currentColor; }
.audit-row { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row small { display: block; color: var(--muted); font-size: 12px; }
.segmented button { font-size: 13px; }

.steps { padding-left: 20px; margin: 6px 0 10px; color: var(--muted); line-height: 1.5; }
.qr { display: block; width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 12px; margin: 6px 0; }
.secret { font-size: 13px; letter-spacing: .08em; word-break: break-all; background: var(--chip); padding: 2px 6px; border-radius: 6px; user-select: all; }
.code-input { width: 130px; font: inherit; font-size: 18px; letter-spacing: .2em; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.login { background: #ffffff; }
.detail-meta, .actions, .att-list, .img-notice { flex-shrink: 0; }
.att-list { padding-top: 6px; }
