:root {
  --ps-ink: #f4f7f4;
  --ps-mute: #a7b5ad;
  --ps-brand: #0a1a14;
  --ps-forest: #123528;
  --ps-brass: #c4a35a;
  --ps-line: rgba(255, 255, 255, 0.12);
  --ps-panel: rgba(10, 26, 20, 0.88);
  --ps-safe-top: env(safe-area-inset-top, 0px);
  --ps-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ps-safe-inline: env(safe-area-inset-left, 0px);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  color: var(--ps-ink);
  background: var(--ps-brand);
  overflow-x: hidden;
  overflow-x: clip;
  overscroll-behavior-x: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(ellipse 70% 55% at 85% -10%, rgba(196, 163, 90, 0.18), transparent 55%),
    radial-gradient(ellipse 55% 45% at 0% 100%, rgba(18, 53, 40, 0.9), transparent 60%),
    linear-gradient(160deg, #07140f 0%, #0a1a14 45%, #123528 100%);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-x: clip;
  position: relative;
}

button,
input {
  font: inherit;
}

.ps-boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--ps-mute);
  padding: var(--ps-safe-top) 1rem var(--ps-safe-bottom);
  background:
    radial-gradient(ellipse 70% 55% at 85% -10%, rgba(196, 163, 90, 0.18), transparent 55%),
    radial-gradient(ellipse 55% 45% at 0% 100%, rgba(18, 53, 40, 0.9), transparent 60%),
    linear-gradient(160deg, #07140f 0%, #0a1a14 45%, #123528 100%);
}

.ps-loader {
  width: 32px;
  height: 32px;
  border: 2px solid var(--ps-line);
  border-top-color: var(--ps-brass);
  border-radius: 50%;
  animation: ps-spin 0.7s linear infinite;
}

@keyframes ps-spin {
  to {
    transform: rotate(360deg);
  }
}

.ps-boot .boot-err {
  text-align: center;
  max-width: 20rem;
  padding: 1.5rem;
}

.ps-boot .boot-err h2 {
  font-family: Alexandria, 'IBM Plex Sans Arabic', sans-serif;
  margin: 0 0 0.5rem;
}

.ps-app {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  opacity: 1;
  transition: opacity 0.3s ease;
  padding-top: var(--ps-safe-top);
  padding-bottom: var(--ps-safe-bottom);
}

.ps-app.ready {
  opacity: 1;
}

.ps-top {
  padding: 1rem 1.25rem;
  flex: none;
}

.ps-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
  max-width: 100%;
}

.ps-mark {
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border-radius: 0.55rem;
  background: color-mix(in srgb, var(--ps-brass) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--ps-brass) 45%, transparent);
  color: var(--ps-brass);
  font-family: Alexandria, sans-serif;
  font-weight: 700;
  flex: none;
}

.ps-brand b {
  display: block;
  font-family: Alexandria, 'IBM Plex Sans Arabic', sans-serif;
  letter-spacing: 0.02em;
  font-size: clamp(1.05rem, 3.8vw, 1.35rem);
  line-height: 1.25;
  max-width: min(18rem, 70vw);
  overflow-wrap: anywhere;
}

.ps-brand small {
  display: block;
  color: var(--ps-mute);
  font-size: 0.82rem;
  margin-top: 0.1rem;
}

.ps-app[data-kind='office'] .ps-mark {
  width: 2.45rem;
  height: 2.45rem;
  font-size: 1.15rem;
}

.ps-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 1.5rem 1.25rem 2.5rem;
  width: 100%;
  max-width: min(40rem, 100%);
  margin: 0 auto;
  min-width: 0;
  box-sizing: border-box;
}

.ps-eyebrow {
  margin: 0 0 0.75rem;
  color: var(--ps-brass);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
}

.ps-hero h1 {
  margin: 0;
  font-family: Alexandria, 'IBM Plex Sans Arabic', sans-serif;
  font-size: clamp(1.7rem, 6vw, 2.7rem);
  font-weight: 700;
  line-height: 1.3;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ps-app[data-kind='office'] .ps-eyebrow {
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.ps-app[data-kind='office'] .ps-hero h1 {
  font-size: clamp(1.32rem, 4.6vw + 0.35rem, 2.35rem);
  max-width: 100%;
  width: 100%;
  line-height: 1.55;
  text-wrap: balance;
  white-space: normal;
}

.ps-lead {
  margin: 1.1rem 0 0;
  color: var(--ps-mute);
  font-size: clamp(0.95rem, 3.5vw, 1.05rem);
  line-height: 1.75;
  max-width: 34rem;
}

.ps-lead .ps-hero-tag {
  display: inline-block;
  margin-bottom: 0.35rem;
  color: #f3f7f4;
  font-weight: 600;
  font-size: clamp(1.02rem, 3.6vw, 1.15rem);
}

.ps-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.75rem;
  width: 100%;
}

.ps-btn {
  appearance: none;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ps-ink);
  border-radius: 0.85rem;
  padding: 0.95rem 1.25rem;
  min-width: 0;
  width: min(100%, 15rem);
  max-width: 100%;
  box-sizing: border-box;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.ps-btn:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--ps-brass) 50%, var(--ps-line));
}

