/* Conversas delegadas — estilos próprios do painel, sem build.
   Visual, tokens e componentes vêm do design system (design-system/, contrato em DESIGN.md).
   Esta folha só compõe o layout do painel: nada de cor, fonte, espaçamento ou raio literal. */

/* ---------- tokens ----------
   Cores, fonte (Inter), espaçamento, raios, sombras e movimento vêm do design system
   (design-system/index.css, carregado antes desta folha; fonte da verdade: DESIGN.md na raiz).
   Aqui só ficam medidas de layout próprias do painel. */
:root {
  --top-h: 56px;
  --nav-h: 0px;
  --thread-max: 860px; /* largura máxima da coluna de mensagens */
}

/* ---------- base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body,
#app {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg-app);
  color: var(--text-strong);
  font: var(--weight-regular) var(--text-base) / var(--leading-normal) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}
::selection {
  background: var(--surface-tint-strong);
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}
button {
  cursor: pointer;
  touch-action: manipulation;
}
.list-body,
.messages,
.page {
  overscroll-behavior: contain;
}
input,
textarea {
  caret-color: var(--focus-outline);
}
::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
:focus-visible {
  outline: 2px solid var(--focus-outline);
  outline-offset: 2px;
}
a {
  color: var(--text-brand);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
h1,
h2 {
  text-wrap: balance;
}
p {
  text-wrap: pretty;
}
.num,
time {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--text-muted);
}

/* ---------- controles ---------- */

input[type='text'],
input[type='search'],
input[type='tel'],
input[type='password'],
input[type='datetime-local'],
select {
  height: 40px;
  border: 1px solid var(--border-input);
  background: var(--surface-card);
  border-radius: var(--radius-md);
  padding: 0 var(--space-6);
  min-width: 0;
  transition:
    border-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
@media (hover: hover) {
  input:hover,
  select:hover {
    border-color: var(--border-default);
  }
}
input:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--focus-outline);
  box-shadow: var(--ring-focus);
}
input[type='search']::-webkit-search-cancel-button {
  cursor: pointer;
}
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}
.field-label {
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-body);
}
.field-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.field input {
  font-size: var(--text-base);
}
.error {
  color: var(--status-danger);
  font-size: var(--text-md);
  min-height: 1.3em;
  margin: calc(var(--space-2) * -1) 0 calc(var(--space-2) * -1);
}
.error:empty {
  min-height: 0;
  margin: calc(var(--space-4) * -1) 0;
}

.count {
  display: inline-block;
  margin-left: var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- estados: carregando (o esqueleto e o estado vazio/erro vêm do design system) ---------- */
.thread-loading {
  margin-top: auto;
}

/* ---------- login ---------- */
.login-wrap {
  position: relative;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: max(var(--space-30), 14vh) var(--space-8) var(--space-20);
  isolation: isolate;
}
.login-wrap::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: calc(max(var(--space-30), 14vh) + 168px);
  background: var(--surface-brand); /* o cartão-herói roxo da tela */
  z-index: -1;
}
.login-theme {
  position: absolute;
  top: calc(var(--space-8) + env(safe-area-inset-top));
  right: var(--space-8);
}
.login-panel {
  width: 100%;
  max-width: 384px;
}
.login-brand {
  color: var(--text-on-brand);
  margin-bottom: var(--space-16);
}
.login-brand .bm-field {
  fill: var(--track-on-brand);
}
.login-brand h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  margin: var(--space-10) 0 var(--space-3);
}
.login-brand p {
  margin: 0;
  color: var(--text-on-brand-muted);
  font-size: var(--text-base);
}
.login {
  background: var(--surface-card);
  border-radius: var(--radius-xl);
  padding: var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  box-shadow: var(--shadow-raised);
}
.login .ds-btn {
  margin-top: var(--space-2);
  height: 44px;
  font-size: var(--text-base);
}
.login-foot {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin: var(--space-10) var(--space-2) 0;
  font-size: var(--text-md);
  color: var(--text-muted);
}
.login-foot .ds-icon {
  margin-top: var(--space-1);
}

