/* المطور الذكي — واجهة مرتبة بهوية الهجده */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --b-bg: #070708;
  --b-surface: #101012;
  --b-elevated: #16161a;
  --b-line: rgba(255, 255, 255, 0.08);
  --b-line-strong: rgba(179, 147, 89, 0.35);
  --b-gold: #b39359;
  --b-gold-soft: rgba(179, 147, 89, 0.12);
  --b-text: #f4f1ea;
  --b-muted: #8b8b93;
  --b-ok: #3d9a6a;
  --b-warn: #c4a35a;
  --b-danger: #c45c5c;
  --b-info: #5a7a9a;
  --b-radius: 14px;
  --b-font: 'IBM Plex Sans Arabic', 'Tajawal', sans-serif;
  --b-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

html, body {
  min-height: 100%;
  height: auto;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(179, 147, 89, 0.08), transparent 55%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(90, 122, 154, 0.06), transparent 50%),
    var(--b-bg);
  color: var(--b-text);
  font-family: var(--b-font);
  scroll-behavior: smooth;
}

.builder-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.builder-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--b-line);
  background: rgba(7, 7, 8, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.builder-brand {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.builder-brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--b-gold);
}

.builder-brand-sep {
  color: var(--b-muted);
  opacity: 0.5;
}

.builder-brand-page {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--b-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.builder-top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.builder-link {
  color: var(--b-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.builder-link:hover {
  color: var(--b-gold);
  border-color: var(--b-line-strong);
  background: var(--b-gold-soft);
}

#ai-builder-root {
  flex: 1;
  min-height: calc(100dvh - 4.25rem);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
}

/* Layout */
.ai-layout {
  display: grid;
  grid-template-columns: 1.95fr 0.75fr;
  gap: 0.85rem;
  flex: 1;
  min-height: calc(100dvh - 5.5rem);
  align-items: stretch;
}

.ai-layout.is-focus .ai-panel--brain {
  display: none;
}

.ai-layout.is-focus {
  grid-template-columns: 1fr;
}

.ai-panel {
  background: var(--b-surface);
  border: 1px solid var(--b-line);
  border-radius: var(--b-radius);
  display: flex;
  flex-direction: column;
  min-height: min(88dvh, 920px);
  max-height: none;
  overflow: visible;
}

#ai-chat-panel {
  position: relative;
  min-height: calc(100dvh - 5.5rem);
}

.ai-panel--brain {
  border-color: var(--b-line-strong);
  background: linear-gradient(180deg, var(--b-elevated) 0%, var(--b-surface) 40%);
}

.ai-panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--b-line);
  background: rgba(0, 0, 0, 0.25);
}

.ai-panel-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--b-gold);
}

.ai-panel-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ai-select {
  background: var(--b-bg);
  color: var(--b-text);
  border: 1px solid var(--b-line);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

.ai-select:focus {
  border-color: var(--b-gold);
}

.ai-chip {
  font-size: 0.75rem;
  font-family: var(--b-mono);
  color: var(--b-ok);
  background: rgba(61, 154, 106, 0.12);
  border: 1px solid rgba(61, 154, 106, 0.28);
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
}

.ai-chip--warn {
  color: #f0e0b0;
  background: rgba(196, 163, 90, 0.14);
  border-color: rgba(196, 163, 90, 0.4);
}

.ai-check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--b-muted);
  cursor: pointer;
  user-select: none;
}

.ai-check-row input {
  accent-color: var(--b-gold);
  width: 1rem;
  height: 1rem;
}

.ai-ghost-btn {
  background: transparent;
  border: 1px solid var(--b-line);
  color: var(--b-muted);
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: 0.2s;
}

.ai-ghost-btn:hover {
  color: var(--b-text);
  border-color: rgba(255, 255, 255, 0.2);
}

.ai-ghost-btn--danger:hover {
  color: #fecaca;
  border-color: rgba(196, 92, 92, 0.5);
}