.ps-btn.primary {
  background: linear-gradient(135deg, #c4a35a, #a8883f);
  color: #1a1408;
  border-color: transparent;
}

.ps-btn.ghost {
  background: rgba(255, 255, 255, 0.06);
}

.ps-trust {
  margin: 1.35rem 0 0;
  color: var(--ps-mute);
  font-size: 0.92rem;
}

.ps-direct {
  margin-top: 1.5rem;
  padding: 1rem 1.15rem;
  border: 1px solid color-mix(in srgb, var(--ps-brass) 35%, var(--ps-line));
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.03);
  max-width: 28rem;
  width: 100%;
}

.ps-direct-label {
  margin: 0;
  font-weight: 700;
  color: var(--ps-ink);
}

.ps-direct-hint {
  margin: 0.35rem 0 0.85rem;
  color: var(--ps-mute);
  font-size: 0.95rem;
}

.ps-btn.wa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: #128c7e;
  border-color: transparent;
  color: #fff;
  min-width: 0;
  width: min(100%, 15rem);
  max-width: 100%;
}

.ps-btn.wa:hover {
  background: #0e7a6e;
}

/* —— نافذة المحادثة —— */
.ps-dialog {
  border: 1px solid var(--ps-line);
  border-radius: 1.05rem;
  padding: 0;
  width: min(640px, calc(100% - 1.5rem));
  max-width: calc(100% - 1.5rem);
  max-height: min(92dvh, 860px);
  background: #0c1c16;
  color: var(--ps-ink);
  color-scheme: dark;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.ps-dialog::backdrop {
  background: rgba(3, 10, 8, 0.72);
  backdrop-filter: blur(4px);
}

.ps-dialog-inner {
  display: flex;
  flex-direction: column;
  height: min(92dvh, 820px);
  max-height: min(92dvh, 820px);
  min-height: 0;
}

.ps-dialog header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--ps-line);
  flex: none;
}

.ps-dialog header > div {
  min-width: 0;
  flex: 1;
}

.ps-dialog h2 {
  margin: 0;
  font-family: Alexandria, sans-serif;
  font-size: 1.1rem;
  line-height: 1.35;
}

.ps-dialog header p {
  margin: 0.35rem 0 0;
  color: var(--ps-mute);
  font-size: 0.82rem;
  line-height: 1.55;
}

.ps-close {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 0.55rem;
  border: 1px solid var(--ps-line);
  background: transparent;
  color: var(--ps-ink);
  cursor: pointer;
  flex: none;
  display: grid;
  place-items: center;
}

.ps-bot {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ps-bot .chat-thread {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 0;
}

.ps-bot .chat-bubble {
  max-width: min(92%, 28rem);
  padding: 0.75rem 0.9rem;
  border-radius: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
}

.ps-bot .chat-bubble.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--ps-line);
}

.ps-bot .chat-bubble.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--ps-brass) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--ps-brass) 35%, transparent);
}

.ps-bot .chat-who {
  display: block;
  font-size: 0.75rem;
  color: var(--ps-brass);
  margin-bottom: 0.25rem;
}

.ps-bot .chat-bubble p {
  margin: 0;
}

.ps-bot .chat-summary {
  display: grid;
  gap: 0.45rem;
  margin: 0.75rem 0 0;
}

.ps-bot .chat-summary div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.88rem;
  border-bottom: 1px dashed var(--ps-line);
  padding-bottom: 0.35rem;
}

.ps-bot .chat-summary dt {
  color: var(--ps-mute);
  flex: none;
}

.ps-bot .chat-summary dd {
  margin: 0;
  text-align: start;
  min-width: 0;
  word-break: break-word;
}

.ps-bot .chat-actions,
.ps-bot .chat-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.ps-bot .chat-composer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--ps-line);
  flex: none;
  background: #0d1f18;
}

.ps-bot .chat-form {
  display: grid;
  gap: 0.45rem;
  width: 100%;
}

.ps-bot .chat-row {
  display: flex;
  align-items: stretch;
  gap: 0.55rem;
  width: 100%;
  min-width: 0;
}

