/* ============================================================================
   CHAT CLIENTES — painel do admin (prefixo ac-).
   Layout: barra de topo + fila a esquerda (30%) + grade de atendimento
   com 4 caixas ocupando cerca de 70% da largura.
   Cores derivadas de --gold (acento do tema escolhido).
   ========================================================================== */

:root {
    --ac-accent: var(--gold, #9b4dff);
    --ac-accent-deep: color-mix(in srgb, var(--ac-accent) 58%, #000);
    --ac-accent-deeper: color-mix(in srgb, var(--ac-accent) 42%, #000);
    --ac-on-accent: #fff;
    --ac-accent-tint: color-mix(in srgb, var(--ac-accent) 14%, transparent);
    --ac-accent-line: color-mix(in srgb, var(--ac-accent) 45%, transparent);
    --ac-accent-glow: color-mix(in srgb, var(--ac-accent) 28%, transparent);

    --ac-text: var(--text-primary, #f3f3f6);
    --ac-text-soft: var(--text-secondary, #c9c4d2);
    --ac-text-muted: var(--text-muted, #8f879d);
    --ac-border: var(--border, rgba(255, 255, 255, 0.13));

    --ac-surface: rgba(255, 255, 255, 0.04);
    --ac-surface-hover: rgba(255, 255, 255, 0.09);
    --ac-bubble-in: rgba(255, 255, 255, 0.07);
    --ac-sunken: rgba(0, 0, 0, 0.22);
    --ac-scroll: rgba(255, 255, 255, 0.16);

    --ac-ok: #4ade80;
    --ac-warn: #fbbf24;
    --ac-danger: #f87171;
}

body[data-theme="light"] {
    --ac-surface: color-mix(in srgb, var(--ac-accent) 7%, transparent);
    --ac-surface-hover: color-mix(in srgb, var(--ac-accent) 15%, transparent);
    --ac-bubble-in: color-mix(in srgb, var(--ac-accent) 10%, transparent);
    --ac-sunken: color-mix(in srgb, var(--ac-accent) 9%, transparent);
    --ac-scroll: color-mix(in srgb, var(--ac-accent) 38%, transparent);
    --ac-ok: #15803d;
    --ac-warn: #b45309;
    --ac-danger: #b42318;
}

/* Esta pagina tem layout proprio de altura total (nao e o app-shell da SPA). */
html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
}

body {
    font-family: var(--font, 'Inter', -apple-system, sans-serif);
    color: var(--ac-text);
    background: var(--bg-primary, #030304);
}

.ac-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ------------------------------------------------------------- barra topo */
.ac-top {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--ac-border);
    background: var(--bg-secondary, #09090d);
}

.ac-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.ac-brand-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--ac-accent-deeper), var(--ac-accent-deep));
    color: var(--ac-on-accent);
    box-shadow: 0 0 18px var(--ac-accent-glow);
}

.ac-brand h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.ac-brand p {
    margin: 1px 0 0;
    font-size: 0.75rem;
    color: var(--ac-text-muted);
}

.ac-stats {
    display: flex;
    gap: 10px;
    margin-left: auto;
    flex-wrap: wrap;
}

.ac-stat {
    min-width: 92px;
    padding: 8px 13px;
    background: var(--ac-surface);
    border: 1px solid var(--ac-border);
    border-radius: 11px;
    text-align: center;
}

.ac-stat-value {
    display: block;
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--ac-text);
}

.ac-stat-label {
    display: block;
    margin-top: 2px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ac-text-muted);
}

.ac-stat.ac-hot .ac-stat-value { color: var(--ac-warn); }

.ac-ai-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    border: 1px solid var(--ac-border);
    color: var(--ac-text-muted);
    white-space: nowrap;
}

.ac-ai-pill .material-icons-round { font-size: 15px; }
.ac-ai-pill.ac-on { color: var(--ac-ok); border-color: color-mix(in srgb, var(--ac-ok) 45%, transparent); }
.ac-ai-pill.ac-off { color: var(--ac-warn); border-color: color-mix(in srgb, var(--ac-warn) 45%, transparent); }

/* ----------------------------------------------------------- corpo (2 col) */
.ac-main {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(260px, 30%) 1fr; /* fila 30% | atendimento ~70% */
    gap: 0;
}

