/* ===========================================================================
   Console Grupo 3RN — design system
   Cores amostradas dos assets oficiais em "Manual marca/3RN/PNG".
   =========================================================================== */

:root {
  /* Marca */
  --azul-marinho: #015393; /* primária — domina o wordmark */
  --turquesa:     #46B2B5; /* secundária — losangos externos */
  --azul-medio:   #0074BC; /* acento — losango central */
  --turquesa-esc: #168CA2;
  --turquesa-med: #2B9DAC;

  --marinho-900: #012F53;
  --marinho-700: #01437A;
  --marinho-300: #4D8CBE;

  /* Superfícies (claro) */
  --bg:          #F4F7FA;
  --surface:     #FFFFFF;
  --surface-alt: #EDF2F7;
  --border:      #D8E1EA;

  --text:        #10222F;
  --text-muted:  #5A7183;
  --text-invert: #FFFFFF;

  --ok:    #1E8E58;
  --warn:  #B4780A;
  --error: #C2321F;

  --ok-bg:    #E4F4EB;
  --warn-bg:  #FBF1DC;
  --error-bg: #FBE7E4;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(1, 47, 83, .06), 0 4px 12px rgba(1, 47, 83, .06);
  --gradiente: linear-gradient(135deg, var(--turquesa) 0%, var(--azul-medio) 100%);

  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0A1620;
    --surface:     #10222F;
    --surface-alt: #16303F;
    --border:      #21455A;

    --text:        #E8EFF5;
    --text-muted:  #93A9BA;

    --ok-bg:    #103224;
    --warn-bg:  #33280C;
    --error-bg: #3A1713;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ login */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--gradiente);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: min(100%, 400px);
}

.login-card img { width: 180px; margin: 0 auto 28px; display: block; }

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--marinho-900);
  color: var(--text-invert);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar img { width: 150px; margin: 4px 8px 28px; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #B9D0E4;
  font: inherit;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }

.nav-item.active {
  background: var(--azul-marinho);
  color: #fff;
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  font-size: 12px;
  color: #7796AF;
  padding: 12px 14px 0;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

.sidebar-foot button {
  background: none;
  border: 0;
  color: #B9D0E4;
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.main { padding: 32px 40px; overflow-x: auto; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 16px; }
.sub { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat { font-size: 30px; font-weight: 600; color: var(--azul-marinho); line-height: 1.2; }
@media (prefers-color-scheme: dark) { .stat { color: var(--turquesa); } }
.stat-label { color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }

/* ------------------------------------------------------------------ forms */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  margin-bottom: 16px;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--azul-medio);
  outline-offset: -1px;
  border-color: var(--azul-medio);
}

textarea { min-height: 110px; resize: vertical; font-family: var(--font); }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

.weekdays { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }

.weekdays input { position: absolute; opacity: 0; pointer-events: none; }

.weekdays label {
  margin: 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}

.weekdays input:checked + label {
  background: var(--azul-marinho);
  border-color: var(--azul-marinho);
  color: #fff;
}

.weekdays input:focus-visible + label { outline: 2px solid var(--azul-medio); outline-offset: 2px; }

/* ----------------------------------------------------------------- botões */

button.btn {
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--azul-marinho);
  color: #fff;
}

button.btn:hover:not(:disabled) { background: var(--marinho-700); }
button.btn:disabled { opacity: .55; cursor: not-allowed; }

button.btn.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

button.btn.secondary:hover:not(:disabled) { background: var(--surface-alt); }

button.btn.danger { background: transparent; color: var(--error); border-color: transparent; padding: 4px 8px; }
button.btn.danger:hover:not(:disabled) { background: var(--error-bg); }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ----------------------------------------------------------------- tabelas */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 0 12px 10px; }
td { padding: 11px 12px; border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-alt); }

.empty { color: var(--text-muted); text-align: center; padding: 36px 0; }

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.ok    { background: var(--ok-bg);    color: var(--ok); }
.badge.warn  { background: var(--warn-bg);  color: var(--warn); }
.badge.error { background: var(--error-bg); color: var(--error); }

/* --------------------------------------------------------------- conexão */

.qr-box { text-align: center; }
.qr-box img { width: 260px; height: 260px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; padding: 8px; }

.conn { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: none; }
.dot.on  { background: var(--ok); }
.dot.off { background: var(--error); }

/* --------------------------------------------------------------- conversas */

