:root {
    --gold: #caa052;
    --gold-2: #f1cd7a;
    --dark: #101418;
    --dark-2: #171d23;
    --surface: #ffffff;
    --surface-2: #f6f2e9;
    --text: #1c1d20;
    --muted: #72757a;
    --border: rgba(202, 160, 82, .24);
    --danger: #b74242;
    --ok: #1f9d6a;
    --shadow: 0 24px 70px rgba(0,0,0,.18);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at top left, rgba(202,160,82,.22), transparent 34%), var(--surface-2); color: var(--text); }
button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.dark-mode, .app-body.dark-mode {
    --surface: #11171c;
    --surface-2: #0b0f13;
    --text: #f7eedb;
    --muted: #b6aa94;
    --border: rgba(241,205,122,.28);
    background: radial-gradient(circle at top left, rgba(202,160,82,.16), transparent 34%), linear-gradient(135deg, #07090b, #15191e);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.full { width: 100%; }

.glass-card {
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 24px;
    backdrop-filter: blur(18px);
}

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(430px, 100%); }
.login-card { padding: 34px; text-align: center; }
.login-logo { width: 155px; height: 155px; object-fit: contain; margin-bottom: 8px; border-radius: 50%; }
.login-card h1 { letter-spacing: 5px; margin: 4px 0 8px; color: var(--gold-2); }
.login-card p { margin-top: 0; color: var(--muted); }
.login-card form { text-align: left; display: grid; gap: 10px; margin: 22px 0; }
label { font-weight: 700; font-size: 13px; color: var(--gold); }
input, textarea, select {
    width: 100%; border: 1px solid var(--border); border-radius: 15px; padding: 13px 14px;
    background: color-mix(in srgb, var(--surface) 86%, #ffffff 14%); color: var(--text); outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(202,160,82,.13); }
.alert { padding: 12px 14px; border-radius: 14px; margin: 12px 0; }
.alert.error { background: rgba(183,66,66,.15); color: #ffb0b0; border: 1px solid rgba(183,66,66,.35); }
.alert.ok { background: rgba(31,157,106,.14); color: #b9f6d7; border: 1px solid rgba(31,157,106,.35); }

.btn {
    border: 1px solid var(--border); border-radius: 15px; padding: 12px 16px; cursor: pointer;
    background: color-mix(in srgb, var(--surface) 88%, var(--gold) 12%); color: var(--text); font-weight: 800;
    transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--gold); }
.btn.primary { background: linear-gradient(135deg, #a8752c, #f1cd7a); color: #101418; border: none; }
.btn.ghost { background: transparent; }
.btn.subtle { background: rgba(202,160,82,.08); text-align: center; display: inline-block; }
.btn.small { padding: 9px 12px; border-radius: 12px; font-size: 13px; }
.btn.tiny { padding: 8px 10px; border-radius: 11px; font-size: 12px; }
.btn.danger { color: #fff; background: var(--danger); border-color: rgba(255,255,255,.12); }

.app-body { min-height: 100vh; }
#app { display: grid; grid-template-columns: 292px minmax(0, 1fr); min-height: 100vh; }
.sidebar { padding: 22px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 72%, transparent); display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 13px; padding: 13px; border: 1px solid var(--border); border-radius: 22px; background: rgba(202,160,82,.08); }
.brand img { width: 58px; height: 58px; object-fit: contain; border-radius: 50%; }
.brand strong { display: block; color: var(--gold-2); letter-spacing: 2px; }
.brand small { color: var(--muted); font-weight: 800; font-size: 12px; }
.tabs { display: grid; gap: 9px; }
.tab { text-align: left; border: 1px solid transparent; background: transparent; color: var(--text); border-radius: 16px; padding: 13px 14px; cursor: pointer; font-weight: 800; }
.tab.active, .tab:hover { border-color: var(--border); background: rgba(202,160,82,.12); color: var(--gold-2); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }

.main-panel { padding: 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.user-pill { text-align: right; border: 1px solid var(--border); border-radius: 16px; padding: 10px 14px; background: rgba(202,160,82,.08); min-width: 150px; }
.user-pill span { display: block; font-weight: 800; }
.user-pill strong { color: var(--gold); font-size: 12px; }

.content-grid { display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 18px; height: calc(100vh - 124px); }
.list-panel, .chat-panel, .page-panel { padding: 18px; min-height: 0; }
.list-actions { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.list-actions.wide input { max-width: 540px; }
.conversation-list { display: grid; gap: 10px; overflow: auto; max-height: calc(100vh - 210px); padding-right: 4px; }
.conversation-item { border: 1px solid var(--border); border-radius: 18px; padding: 13px; cursor: pointer; background: rgba(202,160,82,.055); display: grid; gap: 7px; }
.conversation-item:hover, .conversation-item.active { border-color: var(--gold); background: rgba(202,160,82,.15); }
.conversation-item .row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.conversation-item strong { font-size: 15px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; background: rgba(202,160,82,.14); color: var(--gold-2); font-weight: 900; font-size: 11px; text-transform: uppercase; }
.badge.queue { color: #ffcc73; }
.badge.open { color: #78d6a9; }
.badge.closed { color: #d9a0a0; }
.last-message { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-panel { display: flex; flex-direction: column; }
.empty-state { margin: auto; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); }
.chat-box { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); padding-bottom: 14px; }
.chat-head h2 { margin: 0; }
.chat-head p { margin: 4px 0 0; color: var(--muted); }
.chat-head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.messages { flex: 1; overflow: auto; padding: 18px 4px; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: min(680px, 82%); padding: 12px 14px; border-radius: 18px; border: 1px solid var(--border); line-height: 1.38; }
.message.in { align-self: flex-start; background: color-mix(in srgb, var(--surface) 88%, #ffffff 12%); }
.message.out { align-self: flex-end; background: linear-gradient(135deg, rgba(168,117,44,.92), rgba(241,205,122,.92)); color: #121212; }
.message.redacted { filter: grayscale(.2); opacity: .68; font-weight: 900; }
.message small { display: block; margin-top: 7px; opacity: .68; font-size: 11px; }
.send-form { display: flex; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.send-form textarea { min-height: 48px; }

.page-panel { min-height: calc(100vh - 124px); }
.page-panel h2 { margin-top: 0; }
.form-grid { display: grid; gap: 12px; margin: 14px 0; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.four { grid-template-columns: 1.2fr 1fr 1fr 160px auto; align-items: end; }
.span-2 { grid-column: span 2; }
.selected-client-card { border: 1px dashed var(--border); border-radius: 18px; padding: 16px; min-height: 72px; display: grid; align-content: center; background: rgba(202,160,82,.06); }
.details-box { border: 1px solid var(--border); border-radius: 18px; padding: 14px; margin: 16px 0; }
.details-box summary { cursor: pointer; font-weight: 900; color: var(--gold); }
.start-form { display: grid; gap: 12px; max-width: 760px; }
.mini-results { display: grid; gap: 8px; margin-top: 8px; }
.mini-result { padding: 10px 12px; border: 1px solid var(--border); border-radius: 14px; cursor: pointer; background: rgba(202,160,82,.06); }
.mini-result:hover { border-color: var(--gold); }

.history-results { display: grid; gap: 12px; margin-top: 16px; }
.history-card { border: 1px solid var(--border); border-radius: 18px; padding: 14px; background: rgba(202,160,82,.06); }
.history-card header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.history-messages { display: grid; gap: 8px; }
.history-line { border-left: 3px solid var(--gold); padding: 8px 10px; background: color-mix(in srgb, var(--surface) 88%, transparent); border-radius: 10px; }
.history-line.redacted { border-left-color: var(--danger); font-weight: 900; color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; margin: 18px 0; }
.stat-card { border: 1px solid var(--border); border-radius: 20px; padding: 18px; background: rgba(202,160,82,.08); }
.stat-card span { color: var(--muted); font-weight: 800; }
.stat-card strong { display: block; font-size: 34px; color: var(--gold-2); margin-top: 6px; }
.dashboard-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.data-list { display: grid; gap: 9px; }
.data-row { border: 1px solid var(--border); border-radius: 16px; padding: 11px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: center; background: rgba(202,160,82,.055); }
.data-row div small { display: block; color: var(--muted); }

@media (max-width: 1060px) {
    #app { grid-template-columns: 1fr; }
    .sidebar { position: relative; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .tabs { grid-template-columns: repeat(2, 1fr); }
    .content-grid { grid-template-columns: 1fr; height: auto; }
    .conversation-list { max-height: 330px; }
    .chat-panel { min-height: 580px; }
    .form-grid.two, .form-grid.four, .dashboard-columns, .stats-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .user-pill { text-align: left; }
}

@media (max-width: 560px) {
    .main-panel, .sidebar { padding: 14px; }
    .tabs { grid-template-columns: 1fr; }
    .send-form { flex-direction: column; }
    .message { max-width: 94%; }
}

/* CHATPACK v2 - melhorias de atendimento, mídia e histórico */
.lock-line {
    display: inline-block;
    color: #ffcc73;
    font-size: 12px;
    font-weight: 900;
}
.unread-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    margin-right: 6px;
    background: var(--gold);
    color: #111;
    font-size: 11px;
    font-weight: 900;
}
.transfer-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
}
.transfer-wrap select {
    width: 210px;
    padding: 9px 10px;
    border-radius: 12px;
    font-size: 13px;
}
.send-input-wrap {
    flex: 1;
    display: grid;
    gap: 5px;
}
.file-picker {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 15px;
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    cursor: pointer;
    background: rgba(202,160,82,.08);
    font-size: 20px;
}
.file-picker input {
    display: none;
}
.media-preview {
    color: var(--gold-2);
    font-weight: 800;
    font-size: 12px;
}
.chat-media {
    display: block;
    max-width: min(340px, 100%);
    max-height: 360px;
    border-radius: 14px;
    border: 1px solid rgba(0,0,0,.12);
    object-fit: contain;
    background: rgba(255,255,255,.08);
}
.sticker-media {
    width: 150px;
    max-height: 150px;
    border: none;
    background: transparent;
}
.sticker-bubble {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none;
}
.chat-audio {
    width: min(320px, 100%);
    display: block;
}
.chat-video {
    width: min(360px, 100%);
    max-height: 360px;
    border-radius: 14px;
    display: block;
}
.file-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,.12);
    color: inherit;
    text-decoration: none;
    font-weight: 900;
}
.message-caption {
    margin-top: 8px;
    white-space: pre-wrap;
}
.history-chat.messages {
    max-height: 520px;
    overflow: auto;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(0,0,0,.06);
}
.client-warning {
    margin-top: 8px;
    display: inline-block;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 204, 115, .35);
    background: rgba(255, 204, 115, .10);
    color: #ffcc73;
    font-weight: 900;
}
@media (max-width: 560px) {
    .transfer-wrap { width: 100%; flex-direction: column; align-items: stretch; }
    .transfer-wrap select { width: 100%; }
    .file-picker { width: 100%; }
}

/* CHATPACK v3 */
.form-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.role-form { display: grid; gap: 18px; }
.permission-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-bottom: 12px; }
.perm-item { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,.04); font-size: .92rem; }
.perm-item input { width: auto; margin-top: 2px; }
.role-row button { align-self: center; }
.user-edit-grid { display: grid; grid-template-columns: 1.2fr 1fr 1.2fr 1fr .8fr 1fr auto; gap: 8px; width: 100%; align-items: center; }
.user-edit-row { display: block !important; }
.reaction-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; opacity: .95; }
.reaction-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.14); font-size: .78rem; }
.reaction-actions { display: inline-flex; gap: 2px; opacity: .18; transition: .2s; }
.message:hover .reaction-actions { opacity: 1; }
.reaction-btn { border: 0; background: transparent; border-radius: 999px; cursor: pointer; padding: 2px 4px; font-size: .9rem; }
.reaction-btn.active, .reaction-btn:hover { background: rgba(212,166,74,.24); }
.system-message { align-self: center !important; max-width: 86%; text-align: center; background: rgba(212,166,74,.14) !important; border: 1px solid rgba(212,166,74,.35); }
.modal { position: fixed; inset: 0; z-index: 9998; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.58); }
.modal.hidden { display: none !important; }
.modal-card { width: min(760px, 96vw); max-height: 88vh; overflow: auto; padding: 20px; }
.modal-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.note-form { display: grid; gap: 10px; margin-bottom: 18px; }
.notes-list { display: grid; gap: 10px; }
.note-item { padding: 12px; border: 1px solid var(--border); border-radius: 16px; background: rgba(255,255,255,.05); }
.note-item small { display: block; color: var(--muted); margin: 3px 0 8px; }
.note-item p { white-space: pre-wrap; margin: 0; }
.internal-grid { display: grid; grid-template-columns: 280px 1fr; gap: 18px; min-height: 560px; }
.internal-chat-box { display: grid; grid-template-rows: 1fr auto; gap: 12px; min-height: 560px; }
.internal-messages { min-height: 440px; max-height: 60vh; overflow: auto; }
.login-actions { display: flex; justify-content: center; margin-top: 10px; }
.link-button { background: none; border: 0; color: var(--gold); cursor: pointer; font-weight: 800; }
.reset-box { margin-top: 14px; display: grid; gap: 10px; }
@media (max-width: 1100px) {
  .form-grid.five, .user-edit-grid, .internal-grid { grid-template-columns: 1fr; }
  .internal-chat-box { min-height: 420px; }
}

/* =========================
   CHAT INTERNO MELHORADO
========================= */

.internal-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 18px;
    min-height: 620px;
}

.internal-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 620px;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 16px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.internal-start-box {
    display: grid;
    gap: 8px;
}

.internal-start-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.internal-thread-header {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 10px;
    padding-top: 6px;
}

.internal-thread-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: auto;
    padding-right: 4px;
}

.internal-thread {
    width: 100%;
    display: grid;
    grid-template-columns: 42px 1fr auto;
    gap: 10px;
    align-items: center;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    color: var(--text);
    cursor: pointer;
    transition: .18s ease;
}

.internal-thread:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--gold) 70%, var(--border));
    background: rgba(202,160,82,.09);
}

