:root {
  --navy: #173c6e;
  --teal: #1aa3c8;
  --bg: #eef2f6;
  --panel: #ffffff;
  --line: #dde3ea;
  --text: #1c2633;
  --muted: #6b7887;
  --mine: #d8f1f8;
  --theirs: #ffffff;
  --chat-bg: #f4f7fa;
  --danger: #d64545;
  --ok: #1e9e62;
  --shadow: 0 1px 2px rgba(20, 40, 70, .08), 0 4px 16px rgba(20, 40, 70, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1722;
    --panel: #172231;
    --line: #253448;
    --text: #e6edf5;
    --muted: #93a3b5;
    --mine: #164a5c;
    --theirs: #1d2b3d;
    --chat-bg: #111b28;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { height: 100dvh; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--teal); }

/* ------------------------------------------------ login / cadastro */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.auth-logo { display: block; margin: 0 auto 6px; width: 110px; border-radius: 10px; }
.auth h1 { text-align: center; font-size: 20px; margin: 4px 0 2px; color: var(--navy); }
@media (prefers-color-scheme: dark) { .auth h1 { color: var(--text); } .auth-logo { background: #fff; padding: 6px; } }
.auth p.sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted);
}
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
label small { font-weight: 400; color: var(--muted); }
.field {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
.field:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26, 163, 200, .18); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--navy); color: #fff;
}
.btn.block { width: 100%; margin-top: 18px; }
.btn.teal { background: var(--teal); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ------------------------------------------------ layout do chat */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--navy); color: #fff; min-height: 58px;
}
.topbar img { width: 34px; height: 34px; border-radius: 50%; background: #fff; padding: 3px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { font-size: 12px; opacity: .8; }
.icon-btn {
  border: 0; background: transparent; color: inherit; width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; font-size: 19px; flex: none;
}
.icon-btn:hover { background: rgba(127, 127, 127, .15); }
.icon-btn svg { width: 22px; height: 22px; }

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.msg {
  max-width: min(78%, 560px); padding: 7px 10px 5px; border-radius: 12px; background: var(--theirs);
  box-shadow: var(--shadow); align-self: flex-start; word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap; position: relative;
}
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg + .msg.mine, .msg.mine + .msg:not(.mine) { margin-top: 6px; }
.msg .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.msg .meta .tick { margin-left: 3px; }
.msg .meta .tick.read { color: var(--teal); }
.msg img.shot { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; cursor: zoom-in; background: var(--bg); }
.msg audio { display: block; width: 260px; max-width: 100%; height: 40px; }
.msg .file {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  background: rgba(127, 127, 127, .1); padding: 8px 10px; border-radius: 8px; min-width: 200px;
}
.msg .file .ico { font-size: 26px; }
.msg .file b { display: block; font-size: 14px; font-weight: 600; }
.msg .file small { color: var(--muted); }
.msg .caption { margin-top: 4px; }
.more { align-self: center; margin: 4px 0 8px; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); padding: 30px; max-width: 320px; }
.typing { font-size: 12px; color: var(--muted); padding: 0 16px 4px; height: 18px; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 20px;
  padding: 10px 14px; max-height: 140px; min-height: 42px; outline: none; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--teal); }
.round {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; background: var(--teal); color: #fff;
}
.round svg { width: 22px; height: 22px; }
.round.plain { background: transparent; color: var(--muted); }
.round.plain:hover { background: var(--bg); color: var(--text); }
.round.rec { background: var(--danger); }
.recbar { flex: 1; display: flex; align-items: center; gap: 10px; padding: 0 10px; min-height: 44px; font-variant-numeric: tabular-nums; }
.recbar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.pending { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.pending img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.pending .ico { font-size: 30px; }
.pending .info { flex: 1; min-width: 0; font-size: 14px; }
.pending .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending .info small { color: var(--muted); }

.dropzone {
  position: absolute; inset: 8px; border: 3px dashed var(--teal); border-radius: 16px;
  background: rgba(26, 163, 200, .12); display: grid; place-items: center; font-weight: 700; color: var(--teal);
  font-size: 18px; pointer-events: none; z-index: 5;
}

/* visualizador de imagem */
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: grid; place-items: center; z-index: 50; cursor: zoom-out; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #1c2633; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 20, 35, .5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; padding: 22px; width: 100%; max-width: 420px; box-shadow: var(--shadow); max-height: 100%; overflow: auto; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.linkbox { display: flex; gap: 6px; margin-top: 8px; }
.linkbox input { flex: 1; min-width: 0; font-size: 13px; }

/* ------------------------------------------------ painel admin */
.admin { height: 100%; display: flex; }
.side { width: 340px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.side .topbar { gap: 6px; }
.search { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.search input { border-radius: 20px; padding: 8px 14px; background: var(--bg); border: 0; }
.clients { flex: 1; overflow-y: auto; }
.client {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line);
  background: transparent; border-left: 3px solid transparent; width: 100%; text-align: left; border-top: 0; border-right: 0;
}
.client:hover { background: var(--bg); }
.client.on { background: var(--bg); border-left-color: var(--teal); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: var(--navy); font-size: 15px;
}
.client .body { flex: 1; min-width: 0; }
.client .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.client b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.client .when { font-size: 11px; color: var(--muted); flex: none; }
.client .last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client .badge { background: var(--teal); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 1px 7px; flex: none; }
.client.off b { text-decoration: line-through; opacity: .6; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; background: var(--chat-bg); }
.placeholder img { width: 120px; opacity: .85; border-radius: 12px; }
.back { display: none; }
.menu { position: absolute; right: 8px; top: 52px; background: var(--panel); color: var(--text); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); z-index: 30; min-width: 220px; padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 8px; }
.menu button:hover { background: var(--bg); }
.menu button.danger { color: var(--danger); }
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 10px 0; }
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .side { width: 100%; border-right: 0; }
  .admin.has-chat .side { display: none; }
  .admin:not(.has-chat) .main { display: none; }
  .back { display: inline-grid; }
}
