﻿@layer reset,
       design-system.tokens,
       design-system.base,
       design-system.layout,
       design-system.sidebar,
       design-system.components,
       design-system.tabs,
       design-system.utilities;

/* === core/reset.css === */
@layer reset {
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
}
/* === core/variables.css === */
@layer design-system.tokens {
  :root {
    /* FONTS */
    --font-base: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: "JetBrains Mono", Consolas, monospace;

    /* FONT SIZES (system-wide) */
    --font-size-xxs: 0.625rem;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.75rem;
    --font-size-4xl: 2rem;

    /* FONT WEIGHTS */
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;

    /* LINE HEIGHTS */
    --lh-tight: 1.2;
    --lh-normal: 1.5;

    /* RADII */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;

    /* SHADOWS */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.16);

    /* TRANSITIONS */
    --transition-fast: 0.15s;
    --transition-medium: 0.25s;

    /* SPACING */
    --space-xxs: 0.25rem; /* 4px */
    --space-xs: 0.5rem; /* 8px */
    --space-sm: 0.75rem; /* 12px */
    --space-md: 1rem; /* 16px */
    --space-lg: 1.5rem; /* 24px */
    --space-xl: 2rem; /* 32px */

    /* APP LAYOUT */
    --header-height: 60px;
    --sidebar-width: 72px;

    /* SIDEBAR TOKENS (Layout + Comportamento Visual) */
    --sidebar-icon-size: 1.2rem;
    --sidebar-font-size-label: 0.7rem;
    --sidebar-font-size-popout: 0.8rem;
    --sidebar-item-height: 32px;

    
  }
}
/* === core/colors.css === */
@layer design-system.tokens {
  /* PALETTE BASE (fallback) */
  :root {
    /* RGB BASE (usado em alerts com rgba) */
    --color-primary-rgb: 29, 78, 216;
    --color-success-rgb: 21, 128, 61;
    --color-warning-rgb: 180, 83, 9;
    --color-danger-rgb: 185, 28, 28;
    --color-green-500: #198754;
    --color-yellow-500: #ffc107;
    --color-red-500: #dc3545;
  }

  /* =========================
     THEME: LIGHT
     ========================= */
  body.theme-light {
    /* FUNDO BASE */
    --color-bg-app: #e6eaf0;
    --color-bg-surface: #dde3ea;
    --color-bg-muted: #cfd6df;

    /* TEXTO */
    --color-text-primary: #1f2a37;
    --color-text-secondary: #4b5563;
    --color-text-tertiary: #94a3b8;
    --color-text-inverse: #f1f5f9;

    /* BORDAS */
    --color-border-default: #b8c2cc;
    --color-border-subtle: #cbd5e1;

    /* PRIMARY */
    --color-primary: #2C7A7B; /* Verde-azulado */
    --color-primary-hover: #276D73;
    --color-primary-rgb: 44, 122, 123;

    /* OpÃ§Ãµes alternativas */
    /* --color-primary: #1E40AF;  Azul escuro clÃ¡ssico */
    /* --color-primary-hover: #1B3B9E; */
    /* --color-primary-rgb: 30, 64, 175; */
    /* --color-primary: #6B21A8;  Roxo profundo */
    /* --color-primary-hover: #581C87; */
    /* --color-primary-rgb: 107, 33, 168; */
    /* --color-primary: #D97706;  Ã‚mbar/laranja para destaque */
    /* --color-primary-hover: #B45309; */
    /* --color-primary-rgb: 217, 119, 6; */

    /* STATUS */
    --color-success: #15803d;
    --color-success-rgb: 21, 128, 61;
    --color-warning: #b45309;
    --color-warning-rgb: 180, 83, 9;
    --color-danger: #b91c1c;
    --color-danger-rgb: 185, 28, 28;

    /* TABELA: striped, hover e selecionado */
    --color-bg-muted-light: #e3e7ed;
    --color-bg-hover: #d2dae4;
    --color-bg-accent-light: #cfd6df;
  }

  /* =========================
     THEME: DARK
     ========================= */
  body.theme-dark {
    --color-bg-app: #111827;
    --color-bg-surface: #1f2937;
    --color-bg-muted: #1e293b;

    --color-text-primary: #f9fafb;
    --color-text-secondary: #9ca3af;
    --color-text-tertiary: #6b7280;
    --color-text-inverse: #000000;

    --color-border-default: #374151;
    --color-border-subtle: #4b5563;

    /* PRIMARY (mesma cor para consistÃªncia com light) */
    --color-primary: #2C7A7B; /* Verde-azulado */
    --color-primary-hover: #276D73;
    --color-primary-rgb: 44, 122, 123;

    /* OpÃ§Ãµes alternativas */
    /* --color-primary: #1E40AF; Azul escuro clÃ¡ssico */
    /* --color-primary-hover: #1B3B9E; */
    /* --color-primary-rgb: 30, 64, 175; */
    /* --color-primary: #6B21A8; Roxo profundo */
    /* --color-primary-hover: #581C87; */
    /* --color-primary-rgb: 107, 33, 168; */
    /* --color-primary: #D97706; Ã‚mbar/laranja */
    /* --color-primary-hover: #B45309; */
    /* --color-primary-rgb: 217, 119, 6; */

    /* STATUS */
    --color-success: var(--color-green-500);
    --color-success-rgb: 25, 135, 84;
    --color-warning: var(--color-yellow-500);
    --color-warning-rgb: 255, 193, 7;
    --color-danger: var(--color-red-500);
    --color-danger-rgb: 220, 53, 69;

    /* TABELA: striped, hover e selecionado */
    --color-bg-muted-light: #1e2937;
    --color-bg-hover: #273147;
    --color-bg-accent-light: #2c3a50;
  }
}
/* === core/typography.css === */
@layer design-system.tokens {
/* BASE */
body {
  font-family: var(--font-base);
  font-size: var(--font-size-sm);
  line-height: var(--lh-normal);
  font-weight: var(--fw-regular);
}

/* HEADINGS */
h1 {
  font-size: var(--font-size-4xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

h2 {
  font-size: var(--font-size-3xl);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-normal);
}

h3 {
  font-size: var(--font-size-2xl);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-normal);
}

h4 {
  font-size: var(--font-size-xl);
  font-weight: var(--fw-medium);
  line-height: var(--lh-normal);
}

h5 {
  font-size: var(--font-size-md);
  font-weight: var(--fw-medium);
  line-height: var(--lh-normal);
}

h6 {
  font-size: var(--font-size-sm);
  font-weight: var(--fw-medium);
  line-height: var(--lh-normal);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* TEXT */
p {
  margin-bottom: var(--space-md);
  font-size: var(--font-size-md);
  line-height: var(--lh-normal);
}

small,
.text-muted {
  font-size: var(--font-size-xs);
  line-height: var(--lh-normal);
  opacity: 0.75;
}

/* LABELS & UI TEXT */
label {
  font-size: var(--font-size-xs);
  font-weight: var(--fw-medium);
  line-height: var(--lh-normal);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* MONO (logs, ids, cÃ³digo) */
.text-mono {
  font-family: var(--font-mono);
  font-size: var(--font-size-xxs);
  line-height: var(--lh-normal);
}
}
/* === core/layers.css === */
@layer design-system.tokens {
:root {
  --z-root: 0;
  --z-content: 10;
  --z-dropdown: 500;

  --z-sidebar: 1000;
  --z-navbar: 1100;

  --z-backdrop: 1500;
  --z-modal-backdrop: 1900;
  --z-modal: 2000;
  --z-toast: 2100;
}
}
/* === core/base.css === */
@layer design-system.base {
  html, body {
    height: 100%;
    font-family: var(--font-base);
    font-size: 0.900rem;
    line-height: var(--lh-normal);
    font-weight: var(--fw-regular);
    color: var(--color-text-primary);
    background: var(--color-bg-app);
    -webkit-font-smoothing: antialiased;
    transition: background var(--transition-medium), color var(--transition-medium);
  }

  h1,h2,h3,h4,h5,h6 {
    color: var(--color-text-primary);
  }

  p, label, a, small {
    color: var(--color-text-primary);
  }

  a { text-decoration: none; transition: color var(--transition-fast); }
  a:hover { color: var(--color-primary-hover); }
}
/* === layout/app.css === */
@layer design-system.layout {
  html,
  body {
    height: 100dvh;
    width: 100vw;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  body.layout-app .app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas:
      "header header"
      "sidebar content";
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    transition: grid-template-columns var(--transition-medium) ease;
  }
  body.sidebar-closed .app-layout {
    grid-template-columns: 0px 1fr;
  }
  body.sidebar-closed #menu {
    display: none !important;
  }
  #header-container {
    grid-area: header;
    position: relative;
    z-index: var(--z-navbar);
  }
  #menu {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: var(--z-sidebar);
    height: 100%;
    min-height: 0;
  }
  .app-content {
    grid-area: content;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-app);
    overflow: hidden;
    position: relative;
    z-index: var(--z-content);
  }
  /* FIX CORRETO */
  .app-tabs-bar {
    display: flex;
    align-items: flex-end;
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border-default);
    gap: 2px;
    height: 40px;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden; /* trava vertical */
  }
  /* NÃƒO esconder scrollbar aqui */
  .tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    width: max-content;
    min-width: 60px;
    max-width: 200px;
    height: 32px;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    position: relative;
    top: 1px;
    white-space: nowrap;
    transition: all 0.2s ease;
  }
  .tab-item.active {
    background: var(--color-bg-app);
    height: 33px;
    z-index: 2;
    color: var(--color-primary);
    font-weight: 600;
    border-bottom: 1px solid var(--color-bg-app);
  }
  .tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #tab-content {
    flex: 1;
    position: relative;
    overflow: hidden;
  }
  .tab-pane {
    position: absolute;
    inset: 0;
    display: none;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .tab-pane.active {
    display: flex !important;
    flex-direction: column;
    animation: tab-fade-in 0.15s ease-out;
  }
  @keyframes tab-fade-in {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
/* === layout/login.css === */
@layer design-system.layout {

  .login-container {
    width: 100%;
    max-width: 300px;
    padding: var(--space-xl);
    background: var(--color-bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);

    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .login-header {
    text-align: center;
  }

  .login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .login-footer {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-top: var(--space-md);
  }

  .btn-block {
    width: 100%;
  }

  /* ==============================
     LOGIN ALERT (apenas layout)
  ============================== */

  .login-error {
    margin-bottom: var(--space-sm);
  }

  .login-form .alert {
    width: 100%;
  }
}
/* === layout/header.css === */
@layer design-system.layout {
  .app-header {
    height: var(--header-height);
    padding: 0 1.25rem;
    background: var(--color-bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    border-bottom: 1px solid var(--color-border-default);
    position: relative;
  }

  .header-left { 
    display: flex; 
    align-items: center; 
    gap: 1.5rem;
    flex: 1;
    min-width: 0;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
  }

  .user-avatar {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
  }

  .tenant-name {
    font-weight: 600;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
  }

  .header-search-toggle {
    display: none;
  }

  @media (max-width: 768px) {
    .tenant-name {
      display: none;
    }

    .user-name {
      display: none;
    }

    .header-search-toggle {
      display: inline-flex;
    }

    .ds-search-wrapper.ds-search-global {
      display: none;
    }

    .app-header {
      position: relative;
    }

    .app-header.search-open .ds-search-wrapper {
      display: flex;
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      align-items: center;
      padding: 0 8px;
      background: var(--color-bg-surface);
      z-index: 10;
    }

    .app-header.search-open .ds-search-input-container {
      width: 100%;
    }

    .app-header.search-open .ds-search-input {
      width: 100%;
    }

    .app-header.search-open .header-left > *:not(.ds-search-wrapper),
    .app-header.search-open .header-right {
      display: none !important;
    }
  }
}
/* === layout/chat.css === */
@layer design-system.layout {
  /* LAYOUT BASE */
  .chat-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow: hidden;
    background: var(--color-bg-app);
  }
  .chat-main {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--color-bg-app);
  }
  .chat-wrapper {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  .chat-alert-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    margin: 0 12px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius-md);
    color: #856404;
    font-size: 0.8rem;
    font-weight: var(--fw-medium, 500);
    white-space: pre-wrap;
  }
  .chat-alert-banner.hidden {
    display: none;
  }
  .chat-alert-dismiss:hover {
    opacity: 0.7;
  }

  .chat-messages-area {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  /* SIDEBAR ESQUERDA */
  .chat-sidebar {
    width: 350px;
    min-width: 350px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-surface);
    border-right: 1px solid var(--color-border-default);
    z-index: var(--z-content);
  }
  .chat-list-container {
    flex: 1;
    overflow-y: auto;
  }

  /* TICKET ITEM - NOVO LAYOUT */
  .ticket-item {
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border-default);
    cursor: pointer;
    background: var(--color-bg-surface);
    transition: background var(--transition-fast);
    user-select: none;
    display: flex;
    gap: 8px;
  }
  .ticket-item:hover {
    background: var(--color-bg-muted);
  }
  .ticket-item.active {
    background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg-surface));
    border-left: 3px solid var(--color-primary);
  }
  /* Lado esquerdo - info */
  .ticket-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .ticket-name {
    font-size: 0.8125rem;
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ticket-phone {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
  }
  .ticket-preview {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-style: italic;
  }
  /* Lado direito - aÃ§Ãµes/metadados */
  .ticket-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
  }
  .ticket-avatar-wrap {
    position: relative;
  }
  .ticket-channel-icon {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 0.7rem;
    background: var(--color-bg-surface);
    border-radius: 50%;
    padding: 2px;
    box-shadow: 0 0 0 1.5px var(--color-bg-surface);
    line-height: 1;
  }
  .ticket-channel-icon.whatsapp { color: #25D366; }
  .ticket-channel-icon.instagram { color: #E4405F; }
  .ticket-channel-icon.pabx { color: var(--color-text-secondary); }
  .ticket-priority-tag {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--color-bg-muted);
    color: var(--color-text-secondary);
    white-space: nowrap;
  }
  .btn-start-ticket {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.7rem;
    padding: 3px 10px;
    border: 1px solid var(--color-success);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-success);
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition:
      background var(--transition-fast),
      border var(--transition-fast),
      color var(--transition-fast);
  }
  .btn-start-ticket:hover {
    background: rgba(var(--color-success-rgb), 0.1);
    border-color: var(--color-success);
    color: var(--color-success);
  }
  .ticket-group-badge {
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: #f0ad4e;
    color: #fff;
    white-space: nowrap;
  }

  /* FILTER DROPDOWN */
  .chat-filter-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
  }
  .chat-filter-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: calc(var(--z-dropdown) + 100);
    padding: 8px 0;
    margin-top: 2px;
  }
  .filter-group {
    padding: 4px 12px;
  }
  .filter-group + .filter-group {
    border-top: 1px solid var(--color-border-default);
    margin-top: 4px;
    padding-top: 8px;
  }
  .filter-group-title {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: var(--fw-semibold);
    color: var(--color-text-secondary);
    margin-bottom: 4px;
  }
  .filter-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    padding: 3px 0;
    cursor: pointer;
    color: var(--color-text-primary);
  }
  .filter-option input[type="checkbox"] {
    accent-color: var(--color-primary);
  }
  .filter-tag-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    padding: 4px 12px;
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
  }
  .filter-tag-option:hover {
    background: var(--color-bg-muted);
  }
  .filter-tag-option input[type="checkbox"] {
    accent-color: var(--color-primary);
    flex-shrink: 0;
  }
  .filter-tag-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .filter-tag-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .filter-tags-placeholder {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    font-style: italic;
    padding: 4px 0;
  }
  .filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 6px 12px 2px;
    border-top: 1px solid var(--color-border-default);
    margin-top: 4px;
  }
  .filter-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    background: var(--color-bg-muted);
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    transition: background var(--transition-fast), color var(--transition-fast);
  }
  .filter-btn:hover {
    background: var(--color-bg-app);
    color: var(--color-text-primary);
  }
  .filter-btn.primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
  }
  .filter-btn.primary:hover {
    opacity: 0.9;
  }

  /* HEADER */
  .chat-header-main {
    flex-shrink: 0;
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border-default);
    z-index: var(--z-content);
  }
  .tenant-info-bar {
    font-size: 0.75rem;
    background: var(--color-bg-muted);
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
  }
  .ten-tag {
    border-right: 1px solid var(--color-border-default);
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .ten-tag span {
    opacity: 0.6;
    font-size: 0.7rem;
    text-transform: uppercase;
    flex-shrink: 0;
  }
  .ten-tag b {
    color: var(--color-text-primary);
    font-weight: var(--fw-semibold);
    font-size: 0.75rem;
  }

  /* FINISH DETAILS */
  .finish-details {
    flex-shrink: 0;
    background: var(--color-bg-surface);
    border-top: 2px solid var(--color-primary);
  }
  .finish-details-inner {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .finish-row {
    display: flex;
    gap: 16px;
  }
  .switch-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    cursor: pointer;
  }
  .switch-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
  }
  .finish-textarea {
    width: 100%;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: 6px 8px;
    font: inherit;
    font-size: 0.75rem;
    resize: vertical;
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
    box-sizing: border-box;
  }
  .finish-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .finish-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }

  /* MESSAGE TEXT WITH LINE BREAKS */
  .msg-text {
    white-space: pre-wrap;
    word-break: break-word;
  }
  .msg-audio, .msg-video {
    max-width: 100%;
    display: block;
    border-radius: var(--radius-md);
  }
  .msg-audio {
    height: 40px;
  }
  .msg-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: block;
  }
  .msg-media-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--color-bg-muted, #f3f4f6);
    border-radius: var(--radius-md, 8px);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: background 0.15s;
    max-width: 260px;
  }
  .msg-media-card:hover {
    background: var(--color-bg-surface-hover, #e5e7eb);
  }
  .msg-media-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    color: var(--color-primary, #4f46e5);
  }
  .msg-media-card-info {
    flex: 1;
    min-width: 0;
  }
  .msg-media-card-name {
    font-size: 0.75rem;
    color: var(--color-text-primary, #1f2937);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }
  /* STICKER */
  .msg-sticker {
    display: inline-flex;
    padding: 0;
    background: none;
    cursor: default;
    max-width: 160px;
  }
  .msg-sticker:hover {
    background: none;
  }
  .msg-sticker-img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: var(--radius-md, 8px);
  }
  /* LOCATION CARD */
  .msg-location-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    max-width: 260px;
  }
  .msg-location-icon {
    flex-shrink: 0;
    font-size: 1.3rem;
    color: #ea4335;
    margin-top: 2px;
  }
  .msg-location-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .msg-location-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-primary, #1f2937);
  }
  .msg-location-address {
    font-size: 0.7rem;
    color: var(--color-text-secondary, #6b7280);
  }
  .msg-location-link {
    font-size: 0.7rem;
    color: var(--color-primary, #4f46e5);
    text-decoration: none;
    margin-top: 2px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
  }
  .msg-location-link:hover {
    text-decoration: underline;
  }

  /* EVENT CARD */
  .msg-event-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    max-width: 280px;
  }
  .msg-event-icon {
    flex-shrink: 0;
    font-size: 1.2rem;
    color: var(--color-primary, #4f46e5);
    margin-top: 2px;
  }
  .msg-event-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .msg-event-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-primary, #1f2937);
  }
  .msg-event-desc {
    font-size: 0.7rem;
    color: var(--color-text-secondary, #6b7280);
    white-space: pre-wrap;
  }
  .msg-event-date {
    font-size: 0.7rem;
    color: var(--color-text-secondary, #6b7280);
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .msg-event-location {
    font-size: 0.7rem;
    color: var(--color-text-secondary, #6b7280);
    display: flex;
    align-items: center;
    gap: 4px;
  }
  /* REACTIONS */
  .msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 3px;
  }
  .msg-reaction {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    cursor: default;
    line-height: 1.4;
  }
  .msg-reaction.active {
    background: color-mix(in srgb, var(--color-primary) 12%, var(--color-bg-surface));
    border-color: var(--color-primary);
  }
  .msg-reaction .reaction-count {
    font-size: 0.6rem;
    color: var(--color-text-secondary);
  }
  .reaction-picker {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    display: flex;
    gap: 3px;
    padding: 5px 8px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: 999px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
  }
  .reaction-picker .reaction-emoji {
    font-size: 1.3rem;
    cursor: pointer;
    padding: 2px 3px;
    border-radius: 50%;
    transition: transform var(--transition-fast);
    line-height: 1;
  }
  .reaction-picker .reaction-emoji:hover {
    transform: scale(1.35);
  }

  /* MENSAGENS - BUBBLE LAYOUT */
  .msg-row {
    display: flex;
    margin-bottom: 6px;
    padding: 0 var(--space-md);
  }
  .msg-row.left {
    justify-content: flex-start;
  }
  .msg-row.right {
    justify-content: flex-end;
  }
  .msg-row.center {
    justify-content: center;
  }
  .msg-bubble {
    position: relative;
    max-width: 75%;
    border-radius: var(--radius-lg);
    font-size: 0.8125rem;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    padding: 7px 12px 5px 12px;
  }
  .msg-bubble.received {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    color: var(--color-text-primary);
    border-top-left-radius: 4px;
  }
  .msg-bubble.sent {
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-bg-surface));
    border: 1px solid color-mix(in srgb, var(--color-primary) 18%, var(--color-border-default));
    color: var(--color-text-primary);
    border-top-right-radius: 4px;
  }
  .msg-media-icon { font-size: 1rem; }

  /* META ROW - time + action buttons */
  .msg-meta-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    margin-top: 3px;
    min-height: 18px;
  }
  .msg-time,
  .msg-status {
    font-size: 0.65rem;
    color: var(--color-text-secondary);
  }
  .msg-reply-btn, .msg-react-btn {
    background: transparent;
    border: none;
    font-size: 0.8rem;
    padding: 2px 3px;
    cursor: pointer;
    color: var(--color-text-secondary);
    line-height: 1;
    border-radius: 4px;
    transition: color var(--transition-fast), background var(--transition-fast);
    opacity: 0.5;
  }
  .msg-bubble:hover .msg-reply-btn,
  .msg-bubble:hover .msg-react-btn {
    opacity: 1;
  }
  .msg-reply-btn:hover,
  .msg-react-btn:hover {
    color: var(--color-primary);
    background: var(--color-bg-muted);
    opacity: 1;
  }

  /* REACTION NOTICE */
  .msg-reaction-notice {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    padding: 2px 8px;
    background: var(--color-bg-muted);
    border-radius: 999px;
  }
  .msg-reaction-emoji {
    font-size: 0.9rem;
  }

  /* MENU / CONTEXT */
  .msg-menu-btn {
    position: absolute;
    top: 4px;
    right: 6px;
    background: transparent;
    border: none;
    font-size: 0.75rem;
    opacity: 0;
    cursor: pointer;
    color: inherit;
    z-index: 2;
  }
  .msg-bubble:hover .msg-menu-btn {
    opacity: 0.6;
  }
  .msg-menu-btn:hover {
    opacity: 1;
  }
  .msg-context-menu {
    position: fixed;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-toast);
    min-width: 160px;
    padding: 4px 0;
  }
  .msg-context-menu button {
    width: 100%;
    border: none;
    background: transparent;
    padding: 8px 12px;
    font: inherit;
    text-align: left;
    cursor: pointer;
    color: var(--color-text-primary);
  }
  .msg-context-menu button:hover {
    background: var(--color-bg-muted);
  }
  /* FOOTER */
  .chat-footer-main {
    background: var(--color-bg-surface);
    border-top: 1px solid var(--color-border-default);
    width: 100%;
    min-width: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
  }
  .input-group-styled {
    position: relative;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    padding: 6px 10px;
    gap: 8px;
    transition: border var(--transition-fast);
  }
  .input-group-styled:focus-within {
    border-color: var(--color-primary);
  }
  .input-group-styled textarea {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font: inherit;
    resize: none;
    max-height: 120px;
    min-height: 38px;
    line-height: var(--lh-normal);
    color: var(--color-text-primary);
  }
  .input-group-styled textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  /* SLASH COMMAND MENU */
  .slash-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
    margin-bottom: 4px;
  }
  .slash-option {
    padding: 6px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background var(--transition-fast);
  }
  .slash-option:hover,
  .slash-option.active {
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-bg-muted));
    color: var(--color-primary);
  }
  /* SIDEBAR DIREITA - ACTION SIDEBAR */
  .chat-actions {
    width: 310px;
    min-width: 310px;
    flex-shrink: 0;
    border-left: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }
  .action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: var(--space-xxs);
  }
  .action-grid button.full-width {
    grid-column: 1 / -1;
  }
  .action-grid-vertical {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-xxs);
  }
  @media (max-width: 480px) {
    .action-grid {
      grid-template-columns: 1fr;
    }
    .action-grid button.full-width {
      grid-column: 1 / -1;
    }
  }
  .panel-body {
    padding-top: var(--space-xxs);
    padding-bottom: var(--space-xxs);
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
  }
  .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-xxs) var(--space-sm);
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
    background: var(--color-bg-surface);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    user-select: none;
  }
  .panel-header .bi-chevron-down {
    transition: transform var(--transition-fast);
  }
  .action-panel.collapsed .panel-header .bi-chevron-down {
    transform: rotate(-90deg);
  }
  .action-panel.collapsed > .action-grid,
  .action-panel.collapsed > .action-grid-vertical,
  .action-panel.collapsed > .panel-finish-details,
  .action-panel.collapsed > .panel-action-area,
  .action-panel.collapsed .action-grid-vertical .panel-action-area {
    display: none;
  }
  .profile-block {
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-sm);
    margin-top: var(--space-sm);
  }
  .profile-title {
    font-size: 0.75rem;
    font-weight: var(--fw-semibold);
    margin-bottom: var(--space-xxs);
    color: var(--color-text-primary);
  }
  .profile-content {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
  }
  /* DS search wrapper full width */
  .chat-header .ds-search-wrapper {
    width: 100%;
    box-sizing: border-box;
    padding: 0;
    border-bottom: none !important;
    background: transparent;
  }
  .chat-header .ds-search-wrapper .ds-search-input {
    width: 100%;
    box-sizing: border-box;
    height: 30px;
    padding: 4px 28px 4px 30px;
    font-size: 0.75rem;
  }
  .chat-header .ds-search-wrapper .ds-search-icon {
    left: 8px;
    font-size: 0.8rem;
  }
  /* QUICK REPLIES BAR */
  .quick-replies-bar {
    display: none;
    gap: 4px;
    padding: 4px 8px;
    overflow-x: auto;
    background: var(--color-bg-muted);
    border-bottom: 1px solid var(--color-border-default);
  }
  .quick-replies-bar.visible {
    display: flex;
  }
  .quick-replies-bar .quick-reply-item {
    font-size: 0.7rem;
    padding: 4px 10px;
    flex-shrink: 0;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast), border var(--transition-fast);
    color: var(--color-text-primary);
  }
  .quick-replies-bar .quick-reply-item:hover {
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-bg-surface));
    border-color: var(--color-primary);
  }
  /* FINISH DETAILS IN SIDEBAR */
  .panel-finish-details {
    border-top: 1px solid var(--color-border-default);
    padding: var(--space-xs);
    background: var(--color-bg-muted);
  }
  .finish-details-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .finish-row {
    display: flex;
    gap: 12px;
  }
  .switch-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    cursor: pointer;
  }
  .switch-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
  }
  .finish-textarea {
    width: 100%;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: 6px 8px;
    font: inherit;
    font-size: 0.75rem;
    resize: vertical;
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    box-sizing: border-box;
  }
  .finish-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .finish-actions {
    display: flex;
    gap: 8px;
  }

  /* INLINE CUSTOMER EDIT */
  .customer-edit-area { padding: var(--space-sm); }
  .customer-edit-area .ds-field { margin-bottom: 6px; }
  .customer-edit-area label { font-size: 0.7rem; display: block; margin-bottom: 2px; color: var(--color-text-secondary); }
  .customer-edit-area input,
  .customer-edit-area textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: 4px 6px;
    font: inherit;
    font-size: 0.75rem;
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
  }
  .customer-edit-area input:focus,
  .customer-edit-area textarea:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .customer-edit-area .save-row {
    display: flex;
    gap: 4px;
    margin-top: 6px;
  }
  .customer-edit-area .save-row button {
    flex: 1;
    font-size: 0.7rem;
    padding: 4px 8px;
  }

  /* REPLY PREVIEW */
  .msg-reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--color-bg-muted);
    border-bottom: 1px solid var(--color-border-default);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
  }
  .msg-reply-preview.hidden { display: none; }
  .reply-preview-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .reply-preview-cancel {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    line-height: 1;
    padding: 0 2px;
  }
  .reply-preview-cancel:hover { color: var(--color-danger); }

  /* MESSAGE META ROW */
  .msg-meta-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
  }
  .msg-meta-row .msg-time {
    flex: 1;
  }

  /* REPLY & REACTION BUTTONS ON MESSAGES */
  .msg { position: relative; }
  .msg-reply-btn, .msg-react-btn {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: 4px;
    font-size: 0.75rem;
    padding: 2px 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
    color: var(--color-text-secondary);
    line-height: 1;
    z-index: 2;
  }
  .msg:hover .msg-reply-btn, .msg:hover .msg-react-btn { opacity: 1; }
  .msg-reply-btn:hover, .msg-react-btn:hover {
    background: var(--color-bg-muted);
    color: var(--color-primary);
  }

  /* REACTION NOTICE (inline in message flow) */
  .msg-reaction-notice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
    padding: 2px 10px;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    background: transparent;
    border: none;
  }
  .msg-reaction-notice .msg-time {
    font-size: 0.65rem;
  }
  .msg-reaction-notice-text {
    display: block;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    margin-top: 1px;
  }
  .msg-reaction-text {
    font-style: italic;
  }

  /* MEDIA PREVIEW OVERLAY */
  .media-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
  }
  .media-preview-modal {
    background: var(--color-bg-surface, #fff);
    border-radius: var(--radius-lg, 12px);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  }
  .media-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--color-border-default, #e0e0e0);
  }
  .media-preview-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-text-secondary, #666);
    line-height: 1;
  }
  .media-preview-body {
    flex: 1;
    overflow: auto;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
  }
  .media-preview-img {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
  }
  .media-preview-sticker-img {
    max-width: 256px;
    max-height: 256px;
    width: auto;
    height: auto;
    object-fit: contain;
  }
  .media-preview-audio {
    width: 100%;
  }
  .media-preview-video {
    max-width: 100%;
    max-height: 60vh;
  }
  .media-preview-pdf {
    width: 100%;
    height: 60vh;
    border: none;
  }
  .media-preview-file-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
    background: var(--color-bg-surface, #fff);
    border-radius: var(--radius-md, 8px);
  }
  .media-preview-file-icon {
    font-size: 2rem;
    color: var(--color-text-secondary, #666);
  }
  .media-preview-file-actions {
    display: flex;
    gap: 8px;
  }
  .media-preview-footer-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    justify-content: flex-end;
  }
  .msg-system-text {
    font-size: 0.75rem;
    color: var(--color-text-secondary, #6b7280);
    font-style: italic;
  }
  .media-preview-caption {
    width: 100%;
    border: 1px solid var(--color-border-default, #e0e0e0);
    border-radius: var(--radius-md, 8px);
    padding: 8px;
    font: inherit;
    font-size: 0.75rem;
    resize: none;
    box-sizing: border-box;
    background: var(--color-bg-muted, #f5f5f5);
    color: var(--color-text-primary, #333);
  }
  .media-preview-caption:focus {
    outline: none;
    border-color: var(--color-primary, #4f46e5);
  }
  .media-preview-footer {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .media-preview-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }

  /* REPLY QUOTE IN BUBBLE */
  .msg-reply-quote {
    padding: 6px 10px;
    margin-bottom: 4px;
    background: var(--color-bg-muted, #f0f0f0);
    border-left: 3px solid var(--color-primary, #4f46e5);
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--color-text-secondary, #666);
    cursor: pointer;
    transition: background var(--transition-fast);
  }
  .msg-reply-quote:hover {
    background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg-muted));
  }
  .msg-reply-quote-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
  }

  /* AUDIO RECORDING */
  .audio-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(220, 38, 38, 0.08);
  }
  .audio-controls.preview {
    background: rgba(22, 163, 74, 0.08);
  }
  .audio-controls .audio-timer {
    font-family: var(--font-mono, monospace);
    font-size: 0.8rem;
    font-weight: 600;
    color: #dc2626;
    min-width: 40px;
    text-align: center;
  }
  .audio-controls.preview .audio-timer {
    color: #16a34a;
  }
  .audio-controls .audio-btn {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    font-size: 0.85rem;
    transition: background var(--transition-fast);
    color: var(--color-text-secondary);
  }
  .audio-controls .audio-btn:hover {
    background: rgba(0,0,0,0.08);
  }
  .audio-controls .audio-btn[data-action="audio-cancel"] {
    color: #6b7280;
    font-size: 1rem;
  }
  .audio-controls .audio-btn[data-action="audio-pause-resume"],
  .audio-controls .audio-btn[data-action="audio-play-preview"] {
    color: #2563eb;
  }
  .audio-controls .audio-btn[data-action="audio-stop"] {
    color: #dc2626;
  }
  .audio-controls.preview .audio-btn[data-action="audio-send"] {
    color: #16a34a;
  }
  .audio-controls.preview .audio-btn[data-action="audio-play-preview"] {
    color: #16a34a;
  }
  .btn-audio {
    transition: all var(--transition-fast);
  }
  .btn-audio.recording {
    color: #dc2626 !important;
    background: rgba(220, 38, 38, 0.08);
    border-radius: 8px;
  }
  .btn-audio.preview {
    color: #16a34a !important;
    background: rgba(22, 163, 74, 0.08);
    border-radius: 8px;
  }

  /* AVATAR (chat header, ticket item, group sender) */
  .msg-avatar {
    border-radius: 50%;
    background: var(--color-bg-muted, #e5e7eb);
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    color: var(--color-text-primary, #1f2937);
    font-weight: 600;
    font-size: 0.75rem;
  }
  .msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  .msg-avatar-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
  }
  .msg-avatar.fallback .msg-avatar-fallback { display: flex; }
  .msg-avatar:not(.fallback) .msg-avatar-fallback { display: none; }

  /* TICKET ITEM AVATAR */
  .ticket-avatar-wrap {
    flex-shrink: 0;
    align-self: center;
    position: relative;
  }
  .avatar-new-dot {
    position: absolute;
    top: -2px;
    left: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--color-bg-surface, #fff);
    z-index: 2;
  }
  .chat-customer-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }

  /* CHAT HEADER - avatar inline */
  #chat-customer-name {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
  }

  /* GROUP MESSAGE - sender name on top of bubble */
  .msg-sender-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-primary, #2563eb);
    margin-bottom: 3px;
    padding-left: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
  }
  .msg-row.group.left {
    align-items: flex-end;
    gap: 6px;
  }
  .msg-row.left:not(.center) {
    align-items: flex-end;
  }
  .msg-row {
    align-items: flex-end;
  }

  /* BADGES */
  .badge-auto {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--color-primary, #2563eb) 12%, transparent);
    color: var(--color-primary, #2563eb);
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  .badge-group {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    background: color-mix(in srgb, #7c3aed 12%, transparent);
    color: #7c3aed;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  .badge-person {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    background: color-mix(in srgb, #64748b 12%, transparent);
    color: #64748b;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  /* CUSTOMER CELL WITH AVATAR */
  .customer-cell-name {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .customer-cell-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .customer-cell-text > span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* =========================================
     PRIORITY EAR CARD (ticket item)
     ========================================= */
  .ticket-item {
    position: relative;
    overflow: visible;
  }
  .priority-ear {
    position: absolute;
    right: -1px;
    bottom: 8px;
    padding: 2px 8px;
    border-radius: 4px 0 0 4px;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #fff;
    letter-spacing: 0.3px;
    z-index: 1;
    pointer-events: none;
    line-height: 1.4;
  }
  .priority-ear[data-prio="alta"]   { background: #da3737; }
  .priority-ear[data-prio="media"]  { background: #f58b00; }
  .priority-ear[data-prio="baixa"]  { background: #f0ad4e; color: #333; }
  .priority-ear[data-prio="comum"]  { background: #6c757d; }

  /* =========================================
     SIDEBAR EXPAND BUTTON (inside chat header, visible only when app sidebar is closed)
     ========================================= */
  .sidebar-expand-btn { display: none !important; width: 42px; flex: 0 0 42px !important; }
  body.sidebar-closed .sidebar-expand-btn { display: inline-flex !important; }
  @media (max-width: 1100px) {
    .chat-sidebar:not(.expanded) .sidebar-expand-btn { display: inline-flex !important; }
  }

  /* =========================================
     CONTATOS BUTTON (header)
     ========================================= */
  .chat-header {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 3px 6px;
    background: var(--color-bg-surface);
  }

  /* =========================================
     CONTACTS VIEW (left sidebar)
     ========================================= */
  .sidebar-contacts-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: var(--space-xs);
    gap: 6px;
  }
  .chat-filters-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0 3px;
  }
  .chat-filters-row-main {
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    display: flex;
    gap: 3px;
    border-bottom: 1px solid var(--color-border-default);
    padding-bottom: 3px;
  }
  .chat-filters-row #filter-reset-btn {
    flex-shrink: 0;
  }
  .chat-filters-row .fs-select {
    flex: 1;
    min-width: 0;
    padding: 5px 4px;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 0.75rem;
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
    box-sizing: border-box;
    cursor: pointer;
  }
  .chat-filters-row .fs-select:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .fs-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
  }
  .fs-input {
    width: 100%;
    padding: 5px 6px;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 0.75rem;
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
    box-sizing: border-box;
    cursor: text;
  }
  .fs-input:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .fs-input.filled {
    background: color-mix(in srgb, var(--color-primary) 6%, var(--color-bg-muted));
    border-color: var(--color-primary);
  }
  .fs-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
  }
  .fs-option {
    padding: 5px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fs-option:hover,
  .fs-option.highlighted {
    background: var(--color-bg-muted);
  }
  .fs-option.selected {
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-bg-surface));
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
  }
  .fs-no-results {
    padding: 8px;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    text-align: center;
  }
  .contacts-results {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    min-height: 0;
  }
  .contact-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
  }
  .contact-item:hover {
    background: var(--color-bg-muted);
  }
  .contact-item .contact-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-bg-muted);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    overflow: hidden;
  }
  .contact-item .contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .contact-item .contact-info {
    flex: 1;
    min-width: 0;
  }
  .contact-item .contact-name {
    font-size: 0.75rem;
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .contact-item .contact-phone {
    font-size: 0.65rem;
    color: var(--color-text-secondary);
  }
  .contact-item .contact-start-btn {
    flex-shrink: 0;
    font-size: 0.65rem;
    padding: 3px 8px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-primary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
  }
  .contact-item .contact-start-btn:hover {
    background: var(--color-primary);
    color: #fff;
  }
  .contacts-empty {
    padding: 12px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    font-style: italic;
  }
  .contacts-loading {
    padding: 12px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--color-text-secondary);
  }

  /* =========================================
     FINISH FORM (sidebar-actions)
     ========================================= */
  .panel-finish-details {
    overflow-y: auto;
  }
  .finish-details-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .ff-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .ff-label {
    font-size: 0.65rem;
    font-weight: var(--fw-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
  }
  .ff-required {
    color: #da3737;
  }
  .ff-hint {
    font-size: 0.6rem;
    color: #da3737;
    font-style: italic;
    margin-bottom: 2px;
  }
  .ff-input,
  .ff-select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: 0.7rem;
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
    box-sizing: border-box;
  }
  .ff-input:focus,
  .ff-select:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .ff-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  .ff-row {
    display: flex;
    gap: 6px;
  }
  .ff-col {
    flex: 1;
    min-width: 0;
  }

  /* TOGGLE SWITCH */
  .ff-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
  }
  .ff-switch input {
    opacity: 0;
    width: 0;
    height: 0;
  }
  .ff-slider {
    position: absolute;
    inset: 0;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-radius: 20px;
    transition: background 0.2s;
  }
  .ff-slider::before {
    content: "";
    position: absolute;
    left: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  }
  .ff-switch input:checked + .ff-slider {
    background: var(--color-primary);
    border-color: var(--color-primary);
  }
  .ff-switch input:checked + .ff-slider::before {
    transform: translateX(16px);
  }

  /* CHIPS (categorias) */
  .ff-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .ff-chip {
    font-size: 0.65rem;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-muted);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
  }
  .ff-chip:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
  }
  .ff-chip.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
  }

  /* ATTACH AREA */
  .ff-attach-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    border: 1px dashed var(--color-border-default);
    border-radius: var(--radius-md);
    background: var(--color-bg-muted);
    cursor: pointer;
    color: var(--color-text-secondary);
    font-size: 0.7rem;
    transition: border-color 0.15s, background 0.15s;
  }
  .ff-attach-area:hover {
    border-color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.04);
  }
  .ff-attach-area i {
    color: var(--color-text-secondary);
    font-size: 1.2rem;
  }
  .ff-actions {
    display: flex;
    gap: 6px;
    padding-top: 4px;
  }
  .ff-file-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .ff-file-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
  }
  .ff-file-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-primary);
  }
  .ff-file-item-size {
    font-size: 0.6rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
  }
  .ff-file-item-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
  }
  .ff-file-item-remove:hover {
    background: rgba(var(--color-danger-rgb, 239,68,68), 0.1);
    color: var(--color-danger);
  }
}

  /* =========================================
     ATTACH DROPDOWN - uses design-system dropdown
     ========================================= */
  .btn-attach-group {
    position: relative;
    display: flex;
    align-items: center;
  }
  .attach-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    min-width: 180px;
    margin-bottom: 4px;
    display: none;
  }
  .attach-dropdown.show {
    display: block !important;
  }
  .attach-dropdown.hidden {
    display: none !important;
  }
  .attach-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 0.75rem;
    color: var(--color-text-primary);
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    transition: background var(--transition-fast);
  }
  .attach-option:hover {
    background: var(--color-bg-muted);
    color: var(--color-primary);
  }
  .attach-option i {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
  }
  .attach-option:hover i {
    color: var(--color-primary);
  }

  /* =========================================
     CONTACT SEND OVERLAY (modal)
     ========================================= */


  /* =========================================
     CONTACT CARD (message bubble)
     ========================================= */
  .msg-contact-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-bg-muted);
    border-radius: var(--radius-md);
    cursor: default;
    max-width: 260px;
    position: relative;
  }
  .msg-contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
  }
  .msg-contact-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .msg-contact-name {
    font-size: 0.8rem;
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .msg-contact-phone-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
  }
  .msg-contact-phone {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .msg-contact-icon {
    font-size: 1.2rem;
    color: var(--color-text-secondary);
    flex-shrink: 0;
  }
  .msg-contact-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
  }
  .msg-contact-card:hover .msg-contact-actions {
    opacity: 1;
  }
  .msg-contact-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    background: var(--color-bg-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    transition: background var(--transition-fast), color var(--transition-fast);
  }
  .msg-contact-action-btn:hover {
    background: var(--color-bg-muted);
    color: var(--color-primary);
  }
}

