/*
 * TProTool — Emerald Pro (تصميم A)
 * متغيرات CSS: :root و [data-theme="dark"] للوضع الداكن.
 * البادئة tpt- لجميع أصناف الواجهة. RTL عبر dir على html.
 */

:root {
  --tpt-font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --tpt-font-mono: ui-monospace, "Cascadia Code", "Consolas", monospace;

  --tpt-emerald-600: #128c4a;
  --tpt-emerald-500: #25d366;
  --tpt-emerald-400: #5ee08a;
  --tpt-teal-700: #0d6b4f;

  --tpt-bg: #f4f7f5;
  --tpt-surface: #ffffff;
  --tpt-surface-2: #eef3ef;
  --tpt-border: #d8e2dc;
  --tpt-text: #1a2e24;
  --tpt-text-muted: #5c7268;
  --tpt-sidebar-bg: #0f2419;
  --tpt-sidebar-text: #e8f5ec;
  --tpt-sidebar-muted: #9fb8a8;
  --tpt-accent: var(--tpt-emerald-500);
  --tpt-accent-hover: var(--tpt-emerald-600);
  --tpt-danger: #c0392b;
  --tpt-warning: #d68910;
  --tpt-info: #2471a3;
  --tpt-success: #1e8449;

  --tpt-radius-sm: 6px;
  --tpt-radius: 10px;
  --tpt-radius-lg: 14px;
  --tpt-shadow: 0 1px 3px rgba(15, 36, 25, 0.08);
  --tpt-shadow-lg: 0 12px 40px rgba(15, 36, 25, 0.12);

  --tpt-space-1: 0.25rem;
  --tpt-space-2: 0.5rem;
  --tpt-space-3: 0.75rem;
  --tpt-space-4: 1rem;
  --tpt-space-5: 1.25rem;
  --tpt-space-6: 1.5rem;
  --tpt-space-8: 2rem;

  --tpt-sidebar-w: 260px;
  --tpt-topbar-h: 56px;
  --tpt-content-max: 1200px;

  --tpt-code-bg: #1a2e24;
  --tpt-code-fg: #d5f5e3;
  --tpt-overlay: rgba(0, 0, 0, 0.35);
  --tpt-focus-ring: rgba(37, 211, 102, 0.2);
  --tpt-row-hover: rgba(37, 211, 102, 0.04);
}

[data-theme="dark"] {
  --tpt-bg: #0b100e;
  --tpt-surface: #131a17;
  --tpt-surface-2: #1a2420;
  --tpt-border: #2a3832;
  --tpt-text: #e6efe9;
  --tpt-text-muted: #8fa396;
  --tpt-sidebar-bg: #060a08;
  --tpt-teal-700: #6ee7a0;
  --tpt-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --tpt-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --tpt-code-bg: #060a08;
  --tpt-code-fg: #b8dcc8;
  --tpt-focus-ring: rgba(37, 211, 102, 0.35);
  --tpt-row-hover: rgba(37, 211, 102, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--tpt-font);
  background: var(--tpt-bg);
  color: var(--tpt-text);
  line-height: 1.55;
}

img, svg { display: block; max-width: 100%; }

a { color: var(--tpt-teal-700); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--tpt-accent);
  outline-offset: 2px;
}

/* Layout — sidebar shell */
.tpt-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--tpt-sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
}

.tpt-sidebar {
  grid-area: sidebar;
  background: var(--tpt-sidebar-bg);
  color: var(--tpt-sidebar-text);
  padding: var(--tpt-space-5) var(--tpt-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--tpt-space-6);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.tpt-brand {
  display: flex;
  align-items: center;
  gap: var(--tpt-space-3);
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  text-decoration: none;
}

.tpt-brand:hover { text-decoration: none; opacity: 0.95; }

.tpt-brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--tpt-radius);
  background: linear-gradient(135deg, var(--tpt-emerald-500), var(--tpt-teal-700));
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
}

.tpt-brand-tag {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--tpt-sidebar-muted);
  margin-top: 2px;
}

.tpt-nav { display: flex; flex-direction: column; gap: var(--tpt-space-1); }

.tpt-nav a {
  color: var(--tpt-sidebar-muted);
  padding: var(--tpt-space-2) var(--tpt-space-3);
  border-radius: var(--tpt-radius-sm);
  text-decoration: none;
  font-size: 0.92rem;
}

