/* ==========================================================================
   Pavlov Bot — painel administrativo
   Design system minimo: tokens, tipografia, cards, tabelas, formularios,
   botoes, badges, abas, modal, toast, skeleton. Sem framework, sem CDN.
   ========================================================================== */

/* Precisa vir antes de tudo: varias classes definem `display` (login-view, app,
   pill, badge, btn...) e venceriam a regra do user-agent para [hidden].
   Sem isso, o login continua desenhado depois de entrar. */
[hidden] { display: none !important; }

/* --------------------------- tokens: tema escuro -------------------------- */
:root {
  --bg: #0f1216;
  --bg-elev: #141920;
  --surface: #181e26;
  --surface-2: #1f2731;
  --surface-3: #263140;
  --border: #2a323d;
  --border-strong: #3a4553;
  --text: #e6ebf2;
  --text-dim: #b4c0ce;
  --muted: #8c9aab;
  --primary: #4c8dff;
  --primary-hover: #669dff;
  --primary-soft: rgba(76, 141, 255, .14);
  --on-primary: #05122b;
  --danger: #f2555a;
  --danger-soft: rgba(242, 85, 90, .14);
  --success: #35c07f;
  --success-soft: rgba(53, 192, 127, .14);
  --warning: #f0b429;
  --warning-soft: rgba(240, 180, 41, .14);
  --info: #58a6ff;
  --info-soft: rgba(88, 166, 255, .14);
  --shadow: 0 8px 24px rgba(0, 0, 0, .38);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .28);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --sidebar-w: 236px;
  --topbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

/* --------------------------- tokens: tema claro --------------------------- */
:root[data-theme="light"] {
  --bg: #f2f5f9;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --surface-3: #e8eef5;
  --border: #dde4ec;
  --border-strong: #c4cfdb;
  --text: #17202b;
  --text-dim: #3c4a5a;
  --muted: #64717f;
  --primary: #2563eb;
  --primary-hover: #1d4fd0;
  --primary-soft: rgba(37, 99, 235, .10);
  --on-primary: #ffffff;
  --danger: #d92d3a;
  --danger-soft: rgba(217, 45, 58, .10);
  --success: #14874f;
  --success-soft: rgba(20, 135, 79, .10);
  --warning: #b07208;
  --warning-soft: rgba(176, 114, 8, .12);
  --info: #1d6fd0;
  --info-soft: rgba(29, 111, 208, .10);
  --shadow: 0 8px 24px rgba(20, 32, 48, .12);
  --shadow-sm: 0 1px 4px rgba(20, 32, 48, .10);
  color-scheme: light;
}

/* ------------------------------- base ------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .6rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); font-size: .86em; }
pre {
  margin: 0; padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow-x: auto; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  max-width: 100%;
}
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); font-size: .84em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.break { word-break: break-word; overflow-wrap: anywhere; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------- layout ---------------------------------- */
/* minmax(0, 1fr) em vez de 1fr: com `1fr` o minimo da coluna e o min-content
   do conteudo, e qualquer tabela larga estica a pagina inteira (no celular
   isso fazia o innerWidth virar 558-769 px). */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "sidebar topbar" "sidebar view";
  min-height: 100vh;
  max-width: 100%;
}

.sidebar {
  grid-area: sidebar;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  font-weight: 700; letter-spacing: -.01em;
}
.brand-mark { display: grid; place-items: center; width: 26px; height: 26px; color: var(--primary); }
.brand-mark svg { width: 24px; height: 24px; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active svg { opacity: 1; }

.sidebar-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }

.topbar {
  grid-area: topbar;
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: var(--topbar-h);
  min-width: 0;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-size: 1.02rem; font-weight: 650; margin-right: auto;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-status { display: flex; align-items: center; gap: 8px; min-width: 0; }

.view {
  grid-area: view; padding: 20px; max-width: 1240px;
  width: 100%; min-width: 0; overflow-x: hidden;
}
.view:focus { outline: none; }

.nav-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, .5);
}

