: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;
}