.tpt-nav a:hover,
.tpt-nav a.is-active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.tpt-topbar {
  grid-area: topbar;
  min-height: var(--tpt-topbar-h);
  background: var(--tpt-surface);
  border-bottom: 1px solid var(--tpt-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--tpt-space-5);
  gap: var(--tpt-space-4);
  position: sticky;
  top: 0;
  z-index: 20;
}

.tpt-topbar-start { display: flex; align-items: center; gap: var(--tpt-space-3); }

.tpt-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--tpt-space-2);
}

.tpt-main {
  grid-area: main;
  padding: var(--tpt-space-6) var(--tpt-space-5) var(--tpt-space-8);
  max-width: calc(var(--tpt-content-max) + var(--tpt-space-8));
  min-width: 0;
}

.tpt-page-head { margin-bottom: var(--tpt-space-6); }
.tpt-page-head h1 { margin: 0 0 var(--tpt-space-2); font-size: 1.65rem; font-weight: 700; }
.tpt-page-head p { margin: 0; color: var(--tpt-text-muted); }

.tpt-section { margin-bottom: var(--tpt-space-8); }
.tpt-section h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tpt-text-muted);
  margin: 0 0 var(--tpt-space-4);
  font-weight: 600;
}

.tpt-landing h2 {
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: inherit;
  margin: var(--tpt-space-6) 0 var(--tpt-space-2);
}

.tpt-landing h2:first-child { margin-top: 0; }

.tpt-landing p { margin: 0 0 var(--tpt-space-3); }

.tpt-landing p:last-child { margin-bottom: 0; }

.tpt-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--tpt-space-4);
}

.tpt-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--tpt-space-4);
}

/* Typography */
.tpt-text-muted { color: var(--tpt-text-muted); }
.tpt-text-success { color: var(--tpt-success); }
.tpt-text-sm { font-size: 0.875rem; }
.tpt-text-xs { font-size: 0.78rem; }
.tpt-text-center { text-align: center; }
.tpt-lead { font-size: 1.125rem; }
.tpt-mono { font-family: var(--tpt-font-mono); font-size: 0.88em; }
.tpt-mt-3 { margin-top: var(--tpt-space-3); }
.tpt-mt-4 { margin-top: var(--tpt-space-4); }
.tpt-mt-5 { margin-top: var(--tpt-space-5); }

.tpt-h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 var(--tpt-space-4);
  color: var(--tpt-text);
}

.tpt-card h2.tpt-h3 {
  margin-top: 1.25rem;
}

.tpt-card h2.tpt-h3:first-child {
  margin-top: 0;
}

.tpt-dl { margin: 0; }
.tpt-dl dt {
  font-size: 0.8rem;
  color: var(--tpt-text-muted);
  font-weight: 600;
  margin-top: var(--tpt-space-3);
}
.tpt-dl dt:first-child { margin-top: 0; }
.tpt-dl dd { margin: 0.15rem 0 0; }

.tpt-stack { display: flex; flex-direction: column; }
.tpt-check {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.tpt-check input { margin-top: 0.2em; flex-shrink: 0; }

.tpt-form-inline { display: inline; margin: 0; }

.tpt-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--tpt-space-3);
  margin-bottom: var(--tpt-space-3);
}
.tpt-card-head .tpt-h3 { margin: 0; }

.tpt-card--center {
  display: flex;
  justify-content: center;
  padding: var(--tpt-space-4);
}

.tpt-qr-img { max-width: 100%; height: auto; display: block; }

.tpt-cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.tpt-cell-actions form { margin: 0; display: inline; }

/* Card */
.tpt-card {
  background: var(--tpt-surface);
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-lg);
  box-shadow: var(--tpt-shadow);
  padding: var(--tpt-space-5);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.tpt-card code { word-break: break-all; }

.tpt-stat-label { font-size: 0.82rem; color: var(--tpt-text-muted); margin-bottom: var(--tpt-space-1); }
.tpt-stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }

/* Buttons */
.tpt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tpt-space-2);
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--tpt-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.tpt-btn--primary {
  background: var(--tpt-accent);
  color: #fff;
  border-color: var(--tpt-accent-hover);
}
.tpt-btn--primary:hover:not(:disabled) { background: var(--tpt-accent-hover); }