/* ---------- casco ---------- */
.shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.top {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: env(safe-area-inset-top) var(--space-8) 0 var(--space-10);
  height: calc(var(--top-h) + env(safe-area-inset-top));
  background: var(--surface-card);
  color: var(--text-strong);
  flex: none;
  position: relative;
  z-index: 2;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap;
}
.tabs {
  display: flex;
  align-self: stretch;
  gap: var(--space-1);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-spacer {
  flex: 1;
}
.tab-label .short {
  display: none;
}
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  border: 0;
  background: none;
  color: var(--text-muted);
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  white-space: nowrap;
  transition:
    color var(--duration-fast) var(--ease-standard),
    background-color var(--duration-fast) var(--ease-standard);
}
@media (hover: hover) {
  .tab:hover {
    color: var(--text-strong);
    background: var(--surface-tint);
  }
}
.tab.active {
  color: var(--text-strong);
}
.tab.active::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 3px;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  background: var(--accent);
}
.tab:focus-visible {
  outline-offset: -4px;
  border-radius: var(--radius-sm);
}
.tab-icon {
  position: relative;
  display: inline-flex;
  order: 2;
}
.tab-icon .ds-icon {
  display: none;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
  flex: none;
}
.dot.ok {
  background: var(--status-success);
}
.dot.warn {
  background: var(--status-warning);
}
.dot.bad {
  background: var(--status-danger);
}
.who {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  white-space: nowrap;
  min-width: 0;
}
.who-avatar {
  width: 32px;
  height: 32px;
  font-size: var(--text-sm);
}
.who-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
  margin-right: var(--space-2);
}
.who-name {
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
}
.who-role {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
main {
  flex: 1;
  min-height: 0;
}

/* ---------- conversas: lista ---------- */
.chats-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100%;
}
.chat-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-card);
  border-right: 1px solid var(--border-subtle);
}
.list-head {
  padding: var(--space-10) var(--space-10) var(--space-5);
  flex: none;
}
.list-head h1 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  display: flex;
  align-items: baseline;
}
.list-head p {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.list-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-1) var(--space-4) var(--space-8);
  display: flex;
  flex-direction: column;
}
.chat-item {
  display: flex;
  gap: var(--space-6);
  width: 100%;
  padding: var(--space-5);
  border: 0;
  border-radius: var(--radius-lg);
  background: none;
  text-align: left;
  align-items: center;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.chat-item + .chat-item {
  margin-top: var(--space-1);
}
@media (hover: hover) {
  .chat-item:hover {
    background: var(--surface-tint);
  }
}
.chat-item.active {
  background: var(--status-active-bg);
}
.chat-item:focus-visible {
  outline-offset: -2px;
}
.ci-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ci-top,
.ci-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}
.ci-name {
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ci-time {
  color: var(--text-muted);
  font-size: var(--text-sm);
  flex: none;
  font-variant-numeric: tabular-nums;
}
.ci-preview {
  color: var(--text-muted);
  font-size: var(--text-md);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item.unread .ci-name {
  font-weight: var(--weight-semibold);
}
.chat-item.unread .ci-time {
  color: var(--text-brand);
  font-weight: var(--weight-semibold);
}
.chat-item.unread .ci-preview {
  color: var(--text-body);
}

/* ---------- conversas: thread ---------- */
.thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface-sunken);
}
.thread-empty {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--space-12);
}
.thread-empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  max-width: 34ch;
}
.thread-empty-inner .ds-brand-mark {
  margin-bottom: var(--space-5);
}
.thread-empty .bm-field {
  fill: var(--surface-tint-strong);
}
.thread-empty .bm-talk {
  fill: var(--surface-card);
}
.thread-empty .bm-part {
  fill: var(--accent);
}
.thread-head {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-5) var(--space-10);
  min-height: 64px;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}
.thread-title {
  flex: 1;
  min-width: 0;
}
.thread-title .name {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  letter-spacing: var(--tracking-tight);
  min-width: 0;
}
.name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.thread-sub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: var(--space-6);
  font-size: var(--text-md);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}