.ps-bot .chat-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border-radius: 0.7rem;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ps-ink);
  padding: 0.8rem 0.85rem;
  line-height: 1.4;
}

.ps-bot .chat-input[dir='ltr'] {
  text-align: left;
}

.ps-bot .chat-input.is-missing,
.ps-bot .chat-paste.is-missing,
.ps-bot .review-field.is-missing input,
.ps-bot .review-field.is-missing select,
.ps-bot .review-field.is-missing textarea {
  border-color: color-mix(in srgb, var(--ps-brass) 55%, #b42318);
}

.ps-bot .chat-paste {
  width: 100%;
  min-height: 8.5rem;
  resize: vertical;
  border-radius: 0.7rem;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ps-ink);
  padding: 0.85rem 0.9rem;
  line-height: 1.7;
}

.ps-bot .paste-row {
  margin-top: 0.45rem;
}

.ps-sheet {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}

.ps-sheet-inner {
  padding: 1rem 1.1rem 1.25rem;
}

.ps-sheet-kicker {
  margin: 0 0 0.35rem;
  font-family: Alexandria, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ps-brass);
}

.ps-manual-link {
  display: block;
  margin: 0.85rem 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ps-mute);
  font-size: 0.84rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ps-fill-btn {
  width: 100%;
  margin: 0.55rem 0 1rem;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.choice-opt {
  flex: 1 1 30%;
  min-width: 6.2rem;
  border-radius: 0.6rem;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ps-ink);
  padding: 0.7rem 0.55rem;
  cursor: pointer;
  font-weight: 650;
  font-size: 0.88rem;
}

.choice-opt.on {
  background: color-mix(in srgb, var(--ps-brass) 24%, transparent);
  border-color: var(--ps-brass);
  color: #fff;
}

.suggest-box {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline: 0;
  z-index: 12;
  max-height: 11rem;
  overflow: auto;
  background: #10241c;
  border: 1px solid color-mix(in srgb, var(--ps-brass) 45%, var(--ps-line));
  border-radius: 0.6rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.suggest-item {
  display: block;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  color: var(--ps-ink);
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.suggest-item:hover,
.suggest-item:focus {
  background: color-mix(in srgb, var(--ps-brass) 18%, transparent);
}

.ps-bot .review-field select option {
  background: #f4f7f4;
  color: #0c1c16;
}

.ps-bot .review-banner {
  margin: 0 0 1rem;
  padding: 0.55rem 0.8rem;
  border-radius: 0.65rem;
  background: rgba(196, 163, 90, 0.1);
  border: 1px solid rgba(196, 163, 90, 0.28);
  color: #e8d7a8;
  font-size: 0.84rem;
  line-height: 1.55;
}

.ps-bot .review-banner.ready {
  background: rgba(18, 140, 126, 0.12);
  border-color: rgba(18, 140, 126, 0.32);
  color: #cfeee8;
}

.ps-bot .review-form {
  display: grid;
  gap: 1.05rem;
}

.ps-bot .review-sec h3 {
  margin: 0 0 0.55rem;
  font-family: Alexandria, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ps-brass);
}

.ps-bot .review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem 0.75rem;
}

.ps-bot .review-field {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  min-width: 0;
  position: relative;
}

.ps-bot .review-field.span-2 {
  grid-column: 1 / -1;
}

.ps-bot .review-field > span {
  font-size: 0.78rem;
  font-weight: 600;
  color: #d5ddd8;
}

.ps-bot .review-field .req {
  color: var(--ps-brass);
  font-weight: 700;
}
.ps-bot .review-field .field-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: #9aaba3;
  line-height: 1.45;
}

.ps-bot .review-field input,
.ps-bot .review-field select,
.ps-bot .review-field textarea {
  width: 100%;
  border-radius: 0.65rem;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ps-ink);
  padding: 0.7rem 0.8rem;
  line-height: 1.4;
  color-scheme: dark;
}

.ps-bot .review-field textarea {
  min-height: 4.2rem;
  resize: vertical;
}

.ps-bot .review-field input:focus,
.ps-bot .review-field select:focus,
.ps-bot .review-field textarea:focus,
.ps-bot .chat-paste:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--ps-brass) 70%, var(--ps-line));
  box-shadow: 0 0 0 3px rgba(196, 163, 90, 0.16);
}

.ps-bot .review-field.is-missing > span {
  color: #f0d9a0;
}

.ps-bot .review-extra {
  border: 1px dashed var(--ps-line);
  border-radius: 0.75rem;
  padding: 0.15rem 0.75rem 0.75rem;
}