.tpt-btn--secondary {
  background: var(--tpt-surface);
  color: var(--tpt-text);
  border-color: var(--tpt-border);
}
.tpt-btn--secondary:hover:not(:disabled) { background: var(--tpt-surface-2); }

.tpt-btn--danger {
  background: var(--tpt-danger);
  color: #fff;
}
.tpt-btn--danger:hover:not(:disabled) { filter: brightness(0.92); }

.tpt-btn--ghost {
  background: transparent;
  color: var(--tpt-teal-700);
  border-color: transparent;
}
.tpt-btn--ghost:hover:not(:disabled) { background: var(--tpt-surface-2); }

.tpt-btn--sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }

.tpt-btn-row { display: flex; flex-wrap: wrap; gap: var(--tpt-space-3); align-items: center; }

/* Forms */
.tpt-field { margin-bottom: var(--tpt-space-4); }
.tpt-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: var(--tpt-space-2);
}

.tpt-input,
.tpt-select,
.tpt-textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-sm);
  background: var(--tpt-surface);
  color: var(--tpt-text);
}

.tpt-input:focus,
.tpt-select:focus,
.tpt-textarea:focus {
  border-color: var(--tpt-accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--tpt-focus-ring);
}

.tpt-input.is-error { border-color: var(--tpt-danger); }
.tpt-hint { font-size: 0.8rem; color: var(--tpt-text-muted); margin-top: var(--tpt-space-1); }
.tpt-hint.is-error { color: var(--tpt-danger); }

.tpt-check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--tpt-space-2);
  font-size: 0.9rem;
}

/* Badges — sessions, messages, servers */
.tpt-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.2em 0.55em;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.tpt-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.tpt-badge--working { background: #d5f5e3; color: #1e6b3c; }
.tpt-badge--scan { background: #fef9e7; color: #9a7d0a; }
.tpt-badge--stopped { background: #eaecee; color: #566573; }
.tpt-badge--failed { background: #fadbd8; color: #922b21; }
.tpt-badge--queued { background: #ebf5fb; color: #1f618d; }
.tpt-badge--sent { background: #d6eaf8; color: #1a5276; }
.tpt-badge--unknown { background: #fdebd0; color: #b9770e; }
.tpt-badge--ready { background: #d5f5e3; color: #145a32; }
.tpt-badge--degraded { background: #fdebd0; color: #b7950b; }

.tpt-badge-row { display: flex; flex-wrap: wrap; gap: var(--tpt-space-2); }

/* Table */
.tpt-table-wrap { overflow-x: auto; border-radius: var(--tpt-radius); border: 1px solid var(--tpt-border); }
.tpt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--tpt-surface);
}

.tpt-table th,
.tpt-table td {
  padding: var(--tpt-space-3) var(--tpt-space-4);
  text-align: start;
  border-bottom: 1px solid var(--tpt-border);
  overflow-wrap: anywhere;
}

.tpt-table th {
  background: var(--tpt-surface-2);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--tpt-text-muted);
}

.tpt-table tr:last-child td { border-bottom: none; }
.tpt-table tbody tr:hover { background: var(--tpt-row-hover); }

.tpt-events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.35rem 1rem;
  margin-top: 0.5rem;
}

.tpt-card--form { max-width: 42rem; width: 100%; }

.tpt-input-pair {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tpt-input-pair .tpt-input:first-child { flex: 1 1 8rem; min-width: 0; }
.tpt-input-pair .tpt-input:last-child { flex: 2 1 10rem; min-width: 0; }

.tpt-list-stack {
  display: flex;
  flex-direction: column;
  gap: var(--tpt-space-3);
  margin-top: var(--tpt-space-3);
}
.tpt-list-stack__item {
  padding: var(--tpt-space-3);
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius);
  background: var(--tpt-surface-2);
}
.tpt-list-stack__lead {
  margin: 0 0 0.5rem;
  word-break: break-all;
}
.tpt-list-stack__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
  align-items: center;
}
.tpt-list-stack__actions form { margin: 0; }

.tpt-plan-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--tpt-space-3);
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tpt-plan-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  flex: 1 1 16rem;
  width: auto;
  max-width: 22rem;
  box-sizing: border-box;
  margin: 0;
  padding: var(--tpt-space-4);
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-lg);
  background: var(--tpt-surface);
  text-align: start;
}
label.tpt-plan-card { cursor: pointer; }
.tpt-plan-card__radio { accent-color: var(--tpt-accent); margin: 0; }
.tpt-plan-card:has(.tpt-plan-card__radio:checked) {
  border-color: var(--tpt-accent);
  box-shadow: 0 0 0 1px var(--tpt-accent);
}
.tpt-plan-card__name { font-weight: 700; font-size: 1.05rem; }
.tpt-plan-card__price { font-size: 1.45rem; font-weight: 700; line-height: 1.2; }
.tpt-plan-card__row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  color: var(--tpt-text-muted);
  font-size: 0.9rem;
}
.tpt-plan-card__features {
  list-style: disc;
  margin: 0.5rem 0 0;
  padding-inline-start: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  font-size: 0.875rem;
}
.tpt-plan-card__features li { margin: 0; }

