/* Wave 3 additions: login, recommendation cards, chat, reports, 3D page. Uses tokens.css variables and logical properties (RTL-safe). */

html[lang="ar"] {
  --ed-font-ui: "IBM Plex Sans Arabic", "Geist", "Inter", system-ui, sans-serif;
  --ed-font-display: "IBM Plex Sans Arabic", "Geist", "Outfit", system-ui, sans-serif;
}
html[lang="ar"] .ed-label { letter-spacing: 0; }
html[dir="rtl"] .ed-title, html[dir="rtl"] .ed-h2 { letter-spacing: 0; }

body.is-login .ed-app { display: none; }
body.is-login .ed-backdrop, body.is-login .ed-account-pop { display: none !important; }

.amd-login[hidden] { display: none; }
.amd-login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--ed-bg-page); }
.amd-login-card { width: min(400px, 100%); display: grid; gap: 4px; }
.amd-login-lang { display: flex; justify-content: flex-end; gap: 6px; margin-bottom: 8px; }
.amd-login .ed-label { display: block; margin-bottom: 4px; }

.amd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.amd-head-r { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.amd-state { padding: 22px; text-align: center; color: var(--ed-text-muted); border: 1px dashed var(--ed-border-strong, var(--ed-border)); border-radius: var(--ed-r-card, 20px); margin: 10px 0; }
.amd-state.is-err { color: var(--ed-err-ink); background: var(--ed-err-soft); border-color: transparent; }
.amd-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 16px; }
.amd-jobstatus { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.amd-jobstatus .amd-state { width: 100%; margin: 4px 0; }

.amd-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.amd-reco, .amd-fix { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.amd-reco-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.amd-reco-title { margin: 0; font: 600 var(--ed-fs-body) / 1.3 var(--ed-font-ui); }
.amd-reco-metric { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.amd-reco-value { font: 600 26px / 1.1 var(--ed-font-display); letter-spacing: -0.02em; }
.amd-reco-label { color: var(--ed-text-muted); font-size: var(--ed-fs-sm); }
.amd-reco-ev { margin: 0; color: var(--ed-text-muted); font-size: var(--ed-fs-xs); overflow-wrap: anywhere; }
.amd-reco-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }
.amd-reco-actions a.ed-btn { text-decoration: none; }

.amd-chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; min-height: 520px; }
.amd-chat-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.amd-chat-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow: auto; }
.amd-chat-item { text-align: start; padding: 8px 12px; border: 0; border-radius: 12px; background: transparent; color: var(--ed-text); font: inherit; font-size: var(--ed-fs-sm); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amd-chat-item:hover { background: var(--ed-bg-muted); }
.amd-chat-item.is-active { background: var(--ed-primary-soft); color: var(--ed-primary); }
.amd-chat-main { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--ed-border); border-radius: var(--ed-r-card, 20px); background: var(--ed-bg-card); }
.amd-chat-msgs { flex: 1; min-height: 360px; max-height: 62vh; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.amd-chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--ed-border); align-items: flex-end; }
.amd-chat-form textarea { flex: 1; resize: none; height: auto; min-height: 44px; }
.amd-msg { max-width: min(760px, 94%); display: flex; flex-direction: column; gap: 6px; }
.amd-msg.is-user { align-self: flex-end; }
.amd-msg.is-user .amd-msg-body { background: var(--ed-primary-soft); }
.amd-msg-who { font-size: var(--ed-fs-xs); color: var(--ed-text-muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.amd-msg-body { padding: 10px 14px; border-radius: 16px; background: var(--ed-bg-muted); overflow-wrap: anywhere; }
.amd-msg-body p { margin: 0 0 8px; }
.amd-msg-body p:last-child { margin-bottom: 0; }
.amd-msg.is-err .amd-msg-body { background: var(--ed-err-soft); color: var(--ed-err-ink); }
.amd-msg-sec { font-size: var(--ed-fs-xs); color: var(--ed-text-muted); }
.amd-msg-sec ul { margin: 4px 0 0; padding-inline-start: 18px; }
.amd-msg-foot { font-size: var(--ed-fs-cap); color: var(--ed-text-subtle); }
.amd-md pre { background: var(--ed-bg-inset); padding: 10px; border-radius: 10px; overflow: auto; }
.amd-md-table { overflow: auto; }
.amd-md table { border-collapse: collapse; font-size: var(--ed-fs-sm); }
.amd-md th, .amd-md td { padding: 4px 8px; border: 1px solid var(--ed-border); text-align: start; }

.amd-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.amd-kpi { padding: 12px 14px; }
.amd-kpi-v { font: 600 22px / 1.2 var(--ed-font-display); overflow-wrap: anywhere; }
.amd-table td { vertical-align: top; overflow-wrap: anywhere; }
.amd-clip { display: inline-block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.amd-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.amd-cols ul { margin: 4px 0 0; padding-inline-start: 18px; }
.amd-snip { margin-bottom: 14px; }
.amd-snip-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.amd-snip pre, .amd-fix pre { background: var(--ed-bg-inset); padding: 12px; border-radius: 12px; overflow: auto; max-height: 280px; font: 12px/1.45 var(--ed-font-mono); direction: ltr; text-align: left; }

.amd-swot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.amd-swot ul, .amd-tows { margin: 8px 0 0; padding-inline-start: 18px; display: grid; gap: 10px; }
.amd-swot-s { border-inline-start: 4px solid var(--ed-ok); }
.amd-swot-w { border-inline-start: 4px solid var(--ed-err); }
.amd-swot-o { border-inline-start: 4px solid var(--ed-primary); }
.amd-swot-t { border-inline-start: 4px solid var(--ed-warn); }
.amd-ev { color: var(--ed-text-muted); font-size: var(--ed-fs-xs); overflow-wrap: anywhere; }

.amd-v3 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; }
.amd-v3-stage { height: 580px; min-width: 0; }
.amd-v3-detail { max-height: 580px; overflow: auto; padding: 14px; }
.amd-kv { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--ed-border); font-size: var(--ed-fs-sm); }
.amd-kv span { color: var(--ed-text-muted); }
.amd-pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: var(--ed-fs-sm); }
.amd-pick-list li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }

