/* ================================================================
   الأدوات الذكية — AI Tools pages (news/reports + RAG + SOPs chat)
   Builds on report-form.css design tokens (--card, --gold, --g-main, …).
   ================================================================ */

.tools-intro { margin: 0 auto 8px; max-width: 1100px; }

/* ── Hub cards ─────────────────────────────────────────────────── */
.tools-grid {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  padding: 8px 0 40px;
}
.tool-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  text-decoration: none;
  color: var(--text);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}
.tool-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(13, 36, 24, .14);
  border-color: var(--gold);
}
.tool-card-icon {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  font-size: 28px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--g-main), var(--g-dark));
  color: #fff;
}
.tool-card h3 { font-size: 1.15rem; font-weight: 800; color: var(--g-dark); }
.tool-card p  { font-size: .9rem; color: var(--muted); line-height: 1.7; }
.tool-card .tool-card-go { margin-top: auto; color: var(--g-main); font-weight: 700; font-size: .9rem; }

/* ── Generic tool panels ───────────────────────────────────────── */
.tool-panel {
  max-width: 1100px;
  margin: 0 auto 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.tool-panel h3 { color: var(--g-dark); font-size: 1.05rem; margin-bottom: 12px; }

.tool-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tool-field { display: flex; flex-direction: column; gap: 4px; }
.tool-field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tool-field select, .tool-field input {
  font-family: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: .9rem;
}

.tool-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: .9rem;
  color: #fff;
  background: linear-gradient(135deg, var(--gold), #b8862f);
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}
.tool-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(200, 157, 61, .4); }
.tool-btn.secondary { background: var(--g-main); }
.tool-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── News cards ────────────────────────────────────────────────── */
.news-grid {
  max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.news-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.news-card .news-thumb { width: 100%; height: 150px; object-fit: cover; background: var(--cream2); }
.news-card .news-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.news-card .news-title { font-weight: 800; color: var(--g-dark); font-size: .98rem; line-height: 1.5; }
.news-card .news-desc { font-size: .85rem; color: var(--muted); line-height: 1.7; }
.news-card .news-meta { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: auto; }
.news-card a.news-link { color: var(--g-main); font-weight: 700; font-size: .82rem; text-decoration: none; }

/* ── Report output ─────────────────────────────────────────────── */
.report-output {
  max-width: 1100px; margin: 14px auto 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
  line-height: 2; white-space: pre-wrap;
}
.report-output:empty { display: none; }

.report-library { max-width: 1100px; margin: 0 auto; display: grid; gap: 8px; }
.report-library .lib-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: .85rem;
}

/* ── Chat (RAG / SOPs) ─────────────────────────────────────────── */
.chat-wrap {
  max-width: 900px; margin: 0 auto;
  display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px;
}
.chat-log {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 10px 4px;
}
/* Removed white-space:pre-wrap — HTML markdown handles layout now */
.chat-msg { max-width: 82%; padding: 12px 16px; border-radius: 16px; line-height: 1.9; font-size: .92rem; position: relative; }
.chat-msg.user { align-self: flex-start; background: linear-gradient(135deg, var(--g-main), var(--g-dark)); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.chat-msg.bot  { align-self: flex-end; background: var(--card); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }

/* ── Markdown prose inside bot messages ────────────────────────── */
.chat-msg.bot .bot-answer-text { line-height: 2; }
.chat-msg.bot .bot-answer-text p       { margin: 0 0 6px; }
.chat-msg.bot .bot-answer-text br      { display: block; margin-bottom: 4px; content: ""; }
.chat-msg.bot .bot-answer-text strong  { font-weight: 800; color: var(--g-dark); }
.chat-msg.bot .bot-answer-text em      { font-style: italic; color: var(--muted); }
.chat-msg.bot .bot-answer-text code    { font-family: monospace; background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: .85em; }
.chat-msg.bot .bot-answer-text h3.md-heading,
.chat-msg.bot .bot-answer-text h4.md-heading,
.chat-msg.bot .bot-answer-text h5.md-heading,
.chat-msg.bot .bot-answer-text h6.md-heading {
  font-size: 1rem; font-weight: 800; color: var(--g-dark);
  margin: 10px 0 4px; border-right: 3px solid var(--gold); padding-right: 8px;
}
.chat-msg.bot .bot-answer-text ul,
.chat-msg.bot .bot-answer-text ol {
  margin: 4px 0 8px; padding-right: 20px; padding-left: 0;
}
.chat-msg.bot .bot-answer-text ul { list-style-type: disc; }
.chat-msg.bot .bot-answer-text ol { list-style-type: decimal; }
.chat-msg.bot .bot-answer-text li  { margin-bottom: 3px; }
.chat-msg.bot .bot-answer-text hr  {
  border: none; border-top: 1px dashed var(--border); margin: 10px 0;
}

/* ── Sources ───────────────────────────────────────────────────── */
.chat-sources { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; font-size: .78rem; color: var(--muted); }
.chat-sources details summary { cursor: pointer; font-weight: 700; color: var(--g-main); }
.chat-sources ul { margin: 6px 18px 0; }

/* ── Input row ─────────────────────────────────────────────────── */
.chat-input-row { display: flex; gap: 8px; padding: 12px 0 4px; align-items: flex-end; }
.chat-input {
  flex: 1; resize: none; font-family: inherit; font-size: .95rem;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text);
  max-height: 120px;
}
.chat-send { align-self: stretch; }

