/**
 * Components — wa-gateway
 * مكونات قابلة لإعادة الاستخدام
 */

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  background: var(--surface-alt);
  color: var(--text);
  transition: all var(--transition-fast);
}

.btn:hover {
  text-decoration: none;
  filter: brightness(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--brand-admin);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--brand-admin);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-admin-dark);
}

.btn-brand {
  background: var(--brand-primary);
  color: #fff;
}

.btn-brand:hover {
  background: var(--brand-primary-dark);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

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

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 13px;
}

.form-control,
input:not([type]),
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="time"],
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  background-color: var(--surface);
  color: var(--text);
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Unified native select — professional dropdown (all pages) */
select,
.form-select {
  width: 100%;
  min-height: 42px;
  padding-block: 10px;
  padding-inline-start: 12px;
  padding-inline-end: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background-color: var(--surface);
  line-height: 1.4;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  text-align: start;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-size: 14px 14px;
  background-repeat: no-repeat;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

html[dir="rtl"] select,
html[dir="rtl"] .form-select {
  text-align: right;
  background-position: left 14px center;
}

.form-control:focus,
input:focus,
textarea:focus,
select:focus,
.form-select:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.14);
}

select:disabled,
.form-select:disabled {
  background-color: var(--muted-bg);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.85;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

.help {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info);
}

.badge-muted {
  background: var(--muted-bg);
  color: var(--muted);
}

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-weight: 600;
  border: 1px solid transparent;
}

.alert-success {
  background: var(--success-bg);
  color: #14532d;
  border-color: #bbf7d0;
}

.alert-error,
.alert-danger {
  background: var(--danger-bg);
  color: #7f1d1d;
  border-color: #fecaca;
}

.alert-warning {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.alert-info {
  background: var(--info-bg);
  color: #155e75;
  border-color: #a5f3fc;
}

/* === Alert Banner (for subscription, QR, errors) === */
.alert-banner {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.alert-banner-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.alert-banner-content {
  flex: 1;
}

.alert-banner-action {
  flex-shrink: 0;
}

.alert-banner.success {
  background: var(--success-bg);
  color: #14532d;
  border: 1px solid #bbf7d0;
}

.alert-banner.warning {
  background: var(--warning-bg);
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-banner.danger {
  background: var(--danger-bg);
  color: #7f1d1d;
  border: 1px solid #fecaca;
}

.alert-banner.info {
  background: var(--info-bg);
  color: #155e75;
  border: 1px solid #a5f3fc;
}

/* === Panels === */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-head h2 {
  font-size: 14.5px;
  margin: 0;
  font-weight: 700;
}

.panel-body {
  padding: 18px;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat .label {
  color: var(--text-soft);
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.stat .value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0;
}

.stat .sub {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 4px;
}

.stat .ic {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--surface-alt);
  font-size: 16px;
}

/* === Tables === */
.table-wrap {
  overflow-x: auto;
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.tbl th,
table.tbl td {
  padding: 11px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

table.tbl th {
  background: var(--surface-alt);
  color: var(--text-soft);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

table.tbl tr:last-child td {
  border-bottom: none;
}

table.tbl tbody tr:hover {
  background: #fafcff;
}

/* === Empty State === */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-soft);
}

.empty .ic {
  font-size: 38px;
  opacity: 0.35;
  margin-bottom: 10px;
}

.empty h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--text);
}

.empty p {
  margin: 0 0 16px;
  font-size: 13px;
}

/* === Page Header === */
.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header-title h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}

.page-header-title p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
}

.page-header-actions {
  display: flex;
  gap: 10px;
}

/* === Progress Bar === */
.progress-bar {
  height: 8px;
  background: var(--muted-bg);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--brand-admin);
  transition: width var(--transition);
}

.progress-fill.success {
  background: var(--success);
}

.progress-fill.warning {
  background: var(--warning);
}

.progress-fill.danger {
  background: var(--danger);
}

/* === Usage Meter === */
.usage-meter {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.usage-meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 700;
}

.usage-meter-hint {
  margin: 8px 0 0;
  color: var(--text-soft);
  font-size: 12px;
}

/* === Timeline === */
.timeline {
  position: relative;
  padding-right: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  right: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  right: -19px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted-bg);
  border: 2px solid var(--border);
}

.timeline-item.completed::before {
  background: var(--success);
  border-color: var(--success);
}

.timeline-item.active::before {
  background: var(--brand-admin);
  border-color: var(--brand-admin);
}

.timeline-item h4 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
}

.timeline-item p {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
}

/* === Onboarding Checklist === */
.checklist {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.checklist-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.checklist-item label {
  flex: 1;
  font-weight: 500;
  cursor: pointer;
}

.checklist-item.completed label {
  text-decoration: line-through;
  color: var(--text-soft);
}

/* === Chip === */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 12px;
}

.chip-primary {
  background: #e0f2fe;
  color: #0369a1;
}

.chip-success {
  background: var(--success-bg);
  color: var(--success);
}

.chip-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.chip-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.flex {
  display: flex;
  align-items: center;
  gap: 10px;
}

.between {
  justify-content: space-between;
}

.muted {
  color: var(--text-soft);
}

.mt-0 {
  margin-top: 0;
}

.nowrap {
  white-space: nowrap;
}

.inline-form {
  margin: 0;
}

/* === Responsive === */
@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .btn {
    flex: 1;
    justify-content: center;
  }
}

/* === Send Page === */
.send-page {
  max-width: 680px;
  margin: 0 auto;
}

.send-header {
  text-align: center;
  margin-bottom: 32px;
}

.send-header h1 {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text);
}

.send-header p {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
}

.send-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.send-form .form-group {
  margin-bottom: 24px;
}

.send-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
}

.send-form input,
.send-form textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background-color: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
}

.send-form select {
  width: 100%;
  padding-block: 12px;
  padding-inline-start: 16px;
  padding-inline-end: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background-color: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
  background-position: right 14px center;
}

html[dir="rtl"] .send-form select {
  background-position: left 14px center;
}

.send-form input:focus,
.send-form select:focus,
.send-form textarea:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.send-form textarea {
  min-height: 120px;
  resize: vertical;
}

.send-form .help {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-soft);
}

