:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5b6573;
  --line: #d9dee5;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #a32020;
  --danger-bg: #fdecec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1b2129;
    --text: #e8ecf1;
    --muted: #a3adba;
    --line: #2d3540;
    --accent: #6aa3ff;
    --accent-text: #0d1117;
    --danger: #ff8a8a;
    --danger-bg: #3a1c1c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
header.bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 16px;
  background: var(--card);
  border-block-end: 1px solid var(--line);
}
header.bar .brand { font-weight: 700; margin-inline-end: auto; }
header.bar .who { color: var(--muted); font-size: 0.9em; }
header.bar form { margin: 0; }
main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4em; margin: 8px 0 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.login { max-width: 420px; margin: 8vh auto 0; }
label { display: block; font-weight: 600; margin-block: 12px 4px; }
input[type="text"], input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
button {
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button.secondary {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}
.login button { width: 100%; margin-top: 16px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 8px 12px;
}
.notice { color: var(--muted); }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 0;
}
.tile { margin: 0; }
.tile dt { color: var(--muted); font-size: 0.95em; }
.tile dd { margin: 4px 0 0; font-size: 2em; font-weight: 700; }
.tile .detail { display: block; font-size: 0.45em; font-weight: 400; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; color: var(--muted); margin-block: 16px; }
.meta a { color: var(--accent); }
.num, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
/* User-written text is rendered with dir="auto" and isolated, so bidi controls cannot reorder the UI. */
.user-text { unicode-bidi: isolate; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 700px) {
  main { padding: 12px; }
  .tiles { grid-template-columns: 1fr; }
}
header.bar nav { display: flex; gap: 12px; }
header.bar nav a, table.chats a, .messages a { color: var(--accent); }
h2 { font-size: 1.05em; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.empty { text-align: center; color: var(--muted); }
.banner { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 8px 12px; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-block: 12px; }
.parties p { margin: 4px 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
table.chats { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table.chats th, table.chats td { text-align: start; padding: 8px 12px; border-block-end: 1px solid var(--line); vertical-align: top; }
.messages { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.message { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; max-width: 100%; }
.message.second { background: var(--bg); }
.message.failed { border-color: var(--danger); }
.message-head { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 0.85em; }
@media (max-width: 700px) {
  .parties { grid-template-columns: 1fr; }
  table.chats thead { display: none; }
  table.chats, table.chats tbody, table.chats tr, table.chats td { display: block; }
  table.chats tr { margin-block-end: 12px; border: 1px solid var(--line); border-radius: 10px; }
  table.chats td { border: 0; }
  table.chats td::before { content: attr(data-label) ": "; color: var(--muted); }
}
nav.tabs { display: flex; gap: 12px; margin-block: 8px; }
nav.tabs a { color: var(--accent); padding: 4px 12px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; }
nav.tabs a.current { background: var(--card); font-weight: bold; }
/* Broadcasts (PR 6) */
a.button { display: inline-block; min-height: 44px; padding: 8px 16px; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
textarea, .inline input, .broadcast-form input[type="text"] {
  width: 100%; padding: 8px 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { min-height: 160px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 16px 0; padding: 12px 16px; }
legend { font-weight: 700; padding: 0 4px; }
.field-title { font-weight: 600; margin: 12px 0 4px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px 16px; }
label.choice { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; min-height: 44px; }
label.choice.confirm { font-weight: 700; }
.inline { display: grid; grid-template-columns: max-content 1fr max-content 1fr; gap: 8px; align-items: center; }
.inline label { margin: 0; }
.bubble { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; max-width: 520px; margin: 8px 0; }
.big { font-size: 1.2em; font-weight: 700; }
form.card { margin-block: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
@media (max-width: 700px) { .inline { grid-template-columns: max-content 1fr; } }
