:root {
  --wa: #25d366;
  --wa-dark: #128c7e;
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --ok: #3fb950;
  --err: #f85149;
  --warn: #d29922;
  font-family: "Tajawal", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle at 20% 30%, rgba(37, 211, 102, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(18, 140, 126, 0.1) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.hero {
  position: relative;
  text-align: center;
  margin-bottom: 2rem;
}

.hero-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--wa), var(--wa-dark));
  color: #fff;
  margin-bottom: 1rem;
  box-shadow: 0 12px 40px rgba(37, 211, 102, 0.25);
}

.hero h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
}

.hero-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.banner {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  text-align: right;
}

.banner-warn {
  background: rgba(210, 153, 34, 0.15);
  border: 1px solid rgba(210, 153, 34, 0.4);
  color: #e3b341;
}

.banner-info {
  margin-top: 1rem;
  text-align: right;
  background: rgba(56, 139, 253, 0.1);
  border: 1px solid rgba(56, 139, 253, 0.35);
  color: var(--text);
}

.banner-info a {
  color: #58a6ff;
}

.info-list {
  margin: 0.75rem 0 0;
  padding-right: 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.65;
}

.info-list li {
  margin-bottom: 0.5rem;
}

.info-list code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.req {
  color: var(--err);
}

textarea,
.select,
.input-num,
.file-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
}

textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.85rem 1rem;
  resize: vertical;
  min-height: 100px;
}