.send-form .btn-submit {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.send-info {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.send-info-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.send-info-content {
  flex: 1;
}

.send-info-content h4 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: #0369a1;
}

.send-info-content p {
  margin: 0;
  font-size: 13px;
  color: #0c4a6e;
  line-height: 1.5;
}

.device-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.device-status.active {
  background: #dcfce7;
  color: #166534;
}

.device-status.inactive {
  background: #f1f5f9;
  color: #64748b;
}

@media (max-width: 640px) {
  .send-card {
    padding: 20px;
  }

  .send-header h1 {
    font-size: 24px;
  }
}

/* === Queue Page === */
.queue-page {
  max-width: 1200px;
  margin: 0 auto;
}

.queue-header {
  text-align: center;
  margin-bottom: 32px;
}

.queue-header h1 {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text);
}

.queue-header p {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
}

.queue-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.queue-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.2s;
}

.queue-stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.queue-stat-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.queue-stat-content {
  flex: 1;
}

.queue-stat-value {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 4px;
}

.queue-stat-label {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 500;
}

.queue-stat.queued {
  border-color: #fbbf24;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.queue-stat.queued .queue-stat-value {
  color: #92400e;
}

.queue-stat.processing {
  border-color: #60a5fa;
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
}

.queue-stat.processing .queue-stat-value {
  color: #1e40af;
}

.queue-stat.scheduled {
  border-color: #a78bfa;
  background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
}

.queue-stat.scheduled .queue-stat-value {
  color: #5b21b6;
}

.queue-stat.failed {
  border-color: #f87171;
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
}

.queue-stat.failed .queue-stat-value {
  color: #991b1b;
}

.queue-stat.sent {
  border-color: #4ade80;
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}

.queue-stat.sent .queue-stat-value {
  color: #166534;
}

.queue-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.queue-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.queue-card-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.queue-actions {
  display: flex;
  gap: 8px;
}

.queue-filters {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.queue-filters form {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-group {
  flex: 1;
  min-width: 200px;
}

.filter-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
}

.queue-filters select {
  width: 100%;
  padding-block: 10px;
  padding-inline-start: 14px;
  padding-inline-end: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background-color: var(--surface);
  color: var(--text);
  transition: all 0.2s;
  background-position: right 14px center;
}

html[dir="rtl"] .queue-filters select {
  background-position: left 14px center;
}

.queue-filters select:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.queue-table .queue-message {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-table .queue-actions-cell {
  display: flex;
  gap: 6px;
}

.queue-table .queue-actions-cell form {
  display: inline;
}

.queue-error {
  background: #fef2f2;
  color: #991b1b;
  font-size: 12px;
  padding: 8px 12px;
  border-left: 3px solid #ef4444;
}

.queue-pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .queue-stats {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .queue-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .queue-filters {
    flex-direction: column;
  }

  .queue-filters select,
  .queue-filters button,
  .queue-filters a {
    width: 100%;
  }
}

/* === Dashboard Page === */
.dashboard-page {
  max-width: 1400px;
  margin: 0 auto;
}

.dashboard-header {
  text-align: center;
  margin-bottom: 32px;
}

.dashboard-header h1 {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text);
}

.dashboard-header p {
  margin: 0;
  color: var(--text-soft);
  font-size: 16px;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.dashboard-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: all 0.3s;
  box-shadow: var(--shadow);
}

.dashboard-stat:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.dashboard-stat-icon {
  font-size: 36px;
  flex-shrink: 0;
}

.dashboard-stat-content {
  flex: 1;
}

.dashboard-stat-label {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dashboard-stat-value {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text);
}

.dashboard-stat-sub {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.4;
}

.dashboard-stat.device {
  border-color: #4ade80;
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}

.dashboard-stat.device .dashboard-stat-value {
  color: #166534;
}

.dashboard-stat.messages {
  border-color: #60a5fa;
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
}

.dashboard-stat.messages .dashboard-stat-value {
  color: #1e40af;
}

.dashboard-stat.success {
  border-color: #34d399;
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
}

.dashboard-stat.success .dashboard-stat-value {
  color: #065f46;
}

.dashboard-stat.failed {
  border-color: #f87171;
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
}

.dashboard-stat.failed .dashboard-stat-value {
  color: #991b1b;
}

.dashboard-stat.queue {
  border-color: #fbbf24;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.dashboard-stat.queue .dashboard-stat-value {
  color: #92400e;
}

.dashboard-stat.clients {
  border-color: #a78bfa;
  background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
}

.dashboard-stat.clients .dashboard-stat-value {
  color: #5b21b6;
}

.dashboard-stat.uptime {
  border-color: #2dd4bf;
  background: linear-gradient(135deg, #ccfbf1 0%, #99f6e4 100%);
}

.dashboard-stat.uptime .dashboard-stat-value {
  color: #0f766e;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.dashboard-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.dashboard-card-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

@media (max-width: 768px) {
  .dashboard-stats {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
  }

  .dashboard-stat {
    padding: 20px;
  }

  .dashboard-stat-icon {
    font-size: 28px;
  }

  .dashboard-stat-value {
    font-size: 24px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .dashboard-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}

/* === Device Details Page === */
.device-page {
  max-width: 1200px;
  margin: 0 auto;
}

.device-header {
  margin-bottom: 24px;
}

.device-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 12px;
  transition: color 0.2s;
}

.device-back:hover {
  color: var(--brand-admin);
}

.device-header h1 {
  font-size: 28px;
  font-weight: 800;
  margin: 0;
  color: var(--text);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.device-card-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.device-card-body {
  min-height: 100px;
}

.device-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.device-status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.device-status-badge.success {
  background: #dcfce7;
  color: #166534;
}

.device-status-badge.warning {
  background: #fef3c7;
  color: #92400e;
}

.device-status-badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.device-status-badge.muted {
  background: #f1f5f9;
  color: #64748b;
}

.qr-box {
  text-align: center;
  padding: 20px;
  background: var(--surface-alt);
  border-radius: 12px;
  margin-bottom: 20px;
}

.qr-box img {
  max-width: 280px;
  height: auto;
  border-radius: 8px;
}

.connection-ok {
  font-size: 18px;
  font-weight: 700;
  color: var(--success);
  padding: 40px 20px;
}

.device-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.qr-steps {
  list-style: none;
  padding: 0;
  margin: 0;
}

.qr-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.qr-steps li:last-child {
  border-bottom: none;
}

.qr-steps strong {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--brand-admin);
  color: white;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.qr-steps span {
  flex: 1;
  line-height: 1.5;
}

.device-note {
  margin-top: 16px;
  padding: 12px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.5;
}

.device-info-table {
  margin-bottom: 20px;
}

.device-info-table th {
  width: 140px;
  padding-left: 20px;
}

.device-qr-body {
  text-align: center;
  padding: 20px;
  background: var(--surface-alt);
  border-radius: 12px;
}

.device-qr-body img {
  max-width: 280px;
  height: auto;
  border-radius: 8px;
}

@media (max-width: 768px) {
  .device-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .device-card {
    padding: 20px;
  }

  .device-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .device-actions {
    flex-direction: column;
  }

  .device-actions button,
  .device-actions a {
    width: 100%;
  }

  .device-info-table th {
    width: 120px;
    padding-left: 12px;
  }
}

/* === Tenants Page === */
.tenants-page {
  max-width: 1200px;
  margin: 0 auto;
}

.tenants-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 32px 0;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-radius: 20px;
  border: 1px solid #bae6fd;
}

.tenants-header h1 {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 12px;
  color: #0369a1;
}

.tenants-header p {
  margin: 0;
  color: #0c4a6e;
  font-size: 16px;
}

.tenants-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 28px;
  transition: all 0.3s;
}

.tenants-card:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}

.tenants-card-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tenants-card-header h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.tenants-card-body {
  min-height: 100px;
}

.tenant-switch-form {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.tenant-switch-form .form-group {
  flex: 1;
}

.tenant-switch-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
}

.tenant-switch-form select {
  width: 100%;
  padding-block: 14px;
  padding-inline-start: 18px;
  padding-inline-end: 46px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background-color: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
  cursor: pointer;
  background-position: right 14px center;
}

html[dir="rtl"] .tenant-switch-form select {
  background-position: left 14px center;
}

.tenant-switch-form select:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background-color: var(--surface);
}