#ai-chat {
  flex: 1 1 auto;
  min-height: min(58dvh, calc(100dvh - 320px));
  max-height: min(70dvh, calc(100dvh - 280px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.35rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  background: var(--b-bg);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

/* Messages — حجم أوضح للقراءة على الشاشة */
.ai-msg {
  max-width: 100%;
  padding: 1.25rem 1.4rem;
  border-radius: 16px;
  line-height: 1.95;
  font-size: 1.28rem;
  font-weight: 450;
  letter-spacing: 0.015em;
  position: relative;
  word-break: break-word;
  scroll-margin-bottom: 1.5rem;
}

.ai-msg__label {
  font-size: 1rem;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.ai-msg__body {
  font-size: 1.28rem;
  line-height: 1.95;
  color: inherit;
}

.ai-msg--user {
  align-self: flex-start;
  width: min(100%, 52rem);
  background: var(--b-elevated);
  border: 1px solid var(--b-line);
  border-start-end-radius: 4px;
  color: #faf7f0;
}

.ai-msg--user .ai-msg__label { color: #c4bfb4; }

.ai-msg--ai {
  align-self: flex-end;
  width: min(100%, 52rem);
  background: linear-gradient(160deg, rgba(179, 147, 89, 0.22), rgba(179, 147, 89, 0.1));
  border: 1px solid var(--b-line-strong);
  border-start-start-radius: 4px;
  color: #fffaf0;
}

.ai-msg--ai .ai-msg__label { color: #e4c98a; }

.ai-msg--system {
  align-self: stretch;
  max-width: 100%;
  padding: 0.95rem 1.2rem;
  font-size: 1.12rem;
  line-height: 1.8;
  text-align: start;
  color: #ddd8ce;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--b-line);
  border-radius: 12px;
  border-right: 3px solid rgba(90, 122, 154, 0.65);
}

.ai-msg--system .ai-msg__label {
  font-size: 0.95rem;
  color: #9eb4c9;
  margin-bottom: 0.35rem;
}

.ai-msg--system .ai-msg__body {
  font-size: 1.12rem;
  line-height: 1.8;
}

.ai-msg--typing {
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1.2rem;
  color: var(--b-gold);
  background: var(--b-gold-soft);
  border: 1px solid var(--b-line-strong);
  border-start-start-radius: 4px;
  padding: 1.05rem 1.3rem;
}

.ai-msg code {
  background: rgba(0, 0, 0, 0.4);
  color: #f0dfa8;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  font-family: var(--b-mono);
  font-size: 0.95em;
  direction: ltr;
  display: inline-block;
  border: 1px solid var(--b-line);
}

.ai-msg strong {
  color: #f5e4b8;
  font-weight: 700;
}

.ai-msg ul,
.ai-msg ol {
  margin: 0.45rem 0 0.2rem;
  padding-right: 1.4rem;
}

.ai-msg li {
  margin: 0.25rem 0;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  width: 100%;
}

.ai-suggestion-chip {
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  color: #d8d0c0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--b-line);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.ai-suggestion-chip:hover:not(:disabled) {
  color: var(--b-text);
  border-color: var(--b-line-strong);
  background: var(--b-gold-soft);
}

.ai-suggestion-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Composer — ظاهر دائمًا وقابل للتمرير داخليًا */
.ai-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--b-line);
  background: var(--b-elevated);
  padding: 0.7rem 0.95rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: none;
  overflow: visible;
  position: sticky;
  bottom: 0;
  z-index: 20;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
}

.ai-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ai-row--actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 0.5rem;
}

.ai-btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s, filter 0.2s;
}

.ai-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-btn:not(:disabled):hover {
  filter: brightness(1.08);
}

.ai-btn:not(:disabled):active {
  transform: scale(0.98);
}

.ai-btn--connect {
  flex: 1;
  background: #2f6b4f;
  color: #fff;
}

.ai-btn--preview {
  flex: 1;
  background: #3a4f66;
  color: #fff;
}

.ai-btn--chat {
  background: #3a4f66;
  color: #fff;
}

.ai-btn--build {
  background: var(--b-gold);
  color: #1a140c;
}

.ai-btn--auto {
  background: #4a3f5c;
  color: #f0eaf8;
}

.ai-btn--architect {
  background: #1e3a5f;
  color: #dbeafe;
}

.ai-btn--consult {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(90, 122, 154, 0.35), rgba(179, 147, 89, 0.18));
  color: #e8e4dc;
  border: 1px solid rgba(90, 122, 154, 0.45);
  font-weight: 600;
  font-size: 0.88rem;
}

