/* ===========================================================================
   نظام إصدار كتب عدم الممانعة الإلكتروني - الهيئة العامة للضرائب
   ملف التنسيق الرئيسي - RTL / خط Cairo مستضاف محلياً
   =========================================================================== */

@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo/cairo-arabic-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo/cairo-arabic-500-normal.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo/cairo-arabic-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo/cairo-arabic-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/cairo/cairo-arabic-800-normal.woff2') format('woff2');
  font-weight: 800; font-style: normal; font-display: swap;
}

:root {
  /* ألوان الهوية البصرية */
  --brand-navy: #0d2b4e;
  --brand-navy-2: #163b66;
  --brand-navy-3: #1f4c82;
  --brand-gold: #c9a227;
  --brand-teal: #0f6674;
  --brand-teal-2: #14808f;

  /* أسطح عامة */
  --page-bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --border: #e3e5ea;
  --border-strong: #c9cdd6;

  /* نصوص */
  --ink-primary: #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted: #898781;

  /* حالة (Status - ثابتة حسب دليل الرسوم البيانية) */
  --status-good: #0ca30c;
  --status-good-bg: #e7f7e7;
  --status-warning: #fab219;
  --status-warning-bg: #fff6e2;
  --status-serious: #ec835a;
  --status-serious-bg: #fdece4;
  --status-critical: #d03b3b;
  --status-critical-bg: #fbe7e7;

  /* تصنيفية (للرسوم البيانية) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;

  --grid-line: #e1e0d9;
  --baseline: #c3c2b7;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(11,11,11,0.06), 0 1px 1px rgba(11,11,11,0.04);
  --shadow-md: 0 4px 14px rgba(13,43,78,0.08);
  --shadow-lg: 0 12px 32px rgba(13,43,78,0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--page-bg);
  color: var(--ink-primary);
  font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
  direction: rtl;
  text-align: right;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; margin: 0 0 .5rem; color: var(--brand-navy); }
p { margin: 0 0 .75rem; line-height: 1.7; }
a { color: var(--brand-navy-3); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--page-bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* ===== تخطيط عام ===== */
.app-shell { display: flex; min-height: 100vh; }

.app-topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  background: linear-gradient(90deg, var(--brand-navy) 0%, var(--brand-navy-2) 100%);
  color: #fff;
  padding: .65rem 1.25rem;
  box-shadow: var(--shadow-md);
}
.app-topbar .brand { display: flex; align-items: center; gap: .65rem; }
.app-topbar .brand .emblem {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--brand-gold), #8f7315 78%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--brand-navy); font-size: .95rem;
  border: 2px solid rgba(255,255,255,.65);
  flex-shrink: 0;
}
.app-topbar .brand .titles { line-height: 1.25; }
.app-topbar .brand .titles .t1 { font-weight: 800; font-size: 1.02rem; }
.app-topbar .brand .titles .t2 { font-size: .74rem; opacity: .82; }

.app-topbar .role-chip {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-size: .82rem;
  display: flex; align-items: center; gap: .5rem;
}
.app-topbar .role-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-gold); }

.app-body { display: flex; flex: 1; width: 100%; }

.app-sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1rem .75rem;
  min-height: calc(100vh - 62px);
}
.app-sidebar .nav-section-title {
  font-size: .72rem; color: var(--ink-muted); text-transform: uppercase;
  letter-spacing: .04em; padding: .5rem .6rem .35rem;
  font-weight: 700;
}
.app-sidebar a.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--ink-secondary); font-weight: 600; font-size: .88rem;
  margin-bottom: .15rem;
}
.app-sidebar a.nav-link:hover { background: var(--page-bg); text-decoration: none; color: var(--brand-navy); }
.app-sidebar a.nav-link.active {
  background: var(--brand-navy); color: #fff;
  box-shadow: var(--shadow-sm);
}
.app-sidebar a.nav-link .ic { width: 18px; text-align: center; }

.app-main { flex: 1; padding: 1.5rem; max-width: 1320px; margin: 0 auto; width: 100%; }