@media (max-width: 1100px) {
  .amd-chat { grid-template-columns: minmax(0, 1fr); }
  .amd-swot-grid, .amd-v3 { grid-template-columns: minmax(0, 1fr); }
  .amd-v3-stage { height: 460px; }
}

.amd-login-brand { display: grid; justify-items: center; gap: 4px; margin: 4px 0 6px; }
.amd-login-name { font: 600 20px / 1.2 var(--ed-font-display); letter-spacing: -0.01em; }
.amd-login-tag { margin: 0; text-align: center; }
.amd-pass { position: relative; }
.amd-pass .ed-input { width: 100%; box-sizing: border-box; padding-inline-end: 44px; }
.amd-eye { position: absolute; inset-block: 0; inset-inline-end: 6px; width: 36px; border: 0; background: transparent; color: var(--ed-text-muted); cursor: pointer; font-size: 16px; }
.amd-state.is-warn { color: var(--ed-warn-ink); background: var(--ed-warn-soft); border-color: transparent; padding: 10px; margin: 0 0 12px; }
.amd-login .amd-state.is-err { padding: 10px; margin: 12px 0 0; text-align: start; }
@media (max-width: 480px) {
  .amd-login { padding: 8px; align-items: start; }
  .amd-login-card { margin-top: 24px; }
}