/* ------------------------------------------------------------ coluna fila */
.ac-queue-col {
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--ac-border);
    background: var(--bg-secondary, #09090d);
}

.ac-queue-head {
    flex: 0 0 auto;
    padding: 15px 16px 12px;
    border-bottom: 1px solid var(--ac-border);
}

.ac-queue-head h2 {
    margin: 0 0 3px;
    font-size: 0.92rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 7px;
}

.ac-queue-head h2 .material-icons-round { font-size: 19px; color: var(--ac-accent); }

.ac-queue-head p {
    margin: 0 0 12px;
    font-size: 0.74rem;
    color: var(--ac-text-muted);
    line-height: 1.45;
}

/* botao ATENDER */
.ac-btn-attend {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--ac-accent-deeper), var(--ac-accent-deep));
    color: var(--ac-on-accent);
    border: 1px solid var(--ac-accent-line);
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 6px 20px var(--ac-accent-glow);
    transition: filter 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.ac-btn-attend:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.ac-btn-attend:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.ac-btn-attend .material-icons-round { font-size: 20px; }

.ac-queue-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.ac-queue-list::-webkit-scrollbar { width: 7px; }
.ac-queue-list::-webkit-scrollbar-thumb { background: var(--ac-scroll); border-radius: 4px; }

.ac-qitem {
    padding: 12px;
    background: var(--ac-surface);
    border: 1px solid var(--ac-border);
    border-radius: 11px;
}

.ac-qitem-top {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 7px;
}

.ac-qpos {
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ac-accent-tint);
    border: 1px solid var(--ac-accent-line);
    color: var(--ac-accent);
    font-size: 0.78rem;
    font-weight: 800;
}

body[data-theme="light"] .ac-qpos { color: var(--ac-accent-deep); }

.ac-qname {
    flex: 1;
    min-width: 0;
    font-size: 0.87rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-qwait {
    font-size: 0.7rem;
    color: var(--ac-warn);
    font-weight: 700;
    white-space: nowrap;
}

.ac-qmsg {
    margin: 0;
    font-size: 0.78rem;
    color: var(--ac-text-soft);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ac-qtags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }

.ac-tag {
    padding: 2px 8px;
    background: var(--ac-sunken);
    border: 1px solid var(--ac-border);
    border-radius: 999px;
    font-size: 0.66rem;
    color: var(--ac-text-muted);
    white-space: nowrap;
}

.ac-tag.ac-tag-alert { color: var(--ac-danger); border-color: color-mix(in srgb, var(--ac-danger) 40%, transparent); }
.ac-tag.ac-tag-eta { color: var(--ac-accent); border-color: var(--ac-accent-line); }
body[data-theme="light"] .ac-tag.ac-tag-eta { color: var(--ac-accent-deep); }

/* --------------------------------------------------- grade de atendimento */
.ac-grid-col {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary, #030304);
}

.ac-grid-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--ac-border);
}

.ac-grid-head h2 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 7px;
}

.ac-grid-head h2 .material-icons-round { font-size: 18px; color: var(--ac-accent); }

.ac-grid-actions { margin-left: auto; display: flex; gap: 8px; }

.ac-btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    background: transparent;
    border: 1px solid var(--ac-border);
    border-radius: 9px;
    color: var(--ac-text-soft);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ac-btn-ghost:hover { background: var(--ac-surface-hover); color: var(--ac-text); }
.ac-btn-ghost .material-icons-round { font-size: 16px; }

/* Grade 2x2: 4 caixas de conversa simultaneas. */
.ac-grid {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

/* ---------------------------------------------------------- caixa de chat */
.ac-box {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #09090d);
    border: 1px solid var(--ac-border);
    border-radius: 13px;
    overflow: hidden;
}

.ac-box.ac-box-active { border-color: var(--ac-accent-line); box-shadow: 0 0 0 1px var(--ac-accent-tint); }
.ac-box.ac-box-idle { border-color: color-mix(in srgb, var(--ac-warn) 50%, transparent); }

/* vaga vazia */
.ac-box-empty {
    align-items: center;
    justify-content: center;
    border-style: dashed;
    color: var(--ac-text-muted);
    gap: 8px;
    text-align: center;
    padding: 20px;
}

.ac-box-empty .material-icons-round { font-size: 34px; opacity: 0.4; }
.ac-box-empty p { margin: 0; font-size: 0.82rem; }
.ac-box-empty small { font-size: 0.72rem; opacity: 0.75; }

/* cabecalho da caixa */
.ac-box-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--ac-border);
    background: var(--ac-surface);
}