.only-mobile { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "view"; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; width: 260px; max-width: 86vw;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .view { padding: 14px; }
}

/* Abaixo de 640 px a topbar so aguenta o titulo + 1 badge de estado.
   O rotulo da fase vira parte do card Servidor no Dashboard. */
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 0 10px; }
  #phase-pill { display: none !important; }
  /* mantem um rotulo textual (nunca so a cor), mas curto */
  #conn-badge .conn-text { display: none; }
  #conn-badge::after { content: attr(data-short); }
  #logout { padding: 4px 8px; }
}

/* ------------------------------- cards ----------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card + .card { margin-top: 14px; }
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin-right: auto; }
.card-head .sub { color: var(--muted); font-size: .82rem; font-weight: 400; }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 12px; }
.card-foot {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

.grid { display: grid; gap: 14px; }
/* min(Npx, 100%) evita que a coluna minima estoure telas estreitas */
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
.grid > * { min-width: 0; }

/* metricas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stats > * { min-width: 0; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0;
}
.stat .lbl { overflow-wrap: anywhere; }
.stat .val { font-size: 1.5rem; font-weight: 680; line-height: 1.1; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stat.ok .val { color: var(--success); }
.stat.warn .val { color: var(--warning); }
.stat.bad .val { color: var(--danger); }

.kv { display: grid; grid-template-columns: minmax(110px, auto) minmax(0, 1fr); gap: 6px 14px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: .84rem; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) {
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}

/* ------------------------------ botoes ----------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; min-height: 34px;
  font: inherit; font-weight: 550; line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-loading { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.secondary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn.secondary:hover { background: color-mix(in srgb, var(--primary-soft) 70%, var(--primary) 12%); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { min-height: 28px; padding: 4px 9px; font-size: .82rem; }
.btn.icon { padding: 6px; width: 34px; min-height: 34px; }
.btn.icon.small { width: 28px; padding: 4px; }
.btn.block { width: 100%; }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }


/* --------------------------- badges e pills ------------------------------ */
.badge, .pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; line-height: 1.6;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.neutral, .pill.neutral { background: var(--surface-3); color: var(--text-dim); }
.badge.ok, .pill.ok { background: var(--success-soft); color: var(--success); }
.badge.warn, .pill.warn { background: var(--warning-soft); color: var(--warning); }
.badge.danger, .pill.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info, .pill.info { background: var(--info-soft); color: var(--info); }
.badge.primary, .pill.primary { background: var(--primary-soft); color: var(--primary); }
.badge .dot, .pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: none;
}
.badge-list { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: .78rem;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
}
.chip.ok { border-color: color-mix(in srgb, var(--success) 45%, transparent); color: var(--success); }
.chip.bad { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

/* ----------------------------- formularios ------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label { font-weight: 550; font-size: .86rem; }
.field .help { color: var(--muted); font-size: .79rem; }
.field .err { color: var(--danger); font-size: .79rem; }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }

.input, .select, .textarea {
  width: 100%; padding: 8px 10px; min-height: 34px;
  font: inherit; color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input[disabled], .select[disabled], .textarea[disabled] {
  opacity: .6; cursor: not-allowed; background: var(--surface-2);
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.textarea.mono { font-family: var(--mono); font-size: .84rem; }
.textarea.tall { min-height: 180px; }
.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.input[type="file"] { padding: 6px; }
.input[type="color"] { padding: 2px; height: 34px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

.check-inline {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: .86rem; min-height: 32px;
}
.check-inline input { width: 18px; height: 18px; flex: none; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 0 14px; }
.form-row > * { min-width: 0; }

/* toggle */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: relative; width: 38px; height: 21px; flex: none;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: 999px; transition: background .15s ease, border-color .15s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--muted); transition: transform .15s ease, background .15s ease;
}
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track::after { transform: translateX(17px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input[disabled] + .track { opacity: .5; }
.switch .switch-label { font-size: .86rem; }

/* ------------------------------- tabelas --------------------------------- */
.table-wrap {
  width: 100%; overflow-x: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.card .table-wrap { border: 0; border-radius: 0; }
table.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.table th, table.table td {
  padding: 9px 12px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr:hover { background: var(--surface-2); }
table.table td.actions { white-space: nowrap; text-align: right; }
table.table td .cell-main { font-weight: 550; }
table.table td .cell-sub { color: var(--muted); font-size: .78rem; }
table.table td .mono, table.table td .break { overflow-wrap: anywhere; }
table.table td pre { max-width: 100%; overflow-wrap: anywhere; }

/* Tabela vira lista de cartoes no celular: 9 colunas em 390 px sao ilegiveis
   e obrigavam a pagina inteira a crescer. O rotulo vem do data-label da celula. */
@media (max-width: 700px) {
  .table-wrap { overflow-x: visible; border: 0; background: transparent; border-radius: 0; }
  .card .table-wrap { padding: 10px 12px 2px; }
  table.table { font-size: .9rem; }
  table.table, table.table > tbody, table.table > tbody > tr, table.table > tbody > tr > td { display: block; width: 100%; }
  table.table > thead { display: none; }
  table.table > tbody > tr {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px;
  }
  table.table > tbody > tr:hover { background: var(--surface-2); }
  table.table > tbody > tr > td {
    border-bottom: 0; padding: 4px 0; min-width: 0;
    display: grid; grid-template-columns: minmax(76px, 32%) minmax(0, 1fr);
    gap: 4px 10px; align-items: start;
  }
  table.table > tbody > tr > td::before {
    content: attr(data-label);
    grid-column: 1; grid-row: 1;
    color: var(--muted); font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; line-height: 1.7;
  }
  /* tudo que a celula tem fica na coluna do valor: celulas com varios filhos
     (texto + botao + <pre>) nao caem para debaixo do rotulo */
  table.table > tbody > tr > td > * { grid-column: 2; }
  /* elementos "inline" viram itens de grid e esticariam a coluna toda */
  table.table > tbody > tr > td > .btn,
  table.table > tbody > tr > td > .badge,
  table.table > tbody > tr > td > .pill,
  table.table > tbody > tr > td > .chip,
  table.table > tbody > tr > td > .switch { justify-self: start; }
  table.table > tbody > tr > td[data-label=""] { display: block; }
  table.table > tbody > tr > td.actions {
    display: block; text-align: left; white-space: normal;
    margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border);
  }
  table.table > tbody > tr > td.actions::before { content: none; }
  table.table > tbody > tr > td.actions .btn-group { display: flex; width: 100%; }
  table.table > tbody > tr > td.actions .btn-group .btn { flex: 1 1 auto; }
}

/* --------------------------------- abas ---------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab {
  padding: 8px 12px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 550; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ------------------------------ collapsible ------------------------------ */
details.collapse {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
details.collapse > summary {
  padding: 12px 16px; cursor: pointer; font-weight: 600; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::before {
  content: "▸"; color: var(--muted); transition: transform .15s ease; display: inline-block;
}
details.collapse[open] > summary::before { transform: rotate(90deg); }
details.collapse[open] > summary { border-bottom: 1px solid var(--border); }
details.collapse > .collapse-body { padding: 16px; }

/* ------------------------------- banners --------------------------------- */
.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2);
  margin-bottom: 14px;
}
.banner.warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.banner strong { display: block; }

/* ------------------------------- vazio ----------------------------------- */
.empty {
  padding: 28px 16px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
.empty .empty-title { font-weight: 600; color: var(--text-dim); margin-bottom: 3px; }

/* ------------------------------ skeleton --------------------------------- */
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.sk-line, .sk-block {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: sk 1.3s ease infinite;
  border-radius: var(--radius-sm);
}
.sk-line { height: 13px; }
.sk-block { height: 92px; }
.sk-line.w40 { width: 40%; }
.sk-line.w60 { width: 60%; }
.sk-line.w80 { width: 80%; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .sk-line, .sk-block { animation: none; }
  * { transition-duration: .01ms !important; }
}

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------- modal ---------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6, 9, 13, .6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 560px; margin: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: calc(100vh - 48px);
}
.modal.wide { max-width: 780px; }
.modal.narrow { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin-right: auto; font-size: 1rem; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--border);
}

/* -------------------------------- toast ---------------------------------- */
.toast-area {
  position: fixed; z-index: 200; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(400px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); animation: toast-in .16s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast .bar { width: 3px; align-self: stretch; border-radius: 3px; background: var(--muted); flex: none; }
.toast.ok .bar { background: var(--success); }
.toast.error .bar { background: var(--danger); }
.toast.warn .bar { background: var(--warning); }
.toast.info .bar { background: var(--info); }
.toast .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .87rem; }
.toast .msg ul { margin: 4px 0 0; padding-left: 18px; }
.toast .close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px; }
.toast .close:hover { color: var(--text); }

/* -------------------------------- login ---------------------------------- */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; padding: 26px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin-bottom: 4px; }
.login-card .field { text-align: left; margin-top: 16px; }
.login-card .check-inline { margin-bottom: 14px; }
.login-logo { display: grid; place-items: center; margin-bottom: 10px; color: var(--primary); }
.login-logo svg { width: 42px; height: 42px; }
.login-error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: .85rem; text-align: left;
}

