/* =====================================================================
   Painel de Atendimento — mesmo design system do CRM START DIGITAL.
   Tokens copiados de crm/frontend/src/theme.css; componentes, do
   styles.css de lá. Escuro por padrão, base zinc, vermelho da marca como
   acento. A barra lateral é vermelha nos dois temas: é a âncora da tela.
   ===================================================================== */

:root {
  --radius-sm: 10px; --radius: 14px; --radius-lg: 16px; --radius-xl: 22px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'Cascadia Code', Menlo, monospace;
  --t: 140ms cubic-bezier(0.4, 0, 0.2, 1);
}

:root, :root[data-theme='dark'] {
  --bg: oklch(0.165 0.004 285); --surface: oklch(0.205 0.005 285);
  --surface-2: oklch(0.245 0.006 285); --surface-3: oklch(0.285 0.007 285);
  --border: oklch(0.305 0.007 285); --border-2: oklch(0.405 0.009 285);
  --text: oklch(0.975 0.002 285); --text-2: oklch(0.725 0.009 285); --text-3: oklch(0.555 0.011 285);
  --brand: oklch(0.585 0.213 25.5); --brand-hover: oklch(0.645 0.205 25.5);
  --brand-text: oklch(0.99 0 0); --brand-soft: oklch(0.585 0.213 25.5 / 0.15);
  --brand-glow: oklch(0.585 0.213 25.5 / 0.38);
  --ok: oklch(0.73 0.165 155); --ok-soft: oklch(0.73 0.165 155 / 0.15);
  --warn: oklch(0.79 0.155 80); --warn-soft: oklch(0.79 0.155 80 / 0.15);
  --danger: oklch(0.66 0.215 25); --danger-soft: oklch(0.66 0.215 25 / 0.15);
  --info: oklch(0.71 0.135 230); --info-soft: oklch(0.71 0.135 230 / 0.15);
  --shadow: 0 1px 0 0 oklch(1 0 0 / 0.04) inset, 0 1px 2px 0 oklch(0 0 0 / 0.3);
  --shadow-pop: 0 1px 2px 0 oklch(0 0 0 / 0.4), 0 10px 30px -6px oklch(0 0 0 / 0.4);
  --side-bg: linear-gradient(180deg, oklch(0.545 0.208 25.5) 0%, oklch(0.455 0.178 24) 100%);
  --side-text: oklch(1 0 0); --side-text-2: oklch(1 0 0 / 0.74); --side-text-3: oklch(1 0 0 / 0.55);
  --side-hover: oklch(1 0 0 / 0.13); --side-active-bg: oklch(1 0 0);
  --side-active-tx: oklch(0.48 0.19 25.5); --side-border: oklch(1 0 0 / 0.16);
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: oklch(0.982 0.002 285); --surface: oklch(1 0 0);
  --surface-2: oklch(0.963 0.003 285); --surface-3: oklch(0.932 0.004 285);
  --border: oklch(0.902 0.005 285); --border-2: oklch(0.818 0.008 285);
  --text: oklch(0.175 0.010 285); --text-2: oklch(0.435 0.010 285); --text-3: oklch(0.585 0.010 285);
  --brand: oklch(0.535 0.215 25.5); --brand-hover: oklch(0.472 0.215 25.5);
  --brand-text: oklch(1 0 0); --brand-soft: oklch(0.535 0.215 25.5 / 0.10);
  --brand-glow: oklch(0.535 0.215 25.5 / 0.20);
  --ok: oklch(0.545 0.150 155); --ok-soft: oklch(0.545 0.150 155 / 0.12);
  --warn: oklch(0.595 0.140 70); --warn-soft: oklch(0.595 0.140 70 / 0.13);
  --danger: oklch(0.545 0.205 25); --danger-soft: oklch(0.545 0.205 25 / 0.11);
  --info: oklch(0.535 0.125 230); --info-soft: oklch(0.535 0.125 230 / 0.11);
  --shadow: 0 1px 2px 0 oklch(0 0 0 / 0.06), 0 1px 3px 0 oklch(0 0 0 / 0.04);
  --shadow-pop: 0 2px 4px -1px oklch(0 0 0 / 0.08), 0 12px 32px -8px oklch(0 0 0 / 0.14);
  color-scheme: light;
}
@supports not (color: oklch(0.5 0.1 25)) {
  :root, :root[data-theme='dark'] {
    --bg: #15151a; --surface: #1c1c21; --surface-2: #25252b; --surface-3: #2e2e35;
    --border: #34343c; --border-2: #494952; --text: #f7f7f8; --text-2: #a5a5ac; --text-3: #73737b;
    --brand: #e52332; --brand-hover: #f4404e; --brand-soft: rgba(229,35,50,.15); --brand-glow: rgba(229,35,50,.38);
    --ok: #3fbf7f; --warn: #d9a441; --danger: #e5484d; --info: #4a9eda;
    --side-bg: linear-gradient(180deg, #d81f30, #a8152a); --side-text: #fff;
    --side-text-2: rgba(255,255,255,.74); --side-text-3: rgba(255,255,255,.55);
    --side-hover: rgba(255,255,255,.13); --side-active-bg: #fff; --side-active-tx: #b8162b;
    --side-border: rgba(255,255,255,.16);
  }
  :root[data-theme='light'] {
    --bg: #f7f7f8; --surface: #fff; --surface-2: #f2f2f4; --surface-3: #e7e7ea;
    --border: #e2e2e6; --border-2: #cfcfd6; --text: #16161a; --text-2: #55555e; --text-3: #86868f;
    --brand: #c4162c; --brand-hover: #9d1023; --brand-soft: rgba(196,22,44,.10); --brand-glow: rgba(196,22,44,.20);
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------- base ---------------- */
* { 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; transition: background var(--t), color var(--t);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px;
}
svg { vertical-align: middle; }

/* ---------------- formulário ---------------- */
label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-2);
  margin: 14px 0 6px; letter-spacing: .01em;
}
input, select, textarea {
  width: 100%; padding: 10px 12px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color var(--t), background var(--t);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover, select:hover, textarea:hover { border-color: var(--border-2); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); background: var(--surface); }
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; min-height: 120px; }
input[type='checkbox'] { width: auto; }