.until {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}
.until.soon {
  color: var(--status-warning);
  font-weight: var(--weight-medium);
}
.access-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  height: 30px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-brand);
  background: var(--status-active-bg);
}
.back {
  display: none;
  flex: none;
  width: 40px;
  height: 40px;
  margin-left: calc(var(--space-4) * -1);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-body);
  place-items: center;
}
@media (hover: hover) {
  .back:hover {
    background: var(--surface-tint);
  }
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-8) max(var(--space-10), calc((100% - var(--thread-max)) / 2)) var(--space-12);
  display: flex;
  flex-direction: column;
}
.load-older {
  align-self: center;
  margin: var(--space-2) 0 var(--space-4);
}
.day {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: var(--space-7);
  margin: var(--space-10) 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-normal);
  color: var(--text-muted);
}
.day::before,
.day::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}
.msg {
  position: relative;
  max-width: min(600px, 78%);
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-6) var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  box-shadow: inset 0 0 0 1px var(--border-subtle);
  align-self: flex-start;
  overflow-wrap: anywhere;
}
.msg.in {
  border-top-left-radius: var(--radius-xs);
}
.msg.out {
  align-self: flex-end;
  background: var(--surface-tint-strong);
  box-shadow: none;
  border-top-right-radius: var(--radius-xs);
}
.msg.cont {
  margin-top: var(--space-2);
}
.msg.fresh {
  animation: msg-in var(--duration-slow) var(--ease-standard);
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.msg .sender {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
  color: var(--text-brand);
}
.msg .text {
  white-space: pre-wrap;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}
.msg .text.gone {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-style: italic;
  color: var(--text-muted);
}
.msg .meta {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.msg.out .meta {
  color: var(--text-muted);
}
.msg .meta > * + *::before {
  content: '·';
  margin: 0 var(--space-3);
  color: var(--text-subtle);
}
.msg .m-by {
  color: var(--text-brand);
  font-weight: var(--weight-medium);
}
.msg .m-edited {
  font-style: italic;
}
.msg .media {
  margin: var(--space-1) calc(var(--space-4) * -1) var(--space-3);
}
.msg .media a {
  display: block;
  border-radius: var(--radius-md);
}
.msg .media img,
.msg .media video {
  display: block;
  max-width: 100%;
  max-height: 340px;
  border-radius: var(--radius-md);
  outline: 1px solid var(--border-subtle);
  outline-offset: -1px;
}
.msg .media.audio {
  margin: var(--space-1) calc(var(--space-2) * -1) var(--space-2);
}
.msg .media audio {
  display: block;
  width: 300px;
  max-width: 100%;
  height: 40px;
}
.msg .media.sticker img {
  max-width: 140px;
  outline: none;
}
.msg.bare {
  background: none;
  box-shadow: none;
  padding: 0;
}
.msg.bare .media {
  margin: 0 0 var(--space-2);
}
.msg.bare .meta {
  align-self: flex-end;
}
.msg .doc {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin: var(--space-1) calc(var(--space-3) * -1) var(--space-3);
  padding: var(--space-4) var(--space-6) var(--space-4) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-strong);
  text-decoration: none;
  max-width: 360px;
}
.msg.out .doc {
  background: var(--surface-tint);
}
.msg .doc:hover .doc-name {
  text-decoration: underline;
}
.doc-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  flex: none;
  background: var(--status-active-bg);
  color: var(--text-brand);
}
.msg.out .doc-icon {
  background: var(--surface-card);
}
.doc-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.doc-name {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.doc-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.msg.out .doc-sub {
  color: var(--text-muted);
}
.attach {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  margin: var(--space-1) 0 var(--space-2);
}
.attach .ds-icon {
  color: var(--text-muted);
}
.placeholder {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  font-size: var(--text-base);
  color: var(--text-muted);
  font-style: italic;
  margin: var(--space-1) 0;
}
.placeholder .ds-icon {
  margin-top: var(--space-1);
}

.composer {
  flex: none;
  padding: var(--space-6) max(var(--space-8), calc((100% - var(--thread-max)) / 2)) calc(var(--space-5) + env(safe-area-inset-bottom));
  background: var(--surface-card);
  border-top: 1px solid var(--border-subtle);
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-7);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  transition:
    border-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
.composer-box:focus-within {
  border-color: var(--focus-outline);
  box-shadow: var(--ring-focus);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  background: none;
  padding: var(--space-4) 0;
  min-height: 36px;
  max-height: 160px;
  line-height: var(--leading-normal);
  font-size: var(--text-base);
}
.composer textarea:focus-visible {
  outline: none;
}
.composer .send {
  height: 36px;
  padding: 0 var(--space-7) 0 var(--space-6);
}
.composer-hint {
  margin: var(--space-3) var(--space-1) 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
kbd {
  font: inherit;
  font-weight: var(--weight-medium);
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-default);
  background: var(--surface-tint);
}
@media (hover: none) {
  .composer-hint {
    display: none;
  }
}
.readonly-bar {
  flex: none;
  padding: var(--space-7) var(--space-8) calc(var(--space-7) + env(safe-area-inset-bottom));
  text-align: center;
  background: var(--surface-card);
  border-top: 1px solid var(--border-subtle);
}
.readonly-inner {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-base);
  color: var(--text-body);
}
.readonly-inner .ds-icon {
  color: var(--text-brand);
}

