/* ==========================================================================
   NQ57 METHODOLOGY EXPLORER — APP SHELL LAYOUT
   Sidebar (trái) + Header + Workspace + Panel "HIỂU PHƯƠNG PHÁP" (phải)
   ========================================================================== */

html, body { height: 100%; }
body.shell { overflow: hidden; }

.shell-root {
  display: grid;
  grid-template-columns: 250px 1fr 340px;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "sidebar header header"
    "sidebar main explain";
  height: 100vh;
}
.shell-root.explain-collapsed {
  grid-template-columns: 250px 1fr 0px;
}
.shell-root.explain-collapsed .explain-panel { display: none; }

/* ---------- Sidebar ---------- */
.shell-sidebar {
  grid-area: sidebar;
  background: #0f2744;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1e3a5f;
  overflow-y: auto;
}
.shell-brand {
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.shell-brand .brand-badge {
  display: inline-block;
  background: #b91c1c;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}
.shell-brand .brand-title {
  font-size: 13px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.3;
}
.shell-brand .brand-sub {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}
.shell-nav { padding: 8px 0; flex: 1; }
.shell-nav .nav-group {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #64748b;
  padding: 10px 16px 4px;
  text-transform: uppercase;
}
.shell-nav a.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 12.5px;
  border-left: 3px solid transparent;
}
.shell-nav a.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.shell-nav a.nav-item.active {
  background: rgba(29,78,216,0.35);
  border-left-color: #60a5fa;
  color: #fff;
  font-weight: 600;
}
.shell-nav .nav-num {
  width: 22px;
  height: 20px;
  border: 1px solid #334155;
  border-radius: 3px;
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  flex-shrink: 0;
}
.shell-nav a.nav-item.active .nav-num { border-color: #60a5fa; color: #bfdbfe; }
.shell-nav .nav-hint {
  margin-left: auto;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  color: #94a3b8;
}
.nav-sub-head { font-size: 10px; font-weight: 700; letter-spacing: 0.4px; color: #64748b; padding: 6px 16px 2px 30px; text-transform: uppercase; }
.shell-nav a.nav-item.lab { font-size: 12px; color: #94a3b8; padding: 5px 14px 5px 30px; }
.shell-nav a.nav-item.lab .nav-num { width: 10px; border: 0; font-size: 12px; }
.nav-lab-more { font-size: 10.5px; color: #64748b; padding: 6px 16px 4px 46px; line-height: 1.6; }
.nav-lab-more a { color: #93c5fd; text-decoration: none; }
.nav-lab { border-left: 2px solid rgba(255,255,255,0.08); margin-left: 24px; }
body:not(.role-admin) .nav-lab { display: none; }
body:not(.role-admin) .admin-only { display: none !important; }
.role-select { border: 1px solid var(--border-color); border-radius: 4px; font-size: 11.5px; padding: 3px 6px; background: #fff; }

/* Chế độ kiểm tra kỹ thuật (Diagnostic Mode): nhãn nội bộ, mã quyết định, công cụ giải thích chỉ hiện khi bật.
   Màn công cụ phương pháp (layer-2) luôn hiện đầy đủ. */
body.layer-1:not(.diag-mode) .diag,
body.layer-1:not(.diag-mode) .tag-demo, body.layer-1:not(.diag-mode) .tag-canon, body.layer-1:not(.diag-mode) .tag-proposal,
body.layer-1:not(.diag-mode) .tag-legacy, body.layer-1:not(.diag-mode) .tag-od, body.layer-1:not(.diag-mode) .tag-rule,
body.layer-1:not(.diag-mode) .tag-conflict, body.layer-1:not(.diag-mode) [data-od-tag],
body.layer-1:not(.diag-mode) .task-header-card .tag-demo,
body.layer-1:not(.diag-mode) .explain-badge, body.layer-1:not(.diag-mode) .explain-inline { display: none !important; }
body.layer-1:not(.diag-mode) .shell-root { grid-template-columns: 250px 1fr 0px; }
body.layer-1:not(.diag-mode) .explain-panel { display: none; }
body.layer-1:not(.diag-mode) [data-explain]:hover { outline: none; }
body:not(.diag-mode) .mode-toggle.diag, body:not(.diag-mode) #explain-open.diag { display: none; }
body.diag-mode .diag { display: inline; }
.zone-cap { font-size: 10.5px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase; color: #64748b; margin: 14px 0 6px; padding-left: 2px; border-left: 3px solid #cbd5e1; padding-left: 8px; }
.zone-cap.a1 { border-left-color: var(--axis1); color: var(--axis1); }
.zone-cap.a2 { border-left-color: var(--axis2); color: var(--axis2); }
details.zone-e { border: 1px dashed var(--border-color); border-radius: 6px; padding: 8px 12px; background: #fff; margin-top: 12px; }
details.zone-e summary { cursor: pointer; font-size: 12px; font-weight: 800; color: var(--text-secondary); }
.term { border-bottom: 1px dotted #94a3b8; cursor: help; }
.shell-sidebar-foot {
  padding: 10px 16px;
  font-size: 10.5px;
  color: #64748b;
  border-top: 1px solid rgba(255,255,255,0.08);
  line-height: 1.5;
}

/* ---------- Header ---------- */
.shell-header {
  grid-area: header;
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  z-index: 20;
}
.shell-header .hdr-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}
.shell-header .hdr-crumb {
  font-size: 12px;
  color: var(--text-muted);
}
.shell-header .hdr-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  font-size: 11.5px;
}
.mode-toggle button {
  border: 0;
  background: #fff;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 600;
}
.mode-toggle button.active {
  background: #1d4ed8;
  color: #fff;
}
.hdr-obs {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  padding: 3px 8px;
  border-radius: 3px;
}
.impact-banner {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--od-bg);
  border: 1px solid var(--od-border);
  color: var(--od);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
}
body.impact-mode .impact-banner { display: inline-flex; }
.impact-banner button {
  border: 1px solid var(--od-border);
  background: #fff;
  color: var(--od);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
}

/* ---------- Workspace ---------- */
.shell-main {
  grid-area: main;
  overflow-y: auto;
  background: var(--bg-app);
  padding: 18px 22px 40px;
}
.screen-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}
.screen-head h2 {
  font-size: 19px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}
.screen-head .screen-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 4px;
  max-width: 900px;
}
.screen-head .screen-badges {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------- Explain panel ---------- */
.explain-panel {
  grid-area: explain;
  background: #fff;
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.explain-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 2;
}
.explain-head .ex-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #1e3a8a;
}
.explain-head .ex-close {
  margin-left: auto;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  cursor: pointer;
}
.explain-body { padding: 12px 14px 24px; font-size: 12.5px; }
.explain-body h3 {
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.explain-body .ex-key {
  font-family: monospace;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.explain-body dl { margin: 0; }
.explain-body dt {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #475569;
  margin-top: 10px;
  padding-bottom: 2px;
  border-bottom: 1px dashed var(--border-light);
}
.explain-body dt.wrong { color: var(--critical); }
.explain-body dt.od { color: var(--od); }
.explain-body dd { margin: 4px 0 0; line-height: 1.5; color: var(--text-primary); }
.explain-body dd code { font-size: 11px; background: #f1f5f9; padding: 0 3px; border-radius: 2px; }
.explain-body .ex-src { font-size: 11px; color: var(--text-muted); }
.explain-body .ex-empty { color: var(--text-muted); font-style: italic; }
.explain-body ul { margin: 4px 0 0 16px; }

/* Explain badges injected on components */
.explain-badge {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #1d4ed8;
  background: #fff;
  color: #1d4ed8;
  font-weight: 800;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  z-index: 5;
  box-shadow: var(--shadow-sm);
}
body.explain-mode .explain-badge { display: inline-block; }
body.explain-mode [data-explain] { position: relative; }
body.explain-mode [data-explain]:hover { outline: 1px dashed #93c5fd; outline-offset: 2px; }
.explain-badge:hover { background: #1d4ed8; color: #fff; }
.explain-inline {
  display: none;
  margin-left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #1d4ed8;
  color: #1d4ed8;
  font-size: 10px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  vertical-align: middle;
}
body.explain-mode .explain-inline { display: inline-block; }

/* Impact mode highlight */
.od-impact {
  outline: 2px solid var(--od-border) !important;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(245,158,11,0.18) !important;
  position: relative;
}
.od-impact::after {
  content: attr(data-od-hit);
  position: absolute;
  top: -9px;
  left: 8px;
  background: var(--od);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 3px;
  z-index: 6;
}

/* Responsive: gọn hơn dưới 1280 */
@media (max-width: 1280px) {
  .shell-root { grid-template-columns: 220px 1fr 300px; }
}
@media (max-width: 1024px) {
  .shell-root { grid-template-columns: 200px 1fr 0px; }
  .explain-panel { display: none; }
}
