:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6877;
  --line: #d9dee6;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --mine: #dbe9ff;
  --theirs: #eceff3;
  --ok: #1a7f37;
  --wait: #9a6700;
  --off: #6e7781;
  --warn-bg: #fff8e1;
  --warn-line: #e6c65c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1b212a;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --line: #2f3945;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --mine: #1f3a66;
    --theirs: #262e39;
    --ok: #4ac26b;
    --wait: #d4a72c;
    --off: #8b949e;
    --warn-bg: #2e2a17;
    --warn-line: #6b5a1e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}
header, main, footer { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }
header { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 10px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 8px; }
main { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
footer { color: var(--muted); font-size: 13px; padding-bottom: 14px; }
[hidden] { display: none !important; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card p { margin: 0 0 12px; }
.card p:last-child { margin-bottom: 0; }
.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

.status { font-size: 14px; padding: 4px 10px 4px 24px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); position: relative; white-space: nowrap; }
.status::before { content: ""; position: absolute; left: 9px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: var(--off); }
.status.ok::before { background: var(--ok); }
.status.wait::before { background: var(--wait); }

button, .filebutton {
  font: inherit;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled, .filebutton[aria-disabled="true"] { opacity: 0.5; cursor: default; }
.filebutton { display: inline-block; position: relative; overflow: hidden; }
.filebutton input { position: absolute; inset: 0; opacity: 0; cursor: inherit; }
.filebutton:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"] {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
.linkrow { display: flex; gap: 8px; }
.linkrow input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
progress { width: 100%; height: 10px; }

#chat { flex: 1; display: flex; flex-direction: column; min-height: 240px; }
#log {
  list-style: none;
  margin: 0;
  padding: 12px;
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#log li { max-width: 85%; padding: 8px 12px; border-radius: 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
#log li.mine { align-self: flex-end; background: var(--mine); }
#log li.theirs { align-self: flex-start; background: var(--theirs); }
#log li.note { align-self: center; max-width: 100%; background: none; color: var(--muted); font-size: 13px; padding: 2px 8px; }
#log .who { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; white-space: normal; }
#log .file-name { font-weight: 600; }
#log .file-state { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; white-space: normal; }
#log li.file progress { display: block; margin-top: 6px; min-width: 180px; }
#log a.save { display: inline-block; margin-top: 6px; padding: 6px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }

#composer { display: flex; gap: 8px; margin-top: 10px; }
#composer input[type="text"] { flex: 1; }
body.dragging #log { outline: 3px dashed var(--accent); outline-offset: -3px; }

@media (max-width: 520px) {
  #composer { flex-wrap: wrap; }
  #composer input[type="text"] { flex: 1 1 100%; }
  #composer button, #composer .filebutton { flex: 1; text-align: center; }
  .linkrow { flex-direction: column; }
}
