/* ---------- أزرار ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  transition:
    transform 0.15s var(--ease),
    filter 0.15s,
    background-color 0.15s,
    border-color 0.15s,
    box-shadow 0.2s;
  user-select: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn.primary {
  background: var(--grad);
  color: #fff;
  box-shadow:
    0 10px 26px -10px rgba(47, 140, 255, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn.primary:hover {
  filter: brightness(1.07);
}
.btn.soft {
  background: var(--grad-soft);
  color: var(--brand);
  border-color: rgba(77, 155, 255, 0.28);
}
.btn.ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}
.btn.ghost:hover {
  border-color: var(--line-2);
  background: var(--surface-2);
}
.btn.danger {
  background: rgba(251, 113, 133, 0.14);
  color: var(--bad);
  border-color: rgba(251, 113, 133, 0.35);
}
.btn.danger.solid {
  background: var(--bad);
  color: #fff;
  border-color: transparent;
}
.btn.sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: 12px;
}
.btn.block {
  width: 100%;
}
.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}
.btn.loading {
  color: transparent !important;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.btn.ghost.loading::after,
.btn.soft.loading::after {
  border-color: var(--line-2);
  border-top-color: var(--brand);
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition:
    background-color 0.15s,
    transform 0.15s;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn:active {
  transform: scale(0.94);
}
.icon-btn.sm {
  width: 34px;
  height: 34px;
  border-radius: 11px;
}

/* ---------- حقول ---------- */
.field {
  display: block;
}
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 2px 6px;
  font-weight: 500;
}
.field > .hint {
  margin: 6px 2px 0;
  font-size: 12px;
  color: var(--faint);
  font-weight: 400;
}
input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background-color 0.15s;
  font-size: 15px;
}
textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.7;
}
select {
  appearance: none;
  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='%2393a6c9' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-inline-end: 14px;
  padding-inline-start: 38px;
}
select option {
  background: var(--surface-solid);
  color: var(--text);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(77, 155, 255, 0.18);
  background: var(--surface-2);
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
input[type='range'] {
  padding: 0;
  min-height: 34px;
  accent-color: #2f8cff;
  background: none;
  border: 0;
  box-shadow: none;
}
input[type='time'],
input[type='date'],
input[type='month'],
input[type='number'] {
  direction: ltr;
  text-align: end;
}
input[type='checkbox'] {
  width: 20px;
  height: 20px;
  min-height: 0;
  accent-color: #2f8cff;
  padding: 0;
}
.input-wrap {
  position: relative;
}
.input-wrap .eye {
  position: absolute;
  inset-inline-start: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: 0;
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 10px;
}
.input-wrap input {
  padding-inline-start: 46px;
}
.code-input {
  font-size: 30px;
  letter-spacing: 0.42em;
  text-align: center !important;
  font-weight: 600;
  direction: ltr;
  padding-inline: 8px;
  min-height: 68px;
  border-radius: 18px;
}

/* ---------- بطاقات وعناصر ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.card + .card {
  margin-top: 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head h2,
.card-head h3 {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-head h2 .ic,
.card-head h3 .ic {
  color: var(--brand);
}
.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.7;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.ok {
  background: rgba(52, 211, 153, 0.14);
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.3);
}
.badge.warn {
  background: rgba(251, 191, 36, 0.14);
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.3);
}
.badge.bad {
  background: rgba(251, 113, 133, 0.14);
  color: var(--bad);
  border-color: rgba(251, 113, 133, 0.3);
}
.badge.info {
  background: rgba(122, 162, 255, 0.14);
  color: var(--info);
  border-color: rgba(122, 162, 255, 0.3);
}
.badge.neutral {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--line);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.chip.on {
  background: var(--grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px -10px rgba(47, 140, 255, 0.8);
}
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}
.chips::-webkit-scrollbar {
  display: none;
}
.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.seg button.on {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(47, 140, 255, 0.9);
}
.avatar {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  flex-shrink: 0;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, hsl(var(--h) 75% 55%), hsl(calc(var(--h) + 40) 70% 42%));
  letter-spacing: 0.02em;
}
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 34px 16px;
  color: var(--muted);
  text-align: center;
}
.empty .ic {
  color: var(--faint);
  margin-bottom: 6px;
}
.empty b {
  color: var(--text);
  font-weight: 500;
}
.empty span {
  font-size: 13px;
}
.skel-wrap {
  padding: 4px 0;
}
.skel {
  height: 15px;
  border-radius: 8px;
  margin: 10px 0;
  background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 14px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.pulse-dot {
  animation: blink 1.6s ease-in-out infinite;
}

/* ---------- جداول ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  text-align: start;
  padding: 11px 14px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
td {
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
  text-align: start;
}
tbody tr:hover td {
  background: var(--surface);
}
td.wrap {
  white-space: normal;
  min-width: 220px;
}

/* ---------- إشعارات ---------- */
#toasts {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(var(--safe-b) + 92px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  width: fit-content;
  padding: 13px 18px;
  border-radius: 16px;
  color: #fff;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 14px 40px -10px rgba(0, 0, 0, 0.6);
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  transition: all 0.28s var(--ease);
  cursor: pointer;
  backdrop-filter: blur(14px);
}
.toast.in {
  transform: none;
  opacity: 1;
}
.toast.ok {
  background: linear-gradient(135deg, #0f9f6e, #12b886);
}
.toast.bad {
  background: linear-gradient(135deg, #d6304d, #f0506a);
}
.toast.info {
  background: linear-gradient(135deg, #2a56c6, #3b82f6);
}

/* ---------- نافذة سفلية ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 16, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.22s;
}
.overlay.in {
  opacity: 1;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--line-2);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px 20px calc(var(--safe-b) + 22px);
  transform: translateY(40px);
  transition: transform 0.3s var(--ease);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
}
.overlay.in .sheet {
  transform: none;
}
.sheet.wide {
  max-width: 640px;
}
.sheet-grab {
  width: 42px;
  height: 5px;
  border-radius: 9px;
  background: var(--line-2);
  margin: 0 auto 12px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-head h3 {
  font-size: 18px;
}
.sheet-msg {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.8;
  margin-bottom: 18px;
}
.sheet-actions {
  display: flex;
  gap: 10px;
}
.sheet-actions .btn {
  flex: 1;
}
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 -8px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 12px;
  border-radius: 14px;
  border: 0;
  background: none;
  width: 100%;
  text-align: start;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  transition: background-color 0.15s;
}
.menu-item:hover,
.menu-item:active {
  background: var(--surface-2);
}
.menu-item .ic {
  color: var(--brand);
}
.menu-item.danger,
.menu-item.danger .ic {
  color: var(--bad);
}
.menu-item small {
  display: block;
  color: var(--faint);
  font-size: 12px;
}
@media (min-width: 720px) {
  .overlay {
    align-items: center;
  }
  .sheet {
    border-radius: var(--r-xl);
    border-bottom: 1px solid var(--line-2);
    max-height: 86dvh;
  }
}
@media (min-width: 720px) {
  .sheet {
    transform: translateY(14px) scale(0.98);
  }
  .overlay.in .sheet {
    transform: none;
  }
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--grad-soft);
  border: 1px dashed rgba(77, 155, 255, 0.5);
  border-radius: 18px;
  padding: 16px 18px;
  margin: 6px 0 16px;
}
.code-box b {
  font-size: 30px;
  letter-spacing: 0.2em;
  direction: ltr;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- حركات ---------- */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}
@keyframes blink {
  50% {
    opacity: 0.35;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes ring {
  0% {
    transform: scale(0.62);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.18);
    opacity: 0;
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-7px);
  }
  40%,
  80% {
    transform: translateX(7px);
  }
}
@keyframes pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes floaty {
  50% {
    transform: translateY(-6px);
  }
}
@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}
.rise {
  animation: rise 0.45s var(--ease) both;
}
.rise:nth-child(2) {
  animation-delay: 0.05s;
}
.rise:nth-child(3) {
  animation-delay: 0.1s;
}
.rise:nth-child(4) {
  animation-delay: 0.15s;
}
.rise:nth-child(5) {
  animation-delay: 0.2s;
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

#offline-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  text-align: center;
  font-size: 13px;
  padding: 8px 12px;
  padding-top: calc(var(--safe-t) + 8px);
  background: linear-gradient(135deg, #c1233f, #e0405a);
  color: #fff;
}