/* ── Mic button ─────────────────────────────────────────────────── */
.chat-mic-btn {
  flex-shrink: 0;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--g-main), var(--g-dark));
  color: #fff;
  display: grid; place-items: center;
  transition: transform .2s, box-shadow .2s, background .2s;
  box-shadow: 0 3px 10px rgba(47,111,79,.3);
}
.chat-mic-btn svg { width: 20px; height: 20px; stroke: #fff; fill: none; }
.chat-mic-btn:hover { transform: scale(1.08); box-shadow: 0 6px 18px rgba(47,111,79,.4); }
.chat-mic-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* Recording state — pulse red */
.chat-mic-btn.recording {
  background: linear-gradient(135deg, #d94f4f, #a32828);
  animation: mic-pulse 1s ease-in-out infinite;
}
.chat-mic-btn.mic-error { background: linear-gradient(135deg, #e07b2a, #b35c1a); }

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, .5); }
  50%       { box-shadow: 0 0 0 10px rgba(211, 47, 47, 0); }
}

/* ── Speak (TTS) button on bot messages ─────────────────────────── */
.chat-speak-btn {
  position: absolute;
  bottom: 8px;
  left: 10px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted);
  transition: color .2s, background .2s, transform .2s;
  padding: 0;
}
.chat-speak-btn svg { width: 14px; height: 14px; }
.chat-speak-btn:hover { color: var(--g-main); background: rgba(47,111,79,.08); transform: scale(1.1); }
.chat-speak-btn.speaking {
  color: var(--g-main);
  background: rgba(47,111,79,.12);
  border-color: var(--g-main);
  animation: speak-wave .8s ease-in-out infinite alternate;
}
@keyframes speak-wave {
  from { transform: scale(1);    opacity: 1; }
  to   { transform: scale(1.15); opacity: .8; }
}

/* ── States ────────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--muted); padding: 40px 16px; max-width: 1100px; margin: 0 auto; }
.error-banner {
  max-width: 1100px; margin: 0 auto 14px;
  background: #fdecec; border: 1px solid #f3c0c0; color: #8b2424;
  border-radius: 10px; padding: 12px 16px; font-size: .88rem; font-weight: 600;
}
.error-banner:empty { display: none; }

.spinner {
  display: inline-block; width: 16px; height: 16px; vertical-align: middle;
  border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff;
  border-radius: 50%; animation: tool-spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(47, 111, 79, .3); border-top-color: var(--g-main); }
@keyframes tool-spin { to { transform: rotate(360deg); } }
.loading-note { text-align: center; color: var(--muted); font-size: .85rem; margin: 14px auto; }
