:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fc;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --accent: #4c51bf;
  --accent-light: #667eea;
  --accent-glow: rgba(76, 81, 191, 0.15);
  --border: #e2e8f0;
  --border-focus: #4c51bf;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #818cf8;
  --accent-light: #a5b4fc;
  --accent-glow: rgba(129, 140, 248, 0.15);
  --border: #334155;
  --border-focus: #818cf8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; direction: ltr; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  line-height: 1.6;
}
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; width: 100%; }
.hidden { display: none !important; }

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000 !important; /* أعلى قيمة ممكنة */
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  pointer-events: auto !important; /* ضروري جداً */
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  transform: scale(1.1);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* Header */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 10;
}
.header-content { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo-ring {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: 12px;
  display: grid; place-items: center; font-size: 1.5rem;
  box-shadow: 0 4px 12px var(--accent-glow);
}
h1 { font-size: 1.5rem; font-weight: 700; background: linear-gradient(135deg, var(--accent), var(--accent-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { font-size: 0.85rem; color: var(--text-secondary); margin-top: 2px; }

/* Workspace */
.workspace { max-width: 900px; margin: 30px auto; flex: 1; }
.chat-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 400px;
  max-height: 600px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-md);
}
.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Messages */
.message { display: flex; gap: 12px; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.message-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  font-size: 1.2rem; flex-shrink: 0; box-shadow: 0 2px 8px var(--accent-glow);
}
.user-message { flex-direction: row-reverse; }
.user-message .message-avatar { background: var(--bg-tertiary); box-shadow: none; }
.message-content {
  background: var(--bg-tertiary);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  max-width: 80%;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  line-height: 1.7;
}
.user-message .message-content { background: var(--accent); color: #fff; border-color: transparent; }

/* Input */
.input-wrapper {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}
.input-wrapper:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 4px var(--accent-glow); }
.input-group { display: flex; align-items: flex-end; gap: 12px; }
textarea {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  padding: 12px;
  resize: none;
  min-height: 50px;
  max-height: 180px;
}
textarea:focus { border-color: var(--border-focus); }
textarea::placeholder { color: var(--text-muted); }
.send-btn {
  width: 48px; height: 48px;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; display: grid; place-items: center;
  font-size: 1.2rem; background: var(--accent); color: #fff;
  transition: var(--transition); flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--accent-light); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.input-meta { display: flex; justify-content: space-between; margin-top: 10px; font-size: 0.75rem; color: var(--text-muted); }

/* Report Panel */
.report-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  margin: 30px auto;
  max-width: 900px;
  animation: slideIn 0.4s ease;
}
.panel-header {
  padding: 20px 24px;
  border-bottom: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-tertiary);
  flex-wrap: wrap;
  gap: 12px;
}
.panel-header h2 { font-size: 1.3rem; color: var(--text-primary); margin: 0; font-weight: 700; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.action-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: var(--transition);
  font-family: inherit;
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.report-content {
  padding: 32px;
  font-family: inherit;
  line-height: 1.8;
  color: var(--text-primary);
  background: var(--bg-secondary);
  direction: ltr;
  text-align: left;
}
.report-section { margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.report-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}
.section-content { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.8; padding: 12px 0; }
.steps-list { list-style: none; padding: 0; margin: 0; counter-reset: step-counter; }
.steps-list li {
  counter-increment: step-counter;
  padding: 12px 16px 12px 48px;
  margin-bottom: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  position: relative;
  border: 1px solid var(--border);
}
.steps-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  background: var(--accent); color: #fff;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 24px 20px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
  background: var(--bg-secondary);
}
.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}
.site-footer a:hover { text-decoration: underline; color: var(--accent-light); }

/* Loading */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; backdrop-filter: blur(4px);
}
.loader { text-align: center; }
.loader-ring {
  width: 60px; height: 60px;
  border: 4px solid transparent; border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: #fff; font-size: 1rem; font-weight: 500; }

/* Responsive */
@media (max-width: 768px) {
  .header-content { flex-direction: column; align-items: flex-start; gap: 12px; }
  .message-content { max-width: 90%; }
  .panel-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .panel-actions { width: 100%; justify-content: stretch; }
  .action-btn { flex: 1; text-align: center; }
  .report-content { padding: 20px; }
}