/* unlayered overrides to beat design-system.components/tabs.css */
.chat-header .nav-tabs {
  flex: 1 1 auto;
  min-width: 0;
  padding-bottom: 0;
  align-items: center;
  display: flex;
  margin: 0;
  gap: 2px;
  border-bottom: none;
  position: relative;
}
#btn-contatos {
  flex: 0 0 auto;
}
.chat-tabs-center {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}
.chat-header .nav-tabs .nav-link {
  padding: 6px 8px;
  font-size: 0.65rem;
  white-space: nowrap;
  gap: 3px;
}
.chat-header .nav-tabs .nav-link.active {
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  background: transparent;
}
.chat-header .nav-tabs .nav-link.active::after {
  display: none;
}
.chat-tabs-center .nav-link {
  flex: 1;
}
.chat-tabs-center .nav-link:last-child,
.chat-tabs-center > .chat-filter-wrap:last-child .nav-link {
  flex: 0 0 auto;
  margin-left: auto;
}
.chat-header .nav-tabs .nav-link i {
  font-size: 0.85rem;
}
.chat-header .nav-tabs .tab-badge {
  padding: 1px 4px;
  margin-left: 2px;
  font-size: 0.6rem;
}
.chat-tabs-center > .chat-filter-wrap .btn-action.ghost.info.nav-link {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 0.75rem;
}
.chat-tabs-center > .chat-filter-wrap .btn-action.ghost.info.nav-link.active {
  background: rgba(var(--color-info-rgb, 59,130,246), 0.12);
  color: var(--color-info);
  border-color: var(--color-info);
}