/* ---------- páginas do dono ---------- */
.page {
  height: 100%;
  overflow-y: auto;
  padding: var(--space-20) var(--space-12) var(--space-30);
}
.page-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
}
.page-head {
  margin-bottom: var(--space-2);
}
.page-head h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-4);
}
.page-sub {
  margin: 0;
  color: var(--text-body);
  max-width: 65ch;
}
.page-note {
  display: inline-flex;
  margin-top: var(--space-6);
}
.page .ds-card {
  padding: var(--space-10);
}
.ds-card h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-8);
}

/* convites */
.invite-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.invite-row {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-wrap: wrap;
}
.invite-link:empty {
  display: none;
}
.invite-link {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.invite-copy {
  display: flex;
  gap: var(--space-4);
}
.invite-copy input {
  flex: 1;
  min-width: 0;
}

/* liberar acesso */
.toolbar {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
  align-items: center;
}
.search-field {
  flex: 1 1 300px;
}
.add-number {
  display: flex;
  gap: var(--space-4);
  flex: 0 1 auto;
}
.add-number input {
  width: 190px;
  font-variant-numeric: tabular-nums;
}
.dir-list {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.dir-section {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  padding: var(--space-7) var(--space-8) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.dir-row + .dir-section {
  border-top: 1px solid var(--border-subtle);
  margin-top: calc(var(--space-1) * -1);
}
.dir-section-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-body);
}
.dir-section-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.dir-row + .dir-row {
  border-top: 1px solid var(--border-subtle);
}
.dir-row.open {
  background: var(--surface-tint);
}
.dir-summary {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  width: 100%;
  padding: var(--space-6) var(--space-8);
  border: 0;
  background: none;
  text-align: left;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
@media (hover: hover) {
  .dir-summary:hover {
    background: var(--surface-tint);
  }
}
.dir-summary:focus-visible {
  outline-offset: -3px;
  border-radius: var(--radius-lg);
}
.dir-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: var(--space-1);
}
.dir-name {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  min-width: 0;
}
.dir-row.granted .dir-name {
  font-weight: var(--weight-semibold);
}
.dir-sub {
  font-size: var(--text-md);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.chips {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 58%;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  height: 26px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  background: var(--status-active-bg);
  color: var(--text-brand);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip-name {
  font-weight: var(--weight-semibold);
}
.chip.soon {
  background: var(--status-warning-bg);
  color: var(--status-warning);
}
.chip.off {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border-default);
  color: var(--text-muted);
}
.chip.off .chip-name {
  text-decoration: line-through;
}
.chev {
  flex: none;
  color: var(--text-muted);
  transition: transform var(--duration-base) var(--ease-standard);
}
.dir-row.open .chev {
  transform: rotate(180deg);
}
.editor {
  padding: var(--space-1) var(--space-8) var(--space-8) var(--space-30);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  animation: reveal var(--duration-base) var(--ease-standard);
}
@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
.editor-empty {
  margin: 0;
  font-size: var(--text-base);
  color: var(--text-muted);
}
.grant-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.grant-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 210px auto auto;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.grant-user {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  min-width: 0;
}
.select {
  position: relative;
  display: flex;
  align-items: center;
}
.select select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 36px;
  padding: 0 var(--space-16) 0 var(--space-20);
  font-size: var(--text-base);
  cursor: pointer;
}
.select-mark {
  position: absolute;
  left: 12px;
  color: var(--text-brand);
  pointer-events: none;
}
.select-chev {
  position: absolute;
  right: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.until-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-md);
  color: var(--text-muted);
}
.until-field input {
  height: 36px;
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
}
.editor-foot {
  display: flex;
  align-items: center;
  gap: var(--space-4) var(--space-7);
  flex-wrap: wrap;
  padding-top: var(--space-1);
}
.editor-help {
  font-size: var(--text-sm);
  color: var(--text-muted);
  flex: 1 1 260px;
}