button {
  width: 100%; margin-top: 18px; padding: 11px 18px;
  background: var(--brand); color: var(--brand-text);
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background var(--t), transform var(--t);
}
button:hover:not(:disabled) { background: var(--brand-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: auto; margin-top: 0; padding: 9px 15px; font-size: 14px; line-height: 1.2;
}
.btn-sm { padding: 6px 11px; font-size: 13px; gap: 6px; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); font-weight: 500; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
button.cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; box-shadow: 0 6px 20px -8px var(--brand-glow);
}
button.cta:hover:not(:disabled) { box-shadow: 0 8px 26px -8px var(--brand-glow); }
button.link {
  width: auto; margin: 0; padding: 0; background: none; border: none;
  color: var(--brand); font-size: inherit; font-weight: 500; cursor: pointer;
}
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }

.err {
  background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger);
  padding: 11px 14px; border-radius: var(--radius); font-size: 13px; margin: 16px 0;
}
.aviso {
  background: var(--warn-soft); border: 1px solid var(--warn); color: var(--warn);
  padding: 11px 14px; border-radius: var(--radius); font-size: 13px; margin: 12px 0;
}
.hint { color: var(--text-3); font-size: 12.5px; margin-top: 10px; }
.sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* ---------------- autenticação (igual ao CRM) ---------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.auth-grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 56px 56px; opacity: .5;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 40%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 40%, #000 20%, transparent 78%);
}
.auth-wrap { position: relative; width: 100%; max-width: 412px; }
.auth-marca { text-align: center; margin-bottom: 26px; }
.auth-logo { height: auto; max-width: 190px; }
:root[data-theme='light'] .auth-logo { filter: invert(1) hue-rotate(180deg); }
.auth-marca p { margin: 10px 0 0; font-size: 12.5px; color: var(--text-3); letter-spacing: .01em; }
.auth-rodape { text-align: center; margin-top: 22px; font-size: 11.5px; color: var(--text-3); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 34px; width: 100%; max-width: 412px;
}
.card h1 { font-size: 22px; margin-bottom: 4px; }
.card p.sub { margin: 0 0 22px; color: var(--text-2); font-size: 13.5px; }
.campo {
  display: flex; align-items: center; gap: 9px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius); padding-left: 12px;
  transition: border-color var(--t), background var(--t);
}
.campo:hover { border-color: var(--border-2); }
.campo:focus-within { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--brand-soft); }
.campo svg { color: var(--text-3); flex-shrink: 0; }
.campo:focus-within svg { color: var(--brand); }
.campo input { flex: 1; min-width: 0; background: transparent; border: none; padding: 11px 12px 11px 0; }
.campo input:focus, .campo input:hover { background: transparent; border: none; box-shadow: none; }
.label-linha { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 6px; }
.label-linha label { margin: 0; }
.auth-manter { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 13px; color: var(--text-2); font-weight: 500; }

