/* نظام وحدة الجداول: تنسيق عربي من اليمين لليسار، ألوان هادئة، مساحات بيضاء أوسع، وجداول واضحة */
:root {
  --bg: #f4f6f8; --panel: #ffffff; --ink: #1c2430; --muted: #6b7684; --line: #e3e7ec;
  --brand: #1f5f4a; --brand-2: #2b7a62; --accent: #c8a14a;
  --ok: #1e7f4f; --ok-bg: #e6f4ec; --warn: #a3660b; --warn-bg: #fff4dd; --bad: #b3261e; --bad-bg: #fde8e6; --info: #1f4f8a; --info-bg: #e7eef9;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,40,.06), 0 4px 14px rgba(20,30,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif; font-size: 16px; line-height: 1.7; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 700; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; font-weight: 600; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.quiet { color: var(--muted); font-size: .85rem; }

/* ---- الهيكل: قائمة جانبية بخمس مجموعات + محتوى بعرض مريح */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand-title { font-weight: 700; font-size: 1.25rem; }
.brand-sub { font-size: .85rem; opacity: .8; margin-top: .25rem; }
.sidebar nav { display: flex; flex-direction: column; padding: 1rem .75rem; gap: .35rem; flex: 1; }
.nav-item { color: #fff; padding: .8rem 1rem; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; opacity: .9; font-size: 1.05rem; }
.nav-item:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.18); font-weight: 600; opacity: 1; }
.badge { background: var(--accent); color: #1c2430; border-radius: 999px; padding: 0 .55rem; font-size: .78rem; font-weight: 700; line-height: 1.5; }
.sidebar-foot { padding: 1rem 1.25rem; font-size: .78rem; opacity: .7; }
.content { padding: 1.5rem 2rem 3rem; max-width: 1200px; min-width: 0; }

/* ---- رأس الصفحة: العنوان يميناً، زر الشرح يساراً، ثم أشرطة التبويب الفرعية */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.help-toggle { white-space: nowrap; }
.help-toggle[aria-pressed="true"], body.show-help .help-toggle { background: var(--brand); color: #fff; }
.subnav { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; }
.subnav a { padding: .55rem 1rem; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
.subnav a:hover { color: var(--brand); text-decoration: none; }
.subnav a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---- الشرح: مخفي افتراضياً ويظهر بزر «الشرح» في رأس الصفحة */
.help { display: none; font-size: .85rem; color: var(--muted); margin-top: .25rem; }
body.show-help .help { display: block; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cf; }
.flash-warn { background: var(--warn-bg); color: var(--warn); border-color: #f1d9a3; }
.flash-bad, .flash-error { background: var(--bad-bg); color: var(--bad); border-color: #f3c1bd; }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.kpi-row > * { max-width: 100%; }
@media (min-width: 900px) { .kpi-row { grid-template-columns: repeat(4, minmax(0,1fr)); } .kpi-row:has(> :last-child:nth-child(3)) { grid-template-columns: repeat(3, minmax(0,1fr)); } .kpi-row:has(> :last-child:nth-child(2)) { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.4rem; }
.kpi .label { color: var(--muted); font-size: .95rem; }
.kpi .value { font-size: 2.2rem; font-weight: 700; margin-top: .15rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .85rem; color: var(--muted); margin-top: .35rem; }
.kpi.ok .value { color: var(--ok); } .kpi.warn .value { color: var(--warn); } .kpi.bad .value { color: var(--bad); }

/* ---- بطاقة «الخطوة التالية»: الإجراء الأساسي الواحد في الصفحة */
.next-step { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; border-right: 5px solid var(--accent); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.next-step .title { font-weight: 700; font-size: 1.1rem; margin: 0; }
.next-step .btn { font-size: 1.05rem; padding: .7rem 1.4rem; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: .7rem .8rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { background: #f7f9fb; font-weight: 600; font-size: .9rem; color: #3b4652; position: sticky; top: 0; }
table.sortable th { cursor: pointer; user-select: none; }
tr:hover td { background: #fbfcfd; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); }
/* الأرقام: تُرسم من اليسار لليمين (حتى تبقى الإشارات والكسور بترتيبها) لكنها تُحاذى لليمين تحت عنوان عمودها مثل باقي الخلايا */
.num { text-align: right; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
th.num, td.num { text-align: right; }
.row-actions { display: inline-flex; gap: .35rem; align-items: center; white-space: nowrap; }
.row-actions .btn, .row-actions a { font-size: .85rem; }

.tag { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tag-ok { background: var(--ok-bg); color: var(--ok); } .tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-bad { background: var(--bad-bg); color: var(--bad); } .tag-info { background: var(--info-bg); color: var(--info); }
.tag-muted { background: #eef1f4; color: var(--muted); }

.btn { display: inline-block; padding: .55rem 1.1rem; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: #fff; cursor: pointer; font: inherit; line-height: 1.4; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--brand); }
.btn-secondary:hover { background: #f0f5f3; }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-sm { padding: .3rem .7rem; font-size: .88rem; }
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .85rem 1rem; margin-bottom: .85rem; }
label { display: block; font-size: .9rem; color: #3b4652; margin-bottom: .3rem; font-weight: 500; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=file], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #cfd6de; border-radius: 8px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd9cf; border-color: var(--brand); }
.inline { display: inline-flex; gap: .5rem; align-items: center; }

/* ---- الفلاتر: مطوية داخل زر يحمل نص «تصفية» (نص الـsummary من القالب)، وتنفتح تلقائياً إن كان فيها قيمة */
details.filters { margin-bottom: 1rem; }
details.filters > summary { display: inline-block; list-style: none; cursor: pointer; padding: .45rem 1rem; border-radius: 8px; border: 1px solid var(--brand); background: #fff; color: var(--brand); font-weight: 600; font-size: .95rem; user-select: none; }
details.filters > summary::-webkit-details-marker { display: none; }
details.filters > summary:hover { background: #f0f5f3; }
details.filters[open] > summary { background: var(--brand); color: #fff; border-radius: 8px 8px 0 0; }
details.filters > *:not(summary) { background: var(--panel); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: 1rem 1.25rem .5rem; box-shadow: var(--shadow); }
details.filters form .row { margin-bottom: .5rem; }

.bar { height: 8px; background: #e6eaee; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); } .bar.ok > span { background: var(--ok); }

.alert-item { border-right: 4px solid var(--info); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; margin-bottom: .85rem; }
.alert-item.high { border-right-color: var(--bad); } .alert-item.medium { border-right-color: var(--warn); } .alert-item.low { border-right-color: var(--info); }
.alert-item .meta { color: var(--muted); font-size: .85rem; }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; }
.tabs a { padding: .55rem 1rem; border-radius: 8px 8px 0 0; color: var(--muted); }
.tabs a.active { background: var(--panel); color: var(--brand); font-weight: 600; border: 1px solid var(--line); border-bottom-color: var(--panel); }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }

@media print {
  .sidebar, .page-head .help-toggle, .subnav { display: none; }
  .layout { grid-template-columns: 1fr; } .content { padding: 0; max-width: none; }
  .btn, .toolbar, details.filters { display: none; }
  body { font-size: 12px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; padding: .5rem; }
  .nav-item { padding: .5rem .8rem; font-size: .95rem; }
  .content { padding: 1rem; }
  .page-head { flex-wrap: wrap; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