.tpt-error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--tpt-space-5);
  background: var(--tpt-bg);
}
.tpt-error-card {
  max-width: 520px;
  width: 100%;
  text-align: center;
  padding: var(--tpt-space-8);
}
.tpt-error-code {
  margin: 0 0 var(--tpt-space-3);
  font-size: 3rem;
  line-height: 1;
}
.tpt-error-code--404 { color: var(--tpt-accent); }
.tpt-error-code--500 { color: var(--tpt-danger); }
.tpt-error-lead { margin: 0 0 var(--tpt-space-6); color: var(--tpt-text-muted); }

@media (max-width: 600px) {
  .tpt-main {
    padding: var(--tpt-space-4) var(--tpt-space-3) var(--tpt-space-6);
  }
  .tpt-topbar {
    padding: 0 var(--tpt-space-3);
    gap: var(--tpt-space-2);
    flex-wrap: wrap;
    align-items: center;
  }
  .tpt-topbar-start { min-width: 0; flex: 1 1 8rem; }
  .tpt-topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .tpt-page-head h1 { font-size: 1.35rem; }
  .tpt-events-grid { grid-template-columns: 1fr; }
  .tpt-plan-list { flex-direction: column; }
  .tpt-plan-card { flex: 1 1 auto; width: 100%; max-width: none; }
  .tpt-input-pair { flex-direction: column; }
  .tpt-input-pair .tpt-input { flex: 1 1 auto; width: 100%; }
  .tpt-btn-row:not(.tpt-btn-row--inline) { flex-direction: column; align-items: stretch; }
  .tpt-btn-row:not(.tpt-btn-row--inline) .tpt-btn,
  .tpt-btn-row:not(.tpt-btn-row--inline) a.tpt-btn,
  .tpt-btn-row:not(.tpt-btn-row--inline) form { width: 100%; }
  .tpt-btn-row:not(.tpt-btn-row--inline) form .tpt-btn { width: 100%; }
  .tpt-list-stack__actions { flex-direction: column; align-items: stretch; }
  .tpt-list-stack__actions .tpt-btn,
  .tpt-list-stack__actions a.tpt-btn { width: 100%; text-align: center; box-sizing: border-box; }

  .tpt-table-wrap--stack {
    overflow: visible;
    border: none;
  }

  .tpt-table--stack thead { display: none; }

  .tpt-table--stack tbody {
    display: flex;
    flex-direction: column;
    gap: var(--tpt-space-3);
  }

  .tpt-table--stack tbody tr {
    display: flex;
    flex-direction: column;
    gap: var(--tpt-space-2);
    padding: var(--tpt-space-3);
    border: 1px solid var(--tpt-border);
    border-radius: var(--tpt-radius);
    background: var(--tpt-surface-2);
  }

  .tpt-table--stack tbody tr:hover { background: var(--tpt-surface-2); }

  .tpt-table--stack td {
    display: block;
    padding: 0;
    border: none;
  }

  .tpt-table--stack .tpt-td-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--tpt-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.15rem;
  }

  .tpt-table--stack tr:has(> td[colspan]) {
    background: transparent;
    border: none;
    padding: 0;
  }

  .tpt-table--stack td[colspan] {
    text-align: center;
    padding: var(--tpt-space-2);
  }

  .tpt-table--stack td[colspan] .tpt-td-label { display: none; }

  .tpt-table--stack .tpt-cell-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
    padding-top: var(--tpt-space-2);
    border-top: 1px solid var(--tpt-border);
  }

  .tpt-table--stack .tpt-cell-actions .tpt-td-label {
    flex: 1 1 100%;
  }

  .tpt-table--stack .tpt-cell-actions .tpt-btn {
    flex: 1 1 calc(50% - 0.2rem);
    justify-content: center;
    text-align: center;
  }
}

