:root { --bg:#f3f4f7; --panel:#fff; --text:#1f2633; --muted:#6b7280; --border:#dfe2e8; --accent:#3f68c4;
        --soft:#e7edf9; --mine:#e7edf9; --theirs:#f1f3f7; --ok:#15803d; --okbg:#dcfce7; --warn:#c2410c; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#1b1e24; --panel:#22262d; --text:#e6e8ec; --muted:#9aa1ad; --border:#343943; --accent:#6d93e8;
          --soft:#2c3a57; --mine:#2c3a57; --theirs:#2a2f37; --ok:#4ade80; --okbg:#1f3b2c; --warn:#f0a33a; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text);
       display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel);
       border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.brand img { border-radius: 6px; }
.who { font-size: 13px; color: var(--muted); }
.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-width: 440px;
        width: 100%; }
.card h1 { font-size: 22px; margin: 0 0 8px; }
label { display: block; margin: 14px 0 8px; font-size: 13px; color: var(--muted); }
input, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
                  border-radius: 8px; padding: 10px 12px; margin-top: 4px; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--panel);
         color: var(--text); padding: 9px 16px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
.tabs { display: flex; gap: 6px; margin: 16px 0 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; font-size: 13px; }
.tab.active { background: var(--soft); border-color: var(--accent); color: var(--accent); }
.msg { min-height: 1.4em; color: var(--warn); }
.msg.ok { color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.app { flex: 1; display: flex; min-height: 0; }
.list { width: 340px; background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; }
.group { padding: 12px 14px 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase;
         letter-spacing: .03em; }
.item { padding: 9px 14px; cursor: pointer; border-left: 3px solid transparent; }
.item:hover { background: var(--bg); }
.item.active { background: var(--soft); border-left-color: var(--accent); }
.item .s { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .l { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.unread .s::before { content: "● "; color: var(--accent); }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
#chatview { display: flex; flex-direction: column; height: 100%; }
.chathead { padding: 14px 18px 8px; border-bottom: 1px solid var(--border); }
.chathead h2 { font-size: 18px; margin: 0 0 4px; }
.back { display: none; margin-bottom: 6px; }
#meta { font-size: 13px; }
details { margin-top: 8px; font-size: 14px; }
details summary { cursor: pointer; color: var(--accent); }
#emailtext { white-space: pre-wrap; max-height: 220px; overflow-y: auto; padding: 8px; background: var(--bg);
             border-radius: 8px; margin-top: 6px; }
.conclusion { margin-top: 10px; background: var(--okbg); border-radius: 8px; padding: 10px 12px; font-size: 14px;
              white-space: pre-wrap; max-height: 30vh; overflow-y: auto; }
.messages { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.m { max-width: 78%; padding: 8px 12px; border-radius: 12px; background: var(--theirs); white-space: pre-wrap;
     word-wrap: break-word; }
.m.mine { align-self: flex-end; background: var(--mine); }
.m.conclusion-msg { background: var(--okbg); }
.m .n { font-weight: 600; font-size: 13px; }
.m .n .out { color: var(--warn); font-weight: 400; }
.m .t { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); }
.file { display: inline-block; margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { margin: 0; resize: none; }
.attach { margin: 0; font-size: 22px; cursor: pointer; padding: 6px; color: var(--text); }
#upload { padding: 0 16px 6px; margin: 0; }

@media (max-width: 760px) {
  .list { width: 100%; border-right: 0; }
  .app.open .list { display: none; }
  .app:not(.open) .chat { display: none; }
  .back { display: inline-block; }
  .m { max-width: 90%; }
}