.internal-thread.active {
    border-color: var(--gold);
    background: rgba(202,160,82,.16);
    box-shadow: 0 12px 30px rgba(0,0,0,.10);
}

.internal-avatar {
    width: 42px;
    height: 42px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    font-weight: 900;
    background: linear-gradient(135deg, rgba(168,117,44,.95), rgba(241,205,122,.95));
    color: #121212;
}

.internal-thread-main {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.internal-thread-main strong,
.internal-thread-main span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.internal-thread-main span {
    color: var(--muted);
    font-size: 13px;
}

.internal-thread-meta {
    display: grid;
    justify-items: end;
    gap: 4px;
    min-width: 58px;
}

.internal-thread-meta small {
    color: var(--muted);
    font-size: 10px;
    max-width: 72px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.internal-unread {
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 900;
    background: var(--gold);
    color: #121212;
}

.internal-chat-box {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 12px;
    min-height: 620px;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 16px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.internal-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.internal-chat-header div {
    display: grid;
    gap: 2px;
}

.internal-messages {
    min-height: 460px;
    max-height: 62vh;
    overflow: auto;
    padding: 12px 4px;
}

.internal-empty {
    padding: 14px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    text-align: center;
}

/* =========================
   HISTÓRICO RECOLHIDO
========================= */

.history-card {
    padding: 0;
    overflow: hidden;
}

.history-toggle {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 16px;
    text-align: left;
}

.history-toggle:hover {
    background: rgba(202,160,82,.08);
}

.history-toggle-info {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.history-toggle-info strong,
.history-toggle-info small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-toggle-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.history-arrow {
    font-size: 13px;
    color: var(--gold);
    font-weight: 900;
}

.history-card.open {
    border-color: color-mix(in srgb, var(--gold) 70%, var(--border));
    box-shadow: 0 16px 40px rgba(0,0,0,.10);
}

.history-chat.messages {
    margin: 0 16px 16px;
    padding: 14px;
    min-height: 220px;
    max-height: 520px;
    overflow: auto;
    border-radius: 18px;
    background: color-mix(in srgb, var(--bg) 76%, transparent);
}

@media (max-width: 900px) {
    .internal-layout {
        grid-template-columns: 1fr;
    }

    .internal-sidebar,
    .internal-chat-box {
        min-height: auto;
    }

    .internal-messages {
        min-height: 360px;
    }

    .internal-start-row {
        grid-template-columns: 1fr;
    }
}

/* =========================
   CHATPACK v6 - ajustes solicitados
========================= */
html, body, #app { min-height: 100%; height: 100%; }
body.app-body { min-height: 100dvh; overflow: hidden; }
#app { height: 100dvh; max-height: 100dvh; }
.main-panel { min-height: 0; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.topbar { flex: 0 0 auto; }
.content-grid { flex: 1 1 auto; min-height: 0; height: auto; }
.list-panel, .chat-panel, .page-panel { min-height: 0; }
.conversation-list, .data-list, .history-results, .permission-grid, .roles-list, #usersList, #rolesList, #topUsers, #topSubjects, #servedClients { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--gold) 70%, transparent) transparent; }
.conversation-list { max-height: calc(100dvh - 190px); overflow-y: auto; padding-right: 4px; }
.messages { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--gold) 70%, transparent) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: rgba(255,255,255,.04); border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(202,160,82,.85), rgba(241,205,122,.55)); border-radius: 999px; border: 2px solid rgba(16,20,24,.28); }
*::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, rgba(241,205,122,.95), rgba(202,160,82,.8)); }

