/* صفحة المساعد الذكي داخل لوحة التحكم */
.app-content:has(.ai-page-root) {
  padding-bottom: 16px;
  max-width: none;
}
.ai-page-root {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100vh - var(--header-h, 56px) - 56px);
}
.ai-page-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.ai-page-top h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 0;
}
.ai-page-top p {
  margin: 4px 0 0;
  color: var(--text-3, #94a3b8);
  font-size: .9375rem;
}
.ai-page-shell {
  flex: 1;
  min-height: 520px;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.ai-page-side {
  background: var(--surface-2, #f8fafc);
  border-left: 1px solid var(--border, #e2e8f0);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ai-page-side-h {
  padding: 14px 14px 8px;
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-3, #94a3b8);
  letter-spacing: .06em;
}
.ai-page-side-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
}
.ai-hist-item {
  width: 100%;
  text-align: right;
  border: none;
  background: transparent;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8125rem;
  color: var(--text-2, #475569);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-hist-item:hover,
.ai-hist-item.active {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}
.ai-hist-empty {
  font-size: .8rem;
  color: var(--text-3, #94a3b8);
  padding: 16px 10px;
}

.ai-page-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 42%);
}
.ai-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 12px;
}
.ai-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: flex-start;
}
.ai-msg.user { flex-direction: row-reverse; }
.ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
}
.ai-msg.assistant .ai-avatar { background: #eff6ff; color: #1d4ed8; }
.ai-msg.user .ai-avatar { background: #0c1222; color: #fff; }
.ai-bubble {
  max-width: min(760px, 86%);
  padding: 12px 14px;
  border-radius: 14px;
  font-size: .9375rem;
  line-height: 1.8;
  color: var(--text, #0f172a);
}
.ai-msg.assistant .ai-bubble {
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-top-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.ai-msg.user .ai-bubble {
  background: #1d4ed8;
  color: #fff;
  border-top-left-radius: 4px;
}
.ai-bubble p { margin: 0 0 .65em; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul, .ai-bubble ol { margin: .3em 0 .7em; padding-right: 1.25em; }
.ai-bubble h3, .ai-bubble h4 { margin: .4em 0 .35em; font-size: 1rem; }
.ai-bubble code {
  font-family: var(--font-num, Inter, monospace);
  font-size: .82em;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
}
.ai-msg.user .ai-bubble code { background: rgba(255,255,255,.16); }
.ai-bubble pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: .8rem;
  direction: ltr;
  text-align: left;
}
.ai-bubble table { width: 100%; border-collapse: collapse; font-size: .82rem; margin: 8px 0; }
.ai-bubble th, .ai-bubble td { border: 1px solid #e2e8f0; padding: 6px 8px; }
.ai-bubble th { background: #f8fafc; }
.ai-tools { margin-top: 8px; font-size: .72rem; color: #64748b; display: flex; flex-wrap: wrap; gap: 4px; }
.ai-tools span {
  background: #eef2ff;
  color: #4338ca;
  border-radius: 999px;
  padding: 2px 8px;
}

.ai-welcome { max-width: 820px; }
.ai-welcome h3 { font-size: 1.25rem; margin: 0 0 8px; }
.ai-welcome p { color: var(--text-3, #94a3b8); font-size: .9rem; margin-bottom: 18px; line-height: 1.7; }
.ai-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ai-chip {
  border: 1px solid #dbeafe;
  background: #fff;
  color: #1e3a8a;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: .84rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: right;
  box-shadow: var(--shadow-xs);
}
.ai-chip:hover { background: #eff6ff; border-color: #93c5fd; }
.ai-insight {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  font-size: .84rem;
  color: #92400e;
  line-height: 1.75;
}
.ai-insight strong { display: block; margin-bottom: 6px; color: #b45309; }

.ai-typing { display: flex; gap: 5px; padding: 6px 2px; }
.ai-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #93c5fd;
  animation: aiDot 1s infinite ease-in-out;
}
.ai-typing i:nth-child(2) { animation-delay: .15s; }
.ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aiDot {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.ai-foot {
  flex-shrink: 0;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: #fff;
}
.ai-form { display: flex; gap: 10px; align-items: flex-end; }
.ai-form textarea {
  flex: 1;
  min-height: 48px;
  max-height: 140px;
  resize: none;
  border: 1.5px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: .9375rem;
  background: var(--surface-2, #f8fafc);
  color: var(--text, #0f172a);
}
.ai-form textarea:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.ai-send {
  height: 48px;
  min-width: 48px;
  padding: 0 16px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 700;
}
.ai-send:disabled { opacity: .5; cursor: not-allowed; }
.ai-send svg { width: 18px; height: 18px; }
.ai-hint { margin-top: 7px; font-size: .72rem; color: #94a3b8; }
.ai-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: .82rem;
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  .ai-page-shell { grid-template-columns: 1fr; }
  .ai-page-side { display: none; }
  .ai-chips { grid-template-columns: 1fr; }
}
