/* Painel do TI Robo WhatsApp. Base copiada do TI SG-OS (src/web/styles.css, linhas 1-265): mesmas cores, menu lateral, cartoes, botoes e campos. */
/* Cores do TI OS: azul royal (estrutura, links) + laranja (acoes principais).
   Tema claro e escuro: data-theme no <html> ("claro"/"escuro"); sem escolha,
   segue o tema do aparelho. */
:root {
  --royal: #2547d0;
  --royal-escuro: #1a338f;
  --royal-suave: #e6ecfd;
  --laranja: #f97316;
  --laranja-hover: #ea580c;
  --laranja-suave: #fff1e6;

  --bg: #f2f5fb;
  --card: #ffffff;
  --card-2: #f7f9fe;
  --text: #0f172a;
  --muted: #5b6478;
  --border: #dfe5f1;
  --input-border: #c6cfe2;
  --hover: #f0f4fd;
  --primary: var(--royal-escuro);
  --primary-text: #dbe4ff;
  --primary-hover: #2a46b8;
  --accent: var(--laranja);
  --link: var(--royal);
  --focus: rgba(249, 115, 22, 0.35);
  --danger: #dc2626;
  --danger-border: #fecaca;
  --alerta-bg: #fff4e5;
  --alerta-text: #7c3a06;
  --alerta-border: #fdba74;
  --sombra: 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 10px;
  --nav-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='claro']) {
    --royal: #7c9cff;
    --royal-suave: #1c2a55;
    --laranja-suave: #3a2213;
    --bg: #0b1020;
    --card: #131a2e;
    --card-2: #182240;
    --text: #e5e9f5;
    --muted: #96a0b8;
    --border: #253256;
    --input-border: #33426b;
    --hover: #1b2643;
    --primary: #0e1736;
    --primary-text: #b9c6ef;
    --primary-hover: #1d2c5e;
    --link: #8ea8ff;
    --danger: #f87171;
    --danger-border: #7f1d1d;
    --alerta-bg: #3a2310;
    --alerta-text: #fed7aa;
    --alerta-border: #9a4a0f;
    color-scheme: dark;
  }
}
:root[data-theme='escuro'] {
  --royal: #7c9cff;
  --royal-suave: #1c2a55;
  --laranja-suave: #3a2213;
  --bg: #0b1020;
  --card: #131a2e;
  --card-2: #182240;
  --text: #e5e9f5;
  --muted: #96a0b8;
  --border: #253256;
  --input-border: #33426b;
  --hover: #1b2643;
  --primary: #0e1736;
  --primary-text: #b9c6ef;
  --primary-hover: #1d2c5e;
  --link: #8ea8ff;
  --danger: #f87171;
  --danger-border: #7f1d1d;
  --alerta-bg: #3a2310;
  --alerta-text: #fed7aa;
  --alerta-border: #9a4a0f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--primary); color: var(--primary-text); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
  border-right: 3px solid var(--laranja);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; padding: 4px 8px 18px; }