.ai-btn--consult:not(:disabled):hover {
  color: #fff;
  border-color: rgba(179, 147, 89, 0.55);
  filter: brightness(1.06);
}

.ai-btn--consult.is-online {
  border-color: rgba(61, 154, 106, 0.5);
  box-shadow: 0 0 0 1px rgba(61, 154, 106, 0.15);
}

.ai-btn--consult.is-offline {
  opacity: 0.75;
  border-style: dashed;
}

.ai-btn--stop {
  grid-column: 1 / -1;
  background: var(--b-danger);
  color: #fff;
}

.ai-btn--undo {
  background: transparent;
  color: var(--b-danger);
  border: 1px solid rgba(196, 92, 92, 0.4);
  padding: 0.55rem 0.75rem;
}

.ai-status {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--b-bg);
  border: 1px solid var(--b-line);
  color: var(--b-muted);
  border-radius: 10px;
  font-size: 0.85rem;
  transition: 0.25s;
}

.ai-status.is-ok {
  border-color: rgba(61, 154, 106, 0.45);
  color: #b7e4c7;
  background: rgba(61, 154, 106, 0.1);
}

.ai-status.is-warn {
  border-color: rgba(196, 163, 90, 0.45);
  color: #f0e0b0;
  background: rgba(196, 163, 90, 0.1);
}

.ai-status.is-err {
  border-color: rgba(196, 92, 92, 0.45);
  color: #fecaca;
  background: rgba(196, 92, 92, 0.1);
}

.ai-prompt-wrap {
  position: relative;
  width: 100%;
}

#ai-prompt {
  width: 100%;
  min-height: 72px;
  max-height: 160px;
  padding: 0.85rem 2.9rem 0.85rem 1rem;
  background: var(--b-bg);
  border: 1px solid var(--b-line);
  color: var(--b-text);
  border-radius: 14px;
  resize: vertical;
  outline: none;
  font-family: inherit;
  font-size: 1.15rem;
  line-height: 1.7;
}

#ai-prompt:focus {
  border-color: var(--b-gold);
  box-shadow: 0 0 0 3px var(--b-gold-soft);
}

#ai-prompt::placeholder {
  color: #6a6a72;
}

#voice-dictate-btn {
  position: absolute;
  bottom: 0.7rem;
  left: 0.7rem;
  background: transparent;
  border: none;
  color: var(--b-info);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
}

#ai-auto-target {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--b-bg);
  border: 1px dashed rgba(179, 147, 89, 0.35);
  color: #d4c4a0;
  border-radius: 10px;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
}

#ai-auto-target:focus {
  border-style: solid;
  border-color: var(--b-gold);
}

#ai-cycle-badge {
  display: none;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: center;
  font-size: 0.82rem;
  border-radius: 10px;
  border: 1px solid rgba(179, 147, 89, 0.3);
  background: var(--b-gold-soft);
  color: #e4d5b0;
}

#ai-cycle-badge.is-running {
  border-color: rgba(61, 154, 106, 0.45);
  background: rgba(61, 154, 106, 0.12);
  color: #b7e4c7;
}

.ai-org-status {
  width: 100%;
  padding: 0.4rem 0.75rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--b-muted);
  border-radius: 8px;
  border: 1px dashed var(--b-line);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.25s ease, color 0.25s ease, background 0.25s ease;
}

.ai-org-status.is-live {
  border-style: solid;
  border-color: rgba(179, 147, 89, 0.35);
  color: #e4d5b0;
  background: rgba(179, 147, 89, 0.08);
}

.ai-strategy-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-family: var(--b-mono);
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--b-line);
  color: var(--b-muted);
  background: rgba(255, 255, 255, 0.03);
}

.ai-strategy-chip.is-online {
  color: #b7e4c7;
  border-color: rgba(61, 154, 106, 0.4);
  background: rgba(61, 154, 106, 0.12);
}

.ai-strategy-chip.is-offline {
  color: #f0e0b0;
  border-color: rgba(196, 163, 90, 0.35);
  background: rgba(196, 163, 90, 0.08);
}

