:root {
  --brand: #087f8c;
  --brand-strong: #075f68;
  --brand-soft: #e8f7f8;
  --accent: #f4a261;
  --ink: #163036;
  --muted: #65777b;
  --line: #dce6e7;
  --surface: #ffffff;
  --canvas: #f4f8f8;
  --success: #23856d;
  --warning: #b87318;
  --danger: #bd4557;
  --info: #347aa5;
  --shadow-sm: 0 8px 24px rgba(20, 54, 59, .07);
  --shadow-md: 0 20px 52px rgba(20, 54, 59, .14);
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;
  --ease: cubic-bezier(.2, .75, .2, 1);
  font-family: "Tajawal", "Noto Sans Arabic", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button, a, input, select, textarea { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent); border-color: var(--brand) !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.sr-only:focus { position: fixed !important; inset-block-start: 8px; inset-inline-start: 8px; z-index: 500; width: auto; height: auto; margin: 0; padding: 10px 14px; overflow: visible; clip: auto; border-radius: 8px; color: #fff; background: var(--brand-strong); }

.topbar { position: sticky; inset-block-start: 0; z-index: 30; height: 72px; display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-6); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
.mobile-brand { display: none; align-items: center; gap: var(--space-2); }
.global-search { margin-inline-start: 292px; width: min(520px, 45vw); min-height: 44px; display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-4); color: var(--muted); border: 1px solid transparent; border-radius: 999px; background: var(--canvas); transition: 160ms var(--ease); }
.global-search:focus-within { background: var(--surface); border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
.global-search input { width: 100%; min-width: 0; border: 0; color: var(--ink); background: transparent; }
.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--space-2); }
.status-button, .role-select select, .icon-button { min-height: 42px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); }
.status-button { display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; font-size: .78rem; font-weight: 700; }
.status-button.offline { color: var(--warning); background: #fff8eb; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 14%, transparent); }
.offline .status-dot { background: var(--warning); }
.role-select select { max-width: 156px; padding: 0 12px; }
.icon-button { position: relative; min-width: 42px; padding: 0; font-size: 1.15rem; }
.icon-button b { position: absolute; inset-block-start: -5px; inset-inline-end: -5px; min-width: 19px; height: 19px; display: grid; place-items: center; border-radius: 999px; color: white; background: var(--danger); font-size: .66rem; }

.shell { min-height: calc(100vh - 72px); display: grid; grid-template-columns: 276px minmax(0, 1fr); }
.sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; width: 276px; height: 100vh; display: flex; flex-direction: column; gap: var(--space-5); padding: 24px 16px; color: #eaf6f6; background: linear-gradient(160deg, var(--brand-strong), color-mix(in srgb, var(--brand-strong) 80%, #061e24)); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 16px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; border-radius: 14px; color: var(--brand-strong); background: #fff; font-weight: 900; box-shadow: 0 8px 20px rgba(0,0,0,.16); }
.brand strong { display: block; font-size: 1.02rem; }
.brand small { display: block; margin-top: 2px; color: rgba(255,255,255,.62); font-size: .72rem; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { width: 100%; min-height: 46px; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid transparent; border-radius: 12px; color: rgba(255,255,255,.76); background: transparent; text-align: start; transition: 160ms var(--ease); }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(-2px); }
.nav-item.active { color: #fff; border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.14); box-shadow: inset 3px 0 0 var(--accent); }
.nav-item b { min-width: 25px; padding: 2px 6px; border-radius: 999px; background: rgba(255,255,255,.12); text-align: center; font-size: .7rem; }
.simulation-note { margin-top: auto; padding: 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: rgba(0,0,0,.11); }
.simulation-note span, .local-badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; color: #5b370a; background: #ffe1af; font-size: .68rem; font-weight: 800; }
.simulation-note p { margin: 8px 0 0; color: rgba(255,255,255,.68); font-size: .74rem; line-height: 1.65; }

.main { grid-column: 2; width: 100%; max-width: 1640px; padding: 32px; overflow: hidden; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-head.compact { align-items: center; }
.eyebrow { display: block; margin-bottom: 5px; color: var(--brand); font-size: .72rem; font-weight: 900; letter-spacing: .04em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.28; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 1.15rem; }
.page-head p { max-width: 730px; margin-bottom: 0; color: var(--muted); line-height: 1.75; }
.date-chip { min-width: 220px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.date-chip span, .date-chip strong { display: block; }
.date-chip span { color: var(--muted); font-size: .72rem; }
.date-chip strong { margin-top: 5px; font-size: .86rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { min-height: 126px; display: flex; align-items: center; gap: 14px; padding: 20px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); transition: 170ms var(--ease); }
.metric-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.metric-icon { width: 50px; height: 50px; flex: 0 0 50px; display: grid; place-items: center; border-radius: 16px; color: var(--brand); background: var(--brand-soft); font-size: 1.3rem; }
.metric-icon.warning { color: var(--warning); background: #fff4df; }
.metric-icon.danger { color: var(--danger); background: #fff0f2; }
.metric-icon.info { color: var(--info); background: #eef7fd; }
.metric-card span, .metric-card small { display: block; color: var(--muted); font-size: .76rem; }
.metric-card strong { display: block; margin: 4px 0; font-size: 1.5rem; }

.panel { margin-bottom: 24px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.section-title { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 18px; }
.quick-action { min-height: 108px; display: grid; grid-template-columns: 42px 1fr; grid-template-rows: auto auto; align-items: center; gap: 2px 12px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--canvas); text-align: start; transition: 160ms var(--ease); }
.quick-action:hover { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-2px); }
.quick-action > span { grid-row: 1 / 3; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--surface); font-size: 1.15rem; }
.quick-action small { color: var(--muted); line-height: 1.5; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 24px; }
.queue-list { padding: 8px 16px 16px; }
.queue-row { width: 100%; min-height: 62px; display: grid; grid-template-columns: 38px 1fr 110px 32px; align-items: center; gap: 12px; padding: 8px; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: transparent; text-align: start; }
.queue-row:last-child { border-bottom: 0; }
.queue-row:hover { background: var(--canvas); }
.queue-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--brand-soft); }
.queue-row strong, .queue-row small { display: block; }
.queue-row small { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.progress { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.timeline { margin: 0; padding: 16px 22px; list-style: none; }
.timeline li { position: relative; display: flex; gap: 12px; padding: 0 0 18px; }
.timeline li > span { width: 10px; height: 10px; flex: 0 0 10px; margin-top: 4px; border: 2px solid var(--surface); border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; inset-inline-start: 4px; top: 17px; bottom: 2px; width: 1px; background: var(--line); }
.timeline strong, .timeline small { display: block; }
.timeline strong { font-size: .82rem; line-height: 1.55; }
.timeline small { margin-top: 3px; color: var(--muted); font-size: .68rem; }

.primary-button, .secondary-button, .ghost-button { min-height: 44px; padding: 0 16px; border-radius: var(--r-sm); font-weight: 800; transition: 140ms var(--ease); }
.primary-button { border: 1px solid var(--brand); color: #fff; background: var(--brand); box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 23%, transparent); }
.primary-button:hover { background: var(--brand-strong); transform: translateY(-1px); }
.primary-button:active, .secondary-button:active, .ghost-button:active, .quick-action:active { transform: scale(.98); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.secondary-button:hover { border-color: var(--brand); color: var(--brand); }
.ghost-button { border: 1px solid rgba(255,255,255,.18); color: #fff; background: transparent; }
.ghost-button:hover { background: rgba(255,255,255,.08); }
.full { width: 100%; }

.data-panel { min-height: 480px; }
.toolbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.filter-group, .toolbar-actions { display: flex; align-items: center; gap: 10px; }
.filter-group label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .76rem; }
.filter-group select { min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: var(--surface); }
.result-count { padding: 6px 10px; border-radius: 999px; color: var(--brand); background: var(--brand-soft); font-size: .72rem; font-weight: 800; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: start; }
th, td { min-width: 115px; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: start; font-size: .8rem; }
th { color: var(--muted); background: color-mix(in srgb, var(--canvas) 75%, white); font-size: .7rem; font-weight: 900; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 34%, white); }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 9px; border-radius: 999px; color: var(--warning); background: #fff4df; font-size: .7rem; font-weight: 900; white-space: nowrap; }
.badge.success { color: var(--success); background: #e9f8f3; }
.badge.danger, .badge.error { color: var(--danger); background: #fff0f2; }
.badge.info { color: var(--info); background: #eef7fd; }
.row-actions { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.row-actions button { min-height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: white; font-size: .68rem; }
.row-actions button:hover { color: var(--brand); border-color: var(--brand); }
.row-actions .accent { color: white; border-color: var(--brand); background: var(--brand); }
.empty-state { min-height: 360px; display: grid; place-items: center; align-content: center; padding: 32px; text-align: center; }
.empty-state > span { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 12px; border-radius: 20px; color: var(--brand); background: var(--brand-soft); font-size: 1.6rem; }
.empty-state p { max-width: 430px; color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: rgba(8, 31, 36, .62); backdrop-filter: blur(5px); animation: fade-in 180ms var(--ease); }
.modal { width: min(780px, 100%); max-height: min(820px, 92vh); overflow-y: auto; border: 1px solid rgba(255,255,255,.45); border-radius: 24px; background: var(--surface); box-shadow: 0 28px 80px rgba(0,0,0,.28); animation: modal-in 220ms var(--ease); }
.side-modal { width: min(580px, 100%); justify-self: end; border-radius: 24px 0 0 24px; min-height: 100vh; max-height: 100vh; }
.modal-head { min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 24px; }
.form-field { display: grid; gap: 7px; align-content: start; }
.form-field.wide { grid-column: 1 / -1; }
.form-field > span { font-size: .78rem; font-weight: 800; }
.form-field input, .form-field select, .form-field textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; }
.form-field textarea { resize: vertical; }
.form-field input[type="checkbox"] { width: 46px; min-height: 24px; }
.field-error { min-height: 16px; color: var(--danger); font-size: .68rem; }
.modal-actions { min-height: 74px; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--canvas); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0; padding: 24px; background: var(--line); }
.detail-grid div { min-height: 80px; padding: 14px; background: var(--surface); }
.detail-grid dt { color: var(--muted); font-size: .72rem; }
.detail-grid dd { margin: 8px 0 0; font-weight: 800; }
.detail-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; }
.detail-foot small { color: var(--muted); }
.notification-list { padding: 12px 20px; }
.notification { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.notification.read { opacity: .6; }
.notification p { margin: 4px 0; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.notification small { color: var(--muted); font-size: .68rem; }
.toast { position: fixed; inset-inline-end: 24px; inset-block-end: 24px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); padding: 13px 18px; border: 1px solid color-mix(in srgb, var(--success) 30%, white); border-radius: 12px; color: #145848; background: #e9f8f3; box-shadow: var(--shadow-md); font-weight: 800; animation: toast-in 220ms var(--ease); }
.toast.error { color: #8c2e3c; border-color: #f4c3ca; background: #fff0f2; }

.skeleton { display: block; border-radius: 14px; background: linear-gradient(90deg, #e5ecec 25%, #f6f9f9 45%, #e5ecec 68%); background-size: 300% 100%; animation: shimmer 1450ms linear infinite; }
.skeleton-panel { gap: 15px; background: var(--brand-strong); }
.skeleton-panel .skeleton { opacity: .24; }
.logo-skeleton { height: 56px; }
.nav-skeleton { height: 44px; }
.title-skeleton { width: 46%; height: 56px; margin-bottom: 28px; }
.metric-skeleton { height: 126px; }
.table-skeleton { height: 420px; }

@keyframes shimmer { to { background-position: -300% 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .global-search { width: 36vw; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 72px; flex-wrap: wrap; padding: 10px 16px; }
  .mobile-brand { display: flex; }
  .mobile-brand .brand-mark { width: 36px; height: 36px; flex-basis: 36px; border: 1px solid var(--line); border-radius: 10px; box-shadow: none; }
  .global-search { order: 3; width: 100%; margin-inline-start: 0; }
  .status-button { font-size: 0; min-width: 42px; justify-content: center; }
  .role-select select { width: 112px; }
  .shell { display: block; min-height: 0; }
  .sidebar { position: sticky; inset-block-start: 128px; z-index: 25; width: 100%; height: auto; padding: 8px 12px; background: var(--brand-strong); overflow: hidden; }
  .sidebar .brand, .sidebar .simulation-note, .sidebar > .ghost-button { display: none; }
  .sidebar nav { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-item { width: auto; min-width: max-content; grid-template-columns: 24px auto; padding: 0 12px; }
  .nav-item b { display: none; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .main { width: 100%; padding: 20px 16px 36px; }
  .page-head, .page-head.compact { align-items: stretch; flex-direction: column; }
  .date-chip { min-width: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 104px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions .secondary-button { flex: 1; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  tbody { display: grid; gap: 12px; padding: 12px; }
  tbody tr { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
  td { min-width: 0; display: grid; grid-template-columns: minmax(82px, .55fr) 1fr; gap: 10px; padding: 8px 4px; border-bottom: 1px dashed var(--line); overflow-wrap: anywhere; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .68rem; font-weight: 800; }
  td:last-child { border-bottom: 0; }
  .row-actions { flex-wrap: wrap; }
  .row-actions button { flex: 1 1 auto; }
  .queue-row { grid-template-columns: 38px 1fr 28px; }
  .queue-row .progress { display: none; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal, .side-modal { width: 100%; max-height: 92vh; min-height: 0; border-radius: 24px 24px 0 0; }
  .modal-head, .form-grid, .modal-actions, .detail-grid { padding-inline: 16px; }
  .toast { inset-inline: 16px; inset-block-end: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  .topbar, .sidebar, .toolbar, .page-head .primary-button, .row-actions, .quick-panel { display: none !important; }
  .shell { display: block; }
  .main { width: 100%; max-width: none; padding: 0; }
  .panel, .metric-card { box-shadow: none; break-inside: avoid; }
  body { background: white; }
}
