:root {
  --red: #C62828;
  --red-dark: #9F1D1D;
  --red-soft: #FDECEC;
  --ink: #1F2933;
  --muted: #6B7785;
  --line: #E4E7EB;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --green: #2E7D32;
  --green-soft: #E8F5E9;
  --amber: #B26A00;
  --amber-soft: #FFF4E0;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Cairo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button, input, select, textarea { font-family: inherit; font-size: 15px; }

.loading { padding: 80px 20px; text-align: center; color: var(--muted); }

/* ---------- صفحات الدخول ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #1F2933 0%, #2D3A46 55%, var(--red-dark) 140%);
}
.auth-card {
  background: var(--card);
  width: 100%; max-width: 420px;
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.brand-name { font-weight: 800; font-size: 22px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- نماذج ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--red); }
.field textarea { min-height: 70px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  border: 0; border-radius: 8px; padding: 10px 18px; cursor: pointer;
  font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #F3C4C4; }
.btn-danger:hover { background: var(--red-soft); }
.btn-block { width: 100%; justify-content: center; padding: 12px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.msg { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.msg.error { background: var(--red-soft); color: var(--red-dark); }
.msg.ok { background: var(--green-soft); color: var(--green); }
.msg.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- هيكل التطبيق ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #1F2933; color: #CBD2D9;
  padding: 20px 14px; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.sidebar .brand-name { color: #fff; font-size: 19px; }
.sidebar .company { font-size: 13px; color: #9AA5B1; margin: 4px 0 24px; padding-right: 50px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: #CBD2D9; text-decoration: none;
  margin-bottom: 4px; font-weight: 600;
}
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--red); color: #fff; }
.nav a.soon { opacity: .45; pointer-events: none; }
.nav .soon-tag { font-size: 11px; margin-right: auto; background: rgba(255,255,255,.12); padding: 0 8px; border-radius: 10px; }
.sidebar-foot { margin-top: auto; font-size: 13px; border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { margin-top: 8px; background: transparent; border: 1px solid rgba(255,255,255,.2); color: #CBD2D9; border-radius: 8px; padding: 6px 12px; cursor: pointer; }

.main { flex: 1; padding: 28px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { color: var(--muted); font-size: 14px; }

/* موبايل */
.topbar { display: none; }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0 0 0 auto; z-index: 50; width: 260px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #1F2933; color: #fff; padding: 12px 16px;
  }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 18px 14px; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
}

