/* ===== الهيكل العام والاستجابة ===== */
.root { min-height: 100vh; }

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface-nav); border-inline-start: 1px solid #2B2E2C; color: #CFCFCF; display: flex; flex-direction: column; padding: 0 12px 12px; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 4px; margin-bottom: 6px; border-bottom: 1px solid #2B2E2C; }
.brand-mark { flex: none; width: 34px; height: 34px; color: var(--accent); display: grid; place-items: center; }
.brand-logo { width: 100%; height: 100%; }
.brand-name { color: #FFFFFF; font-family: var(--font-display); font-weight: 700; font-size: var(--fs-14); line-height: 1.35; }
.brand-sub { font-size: var(--fs-12); color: #8A8A8A; }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid #2B2E2C; display: flex; flex-direction: column; gap: 6px; }
.user { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.user-name { color: #FFFFFF; font-weight: 600; font-size: var(--fs-14); line-height: 1.3; }
.user-role { font-size: var(--fs-12); color: #8A8A8A; }
.sidebar-actions { display: flex; gap: 4px; }
.sidebar .avatar { background: var(--accent-soft); color: var(--accent); }
.sidebar .btn-quiet { color: #CFCFCF; }
.sidebar .btn-quiet:hover { background: rgba(255, 255, 255, .08); color: #FFFFFF; }

.main { position: relative; isolation: isolate; min-width: 0; display: flex; flex-direction: column; overflow: clip; background: var(--bg); }
.board-stage { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; opacity: var(--board-opacity); }
.board-stage canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.board-stage .splash-cpu { left: 50%; top: calc(50% - 44px); }
.topbar, .view { position: relative; z-index: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; padding: 12px var(--page-gutter); background: var(--surface-3); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.page-title { font-family: var(--font-display); font-size: var(--fs-20); font-weight: 700; }
.page-sub { font-size: var(--fs-13); color: var(--ink-3); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.view { padding: 24px var(--page-gutter) 56px; max-width: var(--content-max); width: 100%; display: flex; flex-direction: column; gap: var(--page-gap); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--page-gap); align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* ---------- تكيّف ---------- */
@media (max-width: 1199px) {
  :root { --sidebar-w: 68px; }
  .sidebar { padding: 14px 10px; }
  .brand { justify-content: center; padding: 0 0 12px; }
  .brand > div, .nav-label, .user > div, .nav-section { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .user { justify-content: center; padding: 4px 0; }
  .sidebar-actions { flex-direction: column; align-items: center; }
  :root { --page-gutter: 24px; }
  .three-col { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center; gap: 6px; padding: 8px 12px; border-inline-end: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand { padding: 0; border: 0; margin: 0; }
  .nav { flex-direction: row; flex: 1; }
  .nav-item { height: 36px; width: 36px; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .sidebar-actions { flex-direction: row; }
  .topbar { position: static; padding: 12px 16px; }
  .view { padding: 16px 16px 40px; }
  .figures { grid-template-columns: 1fr 1fr; }
  .figure:nth-child(3) { border-inline-start: 0; }
  .figure:nth-child(n+3) { border-top: 1px solid var(--line-2); }
}

@media (max-width: 719px) {
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .period-title { min-width: 120px; }
  /* جدول السجل يتحول إلى كتل */
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; }
  table.data.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data.stack td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; }
  table.data.stack td::before { content: attr(data-label); color: var(--ink-3); font-size: var(--fs-12); }
  table.data.stack td.num { text-align: right; font-size: var(--fs-14); }
  table.data.stack td.actions-cell { justify-content: flex-start; padding-top: 8px; }
  table.data.stack td.actions-cell::before { content: none; }
  /* جدول الإنتاجية يبقى قابلاً للقراءة على الهاتف من دون تمرير أفقي. */
  table.data.employee-table thead { display: none; }
  table.data.employee-table, table.data.employee-table tbody, table.data.employee-table tfoot { display: block; }
  table.data.employee-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  table.data.employee-table td { display: flex; flex-direction: column; gap: 2px; padding: 0; border: 0; text-align: right; font-size: var(--fs-15); }
  table.data.employee-table td::before { content: attr(data-label); color: var(--ink-3); font-size: var(--fs-12); font-weight: 400; }
  table.data.employee-table tbody td:first-child, table.data.employee-table tfoot td:first-child { grid-column: 1 / -1; }
  table.data.employee-table tfoot tr { background: var(--surface-2); border-bottom: 0; }
}

@media print {
  .shell { display: block; }
  .sidebar, .topbar-actions, .toolbar .no-print { display: none !important; }
  .topbar { position: static; border: 0; padding: 0 0 10px; }
  .view { padding: 0; max-width: none; }
  .panel, .figures { break-inside: avoid; }
}