.tenant-switch-form button {
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
}

.tenant-create-form .form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
}

.tenant-create-form .form-group {
  flex: 1;
}

.tenant-create-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
}

.tenant-create-form input,
.tenant-create-form select {
  width: 100%;
  padding-block: 14px;
  padding-inline-start: 18px;
  padding-inline-end: 18px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background-color: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
}

.tenant-create-form select {
  padding-inline-end: 46px;
  background-position: right 14px center;
}

html[dir="rtl"] .tenant-create-form select {
  background-position: left 14px center;
}

.tenant-create-form input:focus,
.tenant-create-form select:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.tenant-create-form button {
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
}

.tenants-table {
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.tenants-table thead {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.tenants-table th {
  padding: 16px 18px;
  text-align: right;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

.tenants-table th:first-child {
  border-top-right-radius: 12px;
}

.tenants-table th:last-child {
  border-top-left-radius: 12px;
}

.tenants-table td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.tenants-table tbody tr {
  transition: background 0.2s;
}

.tenants-table tbody tr:hover {
  background: #f8fafc;
}

.tenants-table tbody tr:last-child td:first-child {
  border-bottom-right-radius: 12px;
}

.tenants-table tbody tr:last-child td:last-child {
  border-bottom-left-radius: 12px;
}

.tenants-table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 768px) {
  .tenants-header {
    padding: 24px 20px;
    margin-bottom: 24px;
  }

  .tenants-header h1 {
    font-size: 24px;
  }

  .tenants-card {
    padding: 24px 20px;
    border-radius: 16px;
  }

  .tenant-switch-form {
    flex-direction: column;
  }

  .tenant-switch-form .form-group {
    width: 100%;
  }

  .tenant-switch-form button {
    width: 100%;
  }

  .tenant-create-form .form-row {
    flex-direction: column;
    gap: 16px;
  }

  .tenant-create-form .form-group {
    width: 100%;
  }

  .tenants-table {
    font-size: 13px;
  }

  .tenants-table th,
  .tenants-table td {
    padding: 12px 10px;
  }
}

/* === Broadcast Page === */
.broadcast-page {
  max-width: 820px;
  margin: 0 auto;
}

.broadcast-header {
  margin-bottom: 18px;
}

.broadcast-header h1 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text);
}

.broadcast-header p {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
}

.broadcast-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 22px;
}

.broadcast-info {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.broadcast-info-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.broadcast-info-content {
  flex: 1;
}

.broadcast-info-content h4 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: #0369a1;
}

.broadcast-info-content p {
  margin: 0;
  font-size: 13px;
  color: #0c4a6e;
  line-height: 1.5;
}

.broadcast-form .form-group {
  margin-bottom: 14px;
}

.broadcast-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
}

.broadcast-form select,
.broadcast-form textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
}

.broadcast-form select:focus,
.broadcast-form textarea:focus {
  outline: none;
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.broadcast-form textarea {
  min-height: 120px;
  resize: vertical;
}

.broadcast-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.broadcast-preview-box {
  margin-top: 20px;
  padding: 16px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  color: #0c4a6e;
}

.broadcast-preview-box pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font-size: 13px;
}

@media (max-width: 640px) {
  .broadcast-card {
    padding: 20px;
  }

  .broadcast-header h1 {
    font-size: 24px;
  }

  .broadcast-actions {
    flex-direction: column;
  }

  .broadcast-actions button {
    width: 100%;
  }
}

/* === Accessibility === */
/* Skip to content link for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  right: 0;
  background: var(--brand-admin);
  color: white;
  padding: 8px 16px;
  z-index: 100;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

/* Links */
a:focus-visible {
  outline: 2px solid var(--brand-admin);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Tables accessibility */
table.tbl th {
  position: relative;
}

table.tbl th[scope="col"] {
  position: relative;
}

/* Modal accessibility */
.modal-overlay {
  background: rgba(0, 0, 0, 0.6);
}

.modal {
  max-height: 90vh;
  overflow-y: auto;
}

/* Form labels */
label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--text);
}

