:root {
  --bg: #0f1720;
  --bg-2: #151f2b;
  --panel: #1b2735;
  --panel-2: #223044;
  --line: #2b3a4e;
  --text: #e8eef5;
  --muted: #8ea1b6;
  --accent: #2dd4bf;
  --accent-2: #0ea5a0;
  --mine: #12463f;
  --theirs: #223044;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* Telas de gate / login / disclosure */
.center-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #16303a, var(--bg));
}
.card {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand .logo { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .3px; }
.brand small { color: var(--muted); display: block; font-weight: 400; }
.field { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-size: 16px; outline: none; }
.field:focus { border-color: var(--accent-2); }
.btn { width: 100%; padding: 14px 16px; border-radius: 12px; border: none; background: var(--accent);
  color: #04231f; font-weight: 700; font-size: 16px; margin-top: 14px; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.notice {
  background: #3a2a12; border: 1px solid #6b4e1e; color: #f6d99a; padding: 14px 16px;
  border-radius: 12px; font-size: 14px; line-height: 1.55;
}
.disclosure ul { margin: 12px 0; padding-left: 18px; }
.disclosure li { margin: 8px 0; line-height: 1.5; }

/* App shell */
#app { display: none; height: 100%; }
#app.on { display: grid; grid-template-columns: 340px 1fr; }
.sidebar { border-right: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-width: 0; }
.side-head { padding: 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.side-head .logo { width: 30px; height: 30px; border-radius: 8px; }
.side-head .name { font-weight: 700; }
.side-head .spacer { flex: 1; }
.iconbtn { background: var(--panel); border: 1px solid var(--line); color: var(--text); width: 38px; height: 38px;
  border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; }
.iconbtn.small { width: 32px; height: 32px; font-size: 15px; }
.tabbar { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; text-align: center; padding: 9px; border-radius: 10px; background: transparent; color: var(--muted);
  border: 1px solid transparent; font-weight: 600; font-size: 13px; }
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line); }
.list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-2), #164e63);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #eafffb; flex-shrink: 0; }
.conv .meta { min-width: 0; flex: 1; }
.conv .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #04231f; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px;
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; align-self: center; }

/* Chat pane */
.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; background: var(--bg-2); }
.chat-head .title { font-weight: 700; }
.chat-head .spacer { flex: 1; }
.supervise-chip { font-size: 11px; color: #f6d99a; background: #3a2a12; border: 1px solid #6b4e1e;
  padding: 3px 8px; border-radius: 999px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 74%; padding: 9px 12px; border-radius: 14px; background: var(--theirs); align-self: flex-start;
  word-wrap: break-word; position: relative; line-height: 1.4; }
.msg.mine { background: var(--mine); align-self: flex-end; }
.msg .who { font-size: 11px; color: var(--accent); margin-bottom: 3px; font-weight: 600; }
.msg .time { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.msg.sticker { background: transparent !important; font-size: 54px; padding: 0; }
.msg img.media, .msg video.media { max-width: 260px; max-height: 320px; border-radius: 10px; display: block; }
.vo { border: 1px dashed var(--warn); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center;
  gap: 10px; color: var(--warn); cursor: pointer; font-size: 14px; }
.vo.spent { opacity: .5; cursor: default; border-style: solid; }

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 10px; background: var(--bg-2); }
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 120px; min-height: 44px; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; outline: none; }
.tools { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.tool { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 7px 10px;
  font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.tool.on { background: var(--warn); color: #241a05; border-color: var(--warn); }
.picker { position: absolute; bottom: 78px; left: 12px; right: 12px; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); display: none;
  grid-template-columns: repeat(8, 1fr); gap: 4px; max-height: 220px; overflow-y: auto; z-index: 30; }
.picker.on { display: grid; }
.picker span { font-size: 24px; text-align: center; padding: 4px; border-radius: 8px; cursor: pointer; }
.picker span:hover { background: var(--panel-2); }
.picker.stickers span { font-size: 34px; }

/* Call overlay */
.call-overlay { position: fixed; inset: 0; background: rgba(6,10,15,.96); z-index: 100; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.call-overlay.on { display: flex; }
.call-videos { position: relative; width: min(92vw, 900px); aspect-ratio: 16/10; background: #05080c; border-radius: 16px; overflow: hidden; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #05080c; }
#localVideo { position: absolute; bottom: 14px; right: 14px; width: 26%; border-radius: 10px; border: 1px solid var(--line); background:#000; }
.call-status { font-size: 18px; }
.call-actions { display: flex; gap: 16px; }
.call-actions .iconbtn { width: 58px; height: 58px; font-size: 22px; border-radius: 50%; }
.hangup { background: var(--danger) !important; border-color: var(--danger) !important; color: #fff !important; }
.accept { background: #22c55e !important; border-color: #22c55e !important; color: #04231f !important; }

/* Admin panels */
.admin-wrap { padding: 18px; overflow-y: auto; flex: 1; min-height: 0; }
.admin-wrap h2 { margin: 6px 0 14px; }
.admin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .admin-cols { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.row-flex { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
.chip { padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.chip.ok { color: #6ee7b7; border-color: #14532d; background: #062a1c; }
.chip.no { color: #fca5a5; border-color: #7f1d1d; background: #2a0a0a; }
.mini { font-size: 12px; padding: 6px 9px; border-radius: 8px; }
select.field { -webkit-appearance: none; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.on { opacity: 1; }
.incoming { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 120; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 18px; box-shadow: var(--shadow); display: none;
  align-items: center; gap: 14px; }
.incoming.on { display: flex; }
.back-btn { display: none; }

/* Mobile */
@media (max-width: 820px) {
  #app.on { grid-template-columns: 1fr; }
  .sidebar { display: flex; }
  #app.on.viewing .sidebar { display: none; }
  #app.on:not(.viewing) .main { display: none; }
  .back-btn { display: inline-flex; }
  .msg { max-width: 86%; }
}