/* --------------------------- tema: icones -------------------------------- */
.icon-sun { display: none; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }

/* ------------------------- blocos especificos ---------------------------- */
/* lista de mensagens */
.type-item {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  color: inherit; text-decoration: none; min-height: 44px;
}
.type-item:last-child { border-bottom: 0; }
.type-item:hover { background: var(--surface-2); text-decoration: none; }
.type-item .type-main { flex: 1; min-width: 0; }
.type-item .type-name { font-weight: 600; }
.type-item .type-key { color: var(--muted); font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
.type-item .type-desc { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.type-item .chevron { color: var(--muted); flex: none; }

/* midias */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 12px; }
.media-grid > * { min-width: 0; }
.media-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); overflow: hidden; display: flex; flex-direction: column;
}
.media-card .thumb {
  height: 118px; display: grid; place-items: center; overflow: hidden;
  background: var(--surface-3);
}
.media-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.media-card .meta { padding: 7px 9px; font-size: .76rem; color: var(--muted); overflow-wrap: anywhere; }
.media-card .meta .name { color: var(--text-dim); }
.media-card .bar { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 6px; gap: 6px; }
.media-card audio { width: 100%; }

/* gatilhos */
.trigger-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.trigger-item + .trigger-item { margin-top: 8px; }
.trigger-item .t-main { flex: 1 1 160px; min-width: 0; }