.ps-bot .review-extra > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.7rem 0 0.45rem;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--ps-mute);
}

.ps-bot .review-extra > summary::-webkit-details-marker {
  display: none;
}

.ps-bot .review-extra > summary small {
  margin-inline-start: 0.4rem;
  font-weight: 500;
  opacity: 0.75;
}

.ps-bot .review-need,
.ps-bot .review-banner ul,
.ps-bot .review-banner .ai-fill-gaps-note {
  display: none;
}

.ps-bot .chat-send:disabled,
.ps-bot .chat-confirm[data-act='send']:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.ps-bot .review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ps-bot .review-actions .chat-confirm {
  width: auto;
  flex: 1 1 10rem;
}

.ps-bot .chat-send {
  flex: 0 0 auto;
  white-space: nowrap;
  min-width: 4.75rem;
}

.ps-bot .chat-send,
.ps-bot .chat-choice,
.ps-bot .chat-confirm,
.ps-bot .chat-again {
  border-radius: 0.7rem;
  border: 1px solid var(--ps-line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ps-ink);
  padding: 0.75rem 0.95rem;
  cursor: pointer;
}

.ps-bot .chat-choice {
  flex: 1 1 calc(50% - 0.5rem);
  min-width: 7rem;
  text-align: center;
}

.ps-bot .chat-send,
.ps-bot .chat-confirm[data-act='send'],
.ps-bot .chat-confirm[data-act='extract'],
.ps-bot .chat-confirm[data-act='fill'],
.ps-bot .chat-again {
  background: linear-gradient(135deg, #c4a35a, #a8883f);
  color: #1a1408;
  border-color: transparent;
  font-weight: 600;
}

.ps-bot .chat-confirm.ghost {
  background: transparent;
  color: var(--ps-ink);
  border-color: var(--ps-line);
  font-weight: 600;
}

.ps-bot .chat-actions {
  width: 100%;
}

.ps-bot .chat-confirm,
.ps-bot .chat-again {
  width: 100%;
  justify-content: center;
}

.ps-bot .chat-success {
  margin-top: 0.35rem;
}

.ps-bot .chat-success-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin: 0 0 0.45rem;
  color: var(--ps-ink);
}

.ps-bot .chat-success p {
  margin: 0.25rem 0;
  line-height: 1.65;
}

.ps-bot .chat-success-note {
  margin-top: 0.55rem !important;
  font-size: 0.9rem;
  opacity: 0.85;
}

.ps-bot .bubble.success {
  border-color: rgba(196, 163, 90, 0.45);
}

.ps-bot .chat-skip-tip {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ps-mute);
}

.ps-bot .chat-status {
  min-height: 1.15rem;
  padding: 0 1rem 0.7rem;
  font-size: 0.85rem;
  color: var(--ps-mute);
  flex: none;
}

.ps-bot .chat-status.err {
  color: #ffb4a8;
}

@media (max-width: 640px) {
  .ps-top {
    padding: 0.85rem 1rem;
  }

  .ps-hero {
    justify-content: flex-start;
    padding: 1.25rem 1rem 2rem;
  }

  .ps-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ps-btn {
    min-width: 0;
    width: 100%;
  }

  .ps-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
  }

  .ps-dialog-inner {
    height: 100dvh;
    max-height: 100dvh;
    padding-top: var(--ps-safe-top);
    padding-bottom: var(--ps-safe-bottom);
  }

  .ps-dialog header {
    padding: 0.85rem 0.9rem;
  }

  .ps-dialog h2 {
    font-size: 1.05rem;
  }

  .ps-dialog header p {
    font-size: 0.78rem;
  }

  .ps-bot .chat-thread {
    padding: 0.85rem 0.9rem;
  }

  .ps-bot .review-grid {
    grid-template-columns: 1fr;
  }

  .ps-sheet-inner {
    padding: 0.9rem 0.95rem 1.1rem;
  }

  .ps-bot .chat-bubble {
    max-width: 94%;
  }

  .ps-bot .chat-composer {
    padding: 0.7rem 0.9rem;
    padding-bottom: max(0.7rem, 0.25rem);
  }

  .ps-bot .chat-row {
    gap: 0.45rem;
  }

  .ps-bot .chat-input {
    padding: 0.85rem 0.8rem;
    font-size: 16px; /* يمنع تكبير iOS التلقائي */
  }

  .ps-bot .chat-send {
    min-width: 4.4rem;
    padding-inline: 0.85rem;
  }

  .ps-bot .chat-choice {
    flex: 1 1 100%;
    min-width: 0;
  }

  .ps-bot .chat-status {
    padding: 0 0.9rem 0.65rem;
  }
}