/* Error messages */
.error-message {
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus visible for all interactive elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--brand-admin);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }
  
  .badge {
    border: 1px solid currentColor;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === Select2 Integration === */
.select2-container {
  width: 100% !important;
  direction: rtl;
}

.select2-container--default .select2-selection--single {
  height: 46px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  transition: all 0.2s;
  outline: none;
}

.select2-container--default .select2-selection--single:focus,
.select2-container--default.select2-container--focus .select2-selection--single {
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  padding: 10px 16px;
  font-size: 15px;
  color: var(--text);
  line-height: 24px;
  padding-left: 40px;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: var(--text-soft);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 44px;
  width: 40px;
  position: absolute;
  right: 0;
  top: 0;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: var(--text-soft) transparent transparent transparent;
  border-width: 6px 5px 0 5px;
  margin-left: -5px;
  margin-top: -3px;
}

.select2-dropdown {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  margin-top: 8px;
  z-index: 99999 !important;
  direction: rtl;
}

.select2-container--default .select2-results__option {
  padding: 12px 16px;
  font-size: 15px;
  color: var(--text);
  transition: background 0.2s;
}

.select2-container--default .select2-results__option--highlighted {
  background: #f0f9ff !important;
  color: #0369a1 !important;
}

.select2-container--default .select2-results__option--selected {
  background: #dbeafe !important;
  color: #1e40af !important;
  font-weight: 600;
}

.select2-container--default .select2-search--dropdown {
  padding: 12px;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface-alt);
  color: var(--text);
  transition: all 0.2s;
  outline: none;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.select2-container--default .select2-results__message {
  padding: 16px;
  color: var(--text-soft);
  font-size: 14px;
}

.select2-container--default .select2-results__option[aria-disabled="true"] {
  color: var(--text-soft) !important;
  opacity: 0.6;
}

/* Select2 Multiple */
.select2-container--default .select2-selection--multiple {
  min-height: 46px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  transition: all 0.2s;
  outline: none;
}

.select2-container--default .select2-selection--multiple:focus,
.select2-container--default.select2-container--focus .select2-selection--multiple {
  border-color: var(--brand-admin);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: var(--surface);
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: #dbeafe;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  color: #1e40af;
  margin: 4px 4px 4px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  color: #1e40af;
  margin-right: 0;
  transition: color 0.2s;
  font-size: 16px;
  line-height: 1;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
  color: #dc2626;
}

.select2-container--default .select2-selection--multiple .select2-selection__clear {
  margin-top: 12px;
  margin-right: 12px;
  color: var(--text-soft);
}

.select2-container--default .select2-selection--multiple .select2-selection__clear:hover {
  color: var(--danger);
}

/* Select2 Close Button */
.select2-container--default .select2-selection--single .select2-selection__clear {
  color: var(--text-soft);
  margin-right: 12px;
  margin-top: 12px;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
  color: var(--danger);
}

/* RTL Support */
.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow {
  right: auto;
  left: 0;
}

.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__rendered {
  padding-right: 16px;
  padding-left: 40px;
}

/* Fix for dropdown positioning */
.select2-container {
  position: relative;
}

.select2-dropdown {
  position: absolute !important;
  top: 100% !important;
  left: 0 !important;
  right: auto !important;
}

/* API key / webhook (tenant + admin) */
.api-key-back-link {
  margin-bottom: 16px;
}

.api-key-page-intro {
  margin-bottom: 16px;
  padding: 16px 18px;
  background: rgba(13, 148, 136, 0.06);
  border: 1px solid rgba(13, 148, 136, 0.18);
  border-radius: 12px;
}

.api-key-page-intro p {
  margin: 0;
  line-height: 1.75;
  color: var(--text-soft, #64748b);
  font-size: 14px;
}

.api-key-stats {
  margin-bottom: 24px;
}

.api-key-token-panel {
  border-color: #bbf7d0;
  margin-bottom: 16px;
}

.api-key-token-alert {
  margin-top: 0;
}

.api-client-form .form-group--full {
  width: 100%;
}

.api-client-form .form-group--full .form-control {
  width: 100%;
}

.api-client-form-actions {
  margin-top: 8px;
}

.api-key-danger-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.api-key-danger-actions form {
  margin: 0;
}

.webhook-info-box {
  margin: 8px 0 20px;
  padding: 16px 18px;
  background: var(--surface-alt, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
}

.webhook-info-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text, #0f172a);
}

.webhook-info-text {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-soft, #64748b);
}

.webhook-info-example {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted, #94a3b8);
}

.webhook-info-example-label {
  font-weight: 600;
  margin-left: 6px;
}

.webhook-field .form-control {
  width: 100%;
  max-width: 100%;
}

.field-optional {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #94a3b8);
  background: var(--surface-alt, #f1f5f9);
  border-radius: 999px;
  vertical-align: middle;
}

.help-security {
  color: var(--warning-ink, #b45309);
}

.webhook-field-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.webhook-test-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.webhook-test-soon {
  margin: 0;
}

/* === SaaS Super Admin Console === */
.admin-console {
  max-width: 1360px;
  margin: 0 auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--topbar-height) - 48px);
  width: 100%;
}

.admin-page-header {
  margin-bottom: 16px;
}

.admin-stat-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.admin-stat-grid .card {
  padding: 14px;
  border-radius: var(--radius-sm);
}

.admin-stat-grid .stat .value {
  font-size: 22px;
}

.admin-stat-status .badge {
  vertical-align: middle;
}

.admin-filter-panel,
.admin-table-panel,
.admin-form-panel {
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.admin-console .admin-page-header,
.admin-console .admin-filter-panel,
.admin-console .admin-form-panel,
.admin-console .admin-stat-grid {
  flex-shrink: 0;
}

.admin-console .admin-table-panel {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
  overflow: visible;
}

.admin-console .admin-table-panel > .panel-head {
  flex-shrink: 0;
}

.admin-console .admin-table-panel > .table-wrap {
  flex: 1 1 0;
  min-height: calc(100dvh - var(--topbar-height) - 300px);
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}

.admin-filter-panel .panel-body,
.admin-form-panel .panel-body {
  padding: 14px;
}

.admin-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-filters .form-group,
.admin-plan-form .form-group,
.admin-action-forms .form-group {
  margin-bottom: 0;
}

.admin-check,
.admin-check-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.admin-check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin: 4px 0 14px;
}

.admin-create-details {
  position: relative;
}

.admin-create-details summary {
  list-style: none;
}

.admin-create-details summary::-webkit-details-marker,
.row-actions-menu summary::-webkit-details-marker {
  display: none;
}

.admin-create-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  width: min(680px, calc(100vw - 48px));
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lg, 0 20px 50px rgba(15, 23, 42, 0.14));
}