.ai-brain-card {
  background: rgba(0, 0, 0, 0.28);
  padding: 0.9rem 1rem;
  border-radius: 10px;
  border-right: 3px solid var(--card-accent, var(--b-gold));
  margin-bottom: 0.85rem;
}

.ai-brain-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
  gap: 0.5rem;
}

.ai-brain-card__title {
  color: var(--card-accent, var(--b-gold));
  font-size: 0.95rem;
  font-weight: 600;
}

.ai-brain-card__body {
  font-size: 0.88rem;
  line-height: 1.7;
  color: #d8d4cc;
}

.ai-brain-card__body ul {
  padding-right: 1.1rem;
  margin: 0.25rem 0 0;
}

.ai-brain-card__body .muted {
  color: var(--b-muted);
  font-size: 0.82rem;
}

.ai-dept-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.ai-dept-pill {
  font-size: 0.68rem;
  font-family: var(--b-mono);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--b-line);
  color: var(--b-muted);
}

.ai-dept-pill.is-active {
  color: #e4d5b0;
  border-color: rgba(179, 147, 89, 0.45);
  background: rgba(179, 147, 89, 0.12);
}

.ai-brain-head {
  flex-shrink: 0;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--b-line);
  text-align: center;
}

.ai-brain-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--b-gold);
}

.ai-brain-sub {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--b-muted);
  letter-spacing: 0.02em;
}

#ai-brain-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.75;
  color: #d8d4cc;
}

.ai-brain-empty {
  text-align: center;
  color: var(--b-muted);
  margin-top: 2.5rem;
  font-size: 0.9rem;
}

/* Modal */
.ai-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.ai-modal__card {
  background: var(--b-elevated);
  padding: 1.5rem;
  border-radius: var(--b-radius);
  border: 1px solid var(--b-line-strong);
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ai-modal__card h3 {
  margin: 0;
  color: var(--b-gold);
  font-size: 1.05rem;
}

.ai-modal__card input {
  padding: 0.7rem 0.85rem;
  background: var(--b-bg);
  border: 1px solid var(--b-line);
  color: var(--b-text);
  border-radius: 8px;
  font-family: inherit;
}

.ai-modal__card input:focus {
  outline: none;
  border-color: var(--b-gold);
}

#slash-commands-popup {
  display: none;
  position: absolute;
  bottom: 12.5rem;
  left: 1rem;
  right: 1rem;
  background: var(--b-elevated);
  border: 1px solid var(--b-line);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

/* Typing dots */
.lds-ellipsis {
  display: inline-block;
  position: relative;
  width: 40px;
  height: 13px;
}
.lds-ellipsis div {
  position: absolute;
  top: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--b-gold);
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
}
.lds-ellipsis div:nth-child(1) { left: 4px; animation: lds-ellipsis1 0.6s infinite; }
.lds-ellipsis div:nth-child(2) { left: 4px; animation: lds-ellipsis2 0.6s infinite; }
.lds-ellipsis div:nth-child(3) { left: 16px; animation: lds-ellipsis2 0.6s infinite; }
@keyframes lds-ellipsis1 { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes lds-ellipsis2 { 0% { transform: translate(0, 0); } 100% { transform: translate(12px, 0); } }

/* مرساة الغرفة — تنقل سريع + وضع تركيز */
.ai-dock {
  position: fixed;
  left: 1rem;
  bottom: 1.1rem;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: stretch;
}

.ai-dock__btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #1a140c;
  background: var(--b-gold);
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

.ai-dock__btn:hover { transform: translateY(-2px); filter: brightness(1.06); }

.ai-dock__btn--ghost {
  background: rgba(16, 16, 18, 0.92);
  color: var(--b-text);
  border: 1px solid var(--b-line-strong);
}

.ai-dock__btn.is-on {
  background: #e4c98a;
}

.ai-dock__pulse {
  display: none;
  max-width: 220px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #f4efe4;
  background: rgba(16, 16, 18, 0.94);
  border: 1px solid var(--b-line-strong);
  border-radius: 14px;
  padding: 0.65rem 0.8rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  animation: dockPulseIn 0.35s ease both;
}

.ai-dock__pulse.is-show { display: block; }

@keyframes dockPulseIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 960px) {
  .ai-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .ai-panel {
    min-height: 0;
  }
  #ai-chat-panel {
    min-height: 0;
  }
  #ai-chat {
    min-height: 45dvh;
    max-height: 55dvh;
  }
  .ai-panel--brain {
    min-height: 240px;
  }
  .ai-row--actions {
    grid-template-columns: 1fr 1fr;
  }
  .ai-btn--build {
    grid-column: 1 / -1;
  }
  .ai-dock {
    left: 0.65rem;
    bottom: 0.75rem;
  }
}

