:root {
  --bg: #efeae2;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #0f766e;
  --mine: #d9fdd3;
  --theirs: #ffffff;
  --border: #e5e7eb;
  --link: #0e7490;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --panel: #1f2c33;
    --text: #e9edef;
    --muted: #8696a0;
    --brand: #14b8a6;
    --mine: #005c4b;
    --theirs: #202c33;
    --border: #2a3942;
    --link: #53bdeb;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--panel); padding: 28px;
  border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.12); display: grid; gap: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--text);
}
.login-card button[type=submit] {
  padding: 11px; border: 0; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600;
}
.error { color: #dc2626; margin: 0; min-height: 1em; font-size: 13px; text-align: center; }

/* Chat layout */
.chat { height: 100dvh; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; position: relative; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar .title { font-weight: 700; font-size: 17px; }
.status { font-size: 12px; opacity: .85; }
.ghost { background: transparent; border: 0; color: inherit; padding: 6px 10px; border-radius: 8px; }
.ghost:hover { background: rgba(255,255,255,.15); }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 4px; }
.day {
  align-self: center; background: var(--panel); color: var(--muted); font-size: 12px;
  padding: 4px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.msg {
  max-width: min(78%, 520px); padding: 6px 9px 4px; border-radius: 10px;
  box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; overflow-wrap: anywhere;
  background: var(--theirs); align-self: flex-start;
}
.msg.mine { background: var(--mine); align-self: flex-end; }
.msg .author { font-size: 12px; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg a { color: var(--link); }
.msg img.photo {
  display: block; max-width: 100%; max-height: 360px; border-radius: 8px; margin: 2px 0 4px; cursor: zoom-in;
  background: rgba(0,0,0,.05);
}
.file {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 2px 0 4px;
  border-radius: 8px; background: rgba(0,0,0,.05); text-decoration: none; color: inherit !important;
}
.file .icon {
  width: 38px; height: 44px; border-radius: 6px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.file .icon.pdf { background: #dc2626; }
.file .icon.doc { background: #2563eb; }
.file .name { font-weight: 500; }
.file .size { font-size: 12px; color: var(--muted); }

.typing { font-size: 12px; color: var(--muted); padding: 0 16px 4px; min-height: 18px; }

.preview {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 12px; padding: 8px 12px; background: var(--panel); border-radius: 10px 10px 0 0;
  font-size: 13px; border: 1px solid var(--border); border-bottom: 0;
}
.preview .ghost { color: var(--muted); }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; font: inherit; padding: 10px 14px; border-radius: 22px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  max-height: 140px; outline: none;
}
.attach, #send {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  border: 0; font-size: 20px;
}
.attach { background: var(--panel); cursor: pointer; }
#send { background: var(--brand); color: #fff; }
#send:disabled { opacity: .5; }

.drop {
  position: absolute; inset: 0; background: rgba(15,118,110,.85); color: #fff;
  display: grid; place-items: center; font-size: 20px; font-weight: 600; pointer-events: none;
}

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center;
  cursor: zoom-out; z-index: 10; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; }