.tenant-switch-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.tenant-switch-mini select {
  min-height: 34px;
  max-width: 220px;
  padding-block: 6px;
  padding-inline-start: 10px;
  padding-inline-end: 36px;
  font-size: 12.5px;
  background-size: 12px 12px;
  background-position: right 10px center;
}

html[dir="rtl"] .tenant-switch-mini select {
  background-position: left 10px center;
}

.admin-compact-table {
  font-size: 12.5px;
}

.admin-compact-table th,
.admin-compact-table td {
  padding: 9px 10px;
  vertical-align: middle;
}

.admin-entity {
  display: grid;
  gap: 3px;
}

.admin-entity strong,
.admin-entity-link {
  color: var(--text);
  font-weight: 800;
}

.admin-entity-link:hover {
  color: var(--brand-admin);
  text-decoration: none;
}

.block {
  display: block;
}

.admin-actions,
.admin-inline-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-inline-actions form,
.admin-actions form,
.quick-actions-grid form {
  margin: 0;
}

.row-actions-menu {
  position: relative;
  display: inline-block;
}

.row-actions-menu summary {
  list-style: none;
}

.row-actions-list {
  display: none;
  gap: 8px;
  min-width: 190px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.row-actions-menu[open] > .row-actions-list {
  display: grid;
}

.row-actions-menu[open] .row-actions-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
}

/* JS promotes open menus to viewport layer — escapes scrollable table clipping */
.row-actions-menu[open] .row-actions-list.is-floating {
  position: fixed !important;
  z-index: 1300;
  margin: 0;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.2);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.row-actions-menu[open] .row-actions-list.is-floating.is-flipped {
  box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.16);
}

.row-actions-list a,
.row-actions-list button {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  text-align: right;
  padding: 7px 9px;
  cursor: pointer;
}

.row-actions-list a:hover,
.row-actions-list button:hover {
  background: var(--muted-bg);
  text-decoration: none;
}

.row-actions-list input,
.row-actions-list select {
  min-height: 34px;
  padding-block: 7px;
  padding-inline-start: 9px;
  padding-inline-end: 40px;
  font-size: 12.5px;
  background-size: 12px 12px;
  background-position: right 10px center;
}

html[dir="rtl"] .row-actions-list select {
  background-position: left 10px center;
}

.action-popover-wide {
  min-width: 300px;
}

.action-popover-wide form {
  display: grid;
  gap: 7px;
  margin: 0;
}

.tenant-profile-head {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.9fr);
  gap: 18px;
  align-items: center;
  padding: 18px;
}

.tenant-profile-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tenant-avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--brand-admin);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.tenant-profile-main h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.tenant-profile-meta {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  color: var(--text-soft);
  font-size: 13px;
}

.tenant-profile-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tenant-profile-facts div {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.tenant-profile-facts span {
  display: block;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 4px;
}

.tenant-profile-facts strong {
  font-size: 13px;
}

.admin-quick-actions {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 16px;
}

.quick-action-btn.danger {
  color: var(--danger);
}

button.quick-action-btn {
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  text-align: right;
}

.admin-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-tabs a {
  padding: 10px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 800;
}

.admin-tabs a:hover,
.admin-tabs a.active {
  background: var(--surface);
  color: var(--brand-admin);
  text-decoration: none;
}

.admin-tabs a.active {
  border: 1px solid var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -1px;
}

.admin-split {
  margin-bottom: 16px;
}

.admin-kv {
  display: grid;
  gap: 8px;
  margin: 0;
}

.admin-kv div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
}

.admin-kv div:last-child {
  border-bottom: 0;
}

.admin-kv dt {
  color: var(--text-soft);
  font-weight: 700;
}

.admin-kv dd {
  margin: 0;
  font-weight: 800;
  text-align: left;
}

.admin-action-forms {
  display: grid;
  gap: 14px;
}

.admin-action-forms form {
  margin: 0;
}

.admin-plan-edit {
  min-width: min(760px, calc(100vw - 48px));
}

/* === Plans page (/plans) === */
.plans-console .admin-plan-form .plans-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.plans-console .admin-plan-form .form-group {
  margin-bottom: 0;
}

.plans-console .admin-plan-form .admin-check-row {
  margin-bottom: 14px;
}

.plans-table-wrap {
  overflow-x: auto;
}

.plans-table {
  table-layout: auto;
  width: 100%;
  min-width: 1180px;
}

.plans-table-admin th,
.plans-table-admin td {
  white-space: nowrap;
}

.plans-table-admin td:nth-child(7) {
  white-space: normal;
  min-width: 120px;
}

.is-muted-row {
  opacity: 0.72;
}

.plan-schema-note {
  font-size: 12.5px;
  margin-bottom: 14px;
}

.plan-schema-note code {
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.plan-usage-sub {
  font-size: 11px;
  margin-top: 2px;
}

.plans-table th,
.plans-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.plans-table th {
  white-space: nowrap;
}

.plan-entity {
  min-width: 0;
}

.plan-entity strong {
  display: block;
  font-weight: 800;
  line-height: 1.35;
}

.plan-code {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-soft);
  direction: ltr;
  text-align: right;
  unicode-bidi: plaintext;
  word-break: break-all;
}

.plan-price {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

.plan-limits {
  display: grid;
  gap: 4px;
  font-size: 12px;
  line-height: 1.35;
  min-width: 0;
}

.plan-limits > span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plans-actions-cell {
  width: 1%;
  white-space: nowrap;
}

.plans-table .badge {
  white-space: nowrap;
}

.admin-plan-edit .plans-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.admin-plan-edit .form-group {
  margin-bottom: 0;
}

.plan-dialog {
  border: 0;
  border-radius: var(--radius-md);
  padding: 0;
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
}

.plan-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.plan-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.plan-dialog-head h2 {
  margin: 0;
  font-size: 16px;
}

.plan-dialog-body {
  padding: 16px 18px 18px;
  overflow: auto;
  max-height: calc(100dvh - 120px);
}

.plan-form-section {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.plan-form-section:last-of-type {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.plan-form-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
}

.plan-form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.plan-feature-groups,
.plan-feature-preview {
  display: grid;
  gap: 12px;
}

.plan-feature-group h4 {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--text-soft);
}

.plan-feature-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.plan-feature-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  background: var(--muted-bg);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
}