/* WhatsApp inbox (crmAi proxy). Logical properties only, so AR/RTL mirrors without overrides. */
.ed-wa-statusbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ed-wa-statusbar__l { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.ed-wa-statusbar__l .ed-sub { margin: 0; overflow-wrap: anywhere; }
.ed-wa-link { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; margin-block-start: 12px; }
.ed-wa-link__body { display: grid; gap: 8px; min-width: 0; }
.ed-wa-link__body .ed-sub { margin: 0; }
.ed-wa-qr { width: 168px; height: 168px; max-width: 100%; border-radius: var(--ed-r-tile); background: #fff; border: 1px solid var(--ed-border); object-fit: contain; }
.ed-wa-code { font: 600 22px var(--ed-font-mono); letter-spacing: 0.14em; overflow-wrap: anywhere; }
.ed-wa-pane { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.ed-wa-list { display: grid; gap: 6px; max-height: 560px; overflow-y: auto; align-content: start; }
.ed-wa-item { display: grid; gap: 3px; padding: 10px 12px; border-radius: var(--ed-r-card); border: 1px solid var(--ed-border); background: var(--ed-bg-card); cursor: pointer; text-align: start; font: inherit; color: inherit; width: 100%; min-width: 0; }
.ed-wa-item:hover { background: var(--ed-bg-muted); }
.ed-wa-item.is-active { background: var(--ed-primary-soft); border-color: transparent; }
.ed-wa-item__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.ed-wa-item__tags { justify-content: flex-start; gap: 6px; }
.ed-wa-item__name { font-weight: 600; font-size: var(--ed-fs-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-wa-item__prev { font-size: var(--ed-fs-xs); color: var(--ed-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-wa-item__time { font-size: var(--ed-fs-cap); color: var(--ed-text-subtle); flex-shrink: 0; }
.ed-wa-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.ed-wa-head__who { min-width: 0; }
.ed-wa-head__who .ed-sub { margin: 0; overflow-wrap: anywhere; }
.ed-wa-head__tags { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-wa-thread { display: flex; flex-direction: column; gap: 8px; height: 440px; overflow-y: auto; padding: 14px; }
.ed-wa-bubble { max-width: 82%; padding: 8px 12px; border-radius: 16px; font-size: var(--ed-fs-body); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--ed-shadow-sm); }
.ed-wa-bubble__meta { display: flex; justify-content: space-between; gap: 12px; font-size: var(--ed-fs-cap); margin-block-end: 3px; opacity: .8; }
.ed-wa-bubble audio { width: 100%; max-width: 260px; margin-block-start: 4px; }
.ed-wa-bubble--customer { align-self: flex-start; background: var(--ed-bg-card); color: var(--ed-text); border: 1px solid var(--ed-border); border-end-start-radius: 4px; }
.ed-wa-bubble--assistant { align-self: flex-end; background: var(--ed-violet-soft); color: var(--ed-violet); border-end-end-radius: 4px; }
.ed-wa-bubble--owner { align-self: flex-end; background: var(--ed-primary); color: var(--ed-text-inverse); border-end-end-radius: 4px; }
.ed-wa-bubble.is-pending { opacity: .6; }
.ed-wa-compose { display: flex; gap: 8px; align-items: flex-end; }
.ed-wa-compose[hidden] { display: none; }
.ed-wa-compose textarea { flex: 1; min-width: 0; min-height: 42px; max-height: 120px; height: auto; resize: vertical; padding: 10px 14px; border-radius: var(--ed-r-input); font-family: var(--ed-font-ui); }
.ed-wa-compose .ed-btn { height: 42px; }
.ed-wa-empty { margin: auto; text-align: center; color: var(--ed-text-muted); font-size: var(--ed-fs-sm); padding: 24px 12px; overflow-wrap: anywhere; }
.ed-wa-matches { display: grid; gap: 8px; }
.ed-wa-match { display: grid; gap: 8px; padding: 10px 12px; border-radius: var(--ed-r-card); background: var(--ed-bg-card); border: 1px solid var(--ed-border); min-width: 0; }
.ed-wa-match__row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ed-wa-match__row strong { overflow-wrap: anywhere; }
.ed-wa-match__facts { font-size: 12px; display: grid; gap: 2px; overflow-wrap: anywhere; }
.ed-wa-dim { color: var(--ed-text-subtle); }
.ed-toast { position: fixed; inset-inline-start: 50%; transform: translateX(-50%); bottom: 84px; z-index: 200; padding: 10px 16px; border-radius: var(--ed-r-pill); background: var(--ed-ink-btn); color: var(--ed-ink-btn-text); font-size: var(--ed-fs-sm); box-shadow: var(--ed-shadow-pop); max-width: 90vw; }
html[dir="rtl"] .ed-toast { transform: translateX(50%); }
.ed-toast--err { background: var(--ed-err); color: #fff; }
@media (max-width: 768px) {
  .ed-wa-link { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .ed-wa-thread { height: 360px; }
  .ed-wa-list { max-height: 260px; }
  .ed-wa-bubble { max-width: 92%; }
}

/* Phones: brand, search, bell and account stay on one row (the account menu holds language and logout); the module nav scrolls on its own row. */
@media (max-width: 768px) {
  .ed-topbar { flex-wrap: wrap; row-gap: 8px; }
  .ed-brand-pill { flex: 1 1 0; min-width: 0; }
  .ed-brand-pill > div:last-child { min-width: 0; }
  .ed-brand-pill > div:last-child > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ed-nav-pill { order: 3; flex: 1 1 100%; }
  .ed-top-cluster { flex-shrink: 0; }
  .ed-user-pill > div:nth-child(2) { display: none; }
}
