/* ============================================================
   UC Tech Mail Studio — style.css
   واجهة التطبيق: نظام متغيرات + وضع داكن + دعم RTL/LTR
   (خصائص منطقية Logical Properties تتكيف تلقائيًا مع الاتجاه)
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* الهوية */
  --brand: #4B1E5A;
  --brand-dark: #2E0F3A;
  --brand-mid: #7B3F8E;
  --brand-soft: #9d6bb8;
  --gold: #D4A94E;

  /* الأسطح والنصوص (وضع نهاري) */
  --bg: #f2edf6;
  --surface: #ffffff;
  --surface-2: #faf7fc;
  --border: #e4d8ee;
  --border-strong: #d3bfe3;
  --text: #2b2430;
  --text-muted: #7a6b85;
  --text-faint: #a797b3;

  /* تفاعل */
  --ring: rgba(75, 30, 90, 0.16);
  --shadow-sm: 0 1px 3px rgba(46, 15, 58, 0.07);
  --shadow-md: 0 6px 22px rgba(46, 15, 58, 0.09);
  --shadow-lg: 0 14px 40px rgba(46, 15, 58, 0.16);

  --radius: 14px;
  --radius-sm: 10px;

  --font-ar: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  --font-en: 'Inter', 'Segoe UI', Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg: #170e1e;
  --surface: #221430;
  --surface-2: #2b1a3d;
  --border: #3d2752;
  --border-strong: #563672;
  --text: #f1e8f7;
  --text-muted: #b49cc6;
  --text-faint: #8a759c;
  --ring: rgba(157, 107, 184, 0.28);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.55);
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-ar);
  background:
    radial-gradient(900px 400px at 85% -10%, rgba(123, 63, 142, 0.10), transparent 60%),
    radial-gradient(700px 380px at 10% -10%, rgba(212, 169, 78, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

html[lang="en"] body { font-family: var(--font-en); }

/* ============ الترويسة ============ */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 36px);
  background: linear-gradient(120deg, var(--brand-dark) 0%, var(--brand) 58%, #6a2c80 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-logo {
  width: 54px; height: 54px;
  background: linear-gradient(140deg, #3c1550, #2E0F3A);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 4px 12px rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.brand-logo img { width: 40px; height: auto; display: block; }

.brand-text h1 { font-size: 17px; font-weight: 800; letter-spacing: 0.2px; line-height: 1.3; }
.brand-text span {
  font-size: 11.5px; opacity: 0.82; letter-spacing: 0.4px;
  display: inline-flex; align-items: center; gap: 7px; margin-top: 2px;
}
.brand-text span::before {
  content: ""; width: 22px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
}

.header-actions { display: flex; align-items: center; gap: 10px; }

.lang-switch {
  display: flex; gap: 4px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 4px; border-radius: 12px;
  backdrop-filter: blur(6px);
}
.lang-switch button {
  border: none; background: transparent; color: #fff;
  padding: 7px 18px; border-radius: 9px; cursor: pointer;
  font-family: inherit; font-weight: 600; font-size: 13.5px;
  transition: all 0.2s ease;
}
.lang-switch button:hover { background: rgba(255, 255, 255, 0.12); }
.lang-switch button.active {
  background: #fff; color: var(--brand);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px; color: #fff; cursor: pointer;
  transition: all 0.2s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.22); transform: translateY(-1px); }

html[data-theme="light"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: block; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: block; }

/* ============ التخطيط ============ */
.app-container {
  display: grid;
  grid-template-columns: minmax(430px, 5fr) 7fr;
  gap: 24px;
  padding: 26px clamp(16px, 3vw, 36px) 18px;
  width: min(1720px, 100%);
  margin: 0 auto;
  flex: 1;
  align-items: start;
}

@media (max-width: 1100px) {
  .app-container { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.panel-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 16.5px; font-weight: 800; color: var(--brand);
}
html[data-theme="dark"] .panel-title { color: #d9b8ea; }
.panel-title svg { color: var(--brand-mid); flex-shrink: 0; }

.autosave {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 999px;
  transition: all 0.25s ease;
}
.autosave::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #4caf7d;
}
.autosave.flash { color: #1d7a4f; border-color: #bfe3cf; background: #edf9f2; }
html[data-theme="dark"] .autosave.flash { color: #7fd8a8; border-color: #2c5e42; background: #1d3a2b; }

/* ============ القوالب الجاهزة ============ */
.presets {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 16px 24px 4px;
}
.presets-label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.preset-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.preset-chip {
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--brand-mid);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
  transition: all 0.18s ease;
}
.preset-chip:hover {
  background: var(--brand); border-color: var(--brand); color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(75, 30, 90, 0.28);
}

/* ============ النموذج ============ */
#email-form { padding: 14px 24px 24px; }

.field-group { padding: 14px 0 4px; }
.field-group + .field-group { border-top: 1px dashed var(--border); }

.field-group-title {
  font-size: 12px; font-weight: 800; letter-spacing: 0.6px;
  color: var(--text-faint); text-transform: uppercase;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.field-group-title::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}

/* مجموعات قابلة للطي */
details.collapsible summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px; font-weight: 800; color: var(--brand);
  padding: 10px 0 6px;
  user-select: none;
}
details.collapsible summary::-webkit-details-marker { display: none; }
details.collapsible summary .chev { transition: transform 0.25s ease; color: var(--text-faint); }
details.collapsible[open] summary .chev { transform: rotate(180deg); }
details.collapsible[open] summary { margin-bottom: 8px; }
.collapsible-body { padding-bottom: 8px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 14px; }

.label-row { display: flex; justify-content: space-between; align-items: baseline; }

.form-group label {
  display: block;
  font-weight: 700; font-size: 12.5px;
  margin-bottom: 6px;
  color: var(--text);
}

.counter { font-size: 10.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
  background: var(--surface-2);
}
.form-group textarea { resize: vertical; min-height: 74px; line-height: 1.7; }
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text-faint); }
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand-mid);
  box-shadow: 0 0 0 4px var(--ring);
  background: var(--surface);
}