textarea:focus,
.select:focus,
.input-num:focus {
  outline: none;
  border-color: var(--wa);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.select,
.input-num {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.65rem 0.85rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.field.grow {
  flex: 1 1 280px;
}

.field:not(.grow) {
  flex: 0 0 200px;
}

.align-end {
  align-items: flex-end;
  margin-top: 1.5rem;
}

.mt {
  margin-top: 1rem;
}

.file-input {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.85rem 1.75rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(145deg, var(--wa), var(--wa-dark));
  color: #fff;
  box-shadow: 0 4px 20px rgba(37, 211, 102, 0.35);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(37, 211, 102, 0.4);
}

.btn-loader {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.section-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.progress-wrap {
  margin-top: 0.5rem;
}

.progress-bar {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--wa-dark), var(--wa));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-label {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stat {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.stat-ok {
  background: rgba(63, 185, 80, 0.15);
  color: var(--ok);
}

.stat-fail {
  background: rgba(248, 81, 73, 0.12);
  color: var(--err);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.results-table th,
.results-table td {
  padding: 0.65rem 0.85rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.results-table th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}

.results-table tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-ok {
  background: rgba(63, 185, 80, 0.2);
  color: var(--ok);
}

.badge-fail {
  background: rgba(248, 81, 73, 0.15);
  color: var(--err);
}

.detail-cell {
  max-width: 220px;
  word-break: break-all;
  color: var(--muted);
  font-size: 0.82rem;
}

.foot {
  text-align: center;
  color: var(--muted);
  margin-top: 2rem;
}

.foot small {
  font-size: 0.8rem;
}

.lang-switch {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 0.4rem;
  justify-content: center;
}

.lang-switch a {
  color: var(--wa);
  text-decoration: none;
  font-weight: 600;
}

.lang-switch a:hover {
  text-decoration: underline;
}

.ltr .hero,
.ltr .section-title,
.ltr .banner,
.ltr .foot,
.ltr .stats {
  text-align: left;
}

.ltr .results-table th,
.ltr .results-table td {
  text-align: left;
}

.ltr .results-table th:nth-child(1),
.ltr .results-table td:nth-child(1) {
  text-align: center;
}

.telnyx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (min-width: 900px) {
  .telnyx-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
@media (max-width: 700px) {
  .telnyx-grid {
    grid-template-columns: 1fr;
  }
}
.telnyx-webrtc-block {
  grid-column: 1 / -1;
}
@media (min-width: 900px) {
  .telnyx-webrtc-block {
    grid-column: auto;
  }
}
.webrtc-status { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--ok); }
.campaign-summary { margin: 0.75rem 0 0; font-size: 0.9rem; color: var(--muted); }
.campaign-summary strong { color: var(--text); }
.webrtc-actions { margin-top: 0.75rem; gap: 0.5rem; }

.chat-dashboard { display: flex; gap: 1rem; min-height: 360px; }
.chat-list-wrap { flex: 0 0 260px; border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; background: var(--bg); }
.chat-list-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.chat-list-head .subsection-title { margin: 0; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.chat-conv-list { list-style: none; margin: 0; padding: 0; }
.chat-conv-list li { padding: 0.6rem 0.5rem; border-radius: 8px; cursor: pointer; margin-bottom: 0.25rem; }
.chat-conv-list li:hover { background: var(--card); }
.chat-conv-list li.active { background: rgba(37, 211, 102, 0.15); }
.chat-conv-list .conv-phone { font-weight: 600; font-size: 0.9rem; }
.chat-conv-list .conv-preview { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-wrap { flex: 1; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.chat-thread-header { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.5rem; }
.chat-thread-title { font-weight: 600; }
.chat-msg-list { list-style: none; margin: 0; padding: 0.75rem; flex: 1; overflow-y: auto; max-height: 280px; }
.chat-msg-list li { margin-bottom: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 10px; max-width: 85%; }
.chat-msg-list li.in { background: var(--card); margin-right: auto; }
.chat-msg-list li.out { background: rgba(37, 211, 102, 0.2); margin-left: auto; }
.chat-msg-list .msg-body { font-size: 0.9rem; }
.chat-msg-list .msg-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.chat-reply-form { padding: 0.5rem 0.75rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-reply-form textarea { flex: 1; min-height: 44px; resize: none; }
@media (max-width: 600px) { .chat-dashboard { flex-direction: column; } .chat-list-wrap { flex: 0 0 auto; } }
.telnyx-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  background: var(--bg);
}
.subsection-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
}

.main-tabs {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}
.main-tab {
  padding: 0.6rem 1.25rem;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.main-tab:hover {
  background: var(--card);
  color: var(--text);
}
.main-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.section-wrap.hidden { display: none !important; }
.sub-tabs { margin-bottom: 0.5rem; }

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  flex: 1;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.tab:hover {
  color: var(--text);
  border-color: var(--wa);
}

.tab.active {
  background: linear-gradient(145deg, rgba(37, 211, 102, 0.2), rgba(18, 140, 126, 0.15));
  border-color: var(--wa);
  color: var(--wa);
}

.tab-panel.hidden {
  display: none;
}

.template-vars-hint { margin-bottom: 0.5rem; font-size: 0.9rem; }
.template-hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 1.25rem;
  line-height: 1.6;
}

.template-hint code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.template-warn {
  margin-bottom: 1.25rem;
  text-align: right;
  line-height: 1.55;
}

.template-warn a {
  color: #e3b341;
  text-decoration: underline;
}

.input-text {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.65rem 0.85rem;
}

.input-text:focus {
  outline: none;
  border-color: var(--wa);
}

.btn-secondary {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--wa);
  color: var(--wa);
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

.lang-switch{margin-top:0.75rem;font-size:0.85rem;color:var(--muted);display:flex;gap:0.4rem;justify-content:center;} .lang-switch a{color:var(--wa);text-decoration:none;font-weight:600;} .lang-switch a:hover{text-decoration:underline;} .ltr .hero,.ltr .section-title,.ltr .banner,.ltr .foot, .ltr .stats, .ltr .results-table th, .ltr .results-table td{direction:ltr;text-align:left;} .ltr .results-table th:nth-child(1),.ltr .results-table td:nth-child(1){text-align:center;} .ltr .results-table th:nth-child(2),.ltr .results-table td:nth-child(2){text-align:left;}

.user-form-wrap { margin: 1rem 0; padding: 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; max-width: 420px; }
.user-permissions-list { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-top: 0.35rem; }
.user-permissions-list label { display: flex; align-items: center; gap: 0.35rem; font-weight: 400; cursor: pointer; }
.users-actions { margin-bottom: 0.5rem; }