:root {
  /* Paleta JNio: noite violeta, azul elétrico e papel azulado */
  --fundo: #F5F8FF;
  --papel: #FFFFFF;
  --tinta: #1B1730;
  --cinza: #45506B;
  --linha: #D6E2F7;
  --linha-2: #E8EEF9;
  --campo: #B9C8E6;
  --azul: #3D8BF2;
  --azul-texto: #2459C7;
  --azul-escuro: #1B3F94;
  --azul-claro: #E6EEFF;
  --azul-fundo: #F1F6FF;
  --azul-noite: #7DB4FF;
  --noite-2: #2C3256;
  --noite-3: #3B4670;
  --noite-texto: #D3DCF2;
  --noite-muted: #A9B5D6;
  --verde: #0B5E57;
  --verde-claro: #D9FAF6;
  --verde-ponto: #0FA396;
  --ambar: #6B4A00;
  --ambar-claro: #FFF1C9;
  --erro: #B42318;
  --erro-claro: #FBE5E2;
  --erro-linha: #F1B8B2;
  --texto: "Plus Jakarta Sans", system-ui, sans-serif;
  --pixel: "VT323", ui-monospace, monospace;
  --pixel-titulo: "Silkscreen", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo);
  color: var(--tinta);
  font: 400 16px/1.55 var(--texto);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--azul-texto); }
