/* ===== RESET & VARIABLES ===== */
:root {
  --bg-dark: #0b141a;
  --bg-panel: #111b21;
  --bg-card: #1f2c33;
  --bg-input: #2a3942;
  --bg-hover: #233138;
  --border: #2a3942;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --danger: #ea4335;
  --warning: #f59e0b;
  --info: #3b82f6;
  --success: #00a884;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-input); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-header {
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.logo-icon {
  font-size: 28px;
  color: var(--accent);
}
.logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.logo-text {
  display: none;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all var(--transition);
  margin-bottom: 2px;
  font-size: 14px;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent);
  color: #fff;
}
.nav-item i { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}
.status-dot.offline { background: var(--danger); animation: none; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: calc(100% - var(--sidebar-width));
}
.topbar {
  height: var(--topbar-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
}
.page-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}
.uptime {
  font-size: 12px;
  color: var(--text-muted);
}
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ===== CARDS & STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.stat-icon.green { background: rgba(0,168,132,0.15); color: var(--accent); }
.stat-icon.blue { background: rgba(59,130,246,0.15); color: var(--info); }
.stat-icon.orange { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-icon.red { background: rgba(234,67,53,0.15); color: var(--danger); }
.stat-icon.purple { background: rgba(168,85,247,0.15); color: #a855f7; }
.stat-info h3 { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-info p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 {
  font-size: 16px;
  font-weight: 600;
}
.card-body { padding: 20px; }
.card-body.no-padding { padding: 0; }

/* ===== TABLES ===== */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
thead { background: var(--bg-dark); }
th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
tr:hover td { background: var(--bg-hover); }
tr:last-child td { border-bottom: none; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #d32f2f; }
.btn-warning { background: var(--warning); color: #000; }
.btn-info { background: var(--info); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-input); color: var(--text-primary); }
.btn-icon.danger:hover { color: var(--danger); }

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 140px; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
select option, select.form-control option {
  background: var(--bg-input);
  color: var(--text-primary);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-inline {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.form-inline .form-group { flex: 1; margin-bottom: 0; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-success { background: rgba(0,168,132,0.15); color: var(--accent); }
.badge-danger { background: rgba(234,67,53,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-secondary { background: rgba(134,150,160,0.15); color: var(--text-secondary); }
.badge-purple { background: rgba(168,85,247,0.15); color: #a855f7; }
.badge-accent { background: var(--accent); color: #fff; }

/* ===== SMALL FORM CONTROLS ===== */
.form-control-sm {
  padding: 5px 10px;
  font-size: 13px;
  height: 32px;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ===== TAG CHIPS ===== */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(0,168,132,0.1);
  border: 1px solid rgba(0,168,132,0.3);
  border-radius: 12px;
  font-size: 11px;
  color: var(--accent);
  margin: 2px;
}

/* ===== TAG BADGES (classification tags) ===== */
.tag-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  margin: 2px;
  line-height: 1.5;
}
.tag-badge-lg {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.tags-cell { max-width: 280px; }

/* ===== TAGS PAGE GRID ===== */
.tags-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.tag-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.tag-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.tag-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tag-card-desc {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 8px;
  margin-bottom: 0;
}

/* ===== COLOR PICKER ===== */
.color-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

/* ===== TAG CHECKBOX (contact tag selector) ===== */
.tag-checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag-checkbox-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.tag-checkbox-label input[type="checkbox"] {
  display: none;
}
.tag-checkbox-label input[type="checkbox"] + .tag-badge {
  opacity: 0.4;
  border: 2px solid transparent;
  transition: opacity 0.15s, border-color 0.15s;
}
.tag-checkbox-label input[type="checkbox"]:checked + .tag-badge {
  opacity: 1;
  border-color: rgba(255,255,255,0.4);
  box-shadow: 0 0 6px rgba(0,0,0,0.3);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 860px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  font-size: 14px;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}
.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== QR CODE ===== */
.qr-container {
  text-align: center;
  padding: 20px;
}
.qr-container img, .qr-container canvas {
  max-width: 280px;
  border-radius: var(--radius);
  background: #fff;
  padding: 16px;
}
.qr-instructions {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar .search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.toolbar .search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}
.toolbar .search-box input {
  padding-left: 36px;
}
.toolbar .tag-filter-box {
  position: relative;
  min-width: 180px;
}
.toolbar .tag-filter-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}
.toolbar .tag-filter-box select {
  padding-left: 36px;
  appearance: auto;
  cursor: pointer;
}

/* ===== DEVICE STATUS ===== */
.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.device-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
}
.device-info { flex: 1; }
.device-info h3 { font-size: 15px; margin-bottom: 4px; }
.device-info p { font-size: 13px; color: var(--text-secondary); }
.device-actions { display: flex; gap: 8px; }

/* ===== GRID LAYOUTS ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* --- Form grid: 4 colunas para cards de criação/edição --- */
.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 16px;
  align-items: start;
}
.form-grid-4 .form-group { margin-bottom: 0; }
.form-grid-4 .fg-full { grid-column: 1 / -1; }
.form-grid-4 .fg-span-2 { grid-column: span 2; }
.form-grid-4 .fg-span-3 { grid-column: span 3; }

/* --- Recipient dropdown overlay --- */
.recip-selector-col { position: relative; }
.recip-trigger-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.recip-trigger-btn i { font-size: 11px; color: var(--text-muted); transition: transform 0.2s; }
.recip-trigger-btn.open i { transform: rotate(180deg); }

.recip-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  min-width: 340px;
  z-index: 500;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  margin-top: 4px;
}
.recip-dropdown .recipient-search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.recip-dropdown .recipient-search .form-control { margin-bottom: 0; }
.recip-dropdown .recipient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  border: none;
  border-radius: 0;
  background: transparent;
}
.recip-dropdown .recipient-grid:empty { display: none; }
.recip-dropdown .recipient-grid .recipient-item {
  margin: 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.recip-dropdown .recipient-grid .recipient-item:hover { border-color: var(--accent); }

/* Modal wide (para formulários de 4 colunas) */
.modal.modal-wide { max-width: 1040px; }

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ===== CHATBOT FLOW ITEM ===== */
.flow-item {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.flow-item .flow-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.flow-item .flow-trigger {
  font-size: 13px;
  color: var(--text-secondary);
}
.flow-item .flow-response {
  font-size: 14px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-top: 8px;
  border-left: 3px solid var(--accent);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 20px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}
.pagination button {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover { background: var(--bg-hover); }
.pagination button.active { background: var(--accent); border-color: var(--accent); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination span { font-size: 13px; color: var(--text-secondary); }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== UNIVERSAL FIELDS GRID ===== */
.universal-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.universal-fields-grid .full-width {
  grid-column: 1 / -1;
}
.field-tag-hint {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(0, 128, 105, 0.12);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
  font-family: 'Courier New', monospace;
}

/* ===== FALLBACK CONFIG (Tags page) ===== */
.fallback-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.fallback-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
}
.fallback-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.fallback-card .field-tag-hint {
  margin-left: 0;
  margin-bottom: 8px;
  display: inline-block;
}
.fallback-card input {
  width: 100%;
}

/* ===== RECIPIENT SELECTOR ===== */
.recipient-search { margin-bottom: 8px; }
.recipient-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 4px;
}
.recipient-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}
.recipient-item:hover { background: var(--bg-hover); }
.recipient-item input[type="checkbox"] { accent-color: var(--accent); flex-shrink: 0; }
.recipient-item span { display: flex; align-items: center; gap: 6px; }
.recipient-item small { color: var(--text-muted); }

/* Alert boxes */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-info {
  background: rgba(59, 130, 246, 0.12);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

/* Custom dates for schedules */
.custom-dates-list { display: flex; flex-direction: column; gap: 6px; }
.custom-date-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}

/* Unified content blocks (.ublock) */
.ublock {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.ublock:hover { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(0,168,132,0.15); }
.ublock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,168,132,0.04);
  border-radius: var(--radius) var(--radius) 0 0;
}
.ublock-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.ublock-title i { margin-right: 6px; color: var(--accent); }
.ublock-actions { display: flex; gap: 4px; align-items: center; }
.ublock-actions .btn-icon { width: 28px; height: 28px; font-size: 12px; }
.ublock-body { padding: 14px; }
.ublock-toolbar { margin-bottom: 10px; }
.ublock-tpl-select {
  width: 100%;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
}
.ublock-textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  margin-bottom: 4px;
}
.btn-add-block {
  width: 100%;
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 16px;
}
.btn-add-block:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0,168,132,0.04);
}
.btn-add-block i { margin-right: 6px; }

/* Legacy content-block (keep for compatibility) */
.content-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: var(--bg-card);
  transition: border-color var(--transition);
}
.content-block:hover { border-color: var(--accent); }
.content-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.content-block-header i { margin-right: 6px; color: var(--accent); }

/* Media upload */
.media-upload-wrap {
  margin-top: 6px;
}
.media-upload-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  transition: all var(--transition);
  border-radius: var(--radius);
}
.media-upload-btn.dragover {
  background: rgba(0, 168, 132, 0.08);
  padding: 8px 12px;
  border: 2px dashed var(--accent);
}
.btn-attach-media {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-attach-media:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}
.btn-attach-media i {
  font-size: 14px;
  color: var(--accent);
}
.media-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.media-file-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.media-file-preview.dragover {
  border-color: var(--accent);
  background: rgba(0, 168, 132, 0.08);
}
.media-preview-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.media-preview-info i {
  font-size: 24px;
  color: var(--accent);
}
.media-preview-info strong { display: block; font-size: 13px; }
.media-preview-info small { color: var(--text-muted); font-size: 12px; }
.media-preview-thumb {
  margin-top: 10px;
  text-align: center;
}
.media-preview-thumb img {
  max-width: 100%;
  max-height: 120px;
  border-radius: 6px;
  object-fit: contain;
}

/* Tag picker buttons for template editor */
.tag-pick-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tag-pick-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== TICKETS MODULE ===== */
.tickets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.ticket-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}
.ticket-card .ticket-card-dates {
  margin-top: auto;
}
.ticket-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transform: translateY(-2px);
}
.ticket-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ticket-number {
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}
.ticket-number-lg {
  font-weight: 700;
  color: var(--accent);
  font-size: 18px;
}
.ticket-status-badge, .ticket-status-badge-lg {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ticket-status-badge-lg {
  font-size: 13px;
  padding: 5px 14px;
}
.ticket-subject {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ticket-card-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.ticket-card-meta i { margin-right: 4px; }
.ticket-card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.ticket-card-footer i { margin-right: 4px; }
.ticket-card-footer .date-highlight {
  background: rgba(59,130,246,0.1);
  color: #3b82f6;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
}

/* Ticket Detail */
.ticket-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.ticket-detail-actions { display: flex; gap: 8px; }
.ticket-detail-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.ticket-detail-subject {
  font-size: 20px;
  margin: 4px 0 0 0;
  line-height: 1.3;
}
.ticket-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.ticket-meta-item label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.ticket-meta-item span {
  font-size: 14px;
  color: var(--text);
}
.ticket-meta-item i { margin-right: 4px; }
.ticket-description {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
}
.ticket-description label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.ticket-description p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}
.ticket-transitions {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.ticket-transitions label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-right: 8px;
}
.transition-buttons {
  display: inline-flex;
  gap: 8px;
  margin-top: 6px;
}
.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.danger-btn {
  background: var(--danger);
  color: #fff;
  border: none;
}
.danger-btn:hover { opacity: 0.85; }

/* Timeline */
.ticket-timeline {
  position: relative;
  padding-left: 24px;
}
.ticket-timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: -24px;
  margin-top: 2px;
  z-index: 1;
  border: 2px solid var(--bg-card);
}
.timeline-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.timeline-label { font-size: 14px; color: var(--text); }
.timeline-date { font-size: 12px; color: var(--text-muted); }