.dashboard-columns { align-items: start; }
.dashboard-columns > div { min-height: 0; }
.dashboard-columns .data-list, #usersList, #rolesList { max-height: min(520px, calc(100dvh - 330px)); overflow-y: auto; padding-right: 4px; }
#panelStats.page-panel, #usersPanel.page-panel, #rolesPanel.page-panel, #historyPanel.page-panel, #callPanel.page-panel { max-height: calc(100dvh - 110px); overflow-y: auto; }

.modern-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.actions-dropdown { position: relative; }
.actions-toggle { min-width: 46px; font-size: 18px; letter-spacing: 1px; border-radius: 14px; background: rgba(255,255,255,.09); border: 1px solid var(--border); }
.actions-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; display: none; padding: 8px; border: 1px solid var(--border); border-radius: 18px; background: color-mix(in srgb, var(--surface) 95%, transparent); box-shadow: var(--shadow); z-index: 40; }
.actions-dropdown:hover .actions-menu, .actions-dropdown:focus-within .actions-menu { display: grid; gap: 6px; }
.action-menu-btn { width: 100%; border: 0; border-radius: 13px; padding: 11px 12px; text-align: left; color: var(--text); background: transparent; font-weight: 800; cursor: pointer; }
.action-menu-btn:hover { background: rgba(202,160,82,.14); }
.action-menu-btn.hidden { display: none !important; }
.danger-text { color: var(--danger); }
.transfer-wrap { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 8px; align-items: center; padding: 6px; border: 1px solid var(--border); border-radius: 18px; background: rgba(255,255,255,.06); }
.transfer-wrap select { min-height: 40px; border-radius: 13px; }
.transfer-btn { border-radius: 13px; background: linear-gradient(135deg, rgba(202,160,82,.95), rgba(241,205,122,.9)); color: #141414; border: 0; box-shadow: 0 10px 26px rgba(202,160,82,.18); }

.reply-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 0; padding: 10px 12px; border-left: 4px solid var(--gold); border-radius: 16px; background: rgba(202,160,82,.13); }
.reply-preview div { display: grid; gap: 2px; min-width: 0; }
.reply-preview strong { font-size: 13px; }
.reply-preview span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview button { width: 30px; height: 30px; border-radius: 999px; border: 1px solid var(--border); background: rgba(255,255,255,.08); color: var(--text); cursor: pointer; font-size: 20px; }
.quoted-message { display: grid; gap: 3px; margin-bottom: 8px; padding: 8px 10px; border-left: 3px solid var(--gold); border-radius: 12px; background: rgba(0,0,0,.10); max-width: 100%; }
.quoted-message strong { font-size: 12px; color: var(--gold-2); }
.quoted-message span { font-size: 12px; color: color-mix(in srgb, var(--text) 72%, var(--muted)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.message-reply-btn { border: 0; border-radius: 999px; padding: 4px 9px; background: rgba(202,160,82,.16); color: var(--text); font-size: 11px; font-weight: 800; cursor: pointer; opacity: .65; }
.message:hover .message-reply-btn { opacity: 1; }
.message-reply-btn:hover { background: rgba(202,160,82,.28); }
.reaction-row, .reaction-actions, .reaction-chip, .reaction-btn { display: none !important; }

.data-row-button { width: 100%; color: var(--text); cursor: pointer; text-align: left; border: 1px solid var(--border); }
.data-row-button:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--gold) 70%, var(--border)); background: rgba(202,160,82,.10); }
.attendance-modal-card { width: min(1120px, 96vw); }
.attendance-modal-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; min-height: 520px; }
.attendance-list { display: grid; align-content: start; gap: 8px; overflow-y: auto; max-height: 64vh; padding-right: 4px; }
.attendance-item { display: grid; gap: 4px; width: 100%; text-align: left; padding: 12px; border-radius: 16px; border: 1px solid var(--border); background: rgba(255,255,255,.05); color: var(--text); cursor: pointer; }
.attendance-item:hover, .attendance-item.active { background: rgba(202,160,82,.14); border-color: var(--gold); }
.attendance-item span, .attendance-item small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attendance-messages { max-height: 64vh; min-height: 520px; overflow-y: auto; padding: 12px; border: 1px solid var(--border); border-radius: 18px; background: rgba(255,255,255,.035); }

@media (max-width: 980px) {
    body.app-body { overflow: auto; }
    #app { height: auto; min-height: 100dvh; display: block; }
    .sidebar { position: sticky; top: 0; z-index: 35; width: 100%; max-width: none; border-radius: 0 0 24px 24px; }
    .tabs { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 4px; }
    .tab { white-space: nowrap; min-width: fit-content; }
    .main-panel { height: auto; min-height: auto; overflow: visible; }
    .content-grid { grid-template-columns: 1fr; height: auto; }
    .conversation-list { max-height: 38dvh; }
    .chat-panel { min-height: 70dvh; }
    .chat-head { align-items: stretch; flex-direction: column; }
    .modern-actions { justify-content: stretch; }
    .transfer-wrap { width: 100%; grid-template-columns: 1fr; }
    .actions-dropdown { width: 100%; }
    .actions-toggle { width: 100%; }
    .actions-menu { position: static; margin-top: 8px; width: 100%; }
    .messages { max-height: 58dvh; }
    #panelStats.page-panel, #usersPanel.page-panel, #rolesPanel.page-panel, #historyPanel.page-panel, #callPanel.page-panel { max-height: none; overflow: visible; }
    .dashboard-columns .data-list, #usersList, #rolesList { max-height: 420px; }
    .attendance-modal-grid { grid-template-columns: 1fr; min-height: auto; }
    .attendance-list, .attendance-messages { max-height: 42vh; min-height: 260px; }
}