.ac-box-avatar {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ac-accent-tint);
    border: 1px solid var(--ac-accent-line);
    color: var(--ac-accent);
    font-size: 0.78rem;
    font-weight: 800;
}

body[data-theme="light"] .ac-box-avatar { color: var(--ac-accent-deep); }

.ac-box-who { flex: 1; min-width: 0; }

.ac-box-name {
    margin: 0;
    font-size: 0.83rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-box-meta {
    margin: 1px 0 0;
    font-size: 0.68rem;
    color: var(--ac-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-box-tools { display: flex; gap: 5px; flex: 0 0 auto; }

.ac-icon-btn {
    display: flex;
    padding: 5px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--ac-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.ac-icon-btn:hover { background: var(--ac-surface-hover); color: var(--ac-text); }
.ac-icon-btn .material-icons-round { font-size: 17px; }

.ac-btn-finish {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: color-mix(in srgb, var(--ac-ok) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--ac-ok) 45%, transparent);
    border-radius: 8px;
    color: var(--ac-ok);
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.ac-btn-finish:hover { background: color-mix(in srgb, var(--ac-ok) 26%, transparent); }
.ac-btn-finish .material-icons-round { font-size: 15px; }

/* aviso de inatividade na caixa */
.ac-box-idle-bar {
    flex: 0 0 auto;
    display: none;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    background: color-mix(in srgb, var(--ac-warn) 12%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--ac-warn) 40%, transparent);
    font-size: 0.72rem;
    color: var(--ac-warn);
}

.ac-box-idle-bar.ac-on { display: flex; }
.ac-box-idle-bar .material-icons-round { font-size: 15px; }

/* corpo da caixa */
.ac-box-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ac-box-body::-webkit-scrollbar { width: 6px; }
.ac-box-body::-webkit-scrollbar-thumb { background: var(--ac-scroll); border-radius: 3px; }

.ac-msg {
    max-width: 88%;
    padding: 8px 11px;
    border-radius: 11px;
    font-size: 0.8rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

/* admin (eu) a direita */
.ac-msg.ac-me {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--ac-accent-deeper), var(--ac-accent-deep));
    color: var(--ac-on-accent);
    border-bottom-right-radius: 4px;
}

/* cliente a esquerda */
.ac-msg.ac-client {
    align-self: flex-start;
    background: var(--ac-bubble-in);
    border: 1px solid var(--ac-border);
    color: var(--ac-text);
    border-bottom-left-radius: 4px;
}

/* IA */
.ac-msg.ac-ai {
    align-self: flex-start;
    background: var(--ac-sunken);
    border: 1px dashed var(--ac-border);
    color: var(--ac-text-soft);
    border-bottom-left-radius: 4px;
}

/* sistema */
.ac-msg.ac-sys {
    align-self: center;
    max-width: 96%;
    background: var(--ac-accent-tint);
    border: 1px solid var(--ac-accent-line);
    color: var(--ac-text-soft);
    font-size: 0.74rem;
}

.ac-msg-who {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    opacity: 0.7;
    margin-bottom: 2px;
}

.ac-msg-time { display: block; font-size: 0.63rem; opacity: 0.6; margin-top: 3px; text-align: right; }

/* Markdown renderizado dentro do balao (ver js/chat-format.js) */
.ac-msg strong { font-weight: 700; }
.ac-msg em { font-style: italic; }

.ac-msg code {
    padding: 1px 5px;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 5px;
    font-family: var(--font-mono, monospace);
    font-size: 0.92em;
}

body[data-theme="light"] .ac-msg code { background: rgba(0, 0, 0, 0.08); }
.ac-msg.ac-me code { background: rgba(0, 0, 0, 0.28); }

.ac-msg a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.ac-msg.ac-client a, .ac-msg.ac-ai a, .ac-msg.ac-sys a { color: var(--ac-accent); }
body[data-theme="light"] .ac-msg.ac-client a,
body[data-theme="light"] .ac-msg.ac-ai a,
body[data-theme="light"] .ac-msg.ac-sys a { color: var(--ac-accent-deep); }

/* composer da caixa */
.ac-box-composer {
    flex: 0 0 auto;
    display: flex;
    gap: 7px;
    padding: 9px 10px;
    border-top: 1px solid var(--ac-border);
    background: var(--ac-sunken);
}

.ac-box-input {
    flex: 1;
    min-height: 36px;
    max-height: 84px;
    padding: 9px 11px;
    background: var(--ac-surface);
    border: 1px solid var(--ac-border);
    border-radius: 9px;
    color: var(--ac-text);
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.4;
    resize: none;
    outline: none;
}

.ac-box-input:focus { border-color: var(--ac-accent); }
.ac-box-input::placeholder { color: var(--ac-text-muted); }

.ac-box-send {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    align-self: flex-end;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--ac-accent-deeper), var(--ac-accent-deep));
    color: var(--ac-on-accent);
    border: 1px solid var(--ac-accent-line);
    border-radius: 9px;
    cursor: pointer;
}

