/* لوحة iraqsoft — الدخول، المعرض، المواقع، والمحرر */

:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --accent: #f59e0b;
  --danger: #dc2626;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }

[hidden] { display: none !important; }

.container { width: min(100% - 2rem, 1200px); margin-inline: auto; }

/* الأزرار */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-accent { background: var(--accent); color: #1f2937; }
.btn-accent:hover { background: #d97706; color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .9rem; font-weight: 500; }
.btn-link { background: none; border: 0; color: var(--primary-dark); padding: .2rem .4rem; font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }

/* الحقول */
label { display: block; font-weight: 700; margin-bottom: .3rem; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="tel"], input[type="search"], textarea, select {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 5rem; resize: vertical; }
.field { margin-bottom: 1rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ltr { direction: ltr; text-align: left; }
.error-text { color: var(--danger); font-size: .9rem; margin-top: .3rem; min-height: 1.2em; }

/* شاشة الدخول */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-card .brand { text-align: center; margin-bottom: 1.5rem; }
.login-card .brand h1 { color: var(--primary-dark); }
.login-card .btn { width: 100%; justify-content: center; }

/* رأس اللوحة */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 60px;
}
.topbar .brand { font-weight: 800; font-size: 1.15rem; color: var(--primary-dark); }
.topbar .brand small { font-weight: 400; color: var(--muted); margin-inline-start: .5rem; }
.topbar-user { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .95rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: 1.5rem 0 1rem; }
.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: .6rem 1rem;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.toolbar-row input[type="search"] { max-width: 320px; }

/* معرض القوالب */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.2rem;
}
.tpl-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s, transform .15s;
}
.tpl-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.tpl-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #eef2f7;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.tpl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpl-thumb iframe {
  width: 1280px;
  height: 800px;
  border: 0;
  transform: scale(.25);
  transform-origin: top right;
  pointer-events: none;
  position: absolute;
  top: 0;
  right: 0;
}
.tpl-body { padding: 1rem 1.1rem; flex: 1; }
.tpl-body p { color: var(--muted); font-size: .92rem; }
.tpl-meta { display: flex; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.badge {
  display: inline-block;
  padding: .1rem .55rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  background: #eef2f7;
  color: var(--muted);
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-muted { background: #eef2f7; color: var(--muted); }
.tpl-actions { display: flex; gap: .5rem; padding: 0 1.1rem 1rem; }

/* جدول المواقع */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .9rem; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f9fafb; font-weight: 700; color: var(--muted); font-size: .9rem; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--muted); font-size: .85rem; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-inline-start: .25rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* النوافذ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-start; gap: .5rem; margin-top: 1.2rem; }

/* التنبيهات */
.toast-wrap {
  position: fixed;
  bottom: 1rem;
  inset-inline-start: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: #111827;
  color: #fff;
  padding: .7rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 360px;
  animation: toast-in .2s ease-out;
}
.toast-error { background: var(--danger); }
.toast-ok { background: var(--primary-dark); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.copy-row { display: flex; gap: .5rem; align-items: center; }
.copy-row input { flex: 1; direction: ltr; }

/* ---------- المحرر ---------- */
.editor-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.editor-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.editor-bar .site-name { font-weight: 800; }
.editor-bar .site-slug { color: var(--muted); font-size: .85rem; direction: ltr; display: inline-block; }
.editor-bar .spacer { flex: 1; }
.editor-status { color: var(--muted); font-size: .9rem; min-width: 8rem; }
.editor-status.dirty { color: #92400e; font-weight: 700; }
.device-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.device-switch button {
  background: #fff;
  border: 0;
  padding: .35rem .7rem;
  font: inherit;
  cursor: pointer;
  color: var(--muted);
}
.device-switch button.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.editor-stage { flex: 1; background: #e5e7eb; overflow: auto; display: flex; justify-content: center; }
.editor-stage iframe {
  border: 0;
  background: #fff;
  width: 100%;
  height: 100%;
  transition: width .2s;
}
.editor-stage.tablet iframe { width: 820px; }
.editor-stage.mobile iframe { width: 400px; }
.editor-loading { display: grid; place-items: center; color: var(--muted); height: 100%; width: 100%; }

.popover {
  position: absolute;
  top: 100%;
  inset-inline-start: 0;
  margin-top: .4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  width: 360px;
  max-width: calc(100vw - 2rem);
  z-index: 50;
}
.popover-host { position: relative; }
.popover .field:last-child { margin-bottom: 0; }

@media (max-width: 700px) {
  .field-row { grid-template-columns: 1fr; }
  .editor-bar { gap: .5rem; }
  .editor-status { min-width: 0; }
}