/* ---------------- shell: lateral vermelha + conteúdo ---------------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--side-bg); color: var(--side-text); padding: 20px 12px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-topo { display: flex; align-items: center; gap: 9px; padding: 4px 6px 14px; margin-bottom: 4px; color: var(--side-text); }
.side-topo svg { flex-shrink: 0; }
.side-ws-txt { min-width: 0; line-height: 1.15; }
.side-ws-txt strong { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-ws-txt small { display: block; font-size: 11px; color: var(--side-text-3); }
.side nav { flex: 1; overflow-y: auto; }
.side nav a {
  display: flex; align-items: center; gap: 9px; padding: 8px 11px; margin-bottom: 2px;
  border-radius: 10px; color: var(--side-text-2); font-size: 13.5px; font-weight: 500;
  transition: background var(--t), color var(--t);
}
.side nav a svg { flex-shrink: 0; opacity: .85; }
.side nav a:hover { background: var(--side-hover); color: var(--side-text); text-decoration: none; }
.side nav a.active {
  background: var(--side-active-bg); color: var(--side-active-tx); font-weight: 600;
  box-shadow: 0 2px 12px -4px oklch(0 0 0 / 0.45);
}
.side nav a.active svg { color: var(--side-active-tx); opacity: 1; }
.nav-grupo-titulo {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--side-text-3); padding: 12px 11px 4px;
}
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--side-border); display: grid; gap: 4px; }
.side-foot button {
  width: 100%; margin: 0; padding: 7px 11px; background: transparent; color: var(--side-text-2);
  border: 0; border-radius: 8px; text-align: left; font-size: 12.5px; font-weight: 500;
  display: flex; align-items: center; gap: 9px;
}
.side-foot button:hover:not(:disabled) { background: var(--side-hover); color: var(--side-text); }
.main { padding: 26px 30px; min-width: 0; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h2 { font-size: 21px; }
.topbar .sub { margin: 0; }
.row { display: flex; gap: 9px; align-items: stretch; flex-wrap: wrap; }
.row input, .row select, .row button { height: 40px; padding-top: 0; padding-bottom: 0; }
.row input, .row select { max-width: 260px; min-width: 0; }
.row button { margin: 0; width: auto; white-space: nowrap; flex-shrink: 0; }

/* ---------------- painéis, tabelas, badges ---------------- */
.painel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 18px 20px; width: 100%; margin-bottom: 16px;
}
.painel h3 { font-size: 15px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.painel > p.sub { margin: 0 0 8px; }
.grade { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grade label { margin-top: 6px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--text-3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
tbody tr { transition: background var(--t); cursor: default; }
tbody tr:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }
.empty {
  color: var(--text-3); padding: 56px 20px; text-align: center; background: var(--surface);
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
}
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--surface-3); color: var(--text-3); }
.badge.late { background: var(--danger-soft); color: var(--danger); }
.badge.today { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 13px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { font-size: 11.5px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------------- chat ---------------- */
.chat {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  height: 420px; overflow-y: auto; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px;
}
.msg { max-width: 76%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.45; }
.msg.eu { background: var(--brand-soft); border: 1px solid color-mix(in oklab, var(--brand) 35%, transparent); margin-left: auto; }
.msg.ia { background: var(--surface); border: 1px solid var(--border); }
.msg.humano { background: var(--info-soft); border: 1px solid color-mix(in oklab, var(--info) 35%, transparent); }
.msg .meta { display: block; font-size: 10.5px; color: var(--text-3); margin-top: 4px; }
.chat-envio { display: flex; gap: 8px; margin-top: 10px; }
.chat-envio input { flex: 1; }
.chat-envio button { margin: 0; width: auto; }

/* ---------------- conversas: lista + chat ---------------- */
.conversas { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 60vh; }
.lista-conv { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.lista-conv a {
  display: block; padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text);
}
.lista-conv a:hover { background: var(--surface-2); text-decoration: none; }
.lista-conv a.active { background: var(--brand-soft); }
.lista-conv .nome { font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; gap: 8px; }
.lista-conv .ultima { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------- WhatsApp / QR ---------------- */
.qr-wpp { display: block; width: 240px; height: 240px; border-radius: 12px; background: #fff; padding: 8px; margin: 12px 0; }
.wa-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------- celular ---------------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; gap: 6px; }
  .side-topo { padding: 4px 6px; margin: 0; width: 100%; }
  .side nav { display: flex; gap: 4px; flex-wrap: wrap; }
  .side nav a { padding: 7px 10px; }
  .nav-grupo-titulo { display: none; }
  .side-foot { margin: 0; padding: 0; border: 0; display: flex; gap: 4px; }
  .main { padding: 16px; }
  .conversas { grid-template-columns: 1fr; }
  .chat { height: 50vh; }
}