@media (max-width: 560px) {
    .topbar-actions { gap: 8px; }
    .topbar-actions .btn { height: 38px; padding: 0 12px; }
    .send-form { grid-template-columns: auto 1fr; }
    .send-form .btn.primary { grid-column: 1 / -1; width: 100%; }
    .message { max-width: 92%; }
    .modal { padding: 10px; }
    .modal-card { width: 100%; max-height: 92vh; padding: 14px; }
}

/* CHATPACK v7 - tema claro mais confortável estilo WhatsApp */
:root {
    --gold: #21a67a;
    --gold-2: #128c7e;
    --surface: #eef2ee;
    --surface-2: #dde5df;
    --text: #17221f;
    --muted: #63736d;
    --border: rgba(18, 140, 126, .22);
    --ok: #21a67a;
}
body { background: radial-gradient(circle at top left, rgba(37, 211, 102, .18), transparent 34%), linear-gradient(135deg, #dce7df, #eef2ee); }
.glass-card, .sidebar, .internal-sidebar, .internal-chat-box { background: color-mix(in srgb, var(--surface) 92%, transparent); }
.btn.primary { background: linear-gradient(135deg, #128c7e, #25d366); color: #06211a; border: none; }
.message.out { background: #d9fdd3; color: #17221f; border-color: rgba(18,140,126,.20); }
.message.in { background: #f7faf7; }
.conversation-item, .data-row, .stat-card, .selected-client-card, .mini-result, .history-card { background: rgba(37,211,102,.055); }
.conversation-item:hover, .conversation-item.active, .internal-thread.active { border-color: var(--gold); background: rgba(37,211,102,.13); }
.badge, .unread-dot, .internal-unread { background: rgba(37,211,102,.18); color: #075e54; }
.delivery-ticks { margin-left: 6px; font-weight: 900; letter-spacing: -2px; opacity: .75; }
.delivery-ticks.delivered { color: #128c7e; opacity: 1; }
.delivery-ticks.pending { letter-spacing: 0; }
.admin-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-card { border: 1px solid var(--border); border-radius: 22px; padding: 16px; background: color-mix(in srgb, var(--surface) 90%, transparent); box-shadow: 0 12px 34px rgba(0,0,0,.06); }
.admin-card.wide { grid-column: span 2; }
.admin-card h3 { margin-top: 0; color: var(--gold-2); }
.compact-form { align-items: end; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.notice-view { border: 1px solid var(--border); border-radius: 16px; padding: 14px; margin-bottom: 10px; background: rgba(37,211,102,.07); }
.notice-view h3 { margin: 0 0 8px; color: var(--gold-2); }
.notice-view p { white-space: pre-wrap; margin: 0 0 8px; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: color-mix(in srgb, var(--surface-2) 80%, transparent); border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--gold) 55%, #9aa 45%); border-radius: 999px; border: 2px solid var(--surface-2); }
*::-webkit-scrollbar-thumb:hover { background: var(--gold); }
@media (max-width: 900px) { .admin-card-grid, .admin-card.wide { grid-template-columns: 1fr; grid-column: span 1; } }

/* CHATPACK v7.1 - ajustes de badges, painel admin em modais e limite do chat interno */
.tab { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-badge {
    min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    background: #25d366; color: #063f32; font-size: 12px; font-weight: 950;
    box-shadow: 0 6px 16px rgba(37,211,102,.25);
}
.admin-home { max-height: calc(100dvh - 110px); overflow-y: auto; }
.admin-action-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 16px; margin-top: 18px; }
.admin-action-card {
    min-height: 150px; border: 1px solid var(--border); border-radius: 24px; padding: 18px;
    display: grid; align-content: center; justify-items: center; gap: 8px; text-align: center;
    background: color-mix(in srgb, var(--surface) 90%, #25d366 10%); color: var(--text); cursor: pointer;
    box-shadow: 0 14px 36px rgba(0,0,0,.07); transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.admin-action-card:hover { transform: translateY(-2px); border-color: var(--gold); background: rgba(37,211,102,.13); }
.admin-action-card span { font-size: 34px; line-height: 1; }
.admin-action-card strong { font-size: 16px; color: var(--gold-2); }
.admin-action-card small { color: var(--muted); font-weight: 700; }
.admin-modal-card { width: min(760px, 96vw); max-height: 88dvh; overflow-y: auto; }
.admin-modal-card.large { width: min(1100px, 96vw); }
.modal-scroll-list { max-height: 46dvh; overflow-y: auto; padding-right: 6px; }
.modal-scroll-list.short { max-height: 28dvh; }
.modal-permission-grid { max-height: 260px; overflow-y: auto; }
.admin-modal-card header { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--surface) 96%, transparent); padding-bottom: 10px; }
.internal-panel { height: calc(100dvh - 124px); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.internal-layout { flex: 1; min-height: 0; height: auto; }
.internal-chat-box { min-height: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.internal-messages { flex: 1; min-height: 0 !important; max-height: none !important; overflow-y: auto; }
.internal-sidebar { min-height: 0; max-height: 100%; overflow: hidden; }
.internal-thread-list { min-height: 0; overflow-y: auto; }
.internal-form, #internalForm { flex: 0 0 auto; }
@media (max-width: 1100px) { .admin-action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .admin-action-grid { grid-template-columns: 1fr; } .internal-panel { height: auto; overflow: visible; } }

/* CHATPACK v7.2 - módulo de clientes */
.panel-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel-head-row h2 { margin-bottom: 4px; }
.clients-panel { max-height: calc(100dvh - 110px); overflow-y: auto; }
.clients-list { max-height: calc(100dvh - 250px); overflow-y: auto; padding-right: 4px; }
.client-row { align-items: center; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.client-modal-card { width: min(980px, 96vw); }
.modal-actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.client-notes-view { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; }
.client-notes-view h3 { margin: 0 0 12px; color: var(--gold-2); }
.note-item { border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; background: rgba(202,160,82,.055); margin-bottom: 8px; }
.note-item p { margin: 6px 0; white-space: pre-wrap; }
.note-item small { color: var(--muted); }
@media (max-width: 760px) {
    .panel-head-row { flex-direction: column; }
    .client-row { align-items: stretch; flex-direction: column; }
    .row-actions { justify-content: flex-start; }
}

/* CHATPACK - correção de legibilidade das mensagens no tema dark */
.dark-mode .message,
.app-body.dark-mode .message {
    color: #eaf3ee;
    border-color: rgba(255,255,255,.10);
    box-shadow: 0 8px 22px rgba(0,0,0,.18);
}

.dark-mode .message.in,
.app-body.dark-mode .message.in {
    background: #1f2a30;
    color: #eef7f2;
    border-color: rgba(255,255,255,.12);
}

.dark-mode .message.out,
.app-body.dark-mode .message.out {
    background: #0f6b57;
    color: #f3fff9;
    border-color: rgba(37,211,102,.28);
}

.dark-mode .message small,
.app-body.dark-mode .message small,
.dark-mode .message-caption,
.app-body.dark-mode .message-caption {
    color: rgba(238,247,242,.76);
    opacity: 1;
}

.dark-mode .message.out small,
.app-body.dark-mode .message.out small,
.dark-mode .message.out .message-caption,
.app-body.dark-mode .message.out .message-caption {
    color: rgba(243,255,249,.78);
}

.dark-mode .quoted-message,
.app-body.dark-mode .quoted-message {
    background: rgba(255,255,255,.08);
    border-left-color: #25d366;
}

.dark-mode .quoted-message strong,
.app-body.dark-mode .quoted-message strong {
    color: #7ee7ad;
}

.dark-mode .quoted-message span,
.app-body.dark-mode .quoted-message span {
    color: rgba(238,247,242,.82);
}

.dark-mode .message-reply-btn,
.app-body.dark-mode .message-reply-btn {
    background: rgba(255,255,255,.10);
    color: #eef7f2;
}

.dark-mode .message-reply-btn:hover,
.app-body.dark-mode .message-reply-btn:hover {
    background: rgba(37,211,102,.20);
}

.dark-mode .delivery-ticks,
.app-body.dark-mode .delivery-ticks {
    color: rgba(243,255,249,.78);
}

.dark-mode .delivery-ticks.delivered,
.app-body.dark-mode .delivery-ticks.delivered {
    color: #7ee7ad;
}

/* CHATPACK v9 - etiquetas, SLA, fixados e dashboard gestor */
html, body { width: 100%; min-height: 100%; overflow-x: hidden; }
#app { min-height: 100svh; }
.main-panel { min-height: 100svh; max-height: 100svh; overflow: auto; }
.page-panel { max-height: calc(100svh - 118px); overflow: auto; }
#panelStats .dashboard-columns > div,
#topUsers, #topSubjects, #servedClients, #peakHours, #auditPreview {
    max-height: 360px;
    overflow: auto;
    padding-right: 5px;
}

/* Scroll moderno */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--gold) 78%, transparent) color-mix(in srgb, var(--surface) 82%, transparent); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: color-mix(in srgb, var(--surface) 82%, transparent); border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--gold), var(--gold-2)); border-radius: 999px; border: 2px solid color-mix(in srgb, var(--surface) 82%, transparent); }
*::-webkit-scrollbar-thumb:hover { background: var(--gold-2); }

.chat-tags,
.conversation-tags-inline,
.tag-list-modal {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 7px;
}
.tag-chip {
    --tag-color: var(--gold);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--tag-color) 22%, transparent);
    border: 1px solid color-mix(in srgb, var(--tag-color) 62%, transparent);
    color: var(--text);
    font-size: 12px;
    font-weight: 900;
}
.tag-chip::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tag-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--tag-color) 18%, transparent);
}
.tag-chip.tiny { font-size: 10px; padding: 3px 7px; }
.tag-chip.removable button {
    border: 0;
    background: rgba(0,0,0,.18);
    color: inherit;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 900;
}
.tiny-text { font-size: 11px; }
.soft-separator { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.conversation-item.pinned { border-color: color-mix(in srgb, var(--gold) 80%, var(--border)); background: rgba(202,160,82,.16); }
.pin-indicator { margin-right: 4px; filter: drop-shadow(0 3px 8px rgba(0,0,0,.22)); }
.conversation-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sla-pill {
    --sla-color: var(--gold);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 900;
    color: var(--text);
    background: color-mix(in srgb, var(--sla-color) 18%, transparent);
    border: 1px solid color-mix(in srgb, var(--sla-color) 55%, transparent);
    white-space: nowrap;
}
.sla-pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--sla-color); }
.pin-list-btn {
    width: 30px;
    height: 30px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(202,160,82,.08);
    cursor: pointer;
    transition: .18s ease;
}
.pin-list-btn:hover, .pin-list-btn.active { background: linear-gradient(135deg, #a8752c, #f1cd7a); transform: translateY(-1px); }

.stat-card-button {
    width: 100%;
    text-align: left;
    cursor: pointer;
    color: var(--text);
}
.stat-card-button small { color: var(--muted); font-weight: 800; }
.advanced-stats { margin: 18px 0; }
.productivity-table { overflow: auto; border: 1px solid var(--border); border-radius: 20px; }
.productivity-table table { width: 100%; border-collapse: collapse; min-width: 720px; }
.productivity-table th, .productivity-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
.productivity-table th { color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.productivity-table td small { display: block; color: var(--muted); margin-top: 2px; }
.audit-row { align-items: flex-start; }
.audit-row span { display: block; max-width: 720px; color: var(--muted); font-size: 12px; margin-top: 5px; word-break: break-word; }
.audit-row em { color: var(--gold); font-style: normal; font-size: 12px; white-space: nowrap; }

.tag-modal-card, .sla-modal-card { width: min(720px, calc(100vw - 28px)); }
.audit-modal-card { width: min(980px, calc(100vw - 28px)); }
.compact-form { align-items: end; }

@media (min-width: 1280px) {
    .content-grid { grid-template-columns: clamp(340px, 25vw, 430px) minmax(0, 1fr); }
    .message { max-width: min(760px, 76%); }
}

@media (max-width: 860px) {
    .main-panel { max-height: none; overflow: visible; }
    .page-panel { max-height: none; }
    #panelStats .dashboard-columns > div,
    #topUsers, #topSubjects, #servedClients, #peakHours, #auditPreview { max-height: 300px; }
    .chat-head { align-items: flex-start; flex-direction: column; }
    .chat-head-actions { width: 100%; justify-content: flex-start; }
    .conversation-foot { align-items: flex-start; flex-direction: column; }
}

/* Correção: lista de conversas não ultrapassar o painel */
.content-grid {
    overflow: hidden;
}

.list-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.list-actions {
    flex: 0 0 auto;
}

.conversation-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    align-content: start;
}

@media (max-width: 640px) {
    #app { display: block; }
    .sidebar { position: sticky; top: 0; z-index: 50; max-height: 46svh; overflow: auto; }
    .brand img { width: 46px; height: 46px; }
    .content-grid { gap: 12px; }
    .list-panel, .chat-panel, .page-panel { padding: 12px; border-radius: 18px; }
    .conversation-list { max-height: 34svh; }
    .messages { max-height: 56svh; }
    .chat-panel { min-height: 64svh; }
    .actions-menu { right: auto; left: 0; }
    .transfer-wrap { width: 100%; grid-template-columns: 1fr; }
    .dashboard-columns { grid-template-columns: 1fr !important; }
    .modal-card { width: calc(100vw - 18px); max-height: 92svh; overflow: auto; }
}

/* =========================
   CHATPACK v10 - Tema verde claro/dark baseado no novo login
   Cole este bloco no FINAL do app.css ou use este arquivo completo gerado.
========================= */
:root {
    --brand-950: #123d31;
    --brand-900: #18352c;
    --brand-850: #1d5a49;
    --brand-800: #22735b;
    --brand-700: #2f9870;
    --brand-600: #42b883;
    --brand-500: #65c99a;
    --brand-400: #9de8c7;
    --brand-300: #bff1d8;
    --brand-200: #dff8ec;
    --brand-100: #eefbf4;
    --brand-50: #f6fbf8;

    /* Mantém compatibilidade com o CSS antigo que usava gold */
    --gold: #22735b;
    --gold-2: #42b883;
    --dark: #123d31;
    --dark-2: #18352c;
    --bg: #f6fbf8;
    --surface: #ffffff;
    --surface-2: #eefbf4;
    --surface-3: #f8fdfb;
    --text: #18352c;
    --muted: #6d8178;
    --border: rgba(31, 98, 77, .14);
    --danger: #c84b4b;
    --ok: #42b883;
    --warning: #d79b32;
    --shadow: 0 26px 70px rgba(18, 61, 49, .13);
}

body {
    background:
        radial-gradient(circle at 10% 15%, rgba(157, 232, 199, .42), transparent 28%),
        radial-gradient(circle at 88% 8%, rgba(66, 184, 131, .18), transparent 30%),
        linear-gradient(135deg, #fbfffd 0%, #f6fbf8 48%, #eefbf4 100%);
    color: var(--text);
}

.app-body {
    background:
        radial-gradient(circle at 10% 15%, rgba(157, 232, 199, .42), transparent 28%),
        radial-gradient(circle at 88% 8%, rgba(66, 184, 131, .18), transparent 30%),
        linear-gradient(135deg, #fbfffd 0%, #f6fbf8 48%, #eefbf4 100%);
}

.dark-mode,
body.dark-mode,
.app-body.dark-mode {
    --gold: #9de8c7;
    --gold-2: #42b883;
    --dark: #07120f;
    --dark-2: #10231d;
    --bg: #07120f;
    --surface: #10201b;
    --surface-2: #07120f;
    --surface-3: #132a22;
    --text: #eaf8f1;
    --muted: #a5bbb2;
    --border: rgba(157, 232, 199, .18);
    --danger: #ff8f8f;
    --ok: #9de8c7;
    --warning: #ffd47c;
    --shadow: 0 28px 80px rgba(0, 0, 0, .38);
    background:
        radial-gradient(circle at 9% 12%, rgba(66, 184, 131, .20), transparent 29%),
        radial-gradient(circle at 88% 8%, rgba(157, 232, 199, .10), transparent 32%),
        linear-gradient(135deg, #07120f 0%, #0d1d18 48%, #10231d 100%);
    color: var(--text);
}

.glass-card,
.sidebar,
.list-panel,
.chat-panel,
.page-panel,
.internal-sidebar,
.internal-chat-box,
.admin-card,
.modal-card,
.admin-modal-card,
.client-modal-card,
.attendance-modal-card,
.tag-modal-card,
.sla-modal-card,
.audit-modal-card {
    background: color-mix(in srgb, var(--surface) 91%, transparent);
    border-color: var(--border);
    box-shadow: var(--shadow);
}

.dark-mode .glass-card,
.dark-mode .sidebar,
.dark-mode .list-panel,
.dark-mode .chat-panel,
.dark-mode .page-panel,
.dark-mode .internal-sidebar,
.dark-mode .internal-chat-box,
.dark-mode .admin-card,
.dark-mode .modal-card,
.dark-mode .admin-modal-card,
.dark-mode .client-modal-card,
.dark-mode .attendance-modal-card,
.dark-mode .tag-modal-card,
.dark-mode .sla-modal-card,
.dark-mode .audit-modal-card,
.app-body.dark-mode .glass-card,
.app-body.dark-mode .sidebar,
.app-body.dark-mode .list-panel,
.app-body.dark-mode .chat-panel,
.app-body.dark-mode .page-panel,
.app-body.dark-mode .internal-sidebar,
.app-body.dark-mode .internal-chat-box,
.app-body.dark-mode .admin-card,
.app-body.dark-mode .modal-card,
.app-body.dark-mode .admin-modal-card,
.app-body.dark-mode .client-modal-card,
.app-body.dark-mode .attendance-modal-card,
.app-body.dark-mode .tag-modal-card,
.app-body.dark-mode .sla-modal-card,
.app-body.dark-mode .audit-modal-card {
    background: rgba(16, 32, 27, .82);
    border-color: rgba(157, 232, 199, .16);
    box-shadow: 0 22px 70px rgba(0, 0, 0, .34);
}

.brand {
    background: linear-gradient(135deg, rgba(223, 248, 236, .90), rgba(255,255,255,.72));
    border-color: rgba(31, 98, 77, .16);
}

.brand strong,
.topbar h1,
.page-panel h2,
.admin-card h3,
.client-notes-view h3,
.notice-view h3 {
    color: var(--gold);
}

.dark-mode .brand,
.app-body.dark-mode .brand {
    background: linear-gradient(135deg, rgba(29, 90, 73, .42), rgba(16, 32, 27, .82));
    border-color: rgba(157, 232, 199, .16);
}

.dark-mode .brand strong,
.dark-mode .topbar h1,
.dark-mode .page-panel h2,
.dark-mode .admin-card h3,
.dark-mode .client-notes-view h3,
.dark-mode .notice-view h3,
.app-body.dark-mode .brand strong,
.app-body.dark-mode .topbar h1,
.app-body.dark-mode .page-panel h2,
.app-body.dark-mode .admin-card h3,
.app-body.dark-mode .client-notes-view h3,
.app-body.dark-mode .notice-view h3 {
    color: #9de8c7;
}

label,
.details-box summary,
.productivity-table th,
.audit-row em,
.link-button,
.history-arrow,
.quoted-message strong {
    color: var(--gold);
}

input,
textarea,
select {
    background: color-mix(in srgb, var(--surface) 92%, #ffffff 8%);
    color: var(--text);
    border-color: var(--border);
}

.dark-mode input,
.dark-mode textarea,
.dark-mode select,
.app-body.dark-mode input,
.app-body.dark-mode textarea,
.app-body.dark-mode select {
    background: rgba(255,255,255,.06);
    color: var(--text);
    border-color: rgba(157, 232, 199, .16);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(66, 184, 131, .15);
}

.btn {
    background: rgba(223, 248, 236, .70);
    border-color: var(--border);
    color: var(--text);
}

.btn:hover {
    border-color: var(--gold);
    background: rgba(157, 232, 199, .22);
}

.btn.primary,
.transfer-btn,
.pin-list-btn:hover,
.pin-list-btn.active {
    background: linear-gradient(135deg, #22735b, #42b883);
    color: #ffffff;
    border: 0;
    box-shadow: 0 16px 36px rgba(66, 184, 131, .26);
}

.dark-mode .btn,
.app-body.dark-mode .btn {
    background: rgba(255,255,255,.07);
    border-color: rgba(157, 232, 199, .16);
    color: var(--text);
}

.dark-mode .btn:hover,
.app-body.dark-mode .btn:hover {
    background: rgba(157, 232, 199, .12);
    border-color: rgba(157, 232, 199, .34);
}

.dark-mode .btn.primary,
.dark-mode .transfer-btn,
.dark-mode .pin-list-btn:hover,
.dark-mode .pin-list-btn.active,
.app-body.dark-mode .btn.primary,
.app-body.dark-mode .transfer-btn,
.app-body.dark-mode .pin-list-btn:hover,
.app-body.dark-mode .pin-list-btn.active {
    background: linear-gradient(135deg, #1d5a49, #42b883);
    color: #f4fff9;
    box-shadow: 0 18px 40px rgba(66, 184, 131, .18);
}

.btn.subtle,
.btn.ghost,
.file-picker,
.selected-client-card,
.details-box,
.notice-view,
.reply-preview,
.note-item,
.history-line,
.history-card,
.mini-result,
.stat-card,
.data-row,
.conversation-item,
.attendance-item,
.internal-thread,
.admin-action-card {
    background: rgba(66, 184, 131, .075);
    border-color: var(--border);
}

.dark-mode .btn.subtle,
.dark-mode .btn.ghost,
.dark-mode .file-picker,
.dark-mode .selected-client-card,
.dark-mode .details-box,
.dark-mode .notice-view,
.dark-mode .reply-preview,
.dark-mode .note-item,
.dark-mode .history-line,
.dark-mode .history-card,
.dark-mode .mini-result,
.dark-mode .stat-card,
.dark-mode .data-row,
.dark-mode .conversation-item,
.dark-mode .attendance-item,
.dark-mode .internal-thread,
.dark-mode .admin-action-card,
.app-body.dark-mode .btn.subtle,
.app-body.dark-mode .btn.ghost,
.app-body.dark-mode .file-picker,
.app-body.dark-mode .selected-client-card,
.app-body.dark-mode .details-box,
.app-body.dark-mode .notice-view,
.app-body.dark-mode .reply-preview,
.app-body.dark-mode .note-item,
.app-body.dark-mode .history-line,
.app-body.dark-mode .history-card,
.app-body.dark-mode .mini-result,
.app-body.dark-mode .stat-card,
.app-body.dark-mode .data-row,
.app-body.dark-mode .conversation-item,
.app-body.dark-mode .attendance-item,
.app-body.dark-mode .internal-thread,
.app-body.dark-mode .admin-action-card {
    background: rgba(157, 232, 199, .065);
    border-color: rgba(157, 232, 199, .15);
}

.tab.active,
.tab:hover,
.conversation-item:hover,
.conversation-item.active,
.conversation-item.pinned,
.internal-thread:hover,
.internal-thread.active,
.attendance-item:hover,
.attendance-item.active,
.data-row-button:hover,
.admin-action-card:hover,
.mini-result:hover,
.history-card.open {
    border-color: var(--gold);
    background: rgba(66, 184, 131, .13);
}

.dark-mode .tab.active,
.dark-mode .tab:hover,
.dark-mode .conversation-item:hover,
.dark-mode .conversation-item.active,
.dark-mode .conversation-item.pinned,
.dark-mode .internal-thread:hover,
.dark-mode .internal-thread.active,
.dark-mode .attendance-item:hover,
.dark-mode .attendance-item.active,
.dark-mode .data-row-button:hover,
.dark-mode .admin-action-card:hover,
.dark-mode .mini-result:hover,
.dark-mode .history-card.open,
.app-body.dark-mode .tab.active,
.app-body.dark-mode .tab:hover,
.app-body.dark-mode .conversation-item:hover,
.app-body.dark-mode .conversation-item.active,
.app-body.dark-mode .conversation-item.pinned,
.app-body.dark-mode .internal-thread:hover,
.app-body.dark-mode .internal-thread.active,
.app-body.dark-mode .attendance-item:hover,
.app-body.dark-mode .attendance-item.active,
.app-body.dark-mode .data-row-button:hover,
.app-body.dark-mode .admin-action-card:hover,
.app-body.dark-mode .mini-result:hover,
.app-body.dark-mode .history-card.open {
    border-color: #9de8c7;
    background: rgba(157, 232, 199, .11);
}

.badge,
.side-badge,
.unread-dot,
.internal-unread,
.sla-pill,
.tag-chip,
.reaction-chip {
    background: rgba(66, 184, 131, .16);
    color: #1d5a49;
    border-color: rgba(66, 184, 131, .24);
}

.dark-mode .badge,
.dark-mode .side-badge,
.dark-mode .unread-dot,
.dark-mode .internal-unread,
.dark-mode .sla-pill,
.dark-mode .tag-chip,
.dark-mode .reaction-chip,
.app-body.dark-mode .badge,
.app-body.dark-mode .side-badge,
.app-body.dark-mode .unread-dot,
.app-body.dark-mode .internal-unread,
.app-body.dark-mode .sla-pill,
.app-body.dark-mode .tag-chip,
.app-body.dark-mode .reaction-chip {
    background: rgba(157, 232, 199, .14);
    color: #dff8ec;
    border-color: rgba(157, 232, 199, .24);
}

.badge.queue,
.lock-line,
.client-warning {
    color: #b87914;
}

.badge.open {
    color: #22735b;
}

.badge.closed,
.danger-text {
    color: var(--danger);
}

.dark-mode .badge.queue,
.dark-mode .lock-line,
.dark-mode .client-warning,
.app-body.dark-mode .badge.queue,
.app-body.dark-mode .lock-line,
.app-body.dark-mode .client-warning {
    color: #ffd47c;
}

.dark-mode .badge.open,
.app-body.dark-mode .badge.open {
    color: #9de8c7;
}

.user-pill,
.transfer-wrap,
.actions-toggle,
.actions-menu,
.modal,
.attendance-messages,
.history-chat.messages,
.internal-empty,
.productivity-table {
    border-color: var(--border);
}

.user-pill,
.transfer-wrap,
.actions-toggle,
.actions-menu,
.attendance-messages,
.history-chat.messages,
.internal-empty {
    background: rgba(255,255,255,.55);
}

.dark-mode .user-pill,
.dark-mode .transfer-wrap,
.dark-mode .actions-toggle,
.dark-mode .actions-menu,
.dark-mode .attendance-messages,
.dark-mode .history-chat.messages,
.dark-mode .internal-empty,
.app-body.dark-mode .user-pill,
.app-body.dark-mode .transfer-wrap,
.app-body.dark-mode .actions-toggle,
.app-body.dark-mode .actions-menu,
.app-body.dark-mode .attendance-messages,
.app-body.dark-mode .history-chat.messages,
.app-body.dark-mode .internal-empty {
    background: rgba(255,255,255,.055);
    border-color: rgba(157, 232, 199, .16);
}

.action-menu-btn:hover,
.history-toggle:hover {
    background: rgba(66, 184, 131, .12);
}

.dark-mode .action-menu-btn:hover,
.dark-mode .history-toggle:hover,
.app-body.dark-mode .action-menu-btn:hover,
.app-body.dark-mode .history-toggle:hover {
    background: rgba(157, 232, 199, .10);
}

.message {
    border-color: var(--border);
    box-shadow: 0 8px 22px rgba(18, 61, 49, .08);
}

.message.in {
    background: #ffffff;
    color: #18352c;
}

.message.out {
    background: linear-gradient(135deg, #dff8ec, #bff1d8);
    color: #18352c;
    border-color: rgba(66, 184, 131, .24);
}

.dark-mode .message,
.app-body.dark-mode .message {
    color: #eaf8f1;
    border-color: rgba(157,232,199,.14);
    box-shadow: 0 10px 28px rgba(0,0,0,.22);
}

.dark-mode .message.in,
.app-body.dark-mode .message.in {
    background: #152822;
    color: #eaf8f1;
}

.dark-mode .message.out,
.app-body.dark-mode .message.out {
    background: linear-gradient(135deg, #1d5a49, #22735b);
    color: #f4fff9;
    border-color: rgba(157,232,199,.20);
}

.message small,
.message-caption,
.last-message,
.internal-thread-main span,
.internal-thread-meta small,
.attendance-item span,
.attendance-item small,
.data-row div small,
.note-item small,
.audit-row span,
.reply-preview span,
.quoted-message span {
    color: var(--muted);
}

.dark-mode .message.out small,
.dark-mode .message.out .message-caption,
.dark-mode .message.in small,
.dark-mode .message.in .message-caption,
.app-body.dark-mode .message.out small,
.app-body.dark-mode .message.out .message-caption,
.app-body.dark-mode .message.in small,
.app-body.dark-mode .message.in .message-caption {
    color: rgba(234, 248, 241, .76);
}

.quoted-message {
    background: rgba(66, 184, 131, .10);
    border-left-color: var(--gold);
}

.dark-mode .quoted-message,
.app-body.dark-mode .quoted-message {
    background: rgba(255,255,255,.07);
    border-left-color: #9de8c7;
}

.internal-avatar {
    background: linear-gradient(135deg, #22735b, #42b883);
    color: #ffffff;
}

.dark-mode .internal-avatar,
.app-body.dark-mode .internal-avatar {
    background: linear-gradient(135deg, #1d5a49, #9de8c7);
    color: #07120f;
}

.alert.error {
    background: rgba(200, 75, 75, .12);
    color: #b83f3f;
    border-color: rgba(200, 75, 75, .28);
}

.alert.ok {
    background: rgba(66,184,131,.13);
    color: #22735b;
    border-color: rgba(66,184,131,.28);
}

.dark-mode .alert.error,
.app-body.dark-mode .alert.error {
    background: rgba(255,143,143,.12);
    color: #ffc4c4;
    border-color: rgba(255,143,143,.28);
}

.dark-mode .alert.ok,
.app-body.dark-mode .alert.ok {
    background: rgba(157,232,199,.12);
    color: #9de8c7;
    border-color: rgba(157,232,199,.28);
}

.login-body:not(.dark-mode) {
    background:
        radial-gradient(circle at 10% 15%, rgba(157, 232, 199, .45), transparent 28%),
        radial-gradient(circle at 88% 8%, rgba(66, 184, 131, .18), transparent 30%),
        linear-gradient(135deg, #fbfffd 0%, #f6fbf8 48%, #eefbf4 100%);
}

.login-card h1 {
    color: var(--gold);
}

.login-logo {
    box-shadow: 0 16px 44px rgba(18, 61, 49, .12);
}

/* Scrollbar alinhado ao novo tema */
* {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--gold) 72%, transparent) color-mix(in srgb, var(--surface) 82%, transparent);
}

*::-webkit-scrollbar-track {
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--gold), var(--gold-2));
    border-radius: 999px;
    border: 2px solid color-mix(in srgb, var(--surface) 82%, transparent);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--gold-2);
}

@media (max-width: 980px) {
    .sidebar {
        background: color-mix(in srgb, var(--surface) 93%, transparent);
        backdrop-filter: blur(18px);
    }

    .dark-mode .sidebar,
    .app-body.dark-mode .sidebar {
        background: rgba(16,32,27,.94);
    }
}

/* CHATPACK v10 - filas e emojis */
.queue-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    background: rgba(202, 160, 82, .12);
    border: 1px solid rgba(202, 160, 82, .25);
    color: var(--text);
    margin-right: 6px;
}

.emoji-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.emoji-toggle {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    cursor: pointer;
    font-size: 20px;
}

.emoji-picker {
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    width: 240px;
    max-height: 220px;
    overflow: auto;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 10px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 20px 60px rgba(0,0,0,.22);
    z-index: 30;
}

.emoji-picker.hidden {
    display: none;
}

.emoji-option {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
}

.emoji-option:hover {
    background: rgba(202, 160, 82, .16);
}

.emoji-large {
    font-size: 24px;
    line-height: 1;
}

.queue-row span,
.emoji-row span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 780px) {
    .emoji-picker {
        left: -8px;
        width: 220px;
    }
}

/* =========================
   Correção Dark Mode: SELECTS e DROPDOWNS
========================= */

/* Todos os selects no tema dark */
.app-body.dark-mode select,
.dark-mode select {
    background-color: #1f332c !important;
    color: #f3fff8 !important;
    border: 1px solid rgba(130, 210, 170, .35) !important;
    box-shadow: none !important;
    text-shadow: none !important;
    color-scheme: dark;
}

/* Opções internas dos selects */
.app-body.dark-mode select option,
.dark-mode select option {
    background-color: #1f332c !important;
    color: #f3fff8 !important;
}

/* Hover/focus dos selects */
.app-body.dark-mode select:hover,
.app-body.dark-mode select:focus,
.dark-mode select:hover,
.dark-mode select:focus {
    background-color: #263d35 !important;
    color: #ffffff !important;
    border-color: rgba(86, 211, 151, .65) !important;
    outline: none !important;
}

/* Select desabilitado */
.app-body.dark-mode select:disabled,
.dark-mode select:disabled {
    background-color: #172821 !important;
    color: rgba(243, 255, 248, .55) !important;
    opacity: 1 !important;
}

/* Placeholder/primeira opção vazia, caso exista */
.app-body.dark-mode select option:disabled,
.dark-mode select option:disabled {
    color: rgba(243, 255, 248, .55) !important;
}

/* =========================
   Correção dropdown de ações
========================= */

.app-body.dark-mode .actions-dropdown,
.dark-mode .actions-dropdown {
    position: relative;
    z-index: 50;
}

/* Botão dos três pontinhos */
.app-body.dark-mode .actions-toggle,
.dark-mode .actions-toggle,
.app-body.dark-mode button.actions-toggle,
.dark-mode button.actions-toggle {
    background: #233a32 !important;
    color: #f3fff8 !important;
    border: 1px solid rgba(130, 210, 170, .35) !important;
    box-shadow: none !important;
    opacity: 1 !important;
}

/* Menu dropdown */
.app-body.dark-mode .actions-menu,
.dark-mode .actions-menu {
    background: #1b3028 !important;
    color: #f3fff8 !important;
    border: 1px solid rgba(130, 210, 170, .35) !important;
    box-shadow: 0 18px 45px rgba(0, 0, 0, .45) !important;
    backdrop-filter: none !important;
    opacity: 1 !important;
    z-index: 9999 !important;
}

/* Botões dentro do dropdown */
.app-body.dark-mode .actions-menu .action-menu-btn,
.dark-mode .actions-menu .action-menu-btn {
    background: transparent !important;
    color: #f3fff8 !important;
    opacity: 1 !important;
}

/* Hover nos itens */
.app-body.dark-mode .actions-menu .action-menu-btn:hover,
.dark-mode .actions-menu .action-menu-btn:hover {
    background: rgba(86, 211, 151, .16) !important;
    color: #ffffff !important;
}

/* Botão de perigo dentro do dropdown */
.app-body.dark-mode .actions-menu .danger-text,
.dark-mode .actions-menu .danger-text {
    color: #ff7777 !important;
}

/* Hover do botão de perigo */
.app-body.dark-mode .actions-menu .danger-text:hover,
.dark-mode .actions-menu .danger-text:hover {
    background: rgba(255, 80, 80, .14) !important;
    color: #ff9a9a !important;
}

/* Dropdowns genéricos que possam estar em cards de atendimento */
.app-body.dark-mode [class*="dropdown"] [class*="menu"],
.dark-mode [class*="dropdown"] [class*="menu"] {
    background-color: #1b3028 !important;
    color: #f3fff8 !important;
    border-color: rgba(130, 210, 170, .35) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
}


/* =========================
   Compactar cabeçalho / topbar
========================= */

.topbar {
    min-height: auto !important;
    padding: 4px 24px !important;
    gap: 12px !important;
}

.topbar-title h1 {
    font-size: 22px !important;
    line-height: 1.1 !important;
    margin: 0 !important;
}

.topbar-title p {
    font-size: 13px !important;
    line-height: 1.2 !important;
    margin: 4px 0 0 !important;
}

.topbar-actions {
    gap: 8px !important;
}

.user-pill {
    padding: 6px 10px !important;
    min-height: 44px !important;
}

.user-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 13px !important;
}

.user-info span {
    font-size: 13px !important;
    line-height: 1.1 !important;
}

.user-info strong {
    font-size: 11px !important;
    line-height: 1.1 !important;
}

.topbar-actions .btn {
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 14px !important;
    border-radius: 999px !important;
    font-size: 13px !important;
}

/* Botões menores: tema, perfil e sair */
#themeToggle,
#topbarProfileBtn {
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 13px !important;
}

/* Reduz espaço vertical abaixo do cabeçalho */
.main-panel {
    gap: 12px !important;
}

/* Mobile */
@media (max-width: 768px) {
    .topbar {
        padding: 10px 14px !important;
        gap: 10px !important;
    }

    .topbar-title h1 {
        font-size: 20px !important;
    }

    .topbar-title p {
        font-size: 12px !important;
    }

    .topbar-actions .btn {
        height: 36px !important;
        min-height: 36px !important;
        padding: 0 12px !important;
    }

    .user-pill {
        min-height: 40px !important;
        padding: 5px 9px !important;
    }
}