/* ---------- بطاقات وإحصائيات ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.alert { border-color: #F3C4C4; background: var(--red-soft); }
.stat.alert .num { color: var(--red); }

/* ---------- جداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #FAFBFC; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #FAFBFC; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.badge { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.gray { background: var(--bg); color: var(--muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }

.back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-block; margin-bottom: 8px; }
.back:hover { color: var(--red); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
.kv div span { display: block; color: var(--muted); font-size: 12px; }
.kv div b { font-weight: 600; }

/* ---------- نافذة منبثقة ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,32,.5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 24px; }
.modal h3 { margin: 0 0 18px; font-size: 19px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 10px;
  transition: transform .25s; z-index: 200; font-weight: 600;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

/* ---------- قائمة الفحص (تطبيق الفني) ---------- */
.check-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-item { font-weight: 600; margin-bottom: 8px; }
.check-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.rb {
  flex: 1; min-width: 90px; padding: 10px 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; font-weight: 700; color: var(--muted);
}
.rb:disabled { cursor: default; }
.rb-pass.on { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.rb-fail.on { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.rb-na.on { background: var(--bg); border-color: #9AA5B1; color: var(--ink); }
.check-extra { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.check-note { flex: 1; min-width: 220px; padding: 9px 12px; border: 1px solid #F3C4C4; border-radius: 8px; background: #FFFBFB; }
.check-note-ro { color: var(--red-dark); font-size: 14px; flex-basis: 100%; }
.check-photo { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-btn { cursor: pointer; }
.sig-pad { width: 100%; height: 180px; border: 2px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; }
@media (max-width: 560px) { .rb { min-width: 0; font-size: 13px; padding: 12px 4px; } }

/* ---------- محرر العقد ---------- */
.party-box { background: #FAFBFC; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 14px; line-height: 1.9; }
.party-box:empty { display: none; }
.warn-link { color: var(--amber); font-weight: 700; }
.hijri { color: var(--muted); font-weight: 400; font-size: 12px; }
.cl-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.cl-num { min-width: 86px; font-weight: 700; color: var(--red); padding-top: 9px; font-size: 14px; }
.cl-row textarea, .cl-pre { flex: 1; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; line-height: 1.8; font-size: 14px; overflow: hidden; }
.cl-row textarea:focus, .cl-pre:focus { outline: none; border-color: var(--red); }
.cl-tools { display: flex; flex-direction: column; gap: 4px; }
.cl-tools button { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 32px; height: 28px; cursor: pointer; font-size: 12px; }
.cl-tools button:hover { background: var(--bg); }
.vars-help { margin-top: 12px; font-size: 13px; color: var(--muted); }
.vars-help summary { cursor: pointer; font-weight: 600; }
.vars-help code { background: var(--bg); padding: 0 6px; border-radius: 4px; color: var(--ink); }
.eq-table input:not([type=checkbox]) { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; min-width: 90px; }
.eq-table td { padding: 6px; }
.save-bar { position: sticky; bottom: 0; background: rgba(245,246,248,.95); backdrop-filter: blur(4px); padding: 12px 0; display: flex; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--line); }
@media (max-width: 560px) { .cl-row { flex-wrap: wrap; } .cl-num { min-width: 100%; padding-top: 0; } }

/* =====================================================================
   تحديث التصميم (v0.4)
   ===================================================================== */
:root { --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 14px rgba(16,24,40,.05); --radius: 14px; }
body { background: #F4F5F7; }

/* ---------- الدخول ---------- */
.auth-wrap { background: radial-gradient(1200px 600px at 100% 0%, var(--red-dark) 0%, transparent 60%), linear-gradient(160deg, #141B23 0%, #1F2933 100%); }
.auth-split { display: grid; grid-template-columns: 1.1fr 1fr; max-width: 920px; width: 100%; border-radius: 20px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-hero { background: linear-gradient(155deg, var(--red) 0%, var(--red-dark) 100%); color: #fff; padding: 44px 38px; position: relative; overflow: hidden; }
.auth-hero::after { content: ""; position: absolute; width: 320px; height: 320px; border-radius: 50%; border: 50px solid rgba(255,255,255,.07); left: -120px; bottom: -140px; }
.auth-hero .brand-mark { background: #fff; color: var(--red); }
.auth-hero .brand-name { color: #fff; }
.auth-hero h2 { font-size: 27px; line-height: 1.5; margin: 34px 0 22px; font-weight: 800; }
.auth-hero ul { list-style: none; padding: 0; margin: 0; }
.auth-hero li { padding: 8px 0 8px 0; padding-right: 30px; position: relative; font-size: 15px; opacity: .95; }
.auth-hero li::before { content: "✓"; position: absolute; right: 0; top: 8px; width: 20px; height: 20px; border-radius: 50%; background: rgba(255,255,255,.2); font-size: 12px; display: flex; align-items: center; justify-content: center; }
.auth-split .auth-card { border-radius: 0; box-shadow: none; max-width: none; padding: 44px 36px; display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 760px) {
  .auth-split { grid-template-columns: 1fr; border-radius: 16px; }
  .auth-hero { display: none; }
}

/* ---------- الشعار ---------- */
.brand-mark { flex-shrink: 0; overflow: hidden; }
.brand-mark.has-logo { background: #fff; padding: 4px; }
.brand-mark.has-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-mark.lg { width: 46px; height: 46px; border-radius: 12px; font-size: 22px; }
.brand-mark.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }

/* ---------- القائمة الجانبية ---------- */
.sidebar { width: 252px; background: linear-gradient(180deg, #17202A 0%, #1C2630 100%); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.sb-company { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; margin-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,.07); }
.sb-name { color: #fff; font-weight: 800; font-size: 15px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sb-sub { color: #7B8794; font-size: 11.5px; }
.nav a { gap: 12px; padding: 10px 12px; color: #B3BCC6; font-size: 14.5px; position: relative; transition: background .15s, color .15s; }
.nav a svg { opacity: .85; flex-shrink: 0; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active::before { content: ""; position: absolute; right: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 4px 0 0 4px; background: var(--red); }
.nav a.active svg { color: var(--red); opacity: 1; filter: brightness(1.35); }
.sidebar-foot { display: flex; align-items: center; gap: 10px; padding: 14px 6px 2px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }
.sidebar-foot .who { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .role { font-size: 12px; color: #7B8794; }
.sidebar-foot button { margin: 0; padding: 7px; display: flex; border-radius: 8px; }
.sidebar-foot button:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ---------- المحتوى ---------- */
.main { padding: 0; display: flex; flex-direction: column; }
.main-top { height: 52px; display: flex; align-items: center; padding: 0 28px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); background: #fff; }
.main-inner { padding: 26px 28px 40px; max-width: 1280px; width: 100%; }
.page-head h1 { font-size: 25px; font-weight: 800; letter-spacing: -.2px; }
.topbar .tb-brand { display: flex; align-items: center; gap: 8px; }
@media (max-width: 860px) {
  .sidebar { position: fixed; height: auto; }
  .main-top { display: none; }
  .main-inner { padding: 16px 14px 40px; }
}

/* ---------- بطاقات وإحصائيات ---------- */
.card { border-color: #E9ECEF; box-shadow: var(--shadow); }
.card h2 { font-size: 16.5px; font-weight: 800; }
.stat { box-shadow: var(--shadow); border-color: #E9ECEF; position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.stat::before { content: ""; position: absolute; top: 0; right: 0; width: 4px; height: 100%; background: #D5DAE0; }
.stat.alert::before { background: var(--red); }
a.stat:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(16,24,40,.08); }
.stat .num { font-size: 32px; }

/* ---------- جداول وأزرار ---------- */
th { background: #F8F9FB; font-size: 12.5px; }
thead th:first-child { border-radius: 0 8px 8px 0; } thead th:last-child { border-radius: 8px 0 0 8px; }
th { border-bottom: 0; }
tr.clickable:hover td { background: #FAFBFC; }
.btn { border-radius: 10px; }
.btn-primary { box-shadow: 0 2px 8px color-mix(in srgb, var(--red) 30%, transparent); }
.tabs button.active { color: var(--red); }

/* ---------- الإعدادات: الشعار والتصميم ---------- */
.settings-grid { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.4fr); gap: 18px; max-width: 1100px; }
.settings-grid .card { margin-bottom: 0; }
@media (max-width: 960px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-grid + .card, .settings-grid ~ .card { margin-top: 18px; }
.logo-zone { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.logo-preview { width: 120px; height: 120px; border: 2px dashed var(--line); border-radius: 14px; display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(#F4F5F7 0% 25%, #fff 0% 50%) 50% / 16px 16px; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
#brandPick { width: 36px; height: 32px; border: 0; background: none; cursor: pointer; padding: 0; }
.d-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.d-card { border: 2px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; text-align: center; transition: border-color .15s, transform .15s; background: #fff; }
.d-card:hover { transform: translateY(-2px); }
.d-card.on { border-color: var(--red); background: var(--red-soft); }
.d-card input { display: none; }
.d-card b { display: block; margin-top: 6px; font-size: 14px; }
.d-card span { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.d-thumb { width: 100%; max-width: 96px; aspect-ratio: 100/140; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.12); background: #fff; }
.d-default { width: 100%; max-width: 96px; aspect-ratio: 100/140; margin: 0 auto; border-radius: 6px; border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; font-size: 28px; background: var(--bg); }
.stat.alert { border-color: color-mix(in srgb, var(--red) 35%, #fff); }
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .num { font-size: 24px; }
}

/* ---------- v0.5: المالية والخطابات والتنبيهات ---------- */
.nav-sec { font-size: 11px; color: #5F6B7A; font-weight: 700; padding: 14px 12px 4px; letter-spacing: .3px; }
.sidebar { overflow-y: auto; }
.nav a { padding: 8px 12px; margin-bottom: 2px; }
.main-top { justify-content: space-between; }
.bell-slot { position: relative; display: inline-flex; }
.bell { position: relative; background: transparent; border: 0; cursor: pointer; padding: 7px; border-radius: 10px; color: inherit; display: flex; }
.main-top .bell { color: var(--ink); }
.bell:hover { background: rgba(127,127,127,.12); }
.bell-n { position: absolute; top: 0; left: 0; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; border: 2px solid #fff; }
.bell-pop { position: absolute; top: 42px; left: 0; width: 340px; max-height: 420px; overflow-y: auto; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(16,24,40,.16); z-index: 80; }
.bell-head { padding: 12px 14px; font-weight: 800; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.bell-head span { background: var(--bg); border-radius: 10px; padding: 0 8px; font-size: 12px; }
.bell-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 13.5px; line-height: 1.6; }
.bell-item:hover { background: var(--bg); }
.bell-item.red { border-right: 3px solid var(--red); } .bell-item.amber { border-right: 3px solid #E0A800; }
@media (max-width: 560px) { .bell-pop { width: calc(100vw - 24px); position: fixed; top: 56px; left: 12px; } }

.items-table input { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.items-table td { padding: 6px; vertical-align: middle; }
.it-line { font-weight: 700; white-space: nowrap; }
.totals-box { margin-top: 14px; margin-right: auto; width: 100%; max-width: 380px; background: #FAFBFC; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.totals-box > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; }
.totals-box input { width: 110px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.totals-box .grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 17px; }
.totals-box .grand b { color: var(--red); }

.grid-split { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.6fr); gap: 18px; align-items: start; }
.grid-split .card { margin-bottom: 0; }
.grid-split + * { margin-top: 18px; }
@media (max-width: 960px) { .grid-split { grid-template-columns: 1fr; } }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13.5px; }
.bar { background: var(--bg); border-radius: 6px; height: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--red); border-radius: 6px; }
.month-input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; }
.chart { display: flex; gap: 10px; align-items: flex-end; height: 200px; padding: 10px 4px 0; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.chart .bars { flex: 1; width: 100%; display: flex; gap: 4px; align-items: flex-end; justify-content: center; }
.chart .bars i { width: 40%; max-width: 22px; border-radius: 5px 5px 0 0; min-height: 2px; }
.chart span { font-size: 12px; color: var(--muted); padding: 6px 0; }
i.rev { background: var(--red); } i.exp { background: #9AA5B1; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tpl-card { background: #fff; border: 1px solid #E9ECEF; border-radius: 12px; padding: 14px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; transition: transform .15s, border-color .15s; }
.tpl-card:hover { transform: translateY(-2px); border-color: var(--red); }
.tpl-card span { font-size: 22px; } .tpl-card b { font-size: 13.5px; line-height: 1.6; }
.letter-body { line-height: 2; font-size: 15px; }
/* ألوان الحالات ثابتة (ما بتتغير مع لون الهوية) */
:root { --danger: #C62828; --danger-soft: #FDECEC; }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.msg.error { background: var(--danger-soft); color: #9F1D1D; }
.stat.alert { background: var(--danger-soft); border-color: #F3C4C4; }
.stat.alert .num { color: var(--danger); }
.stat.alert::before { background: var(--danger); }
.btn-danger { color: var(--danger); border-color: #F3C4C4; }
.btn-danger:hover { background: var(--danger-soft); }
.bell-item.red { border-right-color: var(--danger); }
a.btn { text-decoration: none; }
.tabs button { white-space: nowrap; }

/* ---------- v0.6: ملف سلامة المنشأة ---------- */
.safety-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.safety-card { display: flex; gap: 14px; align-items: center; background: #fff; border: 1px solid #E9ECEF; border-radius: 14px; padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.safety-card:hover { transform: translateY(-2px); border-color: var(--red); }
.readiness { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 18px; font-size: 14px; }
.check-list .ok { color: var(--green); } .check-list .no { color: var(--danger); font-weight: 600; }
.req { font-size: 11px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 0 6px; font-weight: 400; }
.issue { padding: 10px 12px; border: 1px solid var(--line); border-right: 3px solid var(--danger); border-radius: 8px; margin-bottom: 8px; }
.share-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.share-row span { flex: 1; } .share-row.expired { opacity: .55; }
.share-box { background: var(--bg); border-radius: 10px; padding: 12px; margin-bottom: 8px; }
.share-box input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; }
.share-page { min-height: 100vh; background: #F4F5F7; }
.share-head { display: flex; gap: 12px; align-items: center; padding: 14px 20px; background: #fff; border-bottom: 3px solid var(--red); }
.share-head img { max-height: 46px; max-width: 130px; }
.ring { flex-shrink: 0; }
.form-sec { font-size: 14.5px; margin: 18px 0 10px; padding-top: 14px; border-top: 1px dashed var(--line); }
.doc-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; } .doc-row:last-child { border-bottom: 0; }

/* ---------- v0.7: الموبايل والتطبيق والـQR ---------- */
.bottom-nav { display: none; }
@media (max-width: 860px) {
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; right: 0; left: 0; z-index: 60;
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 20px rgba(16,24,40,.06);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; align-items: center;
  }
  .bottom-nav a, .bottom-nav > button:not(.fab) {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none;
    color: #7B8794; font-size: 11px; font-weight: 600; background: none; border: 0; font-family: inherit; padding: 4px 0; cursor: pointer;
  }
  .bottom-nav .on { color: var(--red); }
  .bottom-nav .fab {
    width: 54px; height: 54px; border-radius: 50%; border: 4px solid #fff; background: var(--red); color: #fff;
    font-size: 28px; line-height: 1; margin-top: -26px; box-shadow: 0 6px 16px color-mix(in srgb, var(--red) 40%, transparent); cursor: pointer;
  }
  .main-inner { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .save-bar { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 30; padding-top: calc(12px + env(safe-area-inset-top)); }
  .sidebar.open { overflow-y: auto; padding-bottom: 90px; }
}
.sheet-bg { position: fixed; inset: 0; background: rgba(15,23,32,.45); z-index: 150; opacity: 0; transition: opacity .2s; }
.sheet-bg.show { opacity: 1; }
.sheet { position: absolute; bottom: 0; right: 0; left: 0; background: #fff; border-radius: 20px 20px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .2s; max-width: 640px; margin: 0 auto; }
.sheet-bg.show .sheet { transform: none; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 12px; font-size: 16px; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sheet-grid button { background: var(--bg); border: 0; border-radius: 14px; padding: 12px 4px; font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink); }
.sheet-grid button span { font-size: 24px; }
.contact-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.net-bar { position: fixed; top: 0; right: 0; left: 0; z-index: 300; text-align: center; font-size: 13px; font-weight: 700; padding: 6px 10px calc(6px); color: #fff; }
.net-bar.off { background: #37474F; } .net-bar.sync { background: #E0A800; color: #1F2933; }
.install-btn { margin: 10px 6px 0; background: rgba(255,255,255,.08); color: #fff; border: 1px dashed rgba(255,255,255,.25); border-radius: 10px; padding: 8px; font-family: inherit; font-weight: 700; cursor: pointer; }
.quick-check .rb { font-size: 16px; padding: 14px 8px; }
.asset-qr { text-align: center; }
.asset-qr svg { width: 180px; height: 180px; }
.asset-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; font-size: 12.5px; text-decoration: none; color: var(--muted); background: #fff; }
.chip.pass { background: var(--green-soft); color: var(--green); border-color: #B9DDBB; }
.chip.fail { background: var(--danger-soft); color: var(--danger); border-color: #F3C4C4; }
.scan-vid { width: 100%; border-radius: 12px; background: #000; max-height: 60vh; object-fit: cover; }
.rb-fail.on { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.more-fields { margin: 4px 0 14px; } .more-fields summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------- v0.9: بوابة العميل وطلبات الخدمة ---------- */
.portal { min-height: 100vh; background: #F4F5F7; }
.portal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px calc(12px); padding-top: calc(12px + env(safe-area-inset-top)); background: #fff; border-bottom: 3px solid var(--red); position: sticky; top: 0; z-index: 20; }
.ph-co { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ph-co img { max-height: 44px; max-width: 120px; object-fit: contain; }
.ph-co b { font-size: 16px; }
.ph-act { display: flex; gap: 6px; }
.portal-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); scrollbar-width: none; position: sticky; top: 71px; z-index: 19; }
.portal-tabs::-webkit-scrollbar { display: none; }
.portal-tabs button { flex-shrink: 0; border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 6px 14px; font-family: inherit; font-weight: 700; font-size: 13.5px; color: var(--muted); cursor: pointer; display: flex; gap: 6px; align-items: center; }
.portal-tabs button.on { background: var(--red); border-color: var(--red); color: #fff; }
.portal-tabs em { font-style: normal; background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.portal-tabs button.on em { background: #fff; color: var(--red); }
.portal-main { max-width: 900px; margin: 0 auto; }
.portal-foot { text-align: center; font-size: 12px; color: var(--muted); padding: 20px 14px 40px; }
.portal-cta { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.portal-cta .btn { flex: 1; justify-content: center; padding: 14px; font-size: 15px; min-width: 160px; }
.portal-cta .btn-primary { background: var(--danger); }
.p-title { margin: 0 0 14px; font-size: 20px; }
.p-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.bank-card .iban-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-weight: 800; letter-spacing: .5px; }
.kind-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.kchip input { display: none; }
.kchip span { display: inline-block; border: 1.5px solid var(--line); border-radius: 20px; padding: 7px 14px; cursor: pointer; font-weight: 700; font-size: 13.5px; background: #fff; }
.kchip input:checked + span { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.kchip.em input:checked + span { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.bell-item[data-go] { cursor: pointer; }
.wa-box { background: #F1FBF4; border: 1px solid #CDEBD6; border-radius: 12px; padding: 14px; }
.wa-box textarea { width: 100%; padding: 10px; border: 1px solid #CDEBD6; border-radius: 8px; line-height: 1.8; background: #fff; resize: vertical; }
.btn-wa { background: #25D366; color: #fff; font-size: 15px; padding: 12px; justify-content: center; box-shadow: 0 2px 8px rgba(37,211,102,.35); }
.btn-wa:hover { background: #1EBE5A; }
.brand-mark.platform, .auth-hero .brand-mark.platform { background: transparent; width: 46px; height: 46px; }
.brand-mark.platform img { width: 100%; height: 100%; display: block; }
.auth-hero .brand-mark.platform { background: #fff; border-radius: 12px; padding: 5px; }