.load-more-btn {
  width: 100%;
}

/* Responsive sidebars */
@media (max-width: 1100px) {
  .chat-sidebar { width: 56px; min-width: 56px; overflow: hidden; }
  .chat-sidebar .chat-header .nav-tabs .nav-link .nav-label,
  .chat-sidebar .chat-header .nav-tabs .nav-link .tab-badge,
  .chat-sidebar .chat-header #chat-search-input,
  .chat-sidebar .chat-header .chat-filters-row,
  .chat-sidebar .chat-header .ds-search-wrapper { display: none !important; }
  .chat-sidebar .ticket-item .ticket-info { display: none; }
  .chat-sidebar .ticket-item .ticket-actions { display: none; }
  .chat-sidebar .ticket-item { justify-content: center; padding: 8px 4px; }
  .chat-sidebar .ticket-avatar-wrap { margin: 0; }
  .chat-sidebar.expanded { width: 350px; min-width: 350px; overflow-y: auto; }
  .chat-sidebar.expanded .chat-header .nav-tabs .nav-link .nav-label,
  .chat-sidebar.expanded .chat-header .nav-tabs .nav-link .tab-badge,
  .chat-sidebar.expanded .chat-header #chat-search-input,
  .chat-sidebar.expanded .chat-header .chat-filters-row,
  .chat-sidebar.expanded .chat-header .ds-search-wrapper { display: flex !important; }
  .chat-sidebar.expanded .ticket-item .ticket-info,
  .chat-sidebar.expanded .ticket-item .ticket-actions { display: flex; }
  .chat-sidebar.expanded .ticket-item { justify-content: normal; padding: 8px 10px; }

  .chat-actions { width: 48px; min-width: 48px; overflow: hidden; }
  .chat-actions .action-panel .panel-header .section-title,
  .chat-actions .action-panel .panel-header .bi-chevron-down,
  .chat-actions .action-grid button .action-label,
  .chat-actions .panel-finish-details,
  .chat-actions .panel-action-area { display: none !important; }
  .chat-actions .action-panel .panel-header { justify-content: center; padding: 8px 4px; }
  .chat-actions .action-panel .panel-header .section-icon { font-size: 1.2rem; }
  .chat-actions .action-grid { grid-template-columns: 1fr; gap: 2px; padding: 2px; }
  .chat-actions .action-grid button { padding: 4px; justify-content: center; min-width: 0; font-size: 0.7rem; }
  .chat-actions .action-grid button i { margin: 0; font-size: 1rem; }
  .chat-actions .action-grid button.full-width { grid-column: 1 / -1; }
  .chat-actions.expanded { width: 310px; min-width: 310px; overflow-y: auto; }
  .chat-actions.expanded .action-panel .panel-header .section-title,
  .chat-actions.expanded .action-panel .panel-header .bi-chevron-down,
  .chat-actions.expanded .action-grid button .action-label,
  .chat-actions.expanded .panel-finish-details,
  .chat-actions.expanded .panel-action-area { display: flex !important; }
  .chat-actions.expanded .action-panel .panel-header .section-icon { display: none !important; }
  .chat-actions.expanded .action-panel .panel-header { justify-content: space-between; padding: var(--space-xxs) var(--space-sm); }
  .chat-actions.expanded .action-grid { grid-template-columns: repeat(2, 1fr); gap: 4px; padding: var(--space-xxs); }
  .chat-actions.expanded .action-grid button { font-size: inherit; padding: inherit; justify-content: inherit; min-width: inherit; }
  .chat-actions.expanded .action-grid button i { margin: inherit; font-size: inherit; }
  .chat-actions.expanded .action-grid button.full-width { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .chat-header-main .ten-tag { padding: 3px 6px; }
  .chat-header-main .ten-tag span { display: none; }
  .chat-header-main .ten-tag b { font-size: 0.65rem; }
  .chat-footer-main .input-group-styled { padding: 4px 6px; gap: 4px; }
}
/* === layout/views.css === */
@layer design-system.layout {
  .view-container {
    height: 100%;
    position: relative; /* base do overlay */
  }

  .view-actions {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
  }

  .view-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
  }

  .view-centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: var(--space-md);
  }

  /* =========================
     TOKENS DE OVERLAY
     ========================= */

  :root {
    --overlay-bg: rgba(0, 0, 0, 0.12);
  }

  body.theme-dark {
    --overlay-bg: rgba(0, 0, 0, 0.4);
  }

  /* =========================
     VIEW LOADING OVERLAY
     ========================= */

  .view-loading {
    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--overlay-bg);
    backdrop-filter: blur(3px);

    z-index: 50;
  }

  .view-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);

    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
  }

  /* Spinner integrado ao design system */
  .view-loading .spinner {
    width: 28px;
    height: 28px;

    border: 3px solid var(--color-border-default);
    border-top-color: var(--color-primary);

    border-radius: 50%;
    animation: view-spin 0.7s linear infinite;
  }

  @keyframes view-spin {
    to {
      transform: rotate(360deg);
    }
  }

  .tenant-view {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    width: 100%;
    font-family:
      system-ui,
      -apple-system,
      sans-serif;
    background: var(--color-bg-app);
  }

  .tenant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    flex: 0 0 auto;
  }

  .tenant-header h1 {
    font-size: 1.2rem;
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
  }

  .tenant-search-block {
    position: relative;
  }

  .tenant-search-block input {
    padding: 6px 30px 6px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-default);
    font-size: 0.85rem;
    width: 220px;
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
  }

  .tenant-search-block .input-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    color: var(--color-text-secondary);
    pointer-events: none;
  }

  .tenant-msg {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    color: var(--color-text-inverse);
    background: var(--color-danger);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    display: none;
  }
}
/* === layout/dashboard.css === */
@layer design-system.layout {
  /* DASHBOARD ROOT */
  .dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-height: 100%;
  }
  /* HEADER */
  .dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
  }
  .dashboard-header h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--fw-semibold);
    margin: 0;
  }
  .dashboard-sub {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
  }
  .dashboard-sub .sep {
    opacity: 0.5;
  }
  /* GRID SYSTEM */
  .dashboard-row {
    display: grid;
    gap: var(--space-md);
  }
  .dashboard-row.grid-2 {
    grid-template-columns: 2fr 1fr;
  }
  .dashboard-row.grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .dashboard-row.grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
  /* CARDS (WRAPPER DE WIDGET) */
  .dashboard .card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    position: relative;
    overflow: hidden;
    transition:
      transform var(--transition-fast),
      box-shadow var(--transition-fast),
      border-color var(--transition-fast);
  }
  .dashboard .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
  /* KPI GRID */
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-sm);
  }
  .kpi-card {
    background: var(--color-bg-muted);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: background var(--transition-fast);
  }
  .kpi-card:hover {
    background: var(--color-bg-hover);
  }
  .kpi-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
  }
  .kpi-value {
    font-size: var(--font-size-lg);
    font-weight: var(--fw-bold);
    color: var(--color-text-primary);
  }
  /* TICKETS / LISTAS */
  .ticket-row {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--color-border-default);
    transition:
      background var(--transition-fast),
      transform var(--transition-fast);
  }
  .ticket-row:hover {
    background: var(--color-bg-hover);
  }
  .ticket-row.live {
    animation: dashboardFadeIn 0.25s ease;
  }
  /* EMPTY STATE */
  .dashboard-empty {
    text-align: center;
    padding: var(--space-lg);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
  }
  /* WIDGET LOADING (LOCAL) */
  .widget-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--color-primary-rgb), 0.05);
    backdrop-filter: blur(2px);
    z-index: 2;
  }
  /* ANIMATIONS */
  @keyframes dashboardFadeIn {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  /* MONITOR DASHBOARD */
  .monitor-view .dashboard {
    padding: var(--space-md);
  }
  .monitor-view .dashboard-header {
    margin-bottom: var(--space-sm);
  }
  .monitor-header-actions {
    display: flex;
    gap: var(--space-xs);
  }
  .monitor-last-refresh {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    opacity: 0.7;
  }
  .monitor-kpi-row {
    margin-bottom: var(--space-sm);
  }
  .monitor-kpi .kpi-label {
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .monitor-kpi .kpi-label i {
    font-size: 0.75rem;
  }
  .monitor-kpi .kpi-value {
    font-size: var(--font-size-xl);
  }
  .kpi-waiting .kpi-value { color: var(--color-warning, #f59e0b); }
  .kpi-ongoing .kpi-value { color: var(--color-info, #3b82f6); }
  .kpi-resolved .kpi-value { color: var(--color-success, #22c55e); }
  .kpi-agents .kpi-value { color: var(--color-text-primary); }
  .kpi-alerts .kpi-value { color: var(--color-danger, #ef4444); }
  .kpi-alerts.has-alerts {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.3);
    animation: monitorPulse 2s ease-in-out infinite;
  }
  @keyframes monitorPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.2); }
    50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
  }
  /* Main grid */
  .monitor-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    flex: 1;
    min-height: 0;
  }
  .monitor-bottom {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
  }
  .monitor-card .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
  }
  .monitor-card .card-header h5 {
    margin: 0;
    font-size: var(--font-size-sm);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .monitor-card .card-header h5 i {
    font-size: 0.85rem;
    opacity: 0.7;
  }
  .monitor-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    font-size: var(--font-size-xs);
    font-weight: var(--fw-bold);
    line-height: 1;
  }
  .badge-waiting { background: rgba(245,158,11,0.15); color: #f59e0b; }
  .badge-ongoing { background: rgba(59,130,246,0.15); color: #3b82f6; }
  /* Tables */
  .monitor-table-wrap {
    flex: 1;
    overflow-y: auto;
    max-height: 380px;
  }
  .monitor-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
  }
  .monitor-table thead th {
    text-align: left;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border-default);
    position: sticky;
    top: 0;
    background: var(--color-bg-surface);
    z-index: 1;
  }
  .monitor-table tbody td {
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--color-border-muted);
    vertical-align: middle;
  }
  .monitor-table .th-actions { width: 50px; text-align: center; }
  .monitor-table .td-actions { text-align: center; }
  .monitor-table .td-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
  .monitor-table .td-phone { color: var(--color-text-secondary); font-size: 0.8rem; }
  .monitor-table .td-agent { display: flex; align-items: center; gap: 4px; }
  .monitor-row {
    cursor: pointer;
    transition: background var(--transition-fast);
  }
  .monitor-row:hover {
    background: var(--color-bg-hover);
  }
  .monitor-row:last-child td {
    border-bottom: none;
  }
  .monitor-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
  }
  .monitor-open-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
  }
  .monitor-row:hover .monitor-open-btn {
    opacity: 1;
  }
  /* Agents */
  .monitor-agents-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 240px;
    overflow-y: auto;
  }
  .monitor-agent-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
  }
  .monitor-agent-item:hover {
    background: var(--color-bg-hover);
  }
  .monitor-agent-item.busy {
    border-left: 3px solid var(--color-info, #3b82f6);
  }
  .monitor-agent-item.idle {
    border-left: 3px solid transparent;
  }
  .agent-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-bg-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: var(--fw-bold);
    color: var(--color-text-secondary);
    flex-shrink: 0;
  }
  .agent-info {
    flex: 1;
    min-width: 0;
  }
  .agent-name {
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .agent-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
  }
  .agent-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .agent-status-dot.online { background: var(--color-success, #22c55e); }
  .agent-status-dot.offline { background: var(--color-text-tertiary); }
  .agent-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-success, #22c55e);
    margin-right: 2px;
    flex-shrink: 0;
  }
  .agent-org {
    font-size: 0.65rem;
    color: var(--color-text-secondary);
    opacity: 0.8;
  }
  /* Chart card */
  .chart-card .monitor-chart-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
  }
  .chart-card .chart-container {
    width: 100%;
    max-width: 260px;
  }
  /* MONITOR FULLSCREEN: hide app shell */
  body.monitor-fullscreen #header-container,
  body.monitor-fullscreen #menu,
  body.monitor-fullscreen .app-tabs-bar {
    display: none !important;
  }
  body.monitor-fullscreen .app-layout {
    grid-template-columns: 0 1fr !important;
    grid-template-rows: 0 1fr !important;
  }
  body.monitor-fullscreen .app-content {
    grid-area: 1 / 1 / -1 / -1 !important;
  }

  /* MONITOR VIEW */
  .monitor-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--color-bg-app);
  }
  .monitor-dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
    height: 100%;
    overflow-y: auto;
  }

  /* FLOAT BAR */
  .monitor-float-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
  }
  .monitor-last-refresh {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    opacity: 0.7;
  }
  .monitor-fs-btn {
    font-size: 1.1rem;
  }

  /* KPI STRIP (sortable flex row) */
  .monitor-kpi-strip {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
  }
  .monitor-kpi-strip .kpi-card {
    flex: 1 1 130px;
    min-width: 120px;
    cursor: grab;
    user-select: none;
    transition: opacity var(--transition-fast), box-shadow var(--transition-fast);
  }
  .monitor-kpi-strip .kpi-card.dragging {
    opacity: 0.4;
  }

  /* KPI COLOR CLASSES */
  .kpi-tma .kpi-value { color: var(--color-purple, #8b5cf6); }
  .kpi-avg-wait .kpi-value { color: var(--color-orange, #f97316); }
  .kpi-nps .kpi-value { color: var(--color-emerald, #10b981); }
  .kpi-sla .kpi-value { color: var(--color-rose, #f43f5e); }

  /* WAIT TIME BACKGROUNDS */
  .bg-alert-10 {
    background: rgba(245, 158, 11, 0.12);
  }
  .bg-alert-20 {
    background: rgba(239, 68, 68, 0.12);
  }

  /* SORTABLE CARDS */
  .monitor-sortable {
    display: flex;
  }
  .monitor-sortable[data-mcard].dragging {
    opacity: 0.3;
  }
  .grab-handle {
    cursor: grab;
    user-select: none;
  }
  [data-mcard] {
    cursor: default;
  }

  /* MAIN GRID */
  .monitor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    flex: 1;
    min-height: 0;
  }
  .monitor-grid > .monitor-card {
    min-height: 260px;
  }

  /* AGENTS CARD */
  .agents-card {
    grid-column: span 1;
  }
  .agents-card .monitor-agents-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 280px;
    overflow-y: auto;
  }
  .monitor-agent-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
  }
  .monitor-agent-item:hover {
    background: var(--color-bg-hover);
  }
  .monitor-agent-item.busy {
    border-left: 3px solid var(--color-info, #3b82f6);
  }
  .monitor-agent-item.idle {
    border-left: 3px solid transparent;
  }
  .agent-rank {
    width: 24px;
    text-align: center;
    font-size: var(--font-size-xs);
    font-weight: var(--fw-bold);
    color: var(--color-text-tertiary);
    flex-shrink: 0;
  }
  .agent-rank i {
    font-size: 0.9rem;
  }
  .agent-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-bg-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: var(--fw-bold);
    color: var(--color-text-secondary);
    flex-shrink: 0;
  }
  .agent-info {
    flex: 1;
    min-width: 0;
  }
  .agent-name {
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .agent-bar-wrap {
    height: 4px;
    border-radius: 2px;
    background: var(--color-bg-muted);
    margin-top: 2px;
    overflow: hidden;
  }
  .agent-bar {
    height: 100%;
    border-radius: 2px;
    background: var(--color-success, #22c55e);
    transition: width 0.5s ease;
  }
  .agent-stats {
    text-align: right;
    flex-shrink: 0;
  }
  .agent-stat-num {
    font-size: var(--font-size-sm);
    font-weight: var(--fw-bold);
    color: var(--color-text-primary);
    line-height: 1.2;
  }
  .agent-stat-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
  }
  .agent-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .agent-status-dot.online { background: var(--color-success, #22c55e); }
  .agent-status-dot.offline { background: var(--color-text-tertiary); }

  /* CHART CARD */
  .chart-card {
    grid-column: span 1;
  }
  .chart-card .chart-container {
    width: 100%;
    max-width: 260px;
  }

  /* TABLE ROW IMPROVEMENTS */
  .monitor-table .td-client {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .monitor-table .td-time {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  /* MONITOR PANEL (slide-out drawer) */
  .monitor-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-medium) ease;
  }
  .monitor-panel-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }
  .monitor-panel {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: 420px;
    max-width: 100vw;
    height: calc(100dvh - var(--header-height));
    background: var(--color-bg-surface);
    border-left: 1px solid var(--color-border-default);
    box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    z-index: 1201;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--transition-medium) ease;
  }
  .monitor-panel.open {
    transform: translateX(0);
  }
  .monitor-panel-chat-header {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    flex-shrink: 0;
  }
  .mpch-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px 3px;
    min-width: 0;
  }
  .mpch-client {
    font-size: var(--font-size-sm);
    font-weight: var(--fw-semibold);
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
  }
  .mpch-meta {
    font-size: 0.65rem;
    color: var(--color-text-tertiary);
    white-space: nowrap;
  }
  .mpch-meta::before { content: "· "; }
  .mpch-duration {
    font-size: 0.65rem;
    color: var(--color-text-tertiary);
    white-space: nowrap;
  }
  .mpch-duration::before { content: "· "; }
  .mpch-close-btn {
    font-size: 0.75rem !important;
    padding: 2px 4px !important;
    flex-shrink: 0;
    margin-left: auto;
  }
  .mpch-actions {
    display: flex;
    gap: 4px;
    padding: 0 8px 5px;
  }
  .mpch-actions .btn {
    font-size: 0.65rem;
    padding: 2px 8px;
    white-space: nowrap;
  }
  .monitor-panel-body {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-app);
    min-height: 0;
  }
  .monitor-panel-loading,
  .monitor-panel-empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    flex: 1;
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
  }
  .monitor-panel-loading .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-border-default);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: monitorSpin 0.7s linear infinite;
  }
  @keyframes monitorSpin {
    to { transform: rotate(360deg); }
  }
  .monitor-panel-loading.show,
  .monitor-panel-empty.show {
    display: flex;
  }
  .monitor-panel-empty i {
    font-size: 2rem;
    opacity: 0.4;
  }
  .monitor-panel-messages {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-sm);
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  /* MONITOR ACTION MODAL */
  .monitor-action-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
  }
  .monitor-action-modal {
    background: var(--color-bg-surface);
    border-radius: var(--radius-lg, 12px);
    width: 420px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  }
  .monitor-action-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--color-border-default);
  }
  .monitor-action-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    line-height: 1;
  }
  .monitor-action-body {
    padding: 12px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .monitor-action-body .ff-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .monitor-action-body .ff-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-secondary);
  }
  .monitor-action-body .ff-input,
  .monitor-action-body .ff-select {
    font-size: 0.75rem;
    padding: 6px 8px;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm, 6px);
    background: var(--color-bg-muted);
    color: var(--color-text-primary);
    font-family: inherit;
  }
  .monitor-action-body .ff-select option {
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
  }
  .monitor-action-footer {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    justify-content: flex-end;
    border-top: 1px solid var(--color-border-default);
  }

  /* HIDDEN UTILITY */
  .hidden {
    display: none !important;
  }

  /* Responsive */
  @media (max-width: 1200px) {
    .monitor-grid { grid-template-columns: 1fr; }
    .monitor-bottom { grid-template-columns: 1fr; }
  }
  /* RESPONSIVO */
  @media (max-width: 1024px) {
    .dashboard-row.grid-2 {
      grid-template-columns: 1fr;
    }
    .dashboard-row.grid-3 {
      grid-template-columns: 1fr;
    }
    .monitor-grid {
      grid-template-columns: 1fr;
    }
    .monitor-kpi-strip .kpi-card {
      flex: 1 1 100px;
      min-width: 90px;
    }
  }
}
/* === layout/sidebar.css === */
@layer design-system.sidebar {
  /* CONTAINER VISUAL */
  #menu {
    background-color: var(--color-bg-surface);
    border-right: 1px solid var(--color-border-default);
  }
  /* ÃREA SCROLLÃVEL */
  .sidebar-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    max-height: 100%;
    min-height: 0;
  }
  /* FOOTER */
  .sidebar-footer {
    padding: 10px;
    text-align: center;
    border-top: 1px solid var(--color-border-default);
    flex-shrink: 0;
  }
  /* NÃVEL 0 (ROOT) */
  .btn-nav[data-level="0"] {
    flex-direction: column;
    justify-content: center;
    min-height: 64px;
    gap: 4px;
    padding: 8px 4px;
  }
  .btn-nav[data-level="0"] .sidebar-label {
    white-space: normal !important;
    word-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.1;
    text-align: center;
    font-size: var(--sidebar-font-size-label);
  }
  /* ESTADO COLAPSADO */
  .sidebar-menu.collapsed .sidebar-label,
  .sidebar-menu.collapsed .arrow-indicator {
    display: none;
  }
}
/* === components/badges.css === */
@layer design-system.components {
  .badge {
    font-size: 0.75rem;
    font-weight: var(--fw-semibold);
    border-radius: var(--radius-md);
    padding: var(--space-xxs) var(--space-xs);
    display: inline-flex;
    align-items: center;
    gap: var(--space-xxs);
    transition: background var(--transition-fast), color var(--transition-fast);
  }
  .badge-success { background: var(--color-success); color: var(--color-text-inverse); }
  .badge-warning { background: var(--color-warning); color: var(--color-text-inverse); }
  .badge-danger  { background: var(--color-danger); color: var(--color-text-inverse); }

  .status-bar {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
  }
  .status-dot-success { background: var(--color-success); }
  .status-dot-danger { background: var(--color-danger); }

  .status-indicator-mini .badge { font-size: 0.6rem; padding: 2px 6px; border-radius: 4px; }

  .tab-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    background: var(--color-bg-muted);
    color: var(--color-text-secondary);
  }
  .active .tab-badge {
    background: var(--color-primary);
    color: white;
  }
}
/* === components/buttons.css === */
@layer design-system.components {
  /* ==========================================
     BASE BUTTON
  ========================================== */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    height: 32px;
    padding: 0 var(--space-md);
    font-weight: var(--fw-medium);
    font-size: 0.85rem;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    cursor: pointer;
    transition:
      background var(--transition-fast),
      color var(--transition-fast),
      border-color var(--transition-fast),
      transform 0.1s ease;
  }

  .btn:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.06);
  }

  .btn:active:not(:disabled) {
    transform: scale(0.96);
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* HEADER   */
  .header-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  
  /* ==========================================
   NAV BUTTON (SIDEBAR)
========================================== */

  .btn-nav {
    width: 100%;
    height: var(--sidebar-item-height);
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-sm);
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    border-radius: 0;
    padding: 0 12px;
    position: relative;
  }

  .btn-nav i {
    font-size: var(--sidebar-icon-size);
  }

  .btn-nav:hover {
    background: var(--color-bg-muted);
    color: var(--color-primary);
  }

  .btn-nav.active {
    color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
    box-shadow: inset 3px 0 0 var(--color-primary);
  }

  /* NÃ­vel 0 (raiz colapsada) */
  .level-0 > .btn-nav {
    flex-direction: column;
    justify-content: center;
    height: 64px; /* mantÃ©m padrÃ£o visual original */
    gap: 4px;
    padding: 8px 4px;
  }

  .sidebar-label {
    font-size: var(--sidebar-font-size-label);
  }

  /* ==========================================
     TAMANHOS
  ========================================== */

  .btn-sm {
    height: 28px;
    font-size: 0.8rem;
    padding: 0 var(--space-sm);
  }

  .btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
  }

  /* ==========================================
     PRIMARY
  ========================================== */

  .btn-primary {
    background: var(--color-primary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-primary);
  }

  .btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
  }

  .btn-primary:active:not(:disabled) {
    transform: scale(0.97);
  }

  /* ==========================================
     CHAT ACTION BUTTONS
  ========================================== */

  .btn-action {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1 1 auto;
  }

  .btn-action i {
    font-size: 1.1rem;
    color: inherit;
  }

  .btn-action:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-bg-muted);
  }

  .btn-action.success {
    border-color: var(--color-success);
  }

  .btn-action.success:hover,
  .btn-action.success.active {
    background: rgba(var(--color-success-rgb), 0.1);
    border-color: var(--color-success);
    color: var(--color-success);
  }

  .btn-action.warning {
    border-color: var(--color-warning);
  }

  .btn-action.warning:hover,
  .btn-action.warning.active {
    background: rgba(var(--color-warning-rgb), 0.1);
    border-color: var(--color-warning);
    color: var(--color-warning);
  }

  .btn-action.info {
    border-color: var(--color-primary);
  }

  .btn-action.info:hover,
  .btn-action.info.active {
    background: rgba(var(--color-primary-rgb), 0.1);
    border-color: var(--color-primary);
    color: var(--color-primary);
  }

  .btn-action.ghost {
    border-color: transparent;
    background: transparent;
  }

  .btn-action.ghost:hover,
  .btn-action.ghost.active {
    border-color: transparent;
    background: rgba(var(--color-primary-rgb), 0.08);
    color: var(--color-primary);
  }

  .btn-action.ghost.info:hover,
  .btn-action.ghost.info.active {
    background: rgba(var(--color-primary-rgb), 0.08);
    color: var(--color-primary);
  }

  .btn-action.ghost.warning:hover,
  .btn-action.ghost.warning.active {
    background: rgba(var(--color-warning-rgb), 0.08);
    color: var(--color-warning);
  }

  .btn-action.ghost.success:hover,
  .btn-action.ghost.success.active {
    background: rgba(var(--color-success-rgb), 0.08);
    color: var(--color-success);
  }

  .btn-action.ghost.danger {
    border-color: transparent;
    background: transparent;
    color: var(--color-text-secondary);
  }

  .btn-action.ghost.danger:hover,
  .btn-action.ghost.danger.active {
    background: rgba(var(--color-danger-rgb), 0.08);
    color: var(--color-danger);
  }

  .btn-action .badge {
    background: var(--color-primary);
    color: var(--color-text-inverse);
    font-size: 0.65rem;
    padding: 0 4px;
    border-radius: var(--radius-sm);
  }

  /* ==========================================
     QUICK TAG
  ========================================== */

  .btn-quick-tag {
    white-space: nowrap;
    padding: 3px 12px;
    border-radius: 12px;
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    font-size: 0.68rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
  }

  .btn-quick-tag:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.05);
  }

  /* ==========================================
     SEARCH CLEAR
  ========================================== */

  .search-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    font-size: 1.2rem;
    color: #888;
    cursor: pointer;
    padding: 0;
  }

  .search-clear-btn:hover {
    color: #555;
  }

  /* ==========================================
     LOGIN SUBMIT
  ========================================== */

  #loginForm button[type="submit"] {
    height: 40px;
    font-weight: var(--fw-semibold);
    font-size: 0.9rem;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    border: 1px solid var(--color-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
  }

  #loginForm button[type="submit"]:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
  }

  #loginForm button[type="submit"]:active:not(:disabled) {
    transform: scale(0.97);
  }
}
/* === components/cards.css === */
@layer design-system.components {
  .card {
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast);
  }

  .card:hover {
    box-shadow: var(--shadow-md);
  }


}
/* === components/forms.css === */
@layer design-system.components { 
  input,
  textarea,
  select {
    color: var(--color-text-primary);
  }

  /* WRAPPER BASE (INPUT + AÃ‡Ã•ES INTERNAS) */
  .input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
  }

  /* INPUT */
  .form-control {
    width: 100%;
    height: 40px;
    padding: 0 var(--space-md) 0 var(--space-md);
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
  }

  .form-control-search {
    width: 100%;
    height: 40px;
    padding: 0 42px 0 var(--space-md); /* espaÃ§o Ã  direita pro botÃ£o */
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
  }

  .form-control-login {
    width: 100%;
    height: 40px;
    padding: 0 42px 0 40px;
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
  }

  .form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px
      color-mix(in srgb, var(--color-primary) 15%, transparent);
  }

  /* ERRO */
  .form-control.input-error {
    border-color: var(--color-danger) !important;
    background-color: color-mix(in srgb, var(--color-danger) 5%, transparent);
  }

  /* ICONES ESQUERDA (mantido) */
  .input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
    font-size: 1.1rem;
    pointer-events: none;
  }

  /* =========================
     BOTÃ•ES DENTRO DO INPUT
     ========================= */

  .input-action {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    height: 28px;
    min-width: 28px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-bg-muted);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 3;
  }

  .input-action:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
  }

  .input-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* LOGIN PASSWORD BUTTON (mantido compatÃ­vel) */
  #togglePassword {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-xxs);
  }

  #togglePassword:hover {
    color: var(--color-text-primary);
  }

  /* STATUS BAR */
  .status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
    padding: var(--space-xxs);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
  }

  #loginForm {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  } 

  /* FORM GRID */
  .ds-form-grid {
    display: grid;
    gap: var(--space-sm);
    grid-template-columns: repeat(12, minmax(0, 1fr));
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: 0px 8px 8px 8px;
  }

  .ds-form-grid > legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
  }

  .ds-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }

  /* COLUNAS */
  .col-1 { grid-column: span 1; }
  .col-2 { grid-column: span 2; }
  .col-3 { grid-column: span 3; }
  .col-4 { grid-column: span 4; }
  .col-6 { grid-column: span 6; }
  .col-7 { grid-column: span 7; }
  .col-8 { grid-column: span 8; }
  .col-9 { grid-column: span 9; }
  .col-12 { grid-column: span 12; }

  @media (max-width: 900px) {
    .ds-form-grid {
      grid-template-columns: repeat(6, 1fr);
    }
  }

  @media (max-width: 600px) {
    .ds-form-grid {
      grid-template-columns: repeat(1, 1fr);
    }
  }   

  .main-columns {
    display: grid;
    grid-template-columns: 220px 220px 220px 220px 1fr;
    gap: var(--space-sm);
    padding: 8px;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .column-base {
    margin: 8px 0 0 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-height: 0;
  }

  .column-header {
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--color-border-subtle);
    font-weight: var(--fw-semibold);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .column-content {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-xs) var(--space-md);
  }

  .member-checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    background: var(--color-bg-surface);
  }

  .member-checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
  }

  .member-checkbox-item:hover {
    background: var(--color-bg-muted);
  }

  .member-checkbox-item input[type="checkbox"],
  .member-checkbox-item input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
  }

  .member-checkbox-item input[type="checkbox"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  .member-checkbox-item span {
    font-size: 0.9rem;
    color: var(--color-text-primary);
  }

  .form-control-static {
    padding: 8px 12px;
    font-size: 0.95rem;
    color: var(--color-text-primary);
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    min-height: 40px;
    display: flex;
    align-items: center;
  }
}
/* === components/list.css === */
@layer design-system.components {
  /* LIST VIEW (Flat / Native Style) */
  .list {
    display: flex;
    flex-direction: column;
    width: 100%;

    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-sm);
    overflow: hidden;
  }

  .list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);

    padding: var(--space-sm);

    cursor: pointer;

    background: transparent;
    border: none;
    border-bottom: 1px solid var(--color-border-subtle);

    transition:
      background var(--transition-fast),
      color var(--transition-fast);
  }

  .list-item:last-child {
    border-bottom: none;
  }

  /* Hover leve */
  .list-item:hover {
    background: var(--color-bg-muted);
  }

  /* Estado ativo (selecionado) */
  .list-item.active {
    background: color-mix(
      in srgb,
      var(--color-primary) 10%,
      var(--color-bg-surface)
    );
  }

}
/* === components/dropdown.css === */
@layer design-system.components {
  /* GARANTE QUE O ATRIBUTO HIDDEN FUNCIONE */
  [hidden] {
    display: none !important;
  }

  /* POPUP DO USER MENU (HEADER) */
  .user-menu-popover {
    position: absolute;
    top: calc(var(--header-height) - 5px);
    right: 0;
    min-width: 200px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    padding: 8px 0;
    z-index: 1001;
  }

  .user-menu-popover.active {
    display: block !important;
  }

  .menu-divider {
    height: 1px;
    background: var(--color-border-default);
    margin: 8px 0;
  }

  .menu-item {
    padding: 8px 16px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-primary);
  }

  /* MENU GENÃ‰RICO (dropdown-menu) */
  .dropdown-menu {
    display: none; 
    position: absolute;
    z-index: var(--z-navbar);
    min-width: 160px;
    padding: var(--space-xxs) 0;
    margin: var(--space-xxs) 0 0;
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    list-style: none;
    text-align: left;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  .dropdown-menu.show {
    display: block !important;
  }

  .dropdown-item {
    display: block;
    width: 100%;
    padding: var(--space-xs) var(--space-md);
    clear: both;
    font-weight: var(--fw-regular);
    text-align: inherit;
    white-space: nowrap;
    background-color: transparent;
    border: 0;
    cursor: pointer;
    color: var(--color-text-primary);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  .dropdown-item:hover {
    background: var(--color-bg-muted);
    color: var(--color-primary);
  }

  .dropdown-divider {
    height: 1px;
    margin: var(--space-xxs) 0;
    overflow: hidden;
    background-color: var(--color-border-default);
  }
}
/* === components/search.css === */
@layer design-system.components  {
  .ds-search-wrapper {
    position: relative;
    width: 100%;
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border-default);
    padding: var(--space-sm) 0;
  }

  .ds-search-wrapper.ds-search-global {
    max-width: 280px;
    margin-right: var(--space-md);
  }

  .ds-search-wrapper.ds-search-inline {
    width: auto;
    min-width: 240px;
    padding: 0;
    border-bottom: none;
  }

  .ds-search-input {
    width: 100%;
    height: 38px;
    padding: 8px 32px 8px 34px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    font: inherit;
    transition:
      border var(--transition-fast),
      box-shadow var(--transition-fast);
  }

  .ds-search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px
      color-mix(in srgb, var(--color-primary) 15%, transparent);
    outline: none;
  }

  .ds-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
    pointer-events: none;
    font-size: 1rem;
  }

  .ds-search-clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    font-size: 1.2rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: none;
  }

  .ds-search-input:not(:placeholder-shown) + .ds-search-clear-btn {
    display: block;
  }

  .ds-search-clear-btn:hover {
    color: var(--color-text-primary);
  }

  /* RESULTADOS */
  .search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-top: none;
    box-shadow: var(--shadow-lg);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    display: none;
    z-index: 10001;
    max-height: 400px;
    overflow-y: auto;
  }

  .search-results-dropdown.active {
    display: block !important;
  }

  .search-item,
  .result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
  }

  .search-item:last-child,
  .result-item:last-child {
    border-bottom: none;
  }

  .search-item:hover,
  .result-item:hover {
    background: var(--color-bg-muted);
  }


}
/* === components/tabs.css === */
@layer design-system.tabs {
  .nav-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border-default);
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .nav-tabs .nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0.5rem 1rem;
    font-size: 0.65rem;
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    cursor: pointer;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-secondary);
    transition:
      color var(--transition-fast),
      border-color var(--transition-fast),
      background var(--transition-fast);
  }

  .nav-tabs .nav-link:hover {
    color: var(--color-primary);
  }

  .nav-tabs .nav-link.active {
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
    border-bottom-color: transparent;
    background: rgba(var(--color-primary-rgb), 0.05);
  }
  .nav-tabs .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 4px;
    right: 4px;
    height: 2px;
    background: var(--color-primary);
    border-radius: 2px 2px 0 0;
  }

  .tab-content,
  .tab-pane {
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border-radius: var(--radius-md);
    transition:
      background var(--transition-fast),
      color var(--transition-fast);
  }

  /* =========================================
     FORM TABS (Cadastro / CRUD forms)
     ========================================= */

  .form-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border-default);
    gap: 2px;
  }

  .form-tab {
    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0.5rem 1rem;

    font-size: 0.65rem;
    font-weight: var(--fw-medium);
    text-transform: uppercase;

    cursor: pointer;

    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;

    color: var(--color-text-secondary);

    transition:
      color var(--transition-fast),
      border-color var(--transition-fast),
      background var(--transition-fast);
  }

  .form-tab:hover {
    color: var(--color-primary);
  }

  .form-tab.active {
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
    border-bottom-color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.05);
  }

  /* ConteÃºdo */

  .form-tabs-content {
    margin-top: 12px;
  }

  .form-tab-pane {
    display: none;

    background: var(--color-bg-surface);
    color: var(--color-text-primary);

    border-radius: var(--radius-md);

    transition:
      background var(--transition-fast),
      color var(--transition-fast);
  }

  .form-tab-pane.active {
    display: block;
  }