a:hover { color: var(--azul-escuro); }
:focus-visible { outline: 3px solid var(--azul); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pixel { image-rendering: pixelated; display: block; height: auto; }
.made-by { font: 400 17px/1 var(--pixel); color: var(--azul-noite); }

/* ---------- Estrutura ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--tinta);
  color: var(--fundo);
  padding: 28px 16px;
  display: flex; flex-direction: column; gap: 32px;
  position: sticky; top: 0; height: 100vh;
}
.brand-logo { width: 104px; margin-left: 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  min-height: 44px; display: flex; align-items: center; padding: 0 12px;
  color: var(--noite-texto); text-decoration: none; font-weight: 500; font-size: 15px;
}
.nav a:hover { background: var(--noite-2); color: #fff; }
.nav a[aria-current="page"] { background: var(--azul); color: var(--tinta); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.side-foot button {
  min-height: 44px; padding: 0 12px; background: transparent; border: 1px solid var(--noite-3);
  color: var(--noite-texto); font-size: 15px; text-align: left; cursor: pointer;
}
.side-foot button:hover { border-color: var(--noite-texto); }
.side-foot .made-by { padding-left: 4px; }

main.content { padding: 40px clamp(16px, 4vw, 48px) 56px; max-width: 1192px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 28px; }
.back { display: inline-block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
h1 { font: 700 30px/1.15 var(--texto); letter-spacing: -0.5px; margin: 0; }
h2 { font: 600 17px/1.3 var(--texto); margin: 0 0 12px; }
h3 { font: 600 16px/1.3 var(--texto); margin: 0 0 6px; }
.lede { color: var(--cinza); margin: 8px 0 0; max-width: 62ch; font-size: 16px; }
.muted { color: var(--cinza); }
.small { font-size: 14px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--tinta); background: var(--tinta); color: var(--fundo);
  padding: 0 22px; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none;
  min-height: 48px;
}
.btn:hover { color: var(--fundo); }
.btn.accent { background: var(--azul); border-color: var(--azul); color: var(--tinta); }
.btn.accent:hover { background: #5A9DF5; color: var(--tinta); }
.btn.ghost { background: transparent; color: var(--azul-texto); border-color: var(--campo); }
.btn.ghost:hover { border-color: var(--azul-texto); color: var(--azul-texto); }
.btn.danger { background: transparent; color: var(--erro); border-color: var(--erro-linha); }
.btn.danger:hover { border-color: var(--erro); color: var(--erro); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.linkish { background: none; border: 1px solid var(--campo); min-height: 40px; padding: 0 14px; color: var(--azul-texto); font-weight: 600; font-size: 14px; cursor: pointer; }
.linkish:hover { border-color: var(--azul-texto); }

/* ---------- Blocos ---------- */
.panel { background: var(--papel); border: 1px solid var(--linha); padding: 22px; }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.grid-2 + .grid-2 { margin-top: 24px; }
.block { margin-bottom: 28px; }

.account-chip { display: flex; gap: 12px; align-items: center; padding: 10px 16px 10px 10px; background: var(--papel); border: 1px solid var(--linha); }
.account-chip strong { display: block; font-size: 15px; font-weight: 500; }
.live { display: flex; gap: 6px; align-items: center; font-size: 13px; color: #0B6B63; }
.live::before { content: ""; width: 8px; height: 8px; background: var(--verde-ponto); flex: none; }
.live.vigia { color: var(--ambar); }
.live.vigia::before { background: #C99A00; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat { background: var(--papel); border: 1px solid var(--linha); padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; }
.stat .label { font-size: 15px; color: var(--cinza); }
.big { font-weight: 700; font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }

.hero {
  display: flex; flex-wrap: wrap; gap: 24px; align-items: center;
  background: var(--tinta); color: var(--fundo); padding: 24px 28px; margin-bottom: 28px;
}
.hero .mascot { width: 72px; }
.hero-text { flex: 1 1 320px; display: flex; flex-direction: column; gap: 6px; }
.hero h2 { margin: 0; font: 400 14px/1.3 var(--pixel-titulo); color: var(--azul-noite); }
.hero p { margin: 0; font-size: 16px; line-height: 1.5; color: var(--noite-texto); }

.pill { display: inline-flex; align-items: center; padding: 4px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--verde-claro); color: var(--verde); }
.pill.warn { background: var(--ambar-claro); color: var(--ambar); }
.pill.err { background: var(--erro-claro); color: var(--erro); }
.pill.off { background: var(--linha-2); color: var(--cinza); }

/* ---------- A conversa (elemento assinatura) ---------- */
.convo { display: flex; flex-direction: column; gap: 14px; }
.bubble { max-width: 82%; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
.bubble.in { background: var(--noite-2); color: var(--fundo); align-self: flex-start; }
.bubble.out { background: var(--azul); color: var(--tinta); padding: 12px 14px; }
.bubble.reply { background: transparent; border: 1px solid var(--noite-3); color: var(--noite-texto); align-self: flex-start; font-size: 14px; }
.bubble-meta, .convo .handoff { font-size: 12px; color: var(--noite-muted); text-transform: uppercase; letter-spacing: 0.8px; }
.dm-line { display: flex; gap: 10px; align-items: flex-end; align-self: flex-end; max-width: 92%; }
.dm-line .bubble { max-width: none; }
.dm-line .mascot { width: 32px; flex: none; }

/* ---------- Lista de automações ---------- */
.section-title { margin: 0 0 14px; }
.auto-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.auto { background: var(--papel); border: 1px solid var(--linha); padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.auto.paused { background: #FBFCFF; }
.auto-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.auto-top h3 { margin: 0; }
.auto-where { display: flex; align-items: center; gap: 10px; color: var(--cinza); font-size: 14px; margin: 0; }
.thumb { width: 40px; height: 40px; object-fit: cover; background: var(--azul-claro); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--azul-claro); color: var(--azul-texto); padding: 4px 10px; font-weight: 600; font-size: 13px; }
.dm-box { margin: 0; padding: 12px 14px; background: var(--fundo); font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.dm-box.warn { background: var(--ambar-claro); color: var(--ambar); }
.auto-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; align-items: center; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; font-size: 14px; color: var(--cinza); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 24px; background: var(--campo); position: relative; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--azul); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:checked ~ span:last-child { color: var(--verde); }
.switch input:focus-visible + .track { outline: 3px solid var(--azul); outline-offset: 2px; }

.empty { padding: 36px; border: 1.5px dashed var(--campo); background: transparent; }
.empty h2 { margin-bottom: 6px; }

/* ---------- Formulários ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field legend { font-weight: 600; font-size: 14px; }
.field .hint { display: block; color: var(--cinza); font-size: 13px; font-weight: 400; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], textarea {
  width: 100%; border: 1px solid var(--campo); background: var(--fundo); padding: 0 14px; min-height: 48px; font-size: 15px;
}
input[type="password"] { background: #fff; }
input[type="number"] { max-width: 140px; }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; padding: 12px 14px; }
input:focus, textarea:focus { outline: none; border-color: var(--azul-texto); box-shadow: 0 0 0 3px var(--azul-claro); }
fieldset { border: 0; padding: 0; margin: 0; }
.counter { font-size: 13px; color: var(--cinza); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--erro); font-weight: 600; }

.choice-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; }
.choice label { display: block; height: 100%; border: 1px solid var(--linha); padding: 14px; cursor: pointer; background: #fff; }
.choice label strong { display: block; font-weight: 600; font-size: 15px; }
.choice label span { color: var(--cinza); font-size: 13px; }
.choice input:checked + label { border: 2px solid var(--azul); background: var(--azul-fundo); padding: 13px; }
.choice input:focus-visible + label { outline: 3px solid var(--azul); outline-offset: 2px; }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--campo); padding: 6px 10px; background: var(--fundo); min-height: 48px; }
.tag-input:focus-within { border-color: var(--azul-texto); box-shadow: 0 0 0 3px var(--azul-claro); }
.tag-input input { border: 0; background: transparent; box-shadow: none; flex: 1 1 160px; min-height: 34px; padding: 0 4px; font-size: 14px; }
.tag-input input:focus { box-shadow: none; }
.tag { background: var(--azul-claro); color: var(--azul-texto); padding: 3px 4px 3px 10px; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; width: 22px; height: 22px; line-height: 1; font-size: 16px; }
.tag button:hover { background: #D3E0FF; }

.reply-row { display: flex; gap: 8px; align-items: flex-start; }
.reply-row input { flex: 1; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 28px; align-items: start; }
.editor form { display: flex; flex-direction: column; gap: 16px; }
.editor-section { background: var(--papel); border: 1px solid var(--linha); padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.editor-section h2 { margin: 0; font-size: 16px; }
.phone { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 12px; }
.phone-head { display: flex; align-items: baseline; justify-content: space-between; }
.phone-head h2 { margin: 0; font-size: 16px; }
.phone-head span { font-size: 13px; color: var(--cinza); }
.phone .convo { background: var(--tinta); color: var(--fundo); padding: 22px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 330px; overflow: auto; padding: 2px; }
.media-grid button { border: 2px solid transparent; padding: 0; overflow: hidden; background: var(--azul-claro); cursor: pointer; aspect-ratio: 1; position: relative; }
.media-grid button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid button .noimg { display: grid; place-items: center; height: 100%; font-size: 12px; color: var(--cinza); padding: 6px; text-align: center; }
.media-grid button[aria-pressed="true"] { border-color: var(--azul); box-shadow: 0 0 0 2px var(--azul-claro); }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--fundo); padding: 16px 0 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--azul); flex: none; }

/* ---------- Simulador ---------- */
.sim { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.sim input { flex: 1 1 320px; }
.sim-result { margin: 12px 0 0; font-size: 14px; color: var(--verde); }
.sim-result:empty { display: none; }

/* ---------- Atividade ---------- */
.feed { background: var(--papel); border: 1px solid var(--linha); }
.feed-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--linha-2); }
.feed-head h2 { margin: 0; }
.feed-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 16px 22px; border-top: 1px solid var(--linha-2); }
.feed-head + .feed-row, .feed-row:first-child { border-top: 0; }
.feed-row .what { flex: 1 1 280px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.feed-row .what strong { font-size: 15px; font-weight: 600; }
.feed-row .what span { font-size: 14px; color: var(--cinza); overflow-wrap: anywhere; }
.feed-row time { font-size: 14px; color: var(--cinza); }
.feed .empty { border: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.filters .btn.small { color: var(--tinta); background: var(--papel); border-color: var(--linha); }
.filters .btn.small[aria-pressed="true"] { background: var(--tinta); color: var(--fundo); border-color: var(--tinta); }
.filters .refresh { margin-left: auto; }

/* ---------- Conexão ---------- */
.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.account { display: flex; align-items: center; gap: 14px; }
.account > div { flex: 1; min-width: 0; }
.account img, .account .thumb { width: 48px; height: 48px; flex: none; object-fit: cover; background: var(--azul-claro); }
.account-chip img, .account-chip .thumb { width: 40px; height: 40px; }
.note { background: var(--ambar-claro); padding: 12px 14px; color: var(--ambar); font-size: 14px; }
.note.info { background: var(--azul-claro); color: var(--tinta); }
.note strong { display: block; margin-bottom: 2px; }
dl.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin: 0; }
dl.facts > div { display: flex; flex-direction: column; gap: 2px; }
dl.facts dt { font-size: 13px; color: var(--cinza); }
dl.facts dd { margin: 0; font-size: 15px; font-weight: 600; }
dl.facts dd .muted { font-weight: 400; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-wrap: wrap; background: var(--tinta); }
.login-art { flex: 1 1 520px; min-width: 0; color: var(--fundo); padding: 56px clamp(20px, 5vw, 64px); display: flex; flex-direction: column; justify-content: center; gap: 32px; }
.login-art .brand-logo { width: 132px; margin: 0; }
.login-art h1 { font-size: clamp(32px, 4vw, 44px); line-height: 1.1; letter-spacing: -1px; max-width: 520px; }
.login-art .convo { max-width: 440px; gap: 12px; }
.login-form { flex: 1 1 440px; min-width: 0; background: var(--fundo); display: flex; align-items: center; justify-content: center; padding: 56px clamp(20px, 5vw, 64px); }
.login-form form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.login-form h2 { font-size: 26px; font-weight: 700; margin: 0; }
.login-form p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--cinza); }

.error-box { background: var(--erro-claro); color: var(--erro); padding: 10px 14px; font-weight: 500; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--tinta); color: var(--fundo); padding: 12px 18px; font-weight: 500; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--erro); color: #fff; }

.loading { color: var(--cinza); padding: 24px 0; }

/* ---------- Telas menores ---------- */
@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; }
  .phone { position: static; }
  .auto-list { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side, main.content { min-width: 0; }
  .side { position: static; height: auto; padding: 14px 16px; gap: 12px; }
  .side .brand-logo { width: 80px; margin: 0; }
  .side-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; }
  main.content { padding: 24px 16px 56px; }
  .login-art, .login-form { padding: 32px 16px; }
  .stats { grid-template-columns: 1fr; }
  dl.facts { grid-template-columns: 1fr; }
  .filters .refresh { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Modelos ---------- */
.template-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.template {
  display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--tinta);
  border: 1px solid var(--linha); padding: 18px 20px; background: var(--papel);
}
.template:hover { border-color: var(--azul); color: var(--tinta); }
.template .chip { align-self: flex-start; text-transform: uppercase; }
.template strong { font-size: 16px; font-weight: 600; }
.template span:last-child { font-size: 14px; color: var(--cinza); }