.tpt-table--stack .tpt-td-label { display: none; }

/* Alerts */
.tpt-alert {
  padding: var(--tpt-space-4);
  border-radius: var(--tpt-radius);
  border: 1px solid;
  font-size: 0.92rem;
  margin-bottom: var(--tpt-space-3);
}

.tpt-alert--info { background: #ebf5fb; border-color: #aed6f1; color: #1a5276; }
.tpt-alert--warning { background: #fef9e7; border-color: #f9e79f; color: #7d6608; }
.tpt-alert--success { background: #eafaf1; border-color: #abebc6; color: #186a3b; }
.tpt-alert--danger { background: #fdedec; border-color: #f5b7b1; color: #922b21; }

/* Empty state */
.tpt-empty {
  text-align: center;
  padding: var(--tpt-space-8) var(--tpt-space-4);
  color: var(--tpt-text-muted);
}

.tpt-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--tpt-space-4);
  border-radius: 50%;
  background: var(--tpt-surface-2);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.tpt-empty h3 { margin: 0 0 var(--tpt-space-2); color: var(--tpt-text); font-size: 1.05rem; }

/* Code / API key */
.tpt-code-block {
  font-family: var(--tpt-font-mono);
  font-size: 0.82rem;
  background: var(--tpt-code-bg);
  color: var(--tpt-code-fg);
  padding: var(--tpt-space-4);
  border-radius: var(--tpt-radius);
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}

.tpt-code-inline {
  font-family: var(--tpt-font-mono);
  font-size: 0.85em;
  background: var(--tpt-surface-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  direction: ltr;
  unicode-bidi: embed;
}

/* QR placeholder */
.tpt-qr-box {
  width: 200px;
  height: 200px;
  border: 2px dashed var(--tpt-border);
  border-radius: var(--tpt-radius);
  display: grid;
  place-items: center;
  background: var(--tpt-surface-2);
  color: var(--tpt-text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: var(--tpt-space-3);
}

/* Modal */
.tpt-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--tpt-space-4);
}

.tpt-modal.is-open { display: flex; }

.tpt-modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--tpt-overlay);
}

.tpt-modal-panel {
  position: relative;
  background: var(--tpt-surface);
  border-radius: var(--tpt-radius-lg);
  box-shadow: var(--tpt-shadow-lg);
  max-width: 420px;
  width: 100%;
  padding: var(--tpt-space-6);
}

.tpt-modal-panel h3 { margin: 0 0 var(--tpt-space-3); }
.tpt-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--tpt-space-3);
  margin-top: var(--tpt-space-5);
}

/* Toast */
.tpt-toast-host {
  position: fixed;
  bottom: var(--tpt-space-5);
  inset-inline-start: var(--tpt-space-5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--tpt-space-2);
  pointer-events: none;
}

.tpt-toast {
  background: var(--tpt-sidebar-bg);
  color: #fff;
  padding: var(--tpt-space-3) var(--tpt-space-4);
  border-radius: var(--tpt-radius);
  box-shadow: var(--tpt-shadow-lg);
  font-size: 0.9rem;
  animation: tpt-toast-in 0.25s ease;
}

.tpt-toast--success { border-inline-start: 4px solid var(--tpt-emerald-500); }
.tpt-toast.is-leaving { opacity: 0; transform: translateY(8px); transition: 0.25s; }

@keyframes tpt-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tabs */
.tpt-tabs { display: flex; gap: var(--tpt-space-1); border-bottom: 1px solid var(--tpt-border); margin-bottom: var(--tpt-space-4); }
.tpt-tab {
  padding: var(--tpt-space-2) var(--tpt-space-4);
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  color: var(--tpt-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tpt-tab.is-active { color: var(--tpt-teal-700); border-bottom-color: var(--tpt-accent); font-weight: 600; }

.tpt-footer-note {
  margin-top: var(--tpt-space-8);
  padding-top: var(--tpt-space-4);
  border-top: 1px solid var(--tpt-border);
  font-size: 0.82rem;
  color: var(--tpt-text-muted);
}

.tpt-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 0.6rem;
}

.tpt-footer-links a {
  color: inherit;
}

.tpt-captcha-img {
  display: block;
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-sm);
  background: var(--tpt-surface-2);
}