@media (max-width: 560px) {
  .builder-brand-page { display: none; }
  .builder-topbar { padding: 0.7rem 0.85rem; }
  #ai-builder-root { padding: 0.55rem; }
  .ai-row--actions { grid-template-columns: 1fr; }
}

/* ── شريط الحالة السريع ── */
.ai-kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  padding: 0.55rem 0.95rem;
  border-bottom: 1px solid var(--b-line);
  background: rgba(0, 0, 0, 0.2);
}

.ai-kpi {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--b-muted);
  border: 1px solid var(--b-line);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  text-align: center;
  line-height: 1.35;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-kpi.is-ok {
  color: #b7e4c7;
  border-color: rgba(61, 154, 106, 0.4);
  background: rgba(61, 154, 106, 0.08);
}

.ai-kpi.is-warn {
  color: #f0e0b0;
  border-color: rgba(196, 163, 90, 0.4);
  background: rgba(196, 163, 90, 0.08);
}

.ai-kpi.is-err {
  color: #fecaca;
  border-color: rgba(196, 92, 92, 0.4);
  background: rgba(196, 92, 92, 0.08);
}

.ai-kpi.is-live {
  color: #e4d5b0;
  border-color: rgba(179, 147, 89, 0.45);
  background: rgba(179, 147, 89, 0.1);
  animation: kpiPulse 2.4s ease-in-out infinite;
}

@keyframes kpiPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 147, 89, 0); }
  50% { box-shadow: 0 0 0 3px rgba(179, 147, 89, 0.12); }
}

/* ── دليل الترحيب ── */
.ai-welcome {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 0.5rem 0.25rem 1rem;
  animation: welcomeIn 0.45s ease both;
}

@keyframes welcomeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.ai-welcome__hero {
  text-align: center;
  padding: 1.25rem 1rem 0.5rem;
}

.ai-welcome__hero h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--b-gold);
}

.ai-welcome__hero p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--b-muted);
  line-height: 1.65;
  max-width: 32rem;
  margin-inline: auto;
}

.ai-welcome__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.ai-welcome__card {
  border: 1px solid var(--b-line);
  border-radius: 14px;
  padding: 1rem 0.85rem;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.2s, background 0.2s;
}

.ai-welcome__card:hover {
  border-color: var(--b-line-strong);
  background: var(--b-gold-soft);
}

.ai-welcome__icon {
  font-size: 1.4rem;
  margin-bottom: 0.45rem;
  display: block;
}

.ai-welcome__card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--b-text);
}

.ai-welcome__card p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--b-muted);
  line-height: 1.55;
}

.ai-welcome__steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  padding-top: 0.25rem;
}

.ai-welcome__step {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--b-muted);
  border: 1px dashed var(--b-line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
}

.ai-welcome__step strong {
  color: var(--b-gold);
  font-weight: 700;
}

/* ── تجميع أزرار المُنشئ ── */
.ai-action-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ai-action-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--b-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ai-brain-toggle {
  display: none;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--b-gold);
  background: var(--b-gold-soft);
  border: 1px solid var(--b-line-strong);
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
}

.ai-layout.is-brain-collapsed .ai-panel--brain {
  display: none;
}

@media (max-width: 960px) {
  .ai-kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .ai-welcome__grid {
    grid-template-columns: 1fr;
  }
  .ai-brain-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
  }
  .ai-panel--brain {
    order: 3;
  }
}

@media (max-width: 560px) {
  .ai-kpi-strip {
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    padding: 0.45rem 0.65rem;
  }
  .ai-kpi {
    font-size: 0.68rem;
    padding: 0.4rem 0.45rem;
  }
}
