:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1d2430;
  --muted: #6b7380;
  --line: #e3e6eb;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --ok: #15803d;
  --ok-bg: #e7f6ec;
  --warn: #b45309;
  --warn-bg: #fdf3e3;
  --err: #b91c1c;
  --err-bg: #fdecec;
  --lock: #7c3aed;
  --lock-bg: #f1eafe;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Cairo", Arial, sans-serif;
  font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pad { padding: 0 1rem; }
.mono { font-family: Consolas, "Courier New", monospace; }
.inline { display: inline; }

/* ===== الهيكل ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  background: #111827; color: #fff; padding: .55rem 1rem; min-height: 52px;
}
.brand { color: #fff; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }
.topnav a { color: #cbd5e1; padding: .35rem .7rem; border-radius: 6px; }
.topnav a:hover, .topnav a.active { background: #1f2937; color: #fff; text-decoration: none; }
.userbox { display: flex; align-items: center; gap: .6rem; margin-inline-start: auto; }
.userbox .muted { color: #9ca3af; }
.link-btn { background: none; border: 0; color: #fca5a5; cursor: pointer; font: inherit; padding: 0; }

.shell { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--card); border-inline-end: 1px solid var(--line);
  padding: 1rem 0; position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto;
}
.sidebar-title { font-weight: 700; padding: 0 1rem .5rem; color: var(--muted); font-size: .85rem; }
.site-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.site-list a {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .5rem 1rem; color: var(--text); border-inline-start: 3px solid transparent;
}
.site-list a:hover { background: var(--bg); text-decoration: none; }
.site-list a.active { background: #eef3ff; border-inline-start-color: var(--primary); font-weight: 600; }
.site-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { background: var(--bg); color: var(--muted); border-radius: 99px; padding: 0 .5rem; font-size: .8rem; flex-shrink: 0; }
.sidebar .btn-block { margin: 0 1rem; width: calc(100% - 2rem); }
.main { flex: 1; min-width: 0; padding: 1.25rem; }

.only-mobile { display: none; }
.icon-btn { background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: inherit; padding: .2rem .5rem; }

/* ===== عناصر عامة ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: .45rem .95rem; border-radius: 6px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { color: var(--err); border-color: #f3c3c3; }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: .25rem .6rem; font-size: .88rem; }
.btn-xs { padding: .1rem .45rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }

.alert { padding: .65rem .9rem; border-radius: 6px; margin: 0 0 1rem; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-err { background: var(--err-bg); color: var(--err); }

.badge { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 99px; margin: .1rem 0 .1rem .25rem; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--bg); color: var(--muted); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-lock { background: var(--lock-bg); color: var(--lock); }
.pulse { animation: pulse 1.2s ease-in-out 3; font-weight: 700; }
@keyframes pulse { 50% { background: #bbf7d0; } }

input, select, textarea {
  font: inherit; color: inherit; border: 1px solid #cfd5dd; border-radius: 6px;
  padding: .42rem .6rem; background: #fff; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3ff; border-color: var(--primary); }
.form { display: flex; flex-direction: column; gap: .85rem; max-width: 720px; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .92rem; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
.form textarea { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .9rem; margin: 0; }
legend { font-weight: 600; font-size: .92rem; padding: 0 .3rem; }
.radios label, .sites-box label { margin: .25rem 0; }
.row-btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.or { color: var(--muted); text-align: center; }
.warn-box { background: var(--warn-bg); padding: .6rem .8rem; border-radius: 6px; color: var(--warn); }
.summary-list { margin: 0 0 1rem; padding-inline-start: 1.2rem; }
details { margin: .75rem 0; }
summary { cursor: pointer; font-weight: 600; }
.export-text { width: 100%; direction: rtl; unicode-bidi: plaintext; white-space: pre; tab-size: 6; }

.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.per-page { display: flex; align-items: center; gap: .3rem; font-size: .9rem; }

/* ===== الإحصائيات ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; display: flex; flex-direction: column; }
.card .stat { background: var(--bg); }
.stat-num { font-size: 1.5rem; font-weight: 700; }
.stat-lbl { color: var(--muted); font-size: .85rem; }
.stat-ok .stat-num { color: var(--ok); }
.stat-warn .stat-num { color: var(--warn); }
.stat-err .stat-num { color: var(--err); }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: start; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.simple td.raw { font-family: Consolas, monospace; font-size: .85rem; white-space: pre-wrap; unicode-bidi: plaintext; }
.row-off td { opacity: .55; }
.inline-edit { display: flex; gap: .3rem; }
.inline-edit input { min-width: 140px; }
.log-table .old { color: var(--muted); text-decoration: line-through; text-decoration-color: #d1d5db; }
.log-table .new { color: var(--text); }

.vtable .c-id { width: 80px; font-family: Consolas, monospace; color: var(--muted); }
.vtable .c-by { width: 150px; }
.vtable .c-by span { display: block; }
.vtable .c-st { width: 140px; }
.vtable .c-act { width: 100px; white-space: nowrap; }
.vtable .c-act .btn { margin-inline-end: .2rem; }
.vtable tbody tr:hover { background: #fafbff; }
.title-text { cursor: text; min-height: 1.5em; word-break: break-word; unicode-bidi: plaintext; user-select: text; }
.title-text:hover { background: #f3f6fd; border-radius: 4px; }
tr.is-locked { background: var(--lock-bg); }
tr.is-locked .title-text { cursor: not-allowed; }
tr.is-editing { background: #fffbea !important; }
.edit-wrap { display: flex; flex-direction: column; gap: .3rem; }
.title-input { width: 100%; resize: none; overflow: hidden; line-height: 1.5; min-height: 2.2em; unicode-bidi: plaintext; }
.field-msg { font-size: .85rem; padding: .35rem .5rem; border-radius: 4px; }
.field-err { color: var(--err); background: var(--err-bg); }
.field-warn { color: var(--warn); background: var(--warn-bg); font-size: .85rem; padding: .35rem .5rem; border-radius: 4px; }
.msg-btns { display: flex; gap: .4rem; margin-top: .35rem; }

/* ===== ترقيم الصفحات ===== */
.pager { display: flex; gap: .3rem; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.pg {
  min-width: 2.2rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; text-align: center;
}
a.pg:hover, button.pg:hover { background: var(--bg); text-decoration: none; }
.pg.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pg.disabled { color: #c0c5cc; cursor: default; }
.pg.dots { border: 0; background: none; cursor: default; }
.pg-info { margin-inline-start: .5rem; }

/* ===== نافذة السجل ===== */
.dlg { border: 0; border-radius: 10px; padding: 0; width: min(680px, 95vw); max-height: 85vh; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.dlg-body { padding: 1rem; }
.hist-cur { background: var(--bg); padding: .6rem .8rem; border-radius: 6px; margin-bottom: 1rem; }
.hist-list { list-style: none; margin: 0; padding: 0; }
.hist-list li { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .8rem; margin-bottom: .6rem; }
.hist-meta { font-size: .85rem; margin-bottom: .3rem; }
.hist-old { color: var(--muted); text-decoration: line-through; text-decoration-color: #d1d5db; font-size: .9rem; }
.hist-new { font-weight: 600; }
.hist-act { margin-top: .4rem; }
.hist-orig { background: #fafbfc; }

/* ===== رسالة عائمة ===== */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 100;
  padding: .6rem 1.1rem; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 90vw;
}
.toast-ok { background: #14532d; color: #fff; }
.toast-err { background: #7f1d1d; color: #fff; }

/* ===== صفحات الدخول والتنصيب ===== */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; width: 100%; max-width: 400px; }
.auth-box h1 { margin-bottom: 1rem; text-align: center; }

/* ===== الموبايل ===== */
@media (max-width: 860px) {
  .only-mobile { display: inline-block; }
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .topnav { order: 3; flex-basis: 100%; display: none; }
  .nav-open .topnav { display: flex; }
  .sidebar {
    position: fixed; top: 52px; right: 0; bottom: 0; height: auto; z-index: 25;
    transform: translateX(100%); transition: transform .2s; box-shadow: -4px 0 20px rgba(0,0,0,.1);
  }
  .nav-open .sidebar { transform: none; }
  .main { padding: .75rem; }
  .grid2 { grid-template-columns: 1fr; }
  .stat-num { font-size: 1.2rem; }

  /* الجدول بيتحول لكروت */
  .vtable thead { display: none; }
  .vtable, .vtable tbody, .vtable tr, .vtable td { display: block; width: auto !important; }
  .vtable tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .6rem; padding: .4rem .2rem; position: relative; }
  .vtable td { border: 0; padding: .2rem .6rem; }
  .vtable .c-id { font-size: .8rem; text-align: right; }
  .vtable .c-title { padding-inline-end: .6rem; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .stat { padding: .5rem .6rem; }
  .vtable .c-title { font-size: 1rem; }
  .vtable .c-by span { display: inline; margin-inline-end: .4rem; }
  .vtable .c-act { position: absolute; top: .3rem; left: .3rem; }
  .pg { min-width: 2rem; padding: .25rem .45rem; }
}