/* pessoas */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: var(--space-8);
  align-items: start;
}
.form-grid .ds-btn {
  margin-top: var(--space-12);
}
.ds-card.table-wrap {
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
.table th {
  text-align: left;
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  font-size: var(--text-sm);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.table td {
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table .actions {
  text-align: right;
  white-space: nowrap;
}
.person-cell {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-weight: var(--weight-medium);
  min-width: 0;
}
tr.inactive .person-cell > .name-text,
tr.inactive .person-cell .ds-avatar {
  opacity: 0.6;
}
.inline-form {
  display: inline-flex;
  gap: var(--space-3);
}
.inline-form input {
  height: 32px;
  width: 170px;
  font-size: var(--text-base);
}

/* registro */
.audit .when {
  white-space: nowrap;
  font-size: var(--text-md);
}
.audit .who-cell {
  font-weight: var(--weight-medium);
  white-space: nowrap;
}
.what-cell {
  display: inline-flex;
  align-items: center;
  gap: var(--space-5);
}
.what-cell .ds-access-mark {
  color: var(--text-brand);
}
.act-dot {
  display: inline-block;
  width: 16px;
  height: 9px;
  flex: none;
  position: relative;
}
.act-dot::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-2xs);
  background: var(--text-subtle);
}
.act-dot.bad::before {
  background: var(--status-danger);
}
tr.is-bad .what {
  color: var(--status-danger);
}
.audit .detail {
  font-size: var(--text-md);
}

/* WhatsApp */
.ds-card.wa {
  padding: var(--space-12);
}
.status-line {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
}
.status-line.big {
  font-size: var(--text-xl);
  letter-spacing: var(--tracking-tight);
}
.status-line .dot {
  width: 10px;
  height: 10px;
}
.dot.pulse {
  position: relative;
}
.dot.pulse::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: ping 1.8s var(--ease-standard) infinite;
}
@keyframes ping {
  from {
    transform: scale(1);
    opacity: 0.55;
  }
  to {
    transform: scale(2.8);
    opacity: 0;
  }
}
.wa-account {
  margin: var(--space-5) 0 var(--space-1);
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}
.wa-note {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-size: var(--text-md);
  color: var(--text-muted);
}
.danger-zone {
  margin-top: var(--space-12);
  padding-top: var(--space-10);
  border-top: 1px solid var(--border-subtle);
}
.danger-zone p {
  margin: 0 0 var(--space-7);
  font-size: var(--text-base);
  color: var(--text-body);
  max-width: 62ch;
}
.wa-card {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: var(--space-16);
  align-items: start;
}
.qr-plate {
  background: var(--neutral-0); /* o QR precisa de fundo branco também no tema escuro */
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 0 0 1px var(--neutral-200);
}
.qr-plate img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}
.wa-head {
  margin-bottom: var(--space-10);
}
.wa-steps-title {
  margin: var(--space-1) 0 0;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}