/* === components/notifications.css === */
@layer design-system.components {
  /* BASE VISUAL UNIFICADA */
  .notification-soft {
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(2px);
    transition:
      background var(--transition-fast),
      border-color var(--transition-fast),
      color var(--transition-fast),
      opacity var(--transition-fast);
  }
  /* ALERT */
  .alert {
    display: none;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
    line-height: var(--lh-normal);
    text-align: left;
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(2px);
  }
  .alert.show {
    display: block;
  }

  /* DS-ALERT (always visible) */
  .ds-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
    line-height: var(--lh-normal);
    text-align: left;
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(2px);
  }
  .ds-alert > i {
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 1.1rem;
  }
  .ds-alert > span {
    flex: 1;
    word-break: normal;
    white-space: normal;
  }

  .ds-alert-info {
    background: rgba(var(--color-primary-rgb), 0.08);
    color: var(--color-primary);
    border: 1px solid rgba(var(--color-primary-rgb), 0.25);
    border-left: 4px solid var(--color-primary);
  }
  .ds-alert-warning {
    background: rgba(var(--color-warning-rgb), 0.08);
    color: var(--color-warning);
    border: 1px solid rgba(var(--color-warning-rgb), 0.25);
    border-left: 4px solid var(--color-warning);
  }
  .ds-alert-danger {
    background: rgba(var(--color-danger-rgb), 0.08);
    color: var(--color-danger);
    border: 1px solid rgba(var(--color-danger-rgb), 0.25);
    border-left: 4px solid var(--color-danger);
  }
  .ds-alert-success {
    background: rgba(var(--color-success-rgb), 0.08);
    color: var(--color-success);
    border: 1px solid rgba(var(--color-success-rgb), 0.25);
    border-left: 4px solid var(--color-success);
  }
  /* VARIANTS */
  .variant-error {
    background: rgba(var(--color-danger-rgb), 0.08);
    color: var(--color-danger);
    border: 1px solid rgba(var(--color-danger-rgb), 0.25);
    border-left: 4px solid var(--color-danger);
  }
  .variant-warning {
    background: rgba(var(--color-warning-rgb), 0.08);
    color: var(--color-warning);
    border: 1px solid rgba(var(--color-warning-rgb), 0.25);
    border-left: 4px solid var(--color-warning);
  }
  .variant-success {
    background: rgba(var(--color-success-rgb), 0.08);
    color: var(--color-success);
    border: 1px solid rgba(var(--color-success-rgb), 0.25);
    border-left: 4px solid var(--color-success);
  }
  .variant-info {
    background: rgba(var(--color-primary-rgb), 0.08);
    color: var(--color-primary);
    border: 1px solid rgba(var(--color-primary-rgb), 0.25);
    border-left: 4px solid var(--color-primary);
  }
  /* TOAST SYSTEM */
  .notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
  }
  .toast {
    min-width: 340px;
    padding: 14px 20px;
    font-family: var(--font-base);
    font-size: var(--font-size-sm);
    font-weight: var(--fw-medium);
    line-height: var(--lh-normal);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-8px);
    transition:
      opacity var(--transition-medium),
      transform var(--transition-medium);
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(2px);
  }
  .toast.show {
    opacity: 1;
    transform: translateY(0);
  }
  body.theme-dark .toast {
    background: #dde3ea;
    color: #1f2a37;
    border-color: #b8c2cc;
  }
  body.theme-light .toast {
    background: #1f2937;
    color: #f9fafb;
    border-color: #374151;
  }
  /* MODAL SYSTEM */
  .overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
  }
  .modal-soft {
    width: 100%;
    max-width: 420px;
    padding: var(--space-xl);
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(2px);
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    animation: modalFade var(--transition-medium) ease;
  }
  @keyframes modalFade {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  .modal-soft .modal-title {
    font-size: var(--font-size-lg);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--space-sm);
  }
  .modal-soft .modal-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-lg);
    line-height: var(--lh-normal);
  }
  .modal-soft .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
  }
  /* STATUS BAR */
  .status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
  }
}
/* === components/scrollbar.css === */
@layer design-system.components {
  /*
    GLOBAL (SAFE)
    - SÃ³ estiliza, NÃƒO forÃ§a comportamento
    - NÃ£o cria scrollbar sozinho
  */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-default) transparent;
  }
  *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  *::-webkit-scrollbar-track {
    background: transparent;
  }
  *::-webkit-scrollbar-thumb {
    background: var(--color-border-default);
    border-radius: 999px;
    transition: background 0.2s ease;
  }
  *::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
  }
  /*
    IMPORTANTE:
    NÃƒO usar hacks que escondem scrollbar globalmente
    Isso quebra UX (como aconteceu)
  */
  /* CUSTOM */
  .custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-subtle) transparent;
  }
  .custom-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  .custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: var(--color-border-subtle);
    border-radius: 4px;
  }

}
/* === components/tree-menu.css === */
@layer design-system.components {
  .menu-node-container {
    position: relative;
    width: 100%;
    overflow: visible;
  }

  .arrow-indicator {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    font-size: 0.6rem;
    pointer-events: none;
  }

  .btn-nav[data-level="0"] .arrow-indicator {
    transform: translateY(calc(-50% - 8px));
  }
}
/* === components/flyout.css === */
@layer design-system.components {

  .menu-popout {
    position: fixed;
    min-width: 220px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    z-index: 9999;
    border-radius: 0 6px 6px 0;
    padding: 4px 0;
    animation: flyoutIn 0.15s ease-out;
    pointer-events: auto;
  }

  .popout-header {
    padding: 8px 14px;
    font-weight: 700;
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--color-primary);
    border-bottom: 1px solid var(--color-border-default);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    background: var(--color-bg-muted);
  }

  /* ===============================
     BOTÃ•ES DENTRO DO FLYOUT
  =============================== */

  .menu-popout .btn-nav {
    height: 30px;
    min-height: 30px;
    padding: 4px 12px;
    justify-content: flex-start;
    gap: 10px;
  }

  .menu-popout .btn-nav i {
    font-size: 0.95rem;
    opacity: 0.8;
  }

  .menu-popout .sidebar-label {
    text-align: left;
    font-size: var(--sidebar-font-size-popout);
    white-space: nowrap;
  }

  @keyframes flyoutIn {
    from {
      opacity: 0;
      transform: translateX(-5px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

}
/* === components/datatables.css === */
@layer design-system.components {
  /* ==========================================
     DATATABLE WRAPPER
  ========================================== */
  .ds-table-wrapper {
    width: 100%;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);

    overflow-x: auto; /* scroll horizontal */
    overflow-y: hidden;

    display: flex;
    flex-direction: column;
    gap: var(--space-md);

    font-family: var(--font-base);
    color: var(--color-text-primary);
  }

  /* ==========================================
     TABLE BASE (DATA GRID)
  ========================================== */
  .ds-table {
    width: 100%;
    border-collapse: collapse;

    table-layout: fixed;

    /* ESSENCIAL: forÃ§a scroll ao invÃ©s de esmagar */
    min-width: 900px;

    transition: all 0.2s;
  }

  .ds-table thead {
    background: var(--color-bg-muted);
  }

  .ds-table th,
  .ds-table td {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--color-border-subtle);

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    vertical-align: middle;
  }

  .ds-table th:first-child,
  .ds-table td:first-child {
    border-left: none;
  }

  .ds-table th:last-child,
  .ds-table td:last-child {
    border-right: none;
  }

  .ds-table th {
    text-align: left;
    font-weight: var(--fw-semibold);
    color: var(--color-text-secondary);
    position: relative;
    background: var(--color-bg-muted);
  }

  .ds-table td {
    color: var(--color-text-primary);
  }

  /* ==========================================
     LARGURAS (EQUILIBRADO)
  ========================================== */

  /* AÃ‡Ã•ES */
  .ds-table th:first-child,
  .ds-table td:first-child {
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    text-align: center;
  }

  /* NOME (expande mais) */
  .ds-table th:nth-child(2),
  .ds-table td:nth-child(2) {
    min-width: 220px;
  }

  /* LOGIN */
  .ds-table th:nth-child(3),
  .ds-table td:nth-child(3) {
    min-width: 180px;
  }

  /* TIPO */
  .ds-table th:nth-child(4),
  .ds-table td:nth-child(4) {
    min-width: 140px;
  }

  /* MATRIZ */
  .ds-table th:nth-child(5),
  .ds-table td:nth-child(5) {
    min-width: 200px;
  }

  /* STATUS */
  .ds-table th:nth-child(6),
  .ds-table td:nth-child(6) {
    min-width: 140px;
  }

  /* ==========================================
     COMPORTAMENTO DE TEXTO
  ========================================== */

  .ds-table td code {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ==========================================
     FORM ACTIONS
  ========================================== */
  #account-form-view .ds-table-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }

  #form-actions-view,
  #form-actions-edit {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }

  /* ==========================================
     ROW STATES
  ========================================== */
  .ds-table tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--color-bg-muted) 40%, var(--color-bg-surface));
  }

  .ds-table tbody tr:nth-child(odd) {
    background: var(--color-bg-surface);
  }

  .ds-table tbody tr:hover {
    background: var(--color-bg-hover);
  }

  .ds-table tbody tr.selected {
    background: var(--color-bg-accent-light);
  }

  /* ==========================================
     EMPTY
  ========================================== */
  .ds-table-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--color-text-muted);
    border: 1px dashed var(--color-border-default);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
  }

  /* ==========================================
     HEADER
  ========================================== */
  .ds-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border-default);
    background: var(--color-bg-surface);
    gap: var(--space-sm);
  }

  .ds-table-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
  }

  /* ==========================================
     FOOTER
  ========================================== */
  .ds-table-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--fs-sm);
    color: var(--color-text-secondary);
  }

  /* ==========================================
     SORT ICONS
  ========================================== */
  .ds-table th.sort-asc::after {
    content: "â–²";
    position: absolute;
    right: var(--space-sm);
    font-size: 0.6em;
  }

  .ds-table th.sort-desc::after {
    content: "â–¼";
    position: absolute;
    right: var(--space-sm);
    font-size: 0.6em;
  }

  /* ==========================================
     BOTÃ•ES INLINE
  ========================================== */
  .ds-table .btn {
    padding: 2px 6px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
/* === components/integration.css === */
@layer design-system.components {
  /* QR CODE */
  .qr-display-area {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    padding: var(--space-md);
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
  }

  .qr-image {
    max-width: 280px;
    max-height: 280px;
    image-rendering: pixelated;
  }

  .qr-placeholder {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    text-align: center;
  }

  .qr-status {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-top: var(--space-xs);
    text-align: center;
  }

  /* CONNECTION PANEL */
  .connection-panel {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    min-height: 300px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .connection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .connection-actions {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    align-items: center;
    min-height: 40px;
  }

  .connection-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
  }

  .connection-status {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-bg-muted);
    border-radius: var(--radius-sm);
  }

  .connection-tips {
    font-size: 0.85rem;
  }

  .connection-tips .ds-alert {
    margin: 0;
    padding: var(--space-sm);
  }

  .pairing-code-display {
    text-align: center;
    padding: var(--space-md);
  }

  .pairing-instruction {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-md);
  }

  .pairing-code {
    font-family: monospace;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--color-primary);
    background: var(--color-bg-muted);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    display: inline-block;
    border: 2px dashed var(--color-border-default);
  }

  .pairing-expiry {
    font-size: 0.8rem;
    color: var(--color-text-tertiary);
    margin-top: var(--space-sm);
  }

  .pairing-input-area {
    padding: var(--space-md);
    text-align: center;
  }

  .pairing-input-area .form-control {
    max-width: 300px;
    margin: var(--space-sm) auto;
    text-align: center;
    font-size: 1.1rem;
    letter-spacing: 2px;
  }
}
/* === components/loading.css === */
@layer design-system.components {
  .spinner {
    display: inline-block;
    border-radius: 50%;
    border-style: solid;
    border-color: var(--color-border-default);
    border-top-color: var(--color-primary);
    animation: spinner-rotate 0.7s linear infinite;
  }
  .spinner-md {
    width: 28px;
    height: 28px;
    border-width: 3px;
  }
  .spinner-primary {
    border-top-color: var(--color-primary);
  }
  @keyframes spinner-rotate {
    to {
      transform: rotate(360deg);
    }
  }
}
/* === components/chart.css === */
@layer design-system.components {
  /* BASE */
  .chart-container {
    position: relative;
    width: 100%;
    height: 240px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* essencial para mobile */
  }
  .chart-canvas {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
  }
  .chart-canvas canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
  }
  /* LINE */
  .chart-line {
    height: 260px;
  }
  /* DOUGHNUT */
  .chart-doughnut {
    height: 220px;
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
  }
  .chart-doughnut .chart-canvas {
    flex: 1;
    min-width: 0;
  }
  /* legenda custom lado direito */
  .chart-legend {
    width: 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    padding: 8px 6px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .chart-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
  }
  .chart-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
  }
  /* RESPONSIVO */
  @media (max-width: 768px) {
    .chart-container {
      height: 200px;
    }
    .chart-doughnut {
      flex-direction: column;
      height: 200px;
    }
    .chart-legend {
      width: 100%;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: center;
      overflow: visible;
    }
  }
}
/* === core/utilities.css === */
@layer design-system.utilities {
  .hidden { display: none !important; }
  .status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
  .mt-2 { margin-top: var(--space-xs); }
}