/* Ticket Messages */
.ticket-message {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg-input);
}
.ticket-message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ticket-message-author {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.ticket-message-author i { margin-right: 4px; color: var(--accent); }
.ticket-message-date {
  font-size: 12px;
  color: var(--text-muted);
}
.ticket-message-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}
.ticket-message-actions {
  display: inline-flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.ticket-message:hover .ticket-message-actions {
  opacity: 1;
}
.ticket-message-actions .btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background 0.2s, color 0.2s;
}
.ticket-message-actions .btn-icon:hover {
  background: var(--accent);
  color: #fff;
}
.ticket-message-actions .btn-icon.danger:hover {
  background: #D63031;
  color: #fff;
}

/* Pasted images preview */
.pasted-images-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.pasted-image-item {
  position: relative;
  display: inline-block;
}
.pasted-image-item img {
  max-width: 120px;
  max-height: 90px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  cursor: pointer;
  object-fit: cover;
}
.pasted-image-item img:hover {
  border-color: var(--accent);
}
.pasted-image-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #D63031;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Attachments */
.ticket-attachments { margin-top: 12px; }
.ticket-attachments strong { font-size: 13px; }
.attachment-list, .msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.attachment-thumb, .attachment-thumb-sm {
  display: inline-block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.attachment-thumb img { width: 120px; height: 80px; object-fit: cover; }
.attachment-thumb-sm img { width: 80px; height: 56px; object-fit: cover; }
.attachment-file, .attachment-file-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
}
.attachment-file:hover, .attachment-file-sm:hover { border-color: var(--accent); }