.chat-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* Altura fixa para que só as duas listas rolem, nunca a página. */
  height: calc(100vh - 170px);
  min-height: 420px;
  overflow: hidden;
}

.chat-list { border-right: 1px solid var(--border); overflow-y: auto; }

.chat-item {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.chat-item:hover { background: var(--surface-alt); }
.chat-item.active { background: var(--surface-alt); box-shadow: inset 3px 0 0 var(--azul-marinho); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: none;
  background: var(--gradiente);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-item-body { min-width: 0; flex: 1; }
.chat-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-item-last {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta { text-align: right; flex: none; font-size: 11px; color: var(--text-muted); }

.unread-pill {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--turquesa);
  color: #04303a;
  font-weight: 700;
  font-size: 11px;
  margin-top: 4px;
}

.chat-pane { display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.bubble {
  max-width: min(72%, 560px);
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  /* Preserva as quebras de linha do WhatsApp sem permitir HTML. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}

.bubble.them { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 3px; }

.bubble.me {
  align-self: flex-end;
  background: var(--azul-marinho);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.bubble-meta { font-size: 10px; opacity: .7; margin-top: 5px; text-align: right; }

.day-divider {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 12px;
  border-radius: 999px;
  margin: 10px 0;
}

.chat-composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex: none;
  align-items: flex-end;
}

.chat-composer textarea {
  margin: 0;
  min-height: 42px;
  max-height: 140px;
  resize: none;
}

.chat-empty { display: grid; place-items: center; height: 100%; color: var(--text-muted); padding: 24px; text-align: center; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 820px) {
  .chat-layout { grid-template-columns: 1fr; height: calc(100vh - 210px); }
  .chat-list { display: none; }
  .chat-layout.show-list .chat-list { display: block; border-right: 0; }
  .chat-layout.show-list .chat-pane { display: none; }
}

/* --------------------------------------------------------------- docs API */

.docs { max-width: 900px; }

.docs h2 { margin-top: 0; }
.docs h3 { font-size: 15px; margin: 26px 0 10px; }
.docs p { margin: 0 0 14px; }
.docs ul { margin: 0 0 14px; padding-left: 20px; }
.docs li { margin-bottom: 6px; }

.docs code:not(pre code) {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

.endpoint {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.endpoint-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-alt);
  cursor: pointer;
  user-select: none;
}

.endpoint-head:hover { background: var(--border); }

.method {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 3px 9px;
  border-radius: 4px;
  flex: none;
  min-width: 58px;
  text-align: center;
  color: #fff;
}

.method.get    { background: var(--turquesa-esc); }
.method.post   { background: var(--azul-marinho); }
.method.delete { background: var(--error); }
.method.patch  { background: var(--warn); }

.endpoint-path {
  font-family: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.endpoint-desc { font-size: 13px; color: var(--text-muted); flex: none; }
.endpoint-body { padding: 16px; display: none; border-top: 1px solid var(--border); }
.endpoint.open .endpoint-body { display: block; }
.endpoint-head::after { content: "▾"; color: var(--text-muted); flex: none; }
.endpoint.open .endpoint-head::after { content: "▴"; }

.code-wrap { position: relative; margin: 0 0 14px; }

pre {
  background: var(--marinho-900);
  color: #DCE9F5;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  font-family: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

pre code { background: none; border: 0; padding: 0; color: inherit; font: inherit; }

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 4px;
  background: rgba(255, 255, 255, .1);
  color: #DCE9F5;
  cursor: pointer;
}

.copy-btn:hover { background: rgba(255, 255, 255, .2); }

.lang-tabs { display: flex; gap: 4px; margin-bottom: 8px; }

.lang-tab {
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.lang-tab.active { background: var(--azul-marinho); border-color: var(--azul-marinho); color: #fff; }

.token-value {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.callout {
  border-left: 3px solid var(--warn);
  background: var(--warn-bg);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 0 0 16px;
  font-size: 13.5px;
}

.callout.info { border-left-color: var(--azul-medio); background: var(--surface-alt); }

/* ------------------------------------------------------------------ toast */

#toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--marinho-900);
  color: #fff;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-width: 380px;
  display: none;
}

#toast.error { background: var(--error); }
#toast.show  { display: block; }

.hint { font-size: 12px; color: var(--text-muted); margin: -10px 0 16px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; padding: 12px; }
  .sidebar img { width: 110px; margin: 0 16px 0 4px; }
  .sidebar-foot { display: none; }
  .main { padding: 20px; }
}