.ac-box-send:hover { filter: brightness(1.12); }
.ac-box-send .material-icons-round { font-size: 18px; }

/* --------------------------------------------------------------- toast */
.ac-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(16px);
    padding: 12px 20px;
    background: var(--bg-secondary, #09090d);
    border: 1px solid var(--ac-accent-line);
    border-radius: 11px;
    color: var(--ac-text);
    font-size: 0.85rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 9999;
}

.ac-toast.ac-on { opacity: 1; transform: translateX(-50%) translateY(0); }
.ac-toast.ac-err { border-color: color-mix(in srgb, var(--ac-danger) 55%, transparent); color: var(--ac-danger); }

/* --------------------------------------------------------------- modal */
.ac-modal {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.ac-modal.ac-on { display: flex; }

.ac-modal-card {
    width: 100%;
    max-width: 620px;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #09090d);
    border: 1px solid var(--ac-border);
    border-radius: 15px;
    overflow: hidden;
}

.ac-modal-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--ac-border);
}

.ac-modal-head h3 { margin: 0; font-size: 0.98rem; font-weight: 700; flex: 1; }
.ac-modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.ac-modal-body::-webkit-scrollbar { width: 7px; }
.ac-modal-body::-webkit-scrollbar-thumb { background: var(--ac-scroll); border-radius: 4px; }

.ac-kv { display: grid; grid-template-columns: minmax(150px, auto) 1fr; gap: 8px 14px; font-size: 0.84rem; }
.ac-kv dt { color: var(--ac-text-muted); }
.ac-kv dd { margin: 0; color: var(--ac-text); font-weight: 600; }

.ac-hist-item {
    padding: 11px 13px;
    background: var(--ac-surface);
    border: 1px solid var(--ac-border);
    border-radius: 10px;
    margin-bottom: 9px;
    font-size: 0.81rem;
}

.ac-hist-item-top { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.ac-hist-rate { font-size: 1rem; }
.ac-hist-rate.ac-up { color: var(--ac-ok); }
.ac-hist-rate.ac-down { color: var(--ac-danger); }

.ac-empty {
    padding: 34px 18px;
    text-align: center;
    color: var(--ac-text-muted);
    font-size: 0.85rem;
}

.ac-empty .material-icons-round { display: block; font-size: 38px; opacity: 0.35; margin-bottom: 9px; }

/* ----------------------------------------------------------- responsivo */
@media (max-width: 1100px) {
    .ac-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .ac-queue-col { border-right: none; border-bottom: 1px solid var(--ac-border); max-height: 38vh; }
    .ac-grid { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: minmax(300px, 1fr); overflow-y: auto; }
}

@media (max-width: 620px) {
    .ac-top { flex-wrap: wrap; }
    .ac-stats { width: 100%; margin-left: 0; }
    .ac-stat { flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .ac-btn-attend:hover { transform: none; }
    .ac-toast { transition: none; }
}

@supports not (color: color-mix(in srgb, red 50%, blue)) {
    :root {
        --ac-accent-deep: var(--ac-accent);
        --ac-accent-deeper: var(--ac-accent);
        --ac-accent-tint: rgba(127, 127, 127, 0.14);
        --ac-accent-line: rgba(127, 127, 127, 0.4);
        --ac-accent-glow: rgba(127, 127, 127, 0.25);
    }
}
