/* Flat, minimal theme. Light by default; dark applied via [data-theme="dark"]
   on <html>, chosen server-side (THEME env) and set by app.js before paint. */
:root {
  --bg: #ffffff;
  --panel: #f6f7f8;
  --panel-2: #eef0f2;
  --line: #d9dde2;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --danger: #dc2626;
  /* Chat bubbles — a touch more contrast than panels so they read as cards. */
  --recv-bg: #eef1f5;
  --recv-line: #cfd6df;
  --sent-bg: #dfeafe;
  --sent-line: #b9d0fb;
  --scroll-thumb: #c4cad3;
  --radius: 8px;
  font-size: 16px;
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --panel: #1d2025;
  --panel-2: #24282e;
  --line: #333841;
  --text: #e7ebf2;
  --muted: #9aa4b2;
  --accent: #4f8cff;
  --accent-text: #0b0e14;
  --ok: #35c07a;
  --danger: #f26060;
  --recv-bg: #252a31;
  --recv-line: #3a414c;
  --sent-bg: #23324c;
  --sent-line: #33456a;
  --scroll-thumb: #3a414c;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

/* Scrollbars, themed. */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

#app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
[hidden] { display: none !important; }

/* ---- Scratch pad ---- */
.scratchpad { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0.8rem; }
.scratch-text {
  flex: 1;
  min-height: 0;
  resize: none;
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
}
.scratch-text:focus { outline: none; border-color: var(--accent); }

.file-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.file-preview-img {
  max-width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  align-self: flex-start;
}
.file-preview-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.file-preview-name { color: var(--muted); font-size: 0.9rem; word-break: break-all; }

.scratch-actions { display: flex; align-items: center; gap: 0.7rem; }
.scratch-actions .spacer { flex: 1; }
.scratch-hint { color: var(--muted); font-size: 0.85rem; margin: 0; }

/* Full-view drag overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
}
.drop-overlay-inner {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}

.note { margin-top: 1rem; color: var(--muted); text-align: center; }

/* ---- Panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
}
.panel h2 { margin: 0 0 0.8rem; font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }

.pending-item {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0;
  color: var(--muted);
}
.pending-item .thumb {
  width: 52px; height: 52px; border-radius: var(--radius); object-fit: cover;
  background: var(--panel-2); border: 1px solid var(--line);
}

/* Progress */
.progress { display: flex; align-items: center; gap: 0.7rem; margin: 0.6rem 0; }
.bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.1s; }

/* Requests */
.requests { display: grid; gap: 0.9rem; margin-top: 1.2rem; }
.request-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.request-card .meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }
.request-actions { display: flex; gap: 0.6rem; flex-shrink: 0; }

/* Visual code typography */
.visual-code {
  font-weight: 700;
  font-size: clamp(2.2rem, 12vw, 7rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
  text-align: center;
  word-break: break-word;
  margin: 1rem 0;
}
.visual-code .sep, .request-code .sep { color: var(--muted); opacity: 0.5; }

.receiver-wrap, .message-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
}
.receiver-status { font-size: 1.05rem; color: var(--muted); }
.request-code { font-weight: 700; font-size: clamp(1.4rem, 4vw, 2.2rem); }

/* ---- Buttons ---- */
.btn {
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { filter: brightness(1.05); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-2); filter: none; }
.btn.approve { background: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }

/* ---- Channel ---- */
.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.4rem;
}
.item {
  position: relative;
  border: 1px solid var(--recv-line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  padding-right: 3rem;
  max-width: 85%;
  background: var(--recv-bg);
  word-break: break-word;
}
.item.sent { align-self: flex-end; background: var(--sent-bg); border-color: var(--sent-line); }
.item.recv { align-self: flex-start; }
.item .who { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.3rem; display: flex; gap: 0.5rem; }
.item pre { margin: 0; white-space: pre-wrap; font-family: inherit; }
.item img { max-width: 100%; max-height: 340px; border-radius: var(--radius); display: block; }
.item a { color: var(--accent); }
.item .check { color: var(--ok); }
.dl-btn { margin-top: 0.5rem; }
.item-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  line-height: 1.3;
  cursor: pointer;
}
.item-copy:hover { color: var(--text); }

/* The composer's controls share one base height so the file button lines up
   with the (single-line) input; the textarea grows upward from there. */
.composer { --composer-h: 2.7rem; display: flex; gap: 0.7rem; margin-top: 0.8rem; align-items: flex-end; flex-shrink: 0; }
.composer .channel-drop,
.composer textarea,
.composer .btn { min-height: var(--composer-h); }
.channel-drop {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 0 0.9rem;
  display: flex; align-items: center;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.channel-drop:hover, .channel-drop.dragging { border-color: var(--accent); color: var(--text); }
.text-form { flex: 1; display: flex; gap: 0.6rem; align-items: flex-end; }
.text-form textarea {
  flex: 1;
  resize: none;
  overflow-y: auto;
  max-height: 40vh;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}
.text-form textarea:focus { outline: none; border-color: var(--accent); }
.text-form .btn { flex-shrink: 0; }
.channel-drop { flex-shrink: 0; }

.message-text { font-size: 1.3rem; font-weight: 600; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  z-index: 20;
}

@media (max-width: 560px) {
  .composer { flex-direction: column; }
  .request-card { flex-direction: column; align-items: stretch; }
  .request-actions { justify-content: stretch; }
  .request-actions .btn { flex: 1; }
}
