/* =============================================================================
   BaQeT NeT — Smart Audience Management UI Stylesheet
   Direction: RTL | Language: Arabic | Theme: BaQeT NeT Blue (#0b5d7a)
   ============================================================================= */

:root {
  --primary: #0b5d7a;
  --primary-hover: #084960;
  --primary-light: #e6f3f7;
  --primary-border: #b3d7e5;
  --success: #198754;
  --success-light: #d1e7dd;
  --success-border: #a3cfbb;
  --warning: #b07d04;
  --warning-light: #fff3cd;
  --warning-border: #ffe69c;
  --danger: #dc3545;
  --danger-light: #f8d7da;
  --danger-border: #f1aeb5;
  --info: #0dcaf0;
  --info-light: #cff4fc;
  --info-border: #9eeaf9;
  --dark: #102027;
  --gray-50: #fbfcfd;
  --gray-100: #f8f9fa;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-400: #ced4da;
  --gray-500: #adb5bd;
  --gray-600: #6c757d;
  --gray-700: #495057;
  --gray-800: #343a40;
  --gray-900: #212529;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --font-family: 'Cairo', 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  direction: rtl;
  text-align: right;
  background-color: #f0f2f5;
  color: var(--gray-900);
  line-height: 1.6;
  min-height: 100vh;
}

/* LTR Isolation Helper */
.ltr-text {
  direction: ltr !important;
  text-align: left !important;
  display: inline-block;
  unicode-bidi: isolate;
  font-family: var(--font-mono);
}

/* Layout Container */
.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

/* Header & Brand */
.app-header {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px 28px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 3px solid var(--primary);
  flex-wrap: wrap;
  gap: 15px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.brand-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.brand-subtitle {
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 2px;
}

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

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

.badge-primary { background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary-border); }
.badge-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success-border); }
.badge-warning { background: var(--warning-light); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-danger  { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-gray    { background: var(--gray-200); color: var(--gray-700); border: 1px solid var(--gray-300); }

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  background: white;
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-tab-btn {
  flex: 1;
  min-width: 140px;
  padding: 12px 18px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
}

.nav-tab-btn:hover {
  background: var(--gray-100);
  color: var(--primary);
}

.nav-tab-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* Tab Views Container */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Card Containers */
.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  border: 1px solid var(--gray-200);
}

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

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 4px;
}

/* Notices and Banners */
.notice-box {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  margin-bottom: 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.5;
}

.notice-info    { background: var(--info-light); color: #055160; border: 1px solid var(--info-border); }
.notice-success { background: var(--success-light); color: #0f5132; border: 1px solid var(--success-border); }
.notice-warning { background: var(--warning-light); color: #664d03; border: 1px solid var(--warning-border); }
.notice-danger  { background: var(--danger-light); color: #842029; border: 1px solid var(--danger-border); }

/* Form Controls */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
  margin-right: 4px;
}

.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  background-color: white;
  color: var(--gray-900);
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 93, 122, 0.15);
}

.form-text {
  font-size: 12.5px;
  color: var(--gray-600);
  margin-top: 5px;
}

/* Radio Cards (Delivery Mode Selection) */
.radio-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 8px;
}

.radio-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
}

.radio-card:hover {
  border-color: var(--primary-border);
  background: var(--gray-50);
}

.radio-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.radio-card input[type=\"radio\"] {
  margin-top: 4px;
  accent-color: var(--primary);
}