/* timeline da simulacao */
.timeline { display: flex; flex-direction: column; gap: 6px; }
.timeline-row { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.timeline-row .t-time { font-family: var(--mono); font-size: .82rem; color: var(--muted); }
.phase-bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.phase-seg { display: grid; place-items: center; font-size: .7rem; font-weight: 600; color: #04121f; min-width: 0; overflow: hidden; }
.phase-seg.closed { background: color-mix(in srgb, var(--danger) 55%, var(--surface-3)); }
.phase-seg.opening_soon { background: color-mix(in srgb, var(--warning) 60%, var(--surface-3)); }
.phase-seg.opening_5min { background: color-mix(in srgb, var(--warning) 85%, var(--surface-3)); }
.phase-seg.open { background: color-mix(in srgb, var(--success) 65%, var(--surface-3)); }

/* prever/preview */
.preview-part {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; background: var(--surface-2);
}
.preview-part + .preview-part { margin-top: 8px; }
.preview-part .p-kind { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.preview-part .p-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-part { min-width: 0; }

/* placeholders */
.ph-list { display: flex; flex-wrap: wrap; gap: 5px; }
.ph-list code {
  background: var(--surface-3); padding: 2px 6px; border-radius: 5px;
  color: var(--info); cursor: default;
}

.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.filters .field { margin-bottom: 0; min-width: 160px; max-width: 100%; }
.filters .field.grow { flex: 1 1 220px; }

/* ------------------------------- enquetes -------------------------------- */
.poll-list { display: flex; flex-direction: column; gap: 14px; }

.poll-card { min-width: 0; }
.poll-card .poll-head {
  display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.poll-card .poll-question {
  flex: 1 1 220px; min-width: 0; font-weight: 650; font-size: .98rem;
  overflow-wrap: anywhere;
}
.poll-card .poll-meta {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  color: var(--muted); font-size: .8rem;
}

/* barras de votos */
.poll-bars { display: flex; flex-direction: column; gap: 10px; }
.poll-bar { min-width: 0; }
.poll-bar .pb-top {
  display: flex; gap: 8px; align-items: baseline; justify-content: space-between;
  margin-bottom: 4px;
}
.poll-bar .pb-name { min-width: 0; overflow-wrap: anywhere; }
.poll-bar .pb-num { color: var(--text-dim); font-size: .82rem; white-space: nowrap; flex: none; }
.poll-bar .pb-track {
  height: 10px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border); overflow: hidden;
}
.poll-bar .pb-fill {
  height: 100%; background: var(--primary); border-radius: 999px;
  transition: width .25s ease; min-width: 2px;
}
.poll-bar.is-winner .pb-fill { background: var(--success); }
.poll-bar.is-winner .pb-name { font-weight: 650; }
.poll-bar .pb-voters { margin-top: 4px; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }

/* previa estilo WhatsApp */
.poll-preview {
  max-width: 380px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface-3); border: 1px solid var(--border);
}
.poll-preview .pp-kind {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 6px;
}
.poll-preview .pp-question { font-weight: 650; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 10px; }
.poll-preview .pp-choice {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); overflow-wrap: anywhere;
}
.poll-preview .pp-choice + .pp-choice { margin-top: 6px; }
.poll-preview .pp-mark {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--muted);
}
.poll-preview .pp-mark.square { border-radius: 4px; }
.poll-preview .pp-foot { margin-top: 8px; color: var(--muted); font-size: .76rem; }