/* ===== بطاقات ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.1rem;
}
.card-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: .75rem; flex-wrap: wrap;
}
.card-header-row h3 { margin: 0; font-size: 1.05rem; }
.card-header-row .sub { color: var(--ink-muted); font-size: .82rem; margin-top: .15rem; }

.section-title {
  display: flex; align-items: center; gap: .6rem;
  margin: 1.75rem 0 1rem;
}
.section-title h2 { margin: 0; font-size: 1.2rem; }
.section-title .line { flex: 1; height: 1px; background: var(--border); }

/* ===== أزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .6rem 1.15rem; font-weight: 700; font-size: .88rem;
  cursor: pointer; transition: all .15s ease; font-family: inherit;
  line-height: 1.2;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand-navy); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-navy-2); }
.btn-gold { background: var(--brand-gold); color: #3a2f08; }
.btn-gold:hover:not(:disabled) { background: #b6931f; }
.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--ink-secondary); }
.btn-outline:hover:not(:disabled) { background: var(--page-bg); }
.btn-success { background: var(--status-good); color: #fff; }
.btn-success:hover:not(:disabled) { background: #0a8c0a; }
.btn-danger { background: var(--status-critical); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b83030; }
.btn-sm { padding: .38rem .8rem; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-link-plain { background: transparent; border: none; color: var(--brand-navy-3); font-weight: 700; padding: 0; }

/* ===== شارات الحالة ===== */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .68rem; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.badge-good { background: var(--status-good-bg); color: var(--status-good); }
.badge-warning { background: var(--status-warning-bg); color: #9c6d00; }
.badge-critical { background: var(--status-critical-bg); color: var(--status-critical); }
.badge-neutral { background: var(--page-bg); color: var(--ink-secondary); border: 1px solid var(--border); }
.badge-navy { background: #eaf0f8; color: var(--brand-navy); }
.badge-teal { background: #e6f3f5; color: var(--brand-teal); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ===== نماذج ===== */
label.field-label { display: block; font-weight: 700; font-size: .85rem; margin-bottom: .35rem; color: var(--ink-secondary); }
.field-hint { font-size: .76rem; color: var(--ink-muted); margin-top: .3rem; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-family: inherit; font-size: .9rem;
  background: #fff; color: var(--ink-primary);
}
.form-control:focus { outline: none; border-color: var(--brand-navy-3); box-shadow: 0 0 0 3px rgba(31,76,130,.14); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.form-group { margin-bottom: 1rem; }
.file-drop {
  border: 2px dashed var(--border-strong); border-radius: var(--radius-md);
  padding: 1.5rem; text-align: center; color: var(--ink-muted); background: var(--page-bg);
}
.checkbox-row { display: flex; align-items: center; gap: .5rem; }

/* ===== جداول ===== */
table.data-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data-table th {
  text-align: right; padding: .65rem .75rem; background: var(--page-bg);
  color: var(--ink-secondary); font-weight: 700; font-size: .78rem;
  border-bottom: 1px solid var(--border);
}
table.data-table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:hover td { background: #fafbfc; }

/* ===== متتبّع سير العمل (Step tracker) ===== */
.tracker { display: flex; flex-direction: column; gap: 0; }
.tracker-step { display: flex; gap: .9rem; position: relative; }
.tracker-step .rail { display: flex; flex-direction: column; align-items: center; }
.tracker-step .node {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem; flex-shrink: 0; z-index: 1;
  background: var(--page-bg); color: var(--ink-muted); border: 2px solid var(--border-strong);
}
.tracker-step .connector { width: 2px; flex: 1; background: var(--border-strong); min-height: 22px; }
.tracker-step.done .node { background: var(--status-good); border-color: var(--status-good); color: #fff; }
.tracker-step.done .connector { background: var(--status-good); }
.tracker-step.current .node { background: var(--brand-navy); border-color: var(--brand-navy); color: #fff; box-shadow: 0 0 0 4px rgba(13,43,78,.15); }
.tracker-step.error .node { background: var(--status-critical); border-color: var(--status-critical); color: #fff; }
.tracker-step .content { padding-bottom: 1.4rem; flex: 1; }
.tracker-step .content .lane-tag { font-size: .7rem; color: var(--ink-muted); font-weight: 700; margin-bottom: .15rem; }
.tracker-step .content .title { font-weight: 700; font-size: .92rem; }
.tracker-step .content .detail { font-size: .82rem; color: var(--ink-secondary); margin-top: .15rem; }
.tracker-step .content .time { font-size: .72rem; color: var(--ink-muted); margin-top: .25rem; }

/* ===== لوحة KPI ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.1rem; }
.kpi-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm); }
.kpi-tile .label { font-size: .78rem; color: var(--ink-muted); font-weight: 700; margin-bottom: .4rem; }
.kpi-tile .value { font-size: 1.7rem; font-weight: 800; color: var(--brand-navy); }
.kpi-tile .delta { font-size: .76rem; margin-top: .3rem; color: var(--ink-secondary); }
.kpi-tile.accent-good .value { color: var(--status-good); }
.kpi-tile.accent-warning .value { color: #9c6d00; }
.kpi-tile.accent-critical .value { color: var(--status-critical); }

/* ===== لوحة عمليات خارجية ===== */
.integration-row { display: flex; align-items: center; gap: .85rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.integration-row:last-child { border-bottom: none; }
.integration-row .sys-icon {
  width: 38px; height: 38px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
  background: var(--page-bg); font-weight: 800; font-size: .8rem; color: var(--brand-teal); flex-shrink: 0;
}
.integration-row .main { flex: 1; min-width: 0; }
.integration-row .main .op { font-weight: 700; font-size: .87rem; }
.integration-row .main .sum { font-size: .78rem; color: var(--ink-secondary); }
.integration-row .meta { text-align: left; font-size: .75rem; color: var(--ink-muted); white-space: nowrap; }

/* ===== شعار / نظرة عامة ===== */
.hero {
  background: linear-gradient(135deg, var(--brand-navy) 0%, var(--brand-navy-2) 55%, var(--brand-teal) 130%);
  color: #fff; border-radius: var(--radius-lg); padding: 2.25rem 2rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow-lg); position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 85% 20%, rgba(201,162,39,.25), transparent 45%);
}
.hero h1 { color: #fff; font-size: 1.65rem; margin-bottom: .5rem; position: relative; }
.hero p { color: rgba(255,255,255,.86); max-width: 760px; position: relative; }
.hero .hero-stats { display: flex; gap: 1.5rem; margin-top: 1.5rem; flex-wrap: wrap; position: relative; }
.hero .hero-stats .stat .v { font-size: 1.5rem; font-weight: 800; color: var(--brand-gold); }
.hero .hero-stats .stat .l { font-size: .76rem; color: rgba(255,255,255,.78); }

/* ===== أعمدة الفلوشارت (Lanes) ===== */
.lanes-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.lane-col { background: var(--surface); padding: 1rem .9rem; }
.lane-col .lane-header { font-weight: 800; font-size: .84rem; padding: .5rem .6rem; border-radius: var(--radius-sm); color: #fff; margin-bottom: .8rem; text-align: center; }
.lane-col.lane-applicant .lane-header { background: var(--brand-navy); }
.lane-col.lane-external .lane-header { background: var(--brand-teal); }
.lane-col.lane-system .lane-header { background: #1f7a5c; }
.lane-col.lane-human .lane-header { background: #b5741a; }
.lane-col ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.lane-col li { font-size: .78rem; background: var(--page-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .6rem; line-height: 1.5; }

@media (max-width: 980px) {
  .lanes-grid { grid-template-columns: 1fr; }
  .app-sidebar { display: none; }
}

/* ===== شهادة/كتاب ===== */
.certificate {
  background: #fffdf7;
  border: 3px double var(--brand-gold);
  border-radius: var(--radius-md);
  padding: 2rem; position: relative;
}
.certificate .cert-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--brand-navy); padding-bottom: 1rem; margin-bottom: 1.2rem; }
.certificate .cert-title { text-align: center; margin: 1rem 0 1.5rem; }
.certificate .cert-title h2 { font-size: 1.3rem; margin-bottom: .2rem; }
.certificate .cert-body p { font-size: .95rem; line-height: 2; }
.certificate .cert-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--border-strong); }
.qr-box { width: 118px; height: 118px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; }

/* ===== أدوات مساعدة ===== */
.text-muted { color: var(--ink-muted); }
.text-sm { font-size: .82rem; }
.mt-0 { margin-top: 0 !important; }
.d-flex { display: flex; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ink-muted); }
.empty-state .ic { font-size: 2.2rem; margin-bottom: .5rem; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite; display: inline-block;
}
.spinner-navy { border: 3px solid rgba(13,43,78,.18); border-top-color: var(--brand-navy); }
@keyframes spin { to { transform: rotate(360deg); } }

.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--status-good); box-shadow: 0 0 0 rgba(12,163,12,.55); animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(12,163,12,.5); }
  70% { box-shadow: 0 0 0 8px rgba(12,163,12,0); }
  100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); }
}

.alert { border-radius: var(--radius-sm); padding: .85rem 1rem; font-size: .87rem; display: flex; gap: .6rem; align-items: flex-start; }
.alert-critical { background: var(--status-critical-bg); color: #7a2323; border: 1px solid #f2c6c6; }
.alert-good { background: var(--status-good-bg); color: #145c14; border: 1px solid #c3e8c3; }
.alert-info { background: #eaf0f8; color: var(--brand-navy); border: 1px solid #cfdcee; }
.alert-warning { background: var(--status-warning-bg); color: #7a5600; border: 1px solid #f5dfa4; }

@media print {
  .app-topbar, .app-sidebar, .no-print { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  body { background: #fff; }
}