.plan-feature-pill.is-on {
  background: var(--success-bg);
  color: var(--success);
}

.plan-feature-pill.is-off {
  background: var(--muted-bg);
  color: var(--text-muted);
  opacity: 0.85;
}

.plan-feature-pill.is-toggle {
  cursor: pointer;
}

.plan-feature-pill.is-toggle input {
  width: 15px;
  height: 15px;
  margin: 0;
}

.plan-used-alert {
  margin-bottom: 14px;
}

.plan-ack-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-weight: 600;
}

.plan-sensitive-field[readonly] {
  background: var(--muted-bg);
  cursor: not-allowed;
}

.plan-preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 20px;
}

.plan-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 0;
}

.plan-facts > div {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.plan-facts dt {
  margin: 0 0 4px;
  font-size: 11.5px;
  color: var(--text-soft);
  font-weight: 700;
}

.plan-facts dd {
  margin: 0;
  font-weight: 800;
}

.plan-readonly-value {
  min-height: 42px;
  display: flex;
  align-items: center;
}

.admin-hint {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
}

/* === Users page (/users) === */
.users-table-wrap {
  overflow-x: auto;
}

.users-table {
  table-layout: fixed;
  width: 100%;
  min-width: 900px;
}

.users-col-id { width: 48px; }
.users-col-name { width: 16%; }
.users-col-email { width: 24%; }
.users-col-role { width: 14%; }
.users-col-status { width: 88px; }
.users-col-login { width: 148px; }
.users-col-actions { width: 108px; }

.users-table thead th {
  white-space: nowrap;
  vertical-align: middle;
}

.users-table tbody tr {
  height: 50px;
}

.users-table tbody td {
  padding: 10px;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.users-cell-id {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-soft);
  text-align: center;
}

.users-name,
.users-email,
.users-role-badge {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.users-name {
  font-weight: 800;
}

.users-email {
  font-family: var(--font-mono);
  font-size: 12.5px;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: right;
}

.users-role-badge {
  display: inline-block;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--muted-bg);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 700;
  vertical-align: middle;
}

.users-cell-status {
  text-align: center;
}

.users-cell-status .badge {
  vertical-align: middle;
}

.users-cell-login {
  font-size: 12.5px;
}

.users-actions-cell {
  text-align: center;
  overflow: visible;
  padding-inline: 6px;
}

.users-row-menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.users-action-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 34px;
  height: 34px;
  padding: 0 10px;
  margin: 0;
  white-space: nowrap;
}

.users-row-menu:not([open]) .row-actions-list {
  position: absolute;
  inset: auto;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  padding: 0;
  border: 0;
}

.users-action-menu {
  min-width: 240px;
}

.users-action-head {
  display: grid;
  gap: 2px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.users-action-head strong {
  font-size: 13px;
}

.users-action-head .muted {
  font-size: 11.5px;
}

.users-role-form {
  display: grid;
  gap: 8px;
  margin: 0;
}

.users-action-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}

.users-action-menu form {
  margin: 0;
}

.users-action-menu .btn {
  width: 100%;
  justify-content: center;
}

.form-select-sm {
  width: 100%;
  min-height: 36px;
  padding-block: 7px;
  padding-inline-start: 10px;
  padding-inline-end: 36px;
  font-size: 12.5px;
  background-size: 12px 12px;
  background-position: right 12px center;
}

html[dir="rtl"] .form-select-sm {
  padding-inline-start: 10px;
  padding-inline-end: 36px;
  background-position: left 12px center;
}

.users-create-form .form-group:last-of-type {
  margin-bottom: 0;
}

.user-dialog {
  width: min(480px, calc(100vw - 32px));
}

@media (max-width: 900px) {
  .admin-page-header,
  .tenant-profile-head {
    grid-template-columns: 1fr;
  }

  .page-header.admin-page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .tenant-profile-facts {
    grid-template-columns: 1fr;
  }

  .activity-grid,
  .grid-2.admin-split,
  .plan-preview-grid {
    grid-template-columns: 1fr;
  }

  .admin-create-popover,
  .row-actions-menu[open] .row-actions-list:not(.is-floating) {
    position: static;
    width: auto;
    min-width: 0;
    margin-top: 8px;
  }
}

/* === Sending Safety === */
.safety-console {
  gap: 14px;
}

.safety-console .panel,
.safety-console .admin-table-panel {
  margin-bottom: 0;
}

.safety-console .admin-table-panel {
  flex: 0 0 auto;
}

.safety-console .admin-table-panel > .table-wrap {
  flex: 0 0 auto;
  min-height: 0;
  overflow-y: visible;
  padding-bottom: 0;
}

.safety-console .panel-head p {
  margin: 3px 0 0;
  color: var(--text-soft);
  font-size: 12px;
}

