/* استوديو BME: نفس هوية الموقع (الخط والكحلي والأصفر) بثيم داكن مناسب للصور */
@font-face { font-family: 'IBM Plex Sans Arabic'; src: url('/fonts/plex-arabic-400.woff') format('woff'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans Arabic'; src: url('/fonts/plex-arabic-700.woff') format('woff'); font-weight: 600 700; font-display: swap; }

:root {
  --bg: #0c1524;
  --bg-2: #101c30;
  --panel: #16243b;
  --panel-2: #1c2d48;
  --line: #2a3d5c;
  --ink: #eef3f8;
  --muted: #9aabc2;
  --accent: #f4c430;
  --accent-ink: #2b2100;
  --ok: #34c38f;
  --warn: #f4a030;
  --bad: #ef5b5b;
  --r-s: 10px;
  --r-l: 18px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, .55);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(244, 196, 48, .10), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(64, 120, 220, .14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.4em; margin: 6px 0 0; font-size: 14px; }

/* ---------- العلامة ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; letter-spacing: .2px; }
.brand b { color: var(--accent); }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #ffdf7a); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 6px 18px -6px rgba(244, 196, 48, .6);
}
.brand-lg { font-size: 24px; justify-content: center; }
.brand-lg .brand-mark { width: 46px; height: 46px; font-size: 22px; border-radius: 14px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none; cursor: pointer; transition: transform .08s, background .2s, opacity .2s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 24px -12px rgba(244, 196, 48, .7); }
.btn-primary:hover:not(:disabled) { background: #ffd34d; }
.btn-ghost { background: var(--panel-2); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #3d5680; }
.btn-danger { background: transparent; border-color: rgba(239, 91, 91, .5); color: #ff9a9a; }
.btn-danger:hover { background: rgba(239, 91, 91, .12); }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 18px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%); padding: 32px 26px; border-radius: 24px; text-align: center;
  background: rgba(22, 36, 59, .85); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.login-card .field { text-align: right; margin: 22px 0 16px; }

/* ---------- الإطار ---------- */
.app { max-width: 1040px; margin: 0 auto; padding: 0 16px 40px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 0; background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-end { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pill[data-state="ready"] .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 195, 143, .18); }
.pill[data-state="busy"] .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.pill[data-state="starting"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.pill[data-state="unreachable"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- بطاقة المحرك ---------- */
.engine-card {
  display: grid; grid-template-columns: 120px 1fr; gap: 22px; align-items: center;
  margin: 6px 0 22px; padding: 22px; border-radius: var(--r-l);
  background: linear-gradient(135deg, rgba(244, 196, 48, .10), rgba(22, 36, 59, .9) 45%);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.engine-card h2 { margin: 0 0 4px; font-size: 21px; }
.engine-card p { margin: 0 0 12px; }
.engine-visual { display: grid; place-items: center; }
.orb {
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe9a0, var(--accent) 40%, #a87d00 75%);
  box-shadow: 0 0 40px rgba(244, 196, 48, .35); opacity: .55;
}
.engine-card[data-state="starting"] .orb { animation: breathe 2.4s ease-in-out infinite; opacity: 1; }
@keyframes breathe { 50% { transform: scale(.88); box-shadow: 0 0 70px rgba(244, 196, 48, .6); } }
.engine-steps { margin: 4px 0 14px; padding-inline-start: 20px; color: var(--muted); font-size: 14px; }
.engine-steps b { color: var(--ink); }
.engine-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- التبويبات ---------- */
.tabs {
  display: flex; gap: 6px; padding: 6px; margin-bottom: 18px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line); position: sticky; top: 68px; z-index: 15;
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.tab-ico { color: var(--accent); }
.count { min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--bg-2); font-size: 12px; }

/* ---------- لوحة الإنشاء ---------- */
.composer {
  padding: 20px; border-radius: var(--r-l); background: rgba(22, 36, 59, .88);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.field { display: block; margin-bottom: 16px; }
.field > span:first-child, .field > .label-row { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-weight: 600; }
input, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--ink); outline: none; transition: border-color .2s;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
textarea, #seed { direction: auto; unicode-bidi: plaintext; }
input:focus, textarea:focus { border-color: var(--accent); }
::placeholder { color: #6f819a; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); cursor: pointer; font-size: 14px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--ink); background: rgba(244, 196, 48, .08); }
.ratio { display: block; border: 2px solid currentColor; border-radius: 4px; }
.r11 { width: 22px; height: 22px; } .r916 { width: 15px; height: 26px; } .r45 { width: 19px; height: 24px; } .r169 { width: 28px; height: 16px; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.segmented button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }
.segmented.small button { min-height: 32px; padding: 0 12px; font-size: 14px; }

.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 16px; }
.suggest button {
  padding: 5px 11px; border-radius: 999px; border: 1px dashed var(--line); background: transparent;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.suggest button:hover { color: var(--ink); border-color: var(--accent); }

.source { display: flex; gap: 14px; align-items: center; }
.source-preview {
  width: 110px; height: 110px; flex: none; border-radius: 14px; overflow: hidden;
  background: var(--bg-2); border: 1px dashed var(--line); display: grid; place-items: center;
}
.source-preview img { width: 100%; height: 100%; object-fit: cover; }
.source-preview.empty span { color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }
.source-actions { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.file-btn { cursor: pointer; }

/* ---------- المهام الجارية ---------- */
.jobs { display: grid; gap: 10px; margin: 16px 0; }
.job {
  padding: 14px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
}
.job-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 8px; }
.job-head b { font-weight: 600; }
.job-prompt { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: auto; unicode-bidi: plaintext; }
.bar { height: 8px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #ffdf7a, var(--accent)); transition: width .6s; }
.bar.indeterminate span { width: 35%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(130%); } to { transform: translateX(-300%); } }
.job.error { border-color: rgba(239, 91, 91, .6); }
.job.error .job-head { color: #ff9a9a; }

/* ---------- النتائج ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.card {
  position: relative; border-radius: 16px; overflow: hidden; background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); animation: rise .35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.card-media { display: block; width: 100%; background: #000; cursor: zoom-in; }
.card-media img, .card-media video { display: block; width: 100%; height: auto; max-height: 420px; object-fit: contain; background: #05090f; }
.card-badge {
  position: absolute; top: 8px; inset-inline-start: 8px; padding: 2px 9px; border-radius: 999px;
  background: rgba(12, 21, 36, .8); font-size: 12px; backdrop-filter: blur(4px);
}
.card-body { padding: 10px 12px 12px; }
.card-prompt { margin: 0 0 10px; color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; direction: auto; unicode-bidi: plaintext; }
.card-actions { display: flex; gap: 6px; }
.card-actions .btn { flex: 1; min-height: 38px; padding: 6px 8px; font-size: 14px; }
.card-actions .icon-btn { width: 38px; height: 38px; flex: none; font-size: 15px; }
.grid.small .card { cursor: pointer; }
.grid.small .card img { aspect-ratio: 1; object-fit: cover; max-height: none; }

.gallery-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.gallery-head .hint { margin: 0; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- النوافذ ---------- */
dialog { border: 0; padding: 0; color: var(--ink); background: transparent; }
dialog::backdrop { background: rgba(3, 7, 14, .78); backdrop-filter: blur(4px); }
.picker { width: min(640px, calc(100% - 24px)); max-height: 80vh; padding: 18px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); }
.picker-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.picker-head h3 { margin: 0; }
.viewer { max-width: 96vw; max-height: 94vh; }
.viewer img, .viewer video { display: block; max-width: 96vw; max-height: 90vh; border-radius: 12px; }
.viewer-close { position: fixed; top: 14px; inset-inline-end: 14px; z-index: 2; }

/* ---------- التنبيهات ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(420px, calc(100% - 32px)); }
.toast {
  padding: 12px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; animation: rise .25s ease-out;
}
.toast.ok { border-color: rgba(52, 195, 143, .6); }
.toast.bad { border-color: rgba(239, 91, 91, .6); }

.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; }

@media (max-width: 640px) {
  .app { padding: 0 12px 32px; }
  .brand span:last-child { font-size: 16px; }
  .engine-card { grid-template-columns: 1fr; text-align: center; padding: 18px; }
  .engine-steps { text-align: right; }
  .engine-actions { justify-content: center; }
  .orb { width: 64px; height: 64px; }
  .tabs { top: 64px; }
  .tab { font-size: 14px; }
  .chips { grid-template-columns: repeat(2, 1fr); }
  .chip { flex-direction: row; justify-content: center; }
  .row-2 { grid-template-columns: 1fr; gap: 0; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-actions .btn span { display: none; }
  #enginePillText { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 380px) { .grid { grid-template-columns: 1fr; } .card-actions .btn span { display: inline; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