/* ============ الأزرار ============ */
.action-buttons { display: flex; gap: 10px; margin-top: 20px; }
.action-buttons.secondary { margin-top: 10px; }
.action-buttons .btn { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px;
  border: none;
  border-radius: 12px;
  font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.btn svg { flex-shrink: 0; }
.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-mid) 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(75, 30, 90, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(75, 30, 90, 0.45); filter: brightness(1.06); }

.btn-outline {
  background: var(--surface);
  color: var(--brand);
  border: 1.5px solid var(--border-strong);
}
.btn-outline:hover { border-color: var(--brand-mid); background: var(--surface-2); transform: translateY(-1px); }
html[data-theme="dark"] .btn-outline { color: #d9b8ea; }

.btn-ghost { background: transparent; color: var(--text-muted); font-weight: 600; font-size: 13px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.danger:hover { background: #fdf0f0; color: #c0392b; }
html[data-theme="dark"] .btn-ghost.danger:hover { background: #3d2028; color: #ff8a80; }

/* ============ أدوات المعاينة ============ */
.preview-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tool-group {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 3px;
}

.tool-btn {
  width: 30px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 7px;
  color: var(--text-muted); cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
}
.tool-btn:hover { background: var(--surface-2); color: var(--brand); }
.tool-btn.active { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(75, 30, 90, 0.3); }
.tool-btn.zoom-label { width: auto; padding: 0 8px; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============ مسرح المعاينة ============ */
.preview-stage {
  background:
    radial-gradient(circle at 1px 1px, var(--border-strong) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  padding: 26px 18px;
  overflow: auto;
  min-height: 420px;
  max-height: calc(100vh - 260px);
  display: flex;
  justify-content: center;
}
html[data-theme="dark"] .preview-stage {
  background:
    radial-gradient(circle at 1px 1px, #3d2752 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}

.preview-wrap {
  transform-origin: top center;
  transition: width 0.3s ease;
  flex-shrink: 0;
}
.preview-wrap.device-desktop { width: 100%; max-width: 720px; }
.preview-wrap.device-mobile { width: 375px; }

.preview-wrap iframe {
  width: 100%;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-lg);
  display: block;
}
.preview-wrap.device-mobile iframe {
  border-radius: 22px;
  border: 8px solid var(--brand-dark);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.3);
}

.preview-meta {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-faint);
  background: var(--surface-2);
}

/* ============ تذييل التطبيق ============ */
.app-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px clamp(16px, 3vw, 36px);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  background: var(--surface);
}
.app-footer b { color: var(--brand-mid); }
.kbd-hints kbd {
  font-family: var(--font-en);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 10.5px;
  color: var(--text-muted);
}

/* ============ الإشعارات Toast ============ */
#toast-root {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--brand-dark);
  color: #fff;
  font-size: 13.5px; font-weight: 600;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: min(480px, 88vw);
}
.toast.out { animation: toast-out 0.3s ease forwards; }
.toast .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.toast.success .dot { background: #4caf7d; box-shadow: 0 0 0 4px rgba(76, 175, 125, 0.25); }
.toast.error .dot { background: #ff6b6b; box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.25); }
.toast.info .dot { background: var(--gold); box-shadow: 0 0 0 4px rgba(212, 169, 78, 0.25); }

@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(0.97); } }

/* ============ إمكانية الوصول ============ */
:focus-visible {
  outline: 2px solid var(--brand-mid);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============ شريط التمرير ============ */
.preview-stage::-webkit-scrollbar { width: 10px; height: 10px; }
.preview-stage::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
.preview-stage::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
.preview-stage::-webkit-scrollbar-track { background: transparent; }

/* ============ شاشات صغيرة ============ */
@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: stretch; }
  .header-actions { justify-content: center; }
  .brand { justify-content: center; }
  .panel-head { padding: 14px 16px; }
  #email-form { padding: 10px 16px 18px; }
  .presets { padding: 14px 16px 2px; }
  .action-buttons { flex-direction: column; }
  .preview-stage { padding: 14px 8px; }
  .preview-wrap.device-mobile { width: 100%; max-width: 375px; }
}
