/* app.css — التنسيق المشترك لكل شاشات البوابة */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #e6f4f2;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn: #a16207;
  --warn-soft: #fef6e0;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.35; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, .mono { font-family: Consolas, "Courier New", monospace; direction: ltr; unicode-bidi: embed; }

/* ---------- الشريط العلوي ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-logo { width: 42px; height: 42px; border-radius: 50%; display: block; flex: none; }
.login-logo { width: 150px; height: 150px; border-radius: 50%; display: block; margin: 0 auto 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: .95rem; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: .92rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.usermenu strong { color: var(--text); }

/* ---------- التخطيط ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 22px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
input.ltr { direction: ltr; text-align: left; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }

/* ---------- الأزرار ---------- */
.btn { font: inherit; font-size: .92rem; border: 1px solid transparent; border-radius: 8px; padding: 8px 16px; cursor: pointer; background: var(--primary); color: #fff; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: #cbd5e1; }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #991b1b; }
.btn.ghost { background: transparent; color: var(--primary); padding: 4px 8px; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.ghost.danger { color: var(--danger); background: transparent; }
.btn.ghost.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: middle; }
th { background: var(--surface-2); color: var(--muted); font-weight: 600; position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfd; }
td.num { font-variant-numeric: tabular-nums; }
.data-table td { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: left; }
.data-table th { direction: ltr; text-align: left; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- الشارات والتنبيهات ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dc9c; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c2c2; }
.badge.primary { background: var(--primary-soft); color: var(--primary-dark); border-color: #b9e0db; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.alert { border-radius: 8px; padding: 10px 14px; margin: 10px 0; border: 1px solid var(--border); background: var(--surface-2); }
.alert.ok { background: var(--ok-soft); border-color: #bfe5cb; color: #14532d; }
.alert.warn { background: var(--warn-soft); border-color: #f1dc9c; color: #713f12; }
.alert.danger { background: var(--danger-soft); border-color: #f5c2c2; color: #7f1d1d; }

/* ---------- البلاطات (الصفحة الرئيسية) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); color: var(--text); display: flex; gap: 12px; align-items: flex-start; transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.tile-icon { font-size: 1.5rem; width: 44px; height: 44px; border-radius: 10px; background: var(--primary-soft); display: grid; place-items: center; flex: none; }
.tile h3 { margin: 0 0 2px; }
.tile p { margin: 0; color: var(--muted); font-size: .86rem; }
.group-title { font-size: .9rem; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }

/* ---------- النوافذ المنبثقة ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.sm { max-width: 440px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; }
.x-btn { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- شرح المربعات (Portal.help) ---------- */
.kpi[data-help], .grp[data-help] { position: relative; }
.kpi[data-help]::before, .grp[data-help]::before, h2[data-help]::after, th[data-help]::after {
  content: 'ⓘ'; color: #94a3b8; font-size: .8rem; font-weight: 400;
}
.kpi[data-help]::before, .grp[data-help]::before { position: absolute; top: 6px; left: 9px; }
h2[data-help]::after, th[data-help]::after { margin-right: 4px; }
[data-help]:focus-visible { outline: 2px solid rgba(15, 118, 110, .35); outline-offset: 2px; }
h2[data-help], th[data-help] { cursor: help; }
.help-tip { position: fixed; z-index: 200; max-width: 360px; background: #1e293b; color: #f1f5f9; border-radius: 10px; padding: 10px 13px; font-size: .84rem; line-height: 1.75; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); pointer-events: none; display: none; text-align: right; font-weight: 400; }
.help-tip b { display: block; color: #5eead4; font-size: .9rem; margin-bottom: 2px; }
.help-tip .t { display: block; }
.help-tip .f { display: block; white-space: pre-line; margin-top: 7px; background: rgba(255, 255, 255, .08); border-radius: 6px; padding: 5px 9px; font-variant-numeric: tabular-nums; }
.help-tip .src { display: block; margin-top: 7px; color: #94a3b8; font-size: .76rem; }

/* ---------- الإشعارات ---------- */
.toasts { position: fixed; bottom: 18px; left: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1e293b; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: .9rem; }
.toast.ok { background: var(--ok); }
.toast.danger { background: var(--danger); }

/* ---------- الصلاحيات ---------- */
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: right; }
.perm-table tr.group-row td { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: .82rem; }

/* ---------- تسجيل الدخول ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { justify-content: center; font-size: 1.3rem; margin-bottom: 6px; }

/* ---------- شاشة واتساب ---------- */
.qr-box { display: grid; place-items: center; background: var(--surface-2); border: 1px dashed #cbd5e1; border-radius: 10px; min-height: 300px; padding: 12px; }
.qr-box img { width: 280px; height: 280px; image-rendering: pixelated; }
.steps { margin: 0; padding-inline-start: 20px; }
.steps li { margin-bottom: 4px; }

/* ---------- شاشة ERP ---------- */
.erp-browser { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.table-list { max-height: 560px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-list button { display: flex; width: 100%; justify-content: space-between; gap: 8px; background: none; border: 0; border-bottom: 1px solid var(--border); padding: 7px 10px; font: inherit; font-size: .86rem; cursor: pointer; text-align: left; direction: ltr; color: var(--text); }
.table-list button:hover { background: var(--surface-2); }
.table-list button.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.table-list .cnt { color: var(--muted); font-size: .78rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; cursor: pointer; color: var(--muted); }
.tabs button.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }
.scroll-box { max-height: 520px; overflow: auto; }

@media (max-width: 800px) {
  .erp-browser { grid-template-columns: 1fr; }
  .table-list { max-height: 260px; }
  .topbar-inner { padding: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; }
}