/* Contact Autocomplete */
.form-group { position: relative; }
.contact-autocomplete-list {
  position: absolute;
  z-index: 200;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.contact-autocomplete-list:not(:empty) { display: block; }
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.autocomplete-item:hover { background: var(--bg-input); }
.selected-contact-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  font-size: 13px;
  margin-top: 6px;
}
.selected-contact-badge button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}

/* Card-style selected contact */
.selected-contact-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin-top: 8px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 10px;
}
.selected-contact-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.selected-contact-main > i {
  font-size: 28px;
  color: var(--accent);
  margin-top: 2px;
}
.selected-contact-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color .15s;
}
.selected-contact-remove:hover {
  color: var(--danger);
}

/* Quick Contact Panel */
.quick-contact-panel {
  margin-top: 10px;
  padding: 14px;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.quick-contact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--accent);
  font-size: 14px;
}
.quick-contact-header .btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}
.quick-contact-header .btn-icon:hover { color: var(--text-primary); }
.quick-contact-fields .form-row { margin-bottom: 8px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; width: 100%; }
  .menu-toggle { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid-4 { grid-template-columns: 1fr; }
  .form-grid-4 .fg-span-2, .form-grid-4 .fg-span-3, .form-grid-4 .fg-full { grid-column: 1 / -1; }
  .recip-dropdown .recipient-grid { grid-template-columns: 1fr; }
  .recip-dropdown { min-width: 0; left: 0; right: 0; }
  .modal.modal-wide { max-width: 98vw; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .universal-fields-grid { grid-template-columns: 1fr; }
  .fallback-grid { grid-template-columns: 1fr; }
  .tickets-grid { grid-template-columns: 1fr; }
  .ticket-detail-grid { grid-template-columns: 1fr 1fr; }
  .ticket-detail-top { flex-direction: column; }
}
@media (min-width: 769px) and (max-width: 1024px) {
  .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .form-grid-4 .fg-span-3 { grid-column: 1 / -1; }
}