.steps {
  list-style: none;
  counter-reset: step;
  margin: var(--space-8) 0 var(--space-6);
  padding: 0;
}
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: var(--space-20);
  margin: 0 0 var(--space-6);
  min-height: 24px;
  padding-top: var(--space-1);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--status-active-bg);
  color: var(--text-brand);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.pairing {
  margin-top: var(--space-12);
  padding-top: var(--space-10);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.pairing-intro {
  margin: 0;
  font-size: var(--text-base);
  color: var(--text-body);
}
.pairing-intro strong {
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
}
.pairing-label {
  font-size: var(--text-md);
  color: var(--text-muted);
}
.pairing-code {
  align-self: flex-start;
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  line-height: 1.1;
  letter-spacing: var(--tracking-wordmark);
  font-variant-numeric: tabular-nums;
  padding: var(--space-7) var(--space-10) var(--space-7) var(--space-12);
  border-radius: var(--radius-lg);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--border-subtle);
}
.pairing .steps {
  margin-top: var(--space-3);
}

/* ---------- aviso flutuante ---------- */
#toast {
  position: fixed;
  left: 50%;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 14px);
  transform: translate(-50%, -8px);
  max-width: min(520px, calc(100% - 32px));
  width: max-content;
  padding: var(--space-6) var(--space-8);
  border-radius: var(--radius-lg);
  background: var(--surface-inverse);
  color: var(--text-inverse);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow-overlay);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition:
    opacity var(--duration-base) var(--ease-standard),
    transform var(--duration-base) var(--ease-standard);
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#toast.bad {
  background: var(--status-danger);
  color: var(--text-on-brand);
}