.radio-card-body h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.radio-card-body p {
  font-size: 12.5px;
  color: var(--gray-600);
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #157347; }

.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #bb2d3b; }

.btn-outline-primary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover:not(:disabled) {
  background: var(--primary-light);
}

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

/* =============================================================================
   7 KPI DASHBOARD CARDS
   ============================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  padding: 18px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  border-right: 4px solid var(--primary);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card.kpi-lines       { border-right-color: #0b5d7a; }
.kpi-card.kpi-customers   { border-right-color: #0284c7; }
.kpi-card.kpi-recipients  { border-right-color: #198754; }
.kpi-card.kpi-languages   { border-right-color: #6366f1; }
.kpi-card.kpi-invalid     { border-right-color: #f59e0b; }
.kpi-card.kpi-duplicates  { border-right-color: #8b5cf6; }
.kpi-card.kpi-exclusions  { border-right-color: #ef4444; }
.kpi-card.kpi-intents     { border-right-color: #0d9488; background: #f0fdfa; }

.kpi-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.1;
  font-family: var(--font-family);
}

.kpi-subtext {
  font-size: 11.5px;
  color: var(--gray-500);
  margin-top: 6px;
}

.kpi-language-breakdown {
  display: flex;
  gap: 8px;
  font-size: 11px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.kpi-lang-pill {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
}

/* =============================================================================
   FILTER BUILDER COMPONENT
   ============================================================================= */
.filter-builder-container {
  background: var(--gray-50);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.filter-group {
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}

.filter-group.depth-1 { border-right: 4px solid var(--primary); }
.filter-group.depth-2 { border-right: 4px solid #0284c7; margin-right: 15px; }
.filter-group.depth-3 { border-right: 4px solid #6366f1; margin-right: 30px; }
.filter-group.depth-4 { border-right: 4px solid #8b5cf6; margin-right: 45px; }
.filter-group.depth-5 { border-right: 4px solid #ec4899; margin-right: 60px; }

.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--gray-100);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

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

.operator-toggle {
  display: inline-flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--gray-400);
}

.operator-toggle button {
  padding: 6px 14px;
  background: white;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--gray-700);
}

.operator-toggle button.active {
  background: var(--primary);
  color: white;
}

.filter-rule-row {
  display: grid;
  grid-template-columns: 2fr 1.5fr 2.5fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  margin-bottom: 8px;
}

.filter-rule-row.not-wrapped {
  border-right: 3px solid var(--danger);
}

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

.btn-remove-rule {
  color: var(--danger);
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-remove-rule:hover { background: var(--danger-light); }

.filter-group-footer {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.ast-limits-badge {
  font-size: 12px;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* =============================================================================
   TEMPLATE EDITOR COMPONENT
   ============================================================================= */
.template-editor-container {
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 20px;
}

.template-lang-tabs {
  display: flex;
  background: var(--gray-100);
  border-bottom: 1px solid var(--gray-300);
}

.template-tab-btn {
  padding: 12px 20px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
}

.template-tab-btn.active {
  background: white;
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.template-editor-body {
  padding: 18px;
}

.placeholders-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.placeholders-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gray-600);
}

.btn-placeholder {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  direction: ltr;
  transition: all 0.15s ease;
}

.btn-placeholder:hover {
  background: var(--primary);
  color: white;
}

.template-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  line-height: 1.5;
}

.template-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 93, 122, 0.15);
}

.template-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--gray-600);
}

.char-counter.warning { color: var(--warning); font-weight: bold; }
.char-counter.exceeded { color: var(--danger); font-weight: bold; }

/* =============================================================================
   TABLES & LISTS
   ============================================================================= */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  background: white;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 13.5px;
}

th {
  background-color: #f1f5f9;
  color: var(--gray-800);
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 2px solid var(--gray-300);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
}

tr:hover td {
  background-color: var(--gray-50);
}

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-top: 1px solid var(--gray-200);
  background: white;
  flex-wrap: wrap;
  gap: 10px;
}

.pagination-info {
  font-size: 13px;
  color: var(--gray-600);
}

.pagination-controls {
  display: flex;
  gap: 6px;
}

/* =============================================================================
   MODALS
   ============================================================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: modalSlide 0.2s ease-out;
}

@keyframes modalSlide {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-500);
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--gray-900); }

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Message Render Box */
.rendered-message-box {
  background: #fdfdfd;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: #1e293b;
  margin: 10px 0;
  max-height: 200px;
  overflow-y: auto;
}

/* Fingerprints Card */
.fingerprints-box {
  background: #f8fafc;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin: 12px 0;
}

.fingerprint-item {
  font-size: 12px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fingerprint-label {
  font-weight: 600;
  color: var(--gray-700);
  min-width: 140px;
}

.fingerprint-hash {
  font-family: var(--font-mono);
  background: white;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--gray-300);
  color: #0f172a;
  word-break: break-all;
  direction: ltr;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: white;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  min-width: 300px;
  animation: toastFade 0.3s ease;
  border-right: 4px solid var(--primary);
}

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

.toast.toast-success { border-right-color: var(--success); }
.toast.toast-error   { border-right-color: var(--danger); }
.toast.toast-warning { border-right-color: var(--warning); }

/* Empty / Loading States */
.state-container {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-600);
}

.state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.state-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--gray-800);
}

.state-desc {
  font-size: 13px;
  max-width: 400px;
  margin: 0 auto;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px auto;
}

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

/* Responsive Adjustments */
@media (max-width: 768px) {
  .app-container { padding: 12px; }
  .app-header { padding: 16px; flex-direction: column; align-items: flex-start; }
  .nav-tabs { flex-direction: column; }
  .nav-tab-btn { width: 100%; }
  .filter-rule-row { grid-template-columns: 1fr; gap: 8px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .radio-card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