/* chips de placeholder clicaveis */
.ph-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ph-chip {
  font-family: var(--mono); font-size: .78rem;
  background: var(--surface-3); color: var(--info);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; min-height: 32px;
}
.ph-chip:hover { border-color: var(--primary); color: var(--primary); }

.counter { font-variant-numeric: tabular-nums; }
.counter.bad { color: var(--danger); }
.counter.ok { color: var(--success); }

/* ------------------------- lista com paginacao --------------------------- */
.load-more { display: flex; justify-content: center; padding: 12px; }

/* linha ja resumida no historico */
table.table > tbody > tr.is-done td { opacity: .72; }

/* ---------------------------- alvos de toque ------------------------------ */
/* Fica no fim de proposito: precisa vir depois das definicoes base de
   .input/.select/.textarea/.tab para ganhar por ordem (mesma especificidade). */
@media (max-width: 700px), (pointer: coarse) {
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.small { min-height: 44px; padding: 8px 12px; font-size: .86rem; }
  .btn.icon { width: 44px; min-height: 44px; padding: 10px; }
  .btn.icon.small { width: 44px; padding: 10px; }
  .input, .select, .textarea { min-height: 44px; font-size: 16px; }
  .input[type="file"] { padding: 10px; }
  .input[type="color"] { height: 44px; }
  .input[type="date"], .input[type="time"] { min-height: 44px; }
  .textarea { min-height: 96px; }
  .tab { min-height: 44px; padding: 10px 14px; }
  .nav-item { min-height: 44px; padding: 10px; }
  .type-item { min-height: 56px; }
  .check-inline { min-height: 44px; }
  .switch { min-height: 44px; }
  .toast .close { min-width: 44px; min-height: 44px; }
  .ph-chip { min-height: 44px; }
  details.collapse > summary { min-height: 44px; }
}
