/* ============================================================================
   PromptForge Studio - Main Stylesheet
   Supports: Dark/Light Themes, English (LTR) & Arabic (RTL), Responsive Grid
   ============================================================================ */

:root {
  /* Dark Theme (Default) */
  --bg-body: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #161f33;
  --bg-input: #0f1626;
  --bg-hover: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.14);
  --success: #10b981;
  --danger: #ef4444;
  --border-color: #243049;
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg-body: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --bg-hover: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --success: #059669;
  --danger: #dc2626;
  --border-color: #cbd5e1;
  --shadow-card: 0 8px 20px -4px rgba(15, 23, 42, 0.08);
}

/* Reset & Base Typography */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition), color var(--transition);
}

[dir="rtl"] body {
  font-family: 'Cairo', 'Inter', sans-serif;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: 1.25rem;
}

/* Top Navigation Bar */
.navbar {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  gap: 1rem;
  flex-wrap: wrap;
  padding-block: 0.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 1.25rem;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
}

.brand-logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.brand .accent {
  color: var(--accent);
  font-weight: 700;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 0.48rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.btn-icon:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background-color: var(--accent);
  color: #ffffff;
  padding: 0.75rem 1.35rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.72rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
  border-color: var(--accent);
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
}

.btn-danger:hover {
  background-color: var(--danger);
  color: #ffffff;
}

/* Hero Section */
.hero {
  text-align: center;
  padding-block: 2.25rem 1.25rem;
}

.badge {
  display: inline-block;
  background-color: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
}

.hero h1 {
  font-size: clamp(1.65rem, 3.2vw, 2.45rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.hero-subtitle {
  color: var(--text-muted);
  font-size: 1.02rem;
  max-width: 650px;
  margin-inline: auto;
}

/* Google AdSense Containers */
.ad-wrapper {
  margin-block: 1.15rem;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

.ad-wrapper.hidden {
  display: none;
}

.ad-placeholder {
  width: 100%;
  min-height: 90px;
  background-color: var(--bg-surface);
  border: 1.5px dashed var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 0.75rem;
  text-align: center;
}

.ad-in-result .ad-placeholder {
  min-height: 75px;
}

/* Main Workspace Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
  align-items: start;
  margin-block: 0.75rem 1.5rem;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

/* Mode Tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background-color: var(--bg-input);
  padding: 0.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 1.35rem;
}

.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 0.5rem;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

/* Forms & Inputs */
.mode-form {
  display: none;
}

.mode-form.active {
  display: block;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  margin-bottom: 1.05rem;
}

.form-group label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

input[type="text"],
textarea,
select {
  width: 100%;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
}

.builder-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

/* Output Panel */
.output-panel {
  position: sticky;
  top: 86px;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.output-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.metrics {
  display: flex;
  gap: 0.45rem;
}

.metric-pill {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

#finalPromptOutput {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  line-height: 1.65;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  min-height: 245px;
}

[dir="rtl"] #finalPromptOutput {
  font-family: 'Cairo', 'JetBrains Mono', monospace;
}

.output-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* AI Platform Quick Launchers */
.ai-launchers {
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.launchers-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}

.launcher-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  text-decoration: none;
  background-color: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--transition);
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background-color: var(--accent-soft);
}

/* History Modal */
.modal {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.4rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.05rem;
}

.history-list {
  padding: 1.25rem 1.4rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  padding-block: 2rem;
  font-size: 0.92rem;
}

.history-item {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
}

.history-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.history-tag {
  background-color: var(--accent-soft);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.history-item-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 95px;
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.history-item-actions {
  display: flex;
  gap: 0.5rem;
}

.history-item-actions button {
  font-size: 0.78rem;
  padding: 0.32rem 0.65rem;
  border-radius: 6px;
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.history-item-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 1.5rem;
  inset-inline-end: 1.5rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(15px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Site Footer */
.site-footer {
  margin-top: auto;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding-block: 1.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-nav {
  display: flex;
  gap: 1.25rem;
}

.footer-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-nav a:hover {
  color: var(--accent);
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .output-panel {
    position: static;
  }
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 1.15rem;
  }
  .tabs {
    grid-template-columns: 1fr;
  }
}