.safety-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.admin-stat-card {
  min-width: 0;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-stat-card > i {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  color: #334155;
  background: #eef2f6;
  font-size: 18px;
}

.admin-stat-card span,
.admin-stat-card strong {
  display: block;
}

.admin-stat-card span {
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.4;
}

.admin-stat-card strong {
  margin-top: 2px;
  color: var(--text);
  font-size: 21px;
  line-height: 1.15;
}

.admin-stat-card.is-danger > i {
  color: #b91c1c;
  background: #fef2f2;
}

.admin-stat-card.is-warning > i {
  color: #a16207;
  background: #fffbeb;
}

.admin-stat-card.is-info > i {
  color: #0369a1;
  background: #f0f9ff;
}

.safety-split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.safety-device-table {
  min-width: 980px;
}

.safety-stage {
  display: block;
  font-weight: 800;
  white-space: nowrap;
}

.safety-score {
  min-width: 32px;
  height: 28px;
  padding: 0 7px;
  border-radius: var(--radius-sm);
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
}

.safety-score.is-low {
  color: #166534;
  background: #f0fdf4;
}

.safety-score.is-medium {
  color: #92400e;
  background: #fffbeb;
}

.safety-score.is-high {
  color: #991b1b;
  background: #fef2f2;
}

.status-badge {
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-soft);
  background: var(--muted-bg);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.success,
.safety-quality.is-healthy,
.safety-action.is-allow {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.status-badge.warning,
.safety-quality.is-watch,
.safety-action.is-throttle {
  color: #92400e;
  border-color: #fde68a;
  background: #fffbeb;
}

.status-badge.danger,
.safety-quality.is-limited,
.safety-quality.is-blocked,
.safety-action.is-block {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}

.safety-inline-control {
  min-width: 150px;
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 5px;
  align-items: center;
}

.safety-inline-control select {
  min-height: 34px;
  padding-block: 6px;
  font-size: 12px;
}

.safety-device-menu {
  display: inline-block;
}

.safety-device-popover {
  width: min(430px, calc(100vw - 48px));
}

.safety-device-form {
  display: grid;
  gap: 10px;
}

.safety-device-form > label,
.safety-limit-grid label {
  display: grid;
  gap: 4px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.safety-device-form select,
.safety-device-form input {
  min-height: 34px;
  padding-block: 6px;
  font-size: 12px;
}

.safety-limit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 8px;
}

.safety-block-form-wrap {
  padding-block: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.safety-block-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(160px, 0.8fr) minmax(240px, 1.5fr) auto;
  gap: 10px;
  align-items: end;
}

.safety-block-form .form-group {
  margin: 0;
}

.safety-tenant-limits-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
}

.safety-tenant-limits-form label {
  display: grid;
  gap: 5px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.safety-tenant-limits-form input,
.safety-tenant-limits-form select {
  min-height: 36px;
  padding-block: 7px;
  font-size: 12px;
}

.safety-filters {
  padding-block: 10px;
  border-bottom: 1px solid var(--border);
}

.safety-filters form {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 220px)) auto;
  gap: 8px;
  align-items: center;
}

.safety-filters select {
  min-height: 36px;
  padding-block: 7px;
  font-size: 12px;
}

.safety-reason {
  max-width: 380px;
  white-space: normal;
  line-height: 1.5;
}

