:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #050505;
  --muted: #65676b;
  --border: #e4e6ea;
  --primary: #1877f2;
  --primary-hover: #166fe5;
  --primary-soft: #e7f0ff;
  --primary-text: #ffffff;
  --ok: #12b76a;
  --ok-soft: #e6f9ef;
  --err: #f02849;
  --err-soft: #fde8ec;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Cairo", system-ui, "Segoe UI", Tahoma, sans-serif;
}

.hidden {
  display: none !important;
}

/* ---------- Top bar ---------- */

.topbar {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid rgba(228, 230, 234, 0.6);
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 auto;
  max-width: 100%;
  border-radius: 0;
  box-shadow: none;
  transition: max-width 0.3s ease, margin 0.3s ease, border-radius 0.3s ease,
    box-shadow 0.3s ease, background 0.3s ease;
}

.topbar.is-scrolled {
  margin: 10px auto;
  max-width: calc(100% - 20px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border-bottom-color: transparent;
}

.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
}

.brand a {
  color: var(--primary);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.pill-nav {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
}

.lang-switch {
  position: relative;
}

.lang-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-flag {
  font-size: 15px;
  line-height: 1;
}

.lang-chevron {
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.lang-switch.open .lang-chevron {
  transform: rotate(180deg);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  min-width: 150px;
  z-index: 20;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: start;
  margin: 0;
}

.lang-option:hover {
  background: var(--bg);
}

.lang-option.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.profile-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 8px 4px 4px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.profile-trigger:hover {
  background: var(--bg);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
}

/* ---------- Layout ---------- */

.app-shell {
  display: flex;
  align-items: flex-start;
  gap: 28px;
  max-width: 1180px;
  margin: 0 auto;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 78px;
  padding: 20px 12px;
}

.sidebar .pill-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.sidebar .tab-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  text-align: start;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 16px 70px;
  flex: 1;
  min-width: 0;
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    width: 100%;
    position: static;
    padding: 12px 16px 0;
  }

  .sidebar .pill-nav {
    flex-direction: row;
    background: var(--bg);
    padding: 4px;
    border-radius: 999px;
    overflow-x: auto;
  }

  .sidebar .tab-btn {
    width: auto;
    white-space: nowrap;
  }
}

.page-head {
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.step-card {
  display: flex;
  gap: 16px;
}

.step-num {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-body {
  flex: 1;
  min-width: 0;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--primary-soft);
  border-color: transparent;
}

.banner h2 {
  color: var(--primary);
}

.banner button {
  flex: none;
  margin-top: 0;
}

@media (max-width: 480px) {
  .banner {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
}

.auth-card {
  max-width: 380px;
  margin: 64px auto;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  display: block;
  object-fit: contain;
}

.auth-card label {
  text-align: right;
}

h1 {
  font-size: 1.3rem;
  margin-top: 0;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 4px;
}

.hint {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 4px;
  line-height: 1.7;
}

.row {
  display: flex;
  gap: 14px;
}

.row > div {
  flex: 1;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  margin-top: 12px;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f5f6f8;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

select {
  cursor: pointer;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

/* ---------- Key/value display (masked credentials) ---------- */

.kv-box {
  margin-top: 10px;
}

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

.kv-row:last-of-type {
  border-bottom: none;
}

.kv-label {
  flex: none;
  width: 90px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.kv-value {
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  direction: ltr;
  text-align: right;
}

/* ---------- Password field with show/hide ---------- */

.input-with-icon {
  position: relative;
}

.input-with-icon input {
  padding-inline-end: 42px;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
  font-size: 20px;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}

.icon-toggle {
  position: absolute;
  inset-inline-end: 4px;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  background: transparent;
  border: none;
  padding: 4px 8px;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.icon-toggle:hover {
  background: transparent;
  color: var(--text);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

/* ---------- Buttons ---------- */

button {
  margin-top: 16px;
  padding: 10px 22px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button:hover {
  background: var(--primary-hover);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.7;
  cursor: default;
  transform: none;
}

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

.btn-ghost {
  margin: 0;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.btn-ghost:hover {
  background: var(--bg);
}

.tab-btn {
  margin: 0;
  padding: 6px 16px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 700;
  border-radius: 999px;
  font-size: 0.85rem;
}

.tab-btn:hover {
  background: transparent;
  color: var(--text);
}

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

/* ---------- Modal ---------- */

dialog.modal {
  border: none;
  padding: 0;
  border-radius: var(--radius);
  width: calc(100% - 32px);
  max-width: 520px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  color: var(--text);
  background: var(--card-bg);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-body {
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.campaign-modal-message {
  white-space: pre-wrap;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- Loading spinner ---------- */

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  flex: none;
}

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

/* ---------- Progress bar ---------- */

.progress-wrap {
  margin-top: 14px;
}

.progress-bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0;
  right: auto;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #0a5cd8);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-fill.indeterminate {
  width: 30% !important;
  animation: indeterminate 1.2s ease-in-out infinite;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(430%);
  }
}

.progress-text {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Status / badges ---------- */

.status {
  display: inline-block;
  margin-inline-start: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--err);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge.on {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.off {
  background: var(--err-soft);
  color: var(--err);
}

/* ---------- Table ---------- */

.table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 10px;
}

.table th,
.table td {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: break-word;
}

.table tr {
  cursor: default;
}

.table tr.clickable {
  cursor: pointer;
}

.table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table tbody tr:hover {
  background: #f7f8fa;
}

.table .group-name {
  font-weight: 700;
}

.switch {
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
  margin: 0;
  font-weight: 600;
}

a.download-link {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

a.download-link:hover {
  text-decoration: underline;
}

@media (max-width: 480px) {
  .row {
    flex-direction: column;
    gap: 0;
  }

  .step-card {
    gap: 12px;
  }
}

/* ---------- Send view ---------- */

.source-toggle {
  display: inline-flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 999px;
  margin-top: 10px;
}

.source-toggle .tab-btn {
  font-size: 0.82rem;
}

.sender-add-cell {
  display: flex;
  align-items: flex-end;
}

.sender-add-cell button {
  margin-top: 12px;
  width: 100%;
  justify-content: center;
}

@media (max-width: 700px) {
  #addSenderRow {
    flex-direction: column;
    gap: 0;
  }
}

.table .mono {
  font-family: "Courier New", monospace;
  direction: ltr;
  display: inline-block;
}

.mini-btn {
  margin: 0;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
}

.mini-btn:hover {
  background: var(--bg);
}

.mini-btn.danger {
  color: var(--err);
  border-color: var(--err-soft);
}

.mini-btn.danger:hover {
  background: var(--err-soft);
}
