/* TP Nexy — identidade TP Digital: azul #121C4F, magenta #D11D8B, Arial (D28). */
:root {
  --navy: #121c4f;
  --navy-2: #1d2a6b;
  --navy-3: #2b3a85;
  --magenta: #d11d8b;
  --magenta-soft: #fbe7f3;
  --bg: #f4f5fa;
  --surface: #ffffff;
  --text: #1b1f33;
  --muted: #646a85;
  --line: #e1e4ef;
  --ok: #1f9d6b;
  --warn: #d68a00;
  --danger: #c62f3c;
  --radius: 10px;
  --sidebar: 300px;
  --font: Arial, Helvetica, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--navy-3); }
:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Botões e campos */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; }
.btn:hover { border-color: var(--navy-3); }
.btn.primary { background: var(--magenta); border-color: var(--magenta); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px; color: var(--navy-3); }
.icon-btn { border: 0; background: none; border-radius: 8px; padding: 6px 8px; color: inherit; line-height: 1; }
.icon-btn:hover { background: rgba(127, 127, 160, .15); }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--surface); }
.error-text { color: var(--danger); font-size: 13px; }

/* Telas de entrada */
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 60%, #3a1e5e 100%); }
.card { background: var(--surface); border-radius: 16px; padding: 32px 28px; width: min(440px, 100%); box-shadow: 0 20px 60px rgba(8, 12, 40, .35); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 26px; color: var(--navy); margin-bottom: 4px; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--magenta); }
.google-btn { display: flex; justify-content: center; align-items: center; gap: 10px; width: 100%; padding: 12px; border-radius: 10px; background: var(--navy); color: #fff; text-decoration: none; font-weight: 600; margin: 20px 0 8px; }
.google-btn:hover { background: var(--navy-3); }
.terms-text { white-space: pre-wrap; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--bg); font-size: 14px; }
.notice { background: var(--magenta-soft); color: #7c0f52; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.legal { text-align: center; padding: 4px 0 6px; }
.center-screen .legal { align-self: end; }
.center-screen .legal-link { color: rgba(255, 255, 255, .6); }
.legal-link { border: 0; background: none; padding: 2px 4px; font: inherit; font-size: 11px; color: var(--muted); cursor: pointer; opacity: .8; }
.legal-link:hover { text-decoration: underline; opacity: 1; }
.sidebar .legal-link { color: rgba(232, 234, 246, .55); }

/* Layout principal */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.sidebar { background: var(--navy); color: #e8eaf6; display: flex; flex-direction: column; min-height: 0; }
.sidebar-header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.sidebar-header .brand { color: #fff; font-size: 20px; margin: 0; flex: 1; }
.sidebar-search { margin: 0 14px 10px; }
.sidebar-search input { width: 100%; border: 0; border-radius: 8px; padding: 8px 12px; background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-search input::placeholder { color: #aab0d6; }
.sidebar-scroll { overflow-y: auto; flex: 1; padding-bottom: 12px; }
.section-title { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #9aa1cf; font-weight: 700; }
.section-title .icon-btn { color: #c9cdee; font-size: 16px; padding: 2px 6px; }
.conv-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; color: inherit; text-align: left; padding: 7px 16px; text-decoration: none; }
.conv-item:hover { background: rgba(255, 255, 255, .07); }
.conv-item.active { background: var(--navy-3); }
.conv-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.unread .name { font-weight: 700; color: #fff; }
.conv-item.archived { opacity: .55; }
.conv-icon { width: 22px; text-align: center; color: #9aa1cf; flex: none; }
.unread-badge { background: var(--magenta); color: #fff; border-radius: 10px; font-size: 12px; font-weight: 700; padding: 1px 7px; }
.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, .1); padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.sidebar-footer .me { flex: 1; min-width: 0; border: 0; background: none; color: inherit; text-align: left; display: flex; gap: 10px; align-items: center; padding: 4px; border-radius: 8px; }
.sidebar-footer .me:hover { background: rgba(255, 255, 255, .07); }

.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--magenta); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; position: relative; }
.avatar.small { width: 24px; height: 24px; font-size: 10px; }
.presence { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--navy); background: #8a8fb0; }
.presence.online { background: var(--ok); }
.presence.busy, .presence.dnd { background: var(--danger); }
.presence.away { background: var(--warn); }

/* Conversa */
.column { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.conv-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 58px; }
.conv-header .title { font-weight: 700; font-size: 16px; }
.conv-header .topic { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-header .grow { flex: 1; min-width: 0; }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 12px 0 8px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 40px 16px; }
.day-divider { text-align: center; margin: 14px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.msg { display: flex; gap: 10px; padding: 3px 16px; position: relative; }
.msg:hover { background: #f7f8fc; }
.msg.grouped { padding-top: 0; }
.msg.grouped .avatar { visibility: hidden; height: 0; }
.msg-body { min-width: 0; flex: 1; }
.msg-meta { display: flex; gap: 8px; align-items: baseline; }
.msg-author { font-weight: 700; }
.msg-time { font-size: 12px; color: var(--muted); }
.msg-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-deleted { font-style: italic; color: var(--muted); }
.msg-tag { font-size: 12px; color: var(--muted); }
.msg-status { font-size: 12px; color: var(--muted); }
.msg-status.read { color: var(--navy-3); font-weight: 600; }
.msg.pending { opacity: .6; }
.msg.failed .msg-text { color: var(--danger); }
.quote { border-left: 3px solid var(--magenta); background: var(--bg); border-radius: 6px; padding: 4px 10px; margin: 2px 0 4px; font-size: 13px; cursor: pointer; max-width: 600px; }
.quote .who { font-weight: 700; }
.msg-actions { position: absolute; right: 16px; top: -10px; display: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(20, 24, 60, .1); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg.highlight { background: var(--magenta-soft); transition: background 1.5s; }
.load-older { display: block; margin: 4px auto 10px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 1px 8px; font-size: 13px; }
.reaction[aria-pressed="true"] { border-color: var(--magenta); background: var(--magenta-soft); }
.picker { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 2px; margin-top: 4px; width: max-content; box-shadow: 0 4px 14px rgba(20, 24, 60, .1); }
.picker button { border: 0; background: none; font-size: 18px; padding: 4px 6px; border-radius: 6px; }
.picker button:hover { background: var(--bg); }
.pin-tag { font-size: 12px; color: var(--magenta); font-weight: 600; }
.typing { min-height: 20px; padding: 0 16px; font-size: 13px; color: var(--muted); }
.composer { border-top: 1px solid var(--line); padding: 10px 16px 14px; }
.composer-reply { display: flex; justify-content: space-between; align-items: center; font-size: 13px; background: var(--bg); border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 180px; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.composer-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.readonly-bar { padding: 12px 16px; border-top: 1px solid var(--line); text-align: center; color: var(--muted); }

/* Painéis e diálogos */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(8, 12, 40, .35); }
dialog::backdrop { background: rgba(10, 14, 40, .45); }
.dialog-body { padding: 20px; }
.dialog-body h2 { margin: 0 0 14px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.list li .grow { flex: 1; min-width: 0; }
.search-result { cursor: pointer; }
.search-result:hover { background: var(--bg); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 10; max-width: calc(100% - 32px); }
.connection { background: var(--warn); color: #fff; text-align: center; font-size: 13px; padding: 4px; }

/* Celular: uma coluna, a conversa aberta ocupa a tela */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.has-conversation .sidebar { display: none; }
  .app:not(.has-conversation) .column { display: none; }
  .back-btn { display: inline-flex; }
  /* Sem "hover" no toque: tocar na mensagem mostra as ações. */
  .msg:hover .msg-actions { display: none; }
  .msg.selected .msg-actions { position: static; display: flex; border: 0; box-shadow: none; background: none; margin-top: 2px; }
  .composer-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