/* ---------- celular ---------- */
@media (max-width: 760px) {
  :root {
    --top-h: 54px;
    --nav-h: 62px;
  }
  .top {
    gap: var(--space-6);
    padding: env(safe-area-inset-top) var(--space-5) 0 var(--space-7);
  }
  .who-text {
    display: none;
  }
  .logout-label {
    display: none;
  }
  .who .ds-btn {
    width: 36px;
    height: 36px;
    padding: 0;
  }
  .who-avatar {
    width: 30px;
    height: 30px;
  }

  /* abas do dono viram barra inferior, ao alcance do polegar */
  .is-admin .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding: 0 var(--space-2) env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    background: var(--surface-card);
    border-top: 1px solid var(--border-subtle);
    overflow: visible;
  }
  .is-admin main {
    margin-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
  .is-admin .tab {
    flex-direction: column;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-1) var(--space-2);
    color: var(--text-muted);
    font-size: var(--text-xs);
    letter-spacing: 0;
  }
  .is-admin .tab:hover {
    background: none;
  }
  .is-admin .tab.active {
    color: var(--text-brand);
  }
  .is-admin .tab.active::after {
    top: 0;
    bottom: auto;
    left: 28%;
    right: 28%;
    height: 3px;
    border-radius: 0 0 var(--radius-xs) var(--radius-xs);
    background: var(--text-brand);
  }
  .is-admin .tab:focus-visible {
    outline-color: var(--focus-outline);
  }
  .tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tab-label.has-short .full {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .tab-label.has-short .short {
    display: inline;
  }
  .tab-icon {
    order: 0;
  }
  .tab-icon .ds-icon {
    display: block;
  }
  .tab-icon .dot {
    position: absolute;
    top: -2px;
    right: -5px;
    width: 10px;
    height: 10px;
    box-shadow: 0 0 0 2px var(--surface-card);
  }

  /* conversa aberta ocupa a tela inteira */
  .shell:has(.chats-layout.has-active) .top,
  .shell:has(.chats-layout.has-active) .tabs {
    display: none;
  }
  .shell:has(.chats-layout.has-active) main {
    margin-bottom: 0;
  }
  body:has(.chats-layout.has-active) #toast {
    top: calc(14px + env(safe-area-inset-top));
  }

  .chats-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .chats-layout.has-active .chat-list,
  .chats-layout:not(.has-active) .thread {
    display: none;
  }
  .chat-list {
    border-right: 0;
  }
  .list-head {
    padding: var(--space-8) var(--space-8) var(--space-4);
  }
  .list-body {
    padding: 0 var(--space-3) var(--space-8);
  }
  .back {
    display: grid;
  }
  .thread-head {
    gap: var(--space-5);
    padding: var(--space-4) var(--space-6);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top));
    min-height: 60px;
  }
  .thread-head .ds-avatar {
    width: 36px;
    height: 36px;
    font-size: var(--text-md);
  }
  .access-pill {
    padding: 0 var(--space-5);
    height: 28px;
  }
  .access-pill .access-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .messages {
    padding: var(--space-6) var(--space-6) var(--space-10);
  }
  .msg {
    max-width: 86%;
  }
  .composer {
    padding: var(--space-4) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
  }
  .composer textarea,
  input[type='text'],
  input[type='search'],
  input[type='tel'],
  input[type='password'],
  input[type='datetime-local'],
  select,
  .select select {
    font-size: var(--text-lg);
  }
  .composer .send {
    width: 40px;
    height: 38px;
    padding: 0;
  }
  .send-label {
    display: none;
  }

  .page {
    padding: var(--space-12) var(--space-8) var(--space-20);
  }
  .page-head h1 {
    font-size: var(--text-2xl);
  }
  .toolbar {
    gap: var(--space-4);
  }
  .search-field {
    flex-basis: 100%;
  }
  .add-number {
    flex: 1 1 100%;
    min-width: 0;
  }
  .add-number input {
    flex: 1 1 0;
    width: 0;
  }
  .dir-summary {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 18px;
    column-gap: var(--space-6);
    row-gap: var(--space-4);
    padding: var(--space-6) var(--space-7);
  }
  .chips {
    grid-column: 2 / 4;
    grid-row: 2;
    justify-content: flex-start;
    max-width: none;
  }
  .chips:empty {
    display: none;
  }
  .chip {
    white-space: normal;
    height: auto;
    min-height: 26px;
    padding: var(--space-2) var(--space-5);
  }
  .chev {
    grid-column: 3;
    grid-row: 1;
  }
  .editor {
    padding: 0 var(--space-6) var(--space-7);
  }
  .grant-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-5);
    padding: var(--space-6);
  }
  .grant-user {
    grid-column: 1 / -1;
  }
  .grant-row .select {
    grid-column: 1 / -1;
  }
  .until-field {
    min-width: 0;
  }
  .until-field input {
    flex: 1;
    min-width: 0;
    width: 100%;
  }
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-grid .ds-btn {
    margin-top: var(--space-2);
  }

  .table.stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .table.stack,
  .table.stack tbody {
    display: block;
  }
  .table.stack tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-5);
    padding: var(--space-7) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
  }
  .table.stack tbody tr:last-child {
    border-bottom: 0;
  }
  .table.stack td {
    display: block;
    padding: 0;
    border: 0;
  }
  .table.stack td.person,
  .table.stack .actions {
    flex-basis: 100%;
  }
  .table.stack .actions {
    text-align: left;
    white-space: normal;
    padding-top: var(--space-2);
  }
  .audit.stack tr {
    gap: var(--space-2) var(--space-5);
    padding: var(--space-6) var(--space-4);
  }
  .audit.stack .when {
    order: -1;
    flex-basis: 100%;
    font-size: var(--text-sm);
  }
  .audit.stack .what {
    flex: 1 1 auto;
  }
  .audit.stack .detail {
    flex-basis: 100%;
    font-size: var(--text-md);
  }
  .inline-form {
    display: flex;
  }
  .inline-form input {
    flex: 1;
    width: auto;
  }

  .ds-card.wa {
    padding: var(--space-10);
  }
  .wa-card {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-10);
  }
  .qr-plate {
    width: min(100%, 280px);
    justify-self: center;
  }
  .pairing-code {
    font-size: var(--text-2xl);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