.brand img { width: 34px; height: 34px; border-radius: 8px; object-fit: contain; background: #fff; }
.brand img.app-logo { background: transparent; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: var(--primary-text); padding: 10px 12px; border-radius: 8px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--primary-hover); color: #fff; }
.nav a.active { background: var(--primary-hover); color: #fff; border-left-color: var(--laranja); }
.nav .ico { width: 20px; text-align: center; }
.sidebar .user { margin-top: auto; font-size: 0.85rem; padding: 8px; border-top: 1px solid var(--primary-hover); }
.sidebar .user button { margin-top: 8px; width: 100%; }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.bottom-nav { display: none; }
.mobile-header { display: none; }
.alerta { background: var(--alerta-bg); color: var(--alerta-text); border: 1px solid var(--alerta-border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.alerta a { color: inherit; font-weight: 600; text-decoration: underline; }
.previa { display: flex; gap: 14px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 14px; background: #fff; color: #0f172a; }
.previa img, .previa .sem-logo { width: 90px; height: 60px; object-fit: contain; flex-shrink: 0; }
.previa .sem-logo { display: flex; align-items: center; justify-content: center; border: 1px dashed #cbd5e1; border-radius: 6px; color: #64748b; font-size: 0.75rem; }
.previa .muted { color: #64748b; }
.previa-txt { flex: 1; min-width: 0; }
.previa-nome { font-weight: 700; font-size: 1.1rem; }
.previa-os { text-align: right; white-space: nowrap; }
@media (max-width: 600px) { .previa { flex-wrap: wrap; } .previa-os { width: 100%; text-align: left; } }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .layout { flex-direction: column; }
  .mobile-header {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--primary); color: #fff;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px; position: sticky; top: 0; z-index: 20;
    border-bottom: 3px solid var(--laranja);
  }
  .mobile-header .brand { padding: 0; font-size: 0.95rem; min-width: 0; }
  .mobile-header .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-header .brand img { width: 28px; height: 28px; }
  .mobile-header button { color: var(--primary-text); }
  .main { padding: 14px 12px calc(var(--nav-h) + 24px); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--primary); z-index: 20;
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--primary-text); opacity: 0.75; font-size: 0.68rem; gap: 2px; border-top: 3px solid transparent;
  }
  .bottom-nav a .ico { font-size: 1.2rem; }
  .bottom-nav a.active { color: #fff; opacity: 1; border-top-color: var(--laranja); }
}

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--sombra); }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 820px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1000px) { .cols { grid-template-columns: minmax(0, 1fr); } }
/* PDV: carrinho e pagamento com mais espaco */
.cols.pdv { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
@media (max-width: 1000px) { .cols.pdv { grid-template-columns: minmax(0, 1fr); } }

label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 9px 11px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--card);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); border-color: var(--laranja); }
input[type='checkbox'] { width: auto; accent-color: var(--laranja); }
.field { margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }

/* Botoes com cor propria (azul claro), para nao sumirem no fundo branco. */
button, .btn {
  font: inherit; border: 1px solid color-mix(in srgb, var(--royal) 35%, transparent); background: var(--royal-suave); color: var(--link); padding: 9px 14px;
  border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap; font-weight: 500;
}
button:hover, .btn:hover { background: color-mix(in srgb, var(--royal) 18%, var(--card)); border-color: var(--royal); }
button.primary, .btn.primary { background: var(--laranja); border-color: var(--laranja); color: var(--laranja-texto, #fff); font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--laranja-hover); border-color: var(--laranja-hover); }
button.dark, a.btn.dark { background: var(--royal); border-color: var(--royal); color: #fff; }
button.dark:hover { filter: brightness(1.1); background: var(--royal); }
button.danger, .btn.danger { color: var(--danger); border-color: var(--danger-border); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--hover); }
.mobile-header button.ghost:hover { background: var(--primary-hover); }
button.sm { padding: 5px 9px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: default; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap;
  background: var(--hover); color: var(--muted);
}
.pr-alta { background: #fed7aa; color: #9a3412; }
.pr-urgente { background: #fecaca; color: #991b1b; }

.status-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.status-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer; box-shadow: var(--sombra); }
.status-card .n { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.os-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 70px minmax(0, 1fr) auto; gap: 10px; align-items: center; cursor: pointer; color: inherit;
  box-shadow: var(--sombra);
}
.os-item:hover { border-color: var(--royal); }
.os-item .num { font-weight: 700; font-size: 1.05rem; color: var(--royal); }
.os-item .tit { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.os-item .sub { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.os-item .side { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 1; min-width: 180px; }
.filters select { width: auto; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { text-align: left; font-size: 0.78rem; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.items td { padding: 5px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.items input, table.items select { padding: 6px 8px; }
table.items .q { width: 70px; }
table.items .v { width: 110px; }
table.items .d { width: 150px; }
table.items .t { width: 100px; text-align: right; white-space: nowrap; }
@media (max-width: 820px) {
  table.items thead { display: none; }
  table.items tr { display: grid; grid-template-columns: 70px 1fr auto auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.items td { border: 0; padding: 0; }
  table.items td.desc, table.items td.d { grid-column: 1 / -1; }
  table.items .q, table.items .v, table.items .d { width: auto; }
}
.totals { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-top: 10px; }
.totals .grand { font-size: 1.2rem; font-weight: 700; color: var(--royal); }
.tipo { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }

.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.fotos .foto { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--hover); }
.fotos img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.fotos .del { position: absolute; top: 4px; right: 4px; padding: 2px 7px; background: rgba(255, 255, 255, 0.9); color: #0f172a; }

.hist { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.hist li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.hist .quando { color: var(--muted); font-size: 0.78rem; }

.assinatura-img { max-width: 100%; max-height: 120px; border: 1px dashed var(--border); border-radius: 8px; background: #fff; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 12, 30, 0.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal { background: var(--card); border-radius: var(--radius); padding: 18px; max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; }

/* ---------- Painel do robo ---------- */
.marca { font-weight: 700; color: #fff; padding: 6px 8px 14px; font-size: 1.05rem; }
.marca small { display: block; font-weight: 400; color: var(--primary-text); font-size: 0.78rem; }
.selo { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.selo.robo { background: var(--royal-suave); color: var(--royal); }
.selo.aguardando { background: var(--laranja-suave); color: var(--laranja-hover); }
.selo.atendente { background: #dcfce7; color: #166534; }
.selo.pausada { background: #f1f5f9; color: #475569; }
.conv { display: grid; grid-template-columns: 320px minmax(0, 1fr) 260px; gap: 12px; height: calc(100vh - 110px); }
.conv > div { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.lista-conv { overflow: auto; }
.item-conv { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; cursor: pointer; }
.item-conv:hover, .item-conv.on { background: var(--hover); }
.item-conv .linha1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item-conv .ultima { color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.cab-conv { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.msgs { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: var(--card-2); }
.msg { max-width: 75%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; font-size: 0.92rem; border: 1px solid var(--border); background: var(--card); }
.msg.de-cliente { align-self: flex-start; }
.msg.de-robo, .msg.de-atendente, .msg.de-celular { align-self: flex-end; background: var(--royal-suave); }
.msg.de-atendente { background: #dcfce7; }
.msg .quem { font-size: 0.72rem; color: var(--muted); margin-bottom: 2px; }
.msg img { max-width: 220px; border-radius: 6px; display: block; }
.responder { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.responder textarea { flex: 1; min-height: 42px; max-height: 120px; resize: vertical; }
.lado { padding: 12px 14px; overflow: auto; font-size: 0.9rem; }
.bloco-menu { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--card); }
.bloco-menu .num { font-weight: 700; color: var(--royal); font-size: 1.1rem; text-align: center; }
.bloco-menu.inativo { opacity: 0.6; }
.previa-whats { background: #e7ddd3; border-radius: var(--radius); padding: 14px; }
.previa-whats .balao { background: #fff; color: #0f172a; border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; font-size: 0.9rem; max-width: 92%; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
@media (max-width: 900px) {
  .conv { grid-template-columns: 1fr; height: auto; }
  .conv > .lado-conv { display: none; }
  .conv.aberta > .col-lista { display: none; }
  .conv:not(.aberta) > .col-msgs { display: none; }
  .msgs { min-height: 50vh; }
}

/* Aviso no canto (do TI OS) */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); background: var(--royal-escuro); color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: 90vw; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  border-left: 4px solid var(--laranja);
}
.toast.erro { background: #b91c1c; border-left-color: #fecaca; }

/* Telas medias: sem a coluna do contato (os botoes ficam no cabecalho). */
@media (max-width: 1280px) and (min-width: 901px) {
  .conv { grid-template-columns: 280px minmax(0, 1fr); }
  .conv > .lado-conv { display: none; }
}
@media (min-width: 1281px) { .so-estreito { display: none; } }

.bloco-menu > .row { grid-column: 2; }
.menu-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1100px) { .menu-grid { grid-template-columns: 1fr; } }

/* Logo da loja e alerta de conversa esperando atendente. */
.marca-logo { display: block; max-height: 44px; max-width: 180px; margin-bottom: 6px; background: #fff; border-radius: 6px; padding: 3px; }
.faixa-espera:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
.faixa-espera { position: fixed; top: 0; left: 0; right: 0; z-index: 50; display: block; padding: 10px 16px; text-align: center; font-weight: 700; color: #fff; text-decoration: none; background: #dc2626; animation: piscar-espera 1s steps(2, start) infinite; }
@keyframes piscar-espera { to { background: #f97316; } }
@media (prefers-reduced-motion: reduce) { .faixa-espera { animation: none; } }
.marca-icone { display: block; width: 40px; height: 40px; margin-bottom: 6px; }
