/* lf-chat: plain CSS, no inline styles (style-src 'self'). Light and dark by system preference. */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #15181d;
  --muted: #4b5563;
  --line: #d3d8df;
  --accent: #0b5cd5;
  --accent-text: #ffffff;
  --out: #dbe8ff;
  --in: #eceff3;
  --warn-bg: #fff1d6;
  --warn-text: #5a3b00;
  --bad-bg: #fde2e2;
  --bad-text: #7a1212;
  --ok-text: #14532d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #181c22;
    --text: #e8ebef;
    --muted: #a3acb8;
    --line: #2f3640;
    --accent: #6ea8ff;
    --accent-text: #08111f;
    --out: #1f3354;
    --in: #232932;
    --warn-bg: #3a2c0a;
    --warn-text: #ffe2a3;
    --bad-bg: #4a1a1a;
    --bad-text: #ffc9c9;
    --ok-text: #86efac;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app {
  display: flex;
  flex-direction: column;
  max-width: 40rem;
  min-height: 100%;
  margin: 0 auto;
  padding: 0 16px 16px;
}

.app-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}
.app-title { font-weight: 600; }
.conn {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}
.conn[data-conn="online"] { color: var(--ok-text); }
.conn[data-conn="relay_key_changed"],
.conn[data-conn="auth_failed"],
.conn[data-conn="client_too_old"] { color: var(--bad-text); background: var(--bad-bg); border-color: transparent; }

main { flex: 1; display: flex; flex-direction: column; outline: none; }
.screen { display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row > input { flex: 1; min-width: 0; }

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 8px 0 0; }
p { margin: 0; }
.help { color: var(--muted); font-size: 0.875rem; }

label { font-weight: 500; }
input, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 3.2rem; }
input:disabled, textarea:disabled { opacity: 0.6; }
button {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.link, button.back {
  padding: 4px 8px;
  background: transparent;
  color: var(--accent);
  border-color: var(--line);
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.notice, .banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
}
.banner.blocking { background: var(--bad-bg); color: var(--bad-text); font-weight: 600; }

.contacts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.contacts li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
button.contact { flex: 1; text-align: left; background: transparent; color: var(--text); border: 0; padding: 8px 0; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; border: 1px solid var(--line); color: var(--muted); }
.badge[data-trust="key_changed"] { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }

.thread-head { display: flex; align-items: center; gap: 12px; }
.thread-head h1 { flex: 1; overflow-wrap: anywhere; }
.messages {
  flex: 1;
  min-height: 12rem;
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-line { align-self: center; padding: 2px 12px; color: var(--muted); font-size: 0.85rem; border-bottom: 1px solid var(--line); }
.message { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--in); }
.message[data-dir="out"] { align-self: flex-end; background: var(--out); }
.message .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message .meta { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; color: var(--muted); font-size: 0.75rem; }
.state[data-state="delivered"] { color: var(--ok-text); }
.state[data-state="failed"] { color: var(--bad-text); font-weight: 700; }
.state-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .row { justify-content: space-between; }
.counter { color: var(--muted); font-size: 0.8rem; }
.counter.over { color: var(--bad-text); font-weight: 700; }

.safety { margin: 8px 0; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.safety summary { cursor: pointer; font-weight: 600; }
.safety-number { display: grid; grid-template-columns: repeat(4, max-content); gap: 4px 12px; margin: 8px 0; font-family: ui-monospace, monospace; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.link-panel { margin: 8px 0; }
.link-code { font-family: ui-monospace, monospace; font-size: 2rem; letter-spacing: 0.2em; margin: 4px 0; }
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.devices li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

.active-net { flex: 1; margin: 0 12px; color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.networks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.network, .net-preview { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.network[data-active="1"] { border-color: var(--accent); }
.network[data-state]:not([data-state="ok"]) { border-color: var(--bad-text); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.badges, .policy-rules { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.policy-rules { flex-direction: column; flex-wrap: nowrap; gap: 4px; }
.policy-rules li[data-on="1"] { font-weight: 600; }
.policy-rules li[data-on="0"] { color: var(--muted); }
.net-badge[data-badge="policy_changed"], .net-badge[data-badge="records_calls"], .net-badge[data-badge="archiver_present"], .net-badge[data-badge="external_ai_processor"], .net-badge[data-badge="pstn_not_e2ee"] { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.net-chip { margin-left: 4px; }
button.danger { color: var(--bad-text); }
dialog.sheet { max-width: min(36rem, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.sheet > * + * { margin-top: 10px; }