.tpt-sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--tpt-space-2);
}

.tpt-sidebar-head .tpt-brand {
  flex: 1;
  min-width: 0;
}

.tpt-icon-btn {
  background: var(--tpt-surface-2);
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-sm);
  width: 40px;
  height: 40px;
  cursor: pointer;
  font: inherit;
  display: none;
  place-items: center;
  flex-shrink: 0;
  color: inherit;
}

.tpt-icon-btn--always {
  display: grid;
}

.tpt-icon-btn--on-sidebar {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--tpt-sidebar-text);
}

[dir="rtl"] .tpt-nav-toggle--sidebar {
  transform: scaleX(-1);
}

.tpt-nav-toggle--topbar,
.tpt-nav-toggle--sidebar {
  display: none;
}

@media (max-width: 900px) {
  .tpt-shell:not(.tpt-shell--topnav) .tpt-nav-toggle--topbar {
    display: grid;
  }
}

@media (min-width: 901px) {
  .tpt-shell:not(.tpt-shell--topnav):not(.sidebar-collapsed) .tpt-nav-toggle--sidebar {
    display: grid;
  }

  .tpt-shell.sidebar-collapsed:not(.tpt-shell--topnav) .tpt-nav-toggle--topbar {
    display: grid;
  }

  .tpt-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .tpt-shell.sidebar-collapsed .tpt-sidebar {
    display: none;
  }
}

@media (max-width: 900px) {
  .tpt-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "topbar" "main";
  }

  .tpt-shell--topnav {
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "topbar" "nav" "main";
  }

  .tpt-shell:not(.tpt-shell--topnav) .tpt-sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: min(var(--tpt-sidebar-w), 85vw);
    height: 100vh;
    margin: 0;
    border-radius: 0;
    z-index: 50;
    transition: transform 0.25s ease;
    transform: translateX(-100%);
  }

  [dir="rtl"] .tpt-shell:not(.tpt-shell--topnav) .tpt-sidebar {
    transform: translateX(100%);
  }

  .tpt-shell:not(.tpt-shell--topnav).sidebar-open .tpt-sidebar {
    transform: translateX(0);
  }

  .tpt-shell:not(.tpt-shell--topnav).sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.35);
  }

}

[dir="rtl"] .tpt-code-block,
[dir="rtl"] .tpt-code-inline { direction: ltr; text-align: left; }

/* قائمة اللغة */
.tpt-lang-menu {
  position: relative;
}

.tpt-lang-dropdown {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  margin: 0;
  padding: var(--tpt-space-1);
  list-style: none;
  min-width: 9rem;
  background: var(--tpt-surface);
  border: 1px solid var(--tpt-border);
  border-radius: var(--tpt-radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 40;
}

.tpt-lang-dropdown button,
.tpt-lang-dropdown a {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: start;
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  border-radius: calc(var(--tpt-radius-sm) - 2px);
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.tpt-lang-dropdown form {
  margin: 0;
}

.tpt-lang-dropdown button:hover,
.tpt-lang-dropdown button:focus-visible,
.tpt-lang-dropdown a:hover,
.tpt-lang-dropdown a:focus-visible {
  background: var(--tpt-surface-2);
  outline: none;
}

[data-tpt-theme-toggle] .tpt-theme-icon {
  display: none;
}

[data-theme="dark"] [data-tpt-theme-toggle] .tpt-theme-icon--sun {
  display: block;
}

html:not([data-theme="dark"]) [data-tpt-theme-toggle] .tpt-theme-icon--moon {
  display: block;
}

/* توثيق — أقسام */
.tpt-docs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tpt-space-2);
  margin-bottom: var(--tpt-space-6);
}

.tpt-docs-nav__link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: var(--tpt-radius-sm);
  border: 1px solid var(--tpt-border);
  background: var(--tpt-surface);
  color: var(--tpt-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.tpt-docs-nav__link:hover {
  color: var(--tpt-text);
  border-color: var(--tpt-text-muted);
}

.tpt-docs-nav__link.is-active {
  color: var(--tpt-text);
  border-color: var(--tpt-accent, var(--tpt-text));
  background: var(--tpt-surface-2);
  font-weight: 600;
}

a.tpt-docs-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

a.tpt-docs-card:hover {
  border-color: var(--tpt-text-muted);
}

a.tpt-docs-card h2 {
  margin-top: 0;
}