.safety-campaign-note {
  margin-top: 0;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.safety-campaign-note > i {
  margin-top: 2px;
  font-size: 18px;
}

.campaign-form-row,
.campaign-vars {
  margin-top: 14px;
}

.campaign-compact-field {
  margin: 0;
}

.campaign-preview {
  margin-top: 12px;
  white-space: pre-wrap;
}

.campaign-preview-text {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
}

.safety-consent-check {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: #713f12;
  background: #fffbeb;
  font-size: 12px;
  line-height: 1.65;
  cursor: pointer;
}

.safety-consent-check input {
  margin-top: 3px;
  flex: 0 0 auto;
}

.safety-consent-check.is-required {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.safety-consent-check.is-compact {
  min-height: 34px;
  margin: 0;
  padding: 6px 8px;
  align-items: center;
  white-space: nowrap;
}

.safety-consent-check.is-compact input {
  margin-top: 0;
}

.campaign-actions,
.campaign-filter-form,
.campaign-action-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.campaign-actions {
  margin-top: 16px;
}

.campaign-action-form {
  margin: 0;
}

.campaign-safety-strip {
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface-alt);
}

.campaign-safety-reason {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.campaign-stats-grid {
  margin-bottom: 16px;
}

.campaign-progress {
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: var(--radius-full);
  overflow: hidden;
  accent-color: var(--success);
}

.campaign-progress-label {
  margin-bottom: 16px;
  font-size: 12px;
}

.plan-safety-limits {
  margin-top: 12px;
}

.device-warmup-label {
  margin-top: 4px;
  font-size: 11px;
}

@media (max-width: 1180px) {
  .safety-stat-grid {
    grid-template-columns: repeat(4, minmax(140px, 1fr));
  }
}

@media (max-width: 820px) {
  .safety-stat-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .safety-split-grid,
  .safety-block-form,
  .safety-tenant-limits-form,
  .safety-filters form {
    grid-template-columns: 1fr;
  }

  .safety-block-form .btn,
  .safety-filters .btn {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .safety-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .safety-limit-grid {
    grid-template-columns: 1fr;
  }

  .campaign-actions,
  .campaign-action-form {
    align-items: stretch;
    flex-direction: column;
  }

  .campaign-actions .btn,
  .campaign-action-form .btn {
    width: 100%;
  }
}

@media (max-width: 360px) {
  .safety-stat-grid {
    grid-template-columns: 1fr;
  }
}

/* === Templates Builder === */
.template-console {
  gap: 14px;
}

.template-console .panel,
.template-console .admin-table-panel,
.template-console .admin-filter-panel,
.template-console .admin-stat-grid {
  margin-bottom: 0;
}

.template-console .panel-head p {
  margin: 3px 0 0;
  color: var(--text-soft);
  font-size: 12px;
}

.template-stat-grid {
  grid-template-columns: repeat(5, minmax(140px, 1fr));
}

.template-create-panel[hidden],
.template-tab-panel[hidden],
.template-custom-confirm[hidden],
.template-marketing-warning[hidden],
.send-template-variables[hidden],
.send-template-warning[hidden],
.template-variable-map-note[hidden] {
  display: none;
}

.template-builder-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 16px;
  align-items: start;
}

.template-library {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.template-library-head {
  margin-bottom: 9px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.template-library-head strong {
  font-size: 12px;
}

.template-library-head span {
  color: var(--text-soft);
  font-size: 11px;
}

.template-library-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.template-library-item {
  min-width: 0;
  min-height: 66px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: right;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.template-library-item:hover,
.template-library-item:focus-visible {
  border-color: var(--brand-primary);
  background: #f0fdfa;
}

.template-library-item > i {
  margin-top: 2px;
  color: var(--brand-primary);
  font-size: 18px;
}

.template-library-item span,
.template-library-item strong,
.template-library-item small {
  min-width: 0;
  display: block;
}

.template-library-item strong {
  font-size: 12px;
}

.template-library-item small {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.4;
}

.template-builder-main {
  display: grid;
  gap: 14px;
}

.template-meta-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(130px, 0.8fr));
  gap: 10px;
}

.template-meta-grid label,
.template-field,
.template-preview-values label,
.template-test-form label,
.send-template-variables label {
  display: grid;
  gap: 5px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
}

.template-meta-grid input,
.template-meta-grid select,
.template-field input,
.template-field select,
.template-preview-values input,
.template-test-form input,
.send-template-variables input {
  min-height: 38px;
  font-size: 13px;
}

.template-editor-field {
  display: grid;
  gap: 6px;
}

.template-editor-label,
.template-preview-head,
.template-code-head,
.template-header-badges,
.template-builder-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.template-editor-label {
  justify-content: space-between;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 800;
}

.template-editor-field textarea {
  min-height: 190px;
  resize: vertical;
  line-height: 1.8;
}

.template-variable-picker {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 10px;
  background: var(--surface-alt);
}

.template-variable-group {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.template-variable-group > strong {
  padding-top: 5px;
  color: var(--text-soft);
  font-size: 11px;
}

.template-variable-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.template-variable-chip {
  min-height: 29px;
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  color: #334155;
  background: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
}

.template-variable-chip:hover,
.template-variable-chip:focus-visible {
  border-color: var(--brand-primary);
  color: var(--brand-primary-dark);
  background: #f0fdfa;
}

.template-preview-pane {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  overflow: hidden;
}

.template-preview-pane.is-sticky {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
}

.template-preview-head {
  justify-content: space-between;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.template-preview-head strong {
  font-size: 12px;
}

.whatsapp-preview {
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #efeae2;
}

.template-preview-pane > .whatsapp-preview {
  margin: 13px;
}

.whatsapp-preview-top {
  min-height: 44px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f8fafc;
  background: #075e54;
  font-size: 12px;
  font-weight: 800;
}

.whatsapp-preview-top i {
  font-size: 18px;
}

.whatsapp-preview-body {
  min-height: 230px;
  padding: 18px 12px;
  display: flex;
  align-items: flex-start;
}

.whatsapp-message-bubble {
  width: min(92%, 420px);
  padding: 9px 11px 7px;
  border-radius: 7px 0 7px 7px;
  color: #17212b;
  background: #d9fdd3;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.12);
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.template-diagnostics,
.template-render-result {
  margin: 0 13px 13px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 2px;
  color: var(--text-soft);
  background: #fff;
  font-size: 11px;
}

.template-diagnostics strong {
  color: var(--text);
}

.template-render-result.has-error {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}

.template-custom-confirm {
  padding: 10px;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: #713f12;
  background: #fffbeb;
  font-size: 12px;
  line-height: 1.6;
}

.template-custom-confirm input {
  margin-top: 3px;
}

.template-marketing-warning,
.template-safety-banner,
.template-api-note,
.template-variable-map-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.template-builder-actions {
  justify-content: flex-end;
}

.template-filters {
  grid-template-columns: minmax(200px, 1.4fr) repeat(3, minmax(150px, 0.8fr)) auto;
}

.template-table {
  min-width: 880px;
}

.template-name-cell {
  min-width: 260px;
}

.template-purpose.is-info,
.status-badge.info {
  color: #0369a1;
  border-color: #bae6fd;
  background: #f0f9ff;
}

.template-purpose.is-warning {
  color: #92400e;
  border-color: #fde68a;
  background: #fffbeb;
}

.template-purpose.is-danger {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}

.template-purpose.is-success {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.template-back-link {
  margin-bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.template-header-badges {
  margin-top: 7px;
  flex-wrap: wrap;
}

.template-safety-banner div {
  display: grid;
  gap: 2px;
}

.template-safety-banner span {
  font-size: 12px;
}

.template-tabs {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 3px;
  overflow-x: auto;
  background: #fff;
}

.template-tabs button {
  min-height: 36px;
  padding: 7px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: var(--text-soft);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.template-tabs button.is-active {
  color: #0f766e;
  background: #f0fdfa;
}

.template-tab-panel {
  min-width: 0;
}

.template-editor-panel {
  min-width: 0;
}

.template-preview-workbench,
.template-campaign-usage {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
}

.template-preview-values,
.template-test-form {
  display: grid;
  gap: 10px;
}

.template-code-block {
  border: 1px solid #334155;
  border-radius: var(--radius-sm);
  overflow: hidden;
  direction: ltr;
  text-align: left;
  background: #0f172a;
}

.template-api-examples {
  display: grid;
  gap: 12px;
}

.template-code-head {
  min-height: 40px;
  padding: 7px 10px;
  justify-content: space-between;
  color: #cbd5e1;
  border-bottom: 1px solid #334155;
}

.template-code-block pre {
  margin: 0;
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.template-api-note {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  color: #075985;
  background: #f0f9ff;
  font-size: 12px;
}

.template-danger-zone .panel-body {
  display: flex;
  justify-content: flex-end;
}

.template-missing-alert {
  margin: 7px 0;
  display: block;
  color: #991b1b;
  font-weight: 800;
}

.template-variable-map-note {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  color: #075985;
  background: #f0f9ff;
  font-size: 12px;
}

/* Template selection in individual sending */
.send-template-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.72fr);
  gap: 16px;
  align-items: start;
}

.send-template-layout .send-card {
  max-width: none;
  margin: 0;
}

.send-template-preview {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f8fafc;
}

.send-template-preview .whatsapp-preview {
  margin: 13px;
}

.send-template-variables {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  background: var(--surface-alt);
}

.send-template-warning {
  align-items: flex-start;
}

.send-warm-hint {
  margin-top: 10px;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .template-stat-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .template-meta-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .template-library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .template-builder-layout,
  .template-preview-workbench,
  .template-campaign-usage,
  .send-template-layout {
    grid-template-columns: 1fr;
  }

  .template-preview-pane.is-sticky,
  .send-template-preview {
    position: static;
  }

  .template-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .template-stat-grid,
  .template-meta-grid,
  .template-filters,
  .send-template-variables,
  .template-library-grid {
    grid-template-columns: 1fr;
  }

  .template-variable-group {
    grid-template-columns: 1fr;
  }

  .template-builder-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .template-builder-actions .btn {
    width: 100%;
  }
}
