/* MS Dynamics 365 Navigation Component — v3 */
/* ============================================================
   ROOT VARIABLES
   ============================================================ */
:root {
  --ms-blue: #0078d4;
  --ms-blue-dark: #005a9e;
  --ms-blue-light: #deecf9;
  --ms-topbar-bg: #1b1b1b;
  --ms-topbar-h: 44px;
  --ms-sidebar-w: 240px;
  --ms-sidebar-mini-w: 200px;
  --ms-sidebar-icon-w: 48px;
  --ms-sidebar-bg: #ffffff;
  --ms-border: #e0e0e0;
  --ms-hover: #f3f2f1;
  --ms-active-bg: #deecf9;
  --ms-text: #323130;
  --ms-muted: #605e5c;
  --ms-icon: #8a8886;
  --ms-shadow: 0 4px 20px rgba(0,0,0,0.15);
  --ms-t: 0.2s ease;
  --ms-t-slow: 0.28s cubic-bezier(0.4,0,0.2,1);
  --sidebar-current-w: var(--ms-sidebar-w);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--ms-text);
  background: #faf9f8;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* Focus visible ring */
:focus-visible {
  outline: 2px solid var(--ms-blue);
  outline-offset: 1px;
  border-radius: 2px;
}

/* ============================================================
   SKIP LINK (Accessibility)
   ============================================================ */
.skip-link {
  position: fixed;
  top: -999px; left: 8px;
  background: var(--ms-blue);
  color: #fff;
  padding: 6px 14px;
  border-radius: 2px;
  font-size: 13px;
  z-index: 9999;
  transition: top 0.15s;
}
.skip-link:focus { top: 8px; }

/* ============================================================
   TOP BAR
   ============================================================ */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--ms-topbar-h);
  background: var(--ms-topbar-bg);
  display: flex;
  align-items: center;
  z-index: 1100;
  gap: 0;
}

/* Hamburger */
.topbar-ham {
  width: 48px;
  height: var(--ms-topbar-h);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: rgba(255,255,255,0.85);
  font-size: 18px;
  flex-shrink: 0;
  transition: background var(--ms-t);
  border: none; background: transparent;
  border-radius: 0;
}
.topbar-ham:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Brand */
.topbar-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px 0 4px;
  flex-shrink: 0;
}
.ms-logo {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  width: 16px; height: 16px;
}
.ms-logo span { display: block; }
.ms-logo span:nth-child(1) { background: #f25022; }
.ms-logo span:nth-child(2) { background: #7fba00; }
.ms-logo span:nth-child(3) { background: #00a4ef; }
.ms-logo span:nth-child(4) { background: #ffb900; }
.topbar-divider { width: 1px; height: 18px; background: rgba(255,255,255,0.2); }
.topbar-appname {
  color: rgba(255,255,255,0.9);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}
.topbar-appname strong { font-weight: 600; }

/* TOP NAV */
#topnav {
  display: flex; align-items: stretch;
  height: 100%;
  flex: 1;
  overflow: visible;
  position: relative;
}

.tn-item {
  position: static;
  height: 100%;
  display: flex; align-items: center;
}

.tn-btn {
  display: flex; align-items: center; gap: 4px;
  height: 100%;
  padding: 0 13px;
  color: rgba(255,255,255,0.82);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
  border: none; background: transparent;
  border-bottom: 2px solid transparent;
  transition: color var(--ms-t), background var(--ms-t), border-color var(--ms-t);
  position: relative;
}
.tn-btn .bi-chevron-down { font-size: 10px; opacity: 0.6; transition: transform var(--ms-t); }
.tn-btn:hover, .tn-btn[aria-expanded="true"] {
  color: #fff;
  background: rgba(255,255,255,0.08);
  border-bottom-color: var(--ms-blue);
}
.tn-btn[aria-expanded="true"] .bi-chevron-down { transform: rotate(180deg); }
.tn-btn.active { color: #fff; border-bottom-color: #fff; }

/* DROPDOWN */
.tn-dropdown {
  position: fixed;
  top: var(--ms-topbar-h);
  background: #fff;
  border: 1px solid var(--ms-border);
  border-top: 2px solid var(--ms-blue);
  box-shadow: var(--ms-shadow);
  min-width: 220px;
  z-index: 1200;
  padding: 6px 0;
  border-radius: 0 0 3px 3px;
  /* Animation */
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  display: block !important;
}
.tn-dropdown.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.dd-header {
  padding: 8px 16px 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ms-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  color: var(--ms-text);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--ms-t);
  white-space: nowrap;
  border: none; background: none; width: 100%; text-align: left;
}
.dd-item i { color: var(--ms-icon); font-size: 15px; width: 16px; flex-shrink: 0; }
.dd-item:hover { background: var(--ms-hover); }
.dd-sep { border: none; border-top: 1px solid var(--ms-border); margin: 5px 0; }

/* MEGA MENU */
.tn-mega {
  position: fixed;
  top: var(--ms-topbar-h);
  background: #fff;
  border: 1px solid var(--ms-border);
  border-top: 2px solid var(--ms-blue);
  box-shadow: var(--ms-shadow);
  width: min(720px, 96vw);
  z-index: 1200;
  padding: 20px 24px;
  border-radius: 0 0 3px 3px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  display: block !important;
}
.tn-mega.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.mega-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.mega-col-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ms-blue);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid #e8e8e8;
}
.mega-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 7px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background var(--ms-t);
  border: none; background: none; width: 100%; text-align: left;
}
.mega-item:hover { background: var(--ms-hover); }
.mega-icon {
  width: 30px; height: 30px;
  background: var(--ms-blue-light);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.mega-icon i { color: var(--ms-blue); font-size: 14px; }
.mega-title { font-size: 13px; font-weight: 500; line-height: 1.3; color: var(--ms-text); }
.mega-desc { font-size: 11px; color: var(--ms-muted); margin-top: 1px; }

/* Mobile mega layout */
@media (max-width: 600px) {
  .mega-grid { grid-template-columns: 1fr; gap: 12px; }
}

/* RIGHT TOOLS */
.topbar-tools {
  display: flex; align-items: center;
  margin-left: auto;
  padding-right: 6px;
  gap: 0;
  flex-shrink: 0;
  position: relative;
}

/* Search bar */
.tb-search {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 2px;
  height: 28px;
  padding: 0 10px;
  margin-right: 6px;
  transition: background var(--ms-t), border-color var(--ms-t), width 0.3s ease;
  width: 170px;
}
.tb-search:focus-within {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.35);
}
.tb-search i { color: rgba(255,255,255,0.65); font-size: 13px; flex-shrink: 0; }
.tb-search input {
  background: none; border: none; outline: none;
  color: #fff; font-size: 13px;
  width: 100%;
  font-family: inherit;
}
.tb-search input::placeholder { color: rgba(255,255,255,0.45); }

/* Keyboard shortcut badge */
.kb-badge {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 2px;
  padding: 1px 4px;
  white-space: nowrap;
}

/* Quick search dropdown */
.quick-search-panel {
  position: fixed;
  top: var(--ms-topbar-h);
  right: 56px;
  width: 340px;
  background: #fff;
  border: 1px solid var(--ms-border);
  border-top: 2px solid var(--ms-blue);
  box-shadow: var(--ms-shadow);
  z-index: 1300;
  display: none;
  border-radius: 0 0 3px 3px;
}
.quick-search-panel.open { display: block; }
.qs-header {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ms-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.qs-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background var(--ms-t);
  font-size: 13px;
}
.qs-item:hover { background: var(--ms-hover); }
.qs-item i { color: var(--ms-icon); font-size: 15px; }

/* Icon button */
.tb-btn {
  width: 36px; height: var(--ms-topbar-h);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 16px;
  transition: background var(--ms-t), color var(--ms-t);
  border: none; background: transparent;
  position: relative;
}
.tb-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.notif-dot {
  position: absolute;
  top: 8px; right: 5px;
  width: 8px; height: 8px;
  background: #ff4343;
  border-radius: 50%;
  border: 1.5px solid var(--ms-topbar-bg);
}
.tb-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--ms-blue);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 600;
  cursor: pointer;
  margin: 0 7px;
  flex-shrink: 0;
  border: none;
}
.tb-avatar:hover { opacity: 0.9; }

/* Notif & profile panels */
.topbar-panel {
  position: fixed;
  top: var(--ms-topbar-h); right: 0;
  background: #fff;
  border: 1px solid var(--ms-border);
  border-top: 2px solid var(--ms-blue);
  box-shadow: var(--ms-shadow);
  z-index: 1200;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  display: block !important;
  border-radius: 0 0 3px 3px;
}
.topbar-panel.is-open { opacity: 1; transform: translateY(0); pointer-events: auto; }
#notifPanel { width: 330px; }
#profilePanel { width: 280px; }

.panel-header {
  padding: 12px 16px;
  font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--ms-border);
  display: flex; justify-content: space-between; align-items: center;
}
.panel-link { font-size: 12px; color: var(--ms-blue); font-weight: 400; cursor: pointer; border: none; background: none; }
.notif-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 16px;
  border-bottom: 1px solid #f3f2f1;
  cursor: pointer;
  transition: background var(--ms-t);
}
.notif-item:last-child { border: none; }
.notif-item:hover { background: var(--ms-hover); }
.notif-dot2 { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.notif-text { font-size: 12px; line-height: 1.5; }
.notif-time { font-size: 11px; color: var(--ms-muted); margin-top: 2px; }
.panel-footer { padding: 10px 16px; border-top: 1px solid var(--ms-border); text-align: center; }
.panel-footer a { font-size: 13px; color: var(--ms-blue); }

.profile-head {
  padding: 16px;
  display: flex; gap: 12px; align-items: center;
  border-bottom: 1px solid var(--ms-border);
}
.profile-ava {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--ms-blue);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 600;
  flex-shrink: 0;
}
.profile-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.profile-email { font-size: 12px; color: var(--ms-muted); }
.profile-status { font-size: 11px; background: #dff6dd; color: #107c10; padding: 2px 8px; border-radius: 2px; display: inline-block; margin-top: 4px; }
.profile-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  font-size: 13px; color: var(--ms-text);
  cursor: pointer;
  transition: background var(--ms-t);
  border: none; background: none; width: 100%; text-align: left;
}
.profile-menu-item:hover { background: var(--ms-hover); }
.profile-menu-item i { color: var(--ms-icon); font-size: 15px; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  display: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#sidebar-overlay.active { display: block; opacity: 1; }

#sidebar {
  position: fixed;
  top: var(--ms-topbar-h); left: 0; bottom: 0;
  width: var(--ms-sidebar-w);
  background: var(--ms-sidebar-bg);
  border-right: 1px solid var(--ms-border);
  z-index: 1000;
  display: flex; flex-direction: column;
  transition: width var(--ms-t-slow), transform var(--ms-t-slow);
  overflow: hidden;
  will-change: width;
}
/* Resize handle */
.sidebar-resize {
  position: absolute;
  top: 0; right: -3px; bottom: 0;
  width: 6px;
  cursor: ew-resize;
  z-index: 10;
}
.sidebar-resize:hover::after,
.sidebar-resize.dragging::after {
  content: '';
  position: absolute;
  top: 0; left: 2px; bottom: 0;
  width: 2px;
  background: var(--ms-blue);
  opacity: 0.5;
}

/* Collapsed */
#sidebar.collapsed { width: var(--ms-sidebar-icon-w); }

/* Mobile: hidden by default, overlay-drawer */
@media (max-width: 900px) {
  #sidebar {
    transform: translateX(-100%);
    width: var(--ms-sidebar-w) !important;
    box-shadow: none;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
}

/* Toggle btn at top of sidebar */
.sb-toggle {
  height: 40px;
  display: flex; align-items: center;
  padding: 0 12px; gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  border: none; background: none; width: 100%;
  text-align: left;
  color: var(--ms-muted);
  transition: background var(--ms-t);
  border-bottom: 1px solid #f0f0f0;
}
.sb-toggle:hover { background: var(--ms-hover); }
.sb-toggle i { font-size: 16px; flex-shrink: 0; }
.sb-toggle span { font-size: 13px; font-weight: 500; color: var(--ms-text); white-space: nowrap; overflow: hidden; }

/* Scroll area */
.sb-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #c8c6c4 transparent;
}
.sb-scroll::-webkit-scrollbar { width: 4px; }
.sb-scroll::-webkit-scrollbar-track { background: transparent; }
.sb-scroll::-webkit-scrollbar-thumb { background: #c8c6c4; border-radius: 4px; }

/* Section headers */
.sb-section { margin: 8px 0 4px; }
.sb-section-lbl {
  height: 26px; display: flex; align-items: center;
  padding: 0 14px;
  font-size: 11px; font-weight: 700;
  color: var(--ms-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap; overflow: hidden;
  transition: opacity var(--ms-t);
}
#sidebar.collapsed .sb-section-lbl { opacity: 0; pointer-events: none; }

/* ---- L1 ---- */
.sb-l1 { position: relative; }

.sb-link-l1 {
  display: flex; align-items: center;
  height: 36px; padding: 0 10px 0 12px;
  gap: 10px;
  color: var(--ms-text);
  cursor: pointer;
  transition: background var(--ms-t), border-color var(--ms-t), color var(--ms-t);
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden;
  border: none; background: none; width: 100%; text-align: left;
  border-left: 2px solid transparent;
}
.sb-link-l1:hover { background: var(--ms-hover); }
.sb-link-l1.is-active {
  background: var(--ms-active-bg);
  border-left-color: var(--ms-blue);
  color: var(--ms-blue-dark);
}
.sb-icon {
  font-size: 16px; color: var(--ms-icon);
  flex-shrink: 0; width: 20px; text-align: center;
  transition: color var(--ms-t);
}
.sb-link-l1.is-active .sb-icon { color: var(--ms-blue); }
.sb-lbl { font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sb-chevron {
  font-size: 10px; color: var(--ms-icon);
  margin-left: auto; flex-shrink: 0;
  transition: transform 0.2s;
}
.sb-chevron.open { transform: rotate(90deg); }
.sb-badge {
  font-size: 10px; background: var(--ms-blue);
  color: #fff; border-radius: 10px;
  padding: 1px 6px; flex-shrink: 0;
}

/* Collapsed mode */
#sidebar.collapsed .sb-lbl,
#sidebar.collapsed .sb-chevron,
#sidebar.collapsed .sb-badge { display: none; }
#sidebar.collapsed .sb-link-l1 {
  justify-content: center; padding: 0;
  border-left: none;
}
#sidebar.collapsed .sb-link-l1.is-active {
  background: var(--ms-active-bg);
  position: relative;
}
#sidebar.collapsed .sb-link-l1.is-active::after {
  content: ''; position: absolute;
  left: 0; top: 4px; bottom: 4px; width: 3px;
  background: var(--ms-blue);
  border-radius: 0 2px 2px 0;
}

/* Tooltip in collapsed mode */
.sb-tooltip {
  position: fixed;
  left: calc(var(--ms-sidebar-icon-w) + 8px);
  background: #323130;
  color: #fff;
  padding: 5px 10px;
  border-radius: 3px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.sb-tooltip::before {
  content: '';
  position: absolute;
  left: -5px; top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-left: none;
  border-right-color: #323130;
}

/* ---- L2 ---- */
.sb-sub-l2 {
  max-height: 0; overflow: hidden;
  background: #faf9f8;
  border-left: 1px solid #e8e8e8;
  margin-left: 20px;
  transition: max-height 0.28s cubic-bezier(0.4,0,0.2,1);
}
.sb-sub-l2.open { max-height: 600px; }
#sidebar.collapsed .sb-sub-l2 { display: none !important; }

.sb-link-l2 {
  display: flex; align-items: center;
  height: 32px; padding: 0 8px 0 12px;
  gap: 8px;
  color: var(--ms-text); font-size: 13px;
  cursor: pointer;
  transition: background var(--ms-t), border-color var(--ms-t), color var(--ms-t);
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden;
  border: none; background: none; width: 100%; text-align: left;
  border-left: 2px solid transparent;
}
.sb-link-l2:hover { background: var(--ms-hover); }
.sb-link-l2.is-active {
  color: var(--ms-blue);
  background: var(--ms-active-bg);
  border-left-color: var(--ms-blue);
}
.sb-link-l2 .sb-icon { font-size: 14px; width: 16px; }
.sb-lbl-l2 { font-size: 13px; flex: 1; }
.sb-chevron-l2 {
  font-size: 10px; color: var(--ms-icon);
  margin-left: auto; flex-shrink: 0;
  transition: transform 0.2s;
}
.sb-chevron-l2.open { transform: rotate(90deg); }

/* ---- L3 ---- */
.sb-sub-l3 {
  max-height: 0; overflow: hidden;
  background: #f8f7f6;
  border-left: 1px solid #ddd;
  margin-left: 16px;
  transition: max-height 0.22s ease;
}
.sb-sub-l3.open { max-height: 300px; }

.sb-link-l3 {
  display: flex; align-items: center;
  height: 30px; padding: 0 8px 0 12px; gap: 6px;
  color: var(--ms-muted); font-size: 12px;
  cursor: pointer;
  transition: background var(--ms-t), color var(--ms-t), border-color var(--ms-t);
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden;
  border: none; background: none; width: 100%; text-align: left;
  border-left: 2px solid transparent;
}
.sb-link-l3:hover { background: var(--ms-hover); color: var(--ms-text); }
.sb-link-l3.is-active {
  color: var(--ms-blue);
  background: var(--ms-active-bg);
  border-left-color: var(--ms-blue);
}
.sb-lbl-l3 { font-size: 12px; flex: 1; }

/* Bottom items */
.sb-bottom {
  border-top: 1px solid var(--ms-border);
  padding: 6px 0;
  flex-shrink: 0;
}

/* ============================================================
   CONTENT
   ============================================================ */
#main-content {
  margin-top: var(--ms-topbar-h);
  margin-left: var(--ms-sidebar-w);
  transition: margin-left var(--ms-t-slow);
  min-height: calc(100vh - var(--ms-topbar-h));
  display: flex; flex-direction: column;
}
#main-content.collapsed { margin-left: var(--ms-sidebar-icon-w); }
@media (max-width: 900px) { #main-content { margin-left: 0 !important; } }

/* Sticky command bar area */
.content-header {
  position: sticky;
  top: var(--ms-topbar-h);
  background: #faf9f8;
  z-index: 50;
  padding: 0 24px;
  border-bottom: 1px solid var(--ms-border);
}

/* Breadcrumb */
.ms-bc {
  display: flex; align-items: center; gap: 5px;
  padding: 10px 0 6px;
  font-size: 12px; color: var(--ms-muted);
  flex-wrap: wrap;
}
.ms-bc a { color: var(--ms-blue); cursor: pointer; }
.ms-bc a:hover { text-decoration: underline; }
.ms-bc .sep { font-size: 9px; }

/* Command bar */
.ms-cmdbar {
  display: flex; align-items: center; gap: 3px;
  padding: 6px 0 8px;
  flex-wrap: wrap;
}
.ms-cmd {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border: none; background: transparent;
  color: var(--ms-text); font-size: 13px;
  cursor: pointer; border-radius: 2px;
  font-family: inherit;
  transition: background var(--ms-t);
  white-space: nowrap;
}
.ms-cmd:hover { background: #edebe9; }
.ms-cmd i { font-size: 15px; color: var(--ms-icon); }
.ms-cmd.primary { background: var(--ms-blue); color: #fff; }
.ms-cmd.primary:hover { background: var(--ms-blue-dark); }
.ms-cmd.primary i { color: rgba(255,255,255,0.85); }
.cmd-sep { width: 1px; height: 20px; background: var(--ms-border); margin: 0 3px; }

/* Page body */
.content-body {
  padding: 20px 24px 32px;
  flex: 1;
}

/* Page title area */
.ms-ph {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ms-border);
}
.ms-ph h1 { font-size: 20px; font-weight: 600; color: var(--ms-text); margin-bottom: 3px; }
.ms-ph p { font-size: 13px; color: var(--ms-muted); margin: 0; }

/* Content transition */
.content-body { transition: opacity 0.15s ease; }
.content-body.fading { opacity: 0; }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card {
  background: #fff;
  border: 1px solid var(--ms-border);
  border-radius: 2px;
  padding: 14px 18px;
  transition: box-shadow var(--ms-t);
}
.kpi-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.07); }
.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ms-muted); margin-bottom: 6px; }
.kpi-val { font-size: 26px; font-weight: 300; color: var(--ms-text); margin-bottom: 4px; }
.kpi-trend { font-size: 11px; display: inline-flex; align-items: center; gap: 2px; padding: 2px 6px; border-radius: 2px; }
.t-up { background: #dff6dd; color: #107c10; }
.t-dn { background: #fde7e9; color: #a80000; }

/* Table */
.ms-card { background: #fff; border: 1px solid var(--ms-border); border-radius: 2px; }
.ms-card-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--ms-border);
  display: flex; justify-content: space-between; align-items: center;
}
.ms-card-head-title { font-size: 14px; font-weight: 600; }
.ms-card-head a { font-size: 13px; color: var(--ms-blue); }
.ms-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.ms-tbl th {
  text-align: left;
  padding: 10px 14px;
  background: #f3f2f1;
  font-size: 12px; font-weight: 600; color: var(--ms-muted);
  border-bottom: 1px solid var(--ms-border);
  white-space: nowrap;
}
.ms-tbl td {
  padding: 10px 14px;
  border-bottom: 1px solid #f3f2f1;
  vertical-align: middle;
}
.ms-tbl tr:hover td { background: var(--ms-hover); }
.ms-tbl a { color: var(--ms-blue); }

/* Status badges */
.ms-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 2px;
  font-size: 11px; font-weight: 600;
}
.b-active { background: #dff6dd; color: #107c10; }
.b-pending { background: #fff4ce; color: #8a6914; }
.b-neutral { background: #f3f2f1; color: #605e5c; }

/* Progress bar */
.pb-wrap { display: flex; align-items: center; gap: 8px; }
.pb-bar { flex: 1; height: 4px; background: #e0e0e0; border-radius: 2px; min-width: 60px; }
.pb-fill { height: 100%; border-radius: 2px; }
.pb-lbl { font-size: 12px; color: var(--ms-muted); min-width: 28px; text-align: right; }

/* Skeleton loader */
.skel {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 2px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================
   MOBILE APP MENU (top nav inside sidebar, mobile only)
   ============================================================ */
.mob-appmenu { display: none; }

@media (max-width: 900px) {
  .mob-appmenu {
    display: block;
    border-bottom: 2px solid var(--ms-border);
    margin-bottom: 4px;
  }
  .mob-appmenu-header {
    height: 32px;
    display: flex; align-items: center;
    padding: 0 14px;
    font-size: 11px; font-weight: 700;
    color: var(--ms-blue);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: var(--ms-blue-light);
    gap: 6px;
  }
  .mob-appmenu-header i { font-size: 13px; }

  /* L1 item inside mobile app menu */
  .mob-l1-btn {
    display: flex; align-items: center;
    height: 40px; padding: 0 10px 0 14px; gap: 10px;
    width: 100%; text-align: left;
    border: none; background: none;
    font-family: inherit; font-size: 13px; font-weight: 500;
    color: var(--ms-text);
    cursor: pointer;
    transition: background var(--ms-t);
    border-left: 2px solid transparent;
    white-space: nowrap; overflow: hidden;
  }
  .mob-l1-btn:hover { background: var(--ms-hover); }
  .mob-l1-btn .sb-icon { font-size: 16px; color: var(--ms-icon); flex-shrink: 0; width: 20px; text-align: center; }
  .mob-l1-btn .mob-lbl { flex: 1; }
  .mob-l1-btn .mob-chv { font-size: 10px; color: var(--ms-icon); transition: transform 0.2s; flex-shrink: 0; }
  .mob-l1-btn .mob-chv.open { transform: rotate(90deg); }

  /* Sub panel — slides down */
  .mob-sub {
    max-height: 0; overflow: hidden;
    background: #f5f5f5;
    border-left: 2px solid var(--ms-blue-light);
    margin-left: 22px;
    transition: max-height 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  .mob-sub.open { max-height: 600px; }

  .mob-sub-item {
    display: flex; align-items: center; gap: 10px;
    height: 36px; padding: 0 12px;
    width: 100%; text-align: left;
    border: none; background: none;
    font-family: inherit; font-size: 13px;
    color: var(--ms-text);
    cursor: pointer;
    transition: background var(--ms-t);
    white-space: nowrap; overflow: hidden;
  }
  .mob-sub-item:hover { background: var(--ms-hover); }
  .mob-sub-item i { color: var(--ms-icon); font-size: 14px; flex-shrink: 0; }

  .mob-sub-header {
    padding: 8px 12px 3px;
    font-size: 10px; font-weight: 700;
    color: var(--ms-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
  }
  .mob-sub-sep { border: none; border-top: 1px solid #e0e0e0; margin: 4px 0; }

  /* Mega sub-group for mobile */
  .mob-mega-group-title {
    padding: 8px 12px 3px;
    font-size: 10px; font-weight: 700;
    color: var(--ms-blue);
    text-transform: uppercase; letter-spacing: 0.5px;
  }
}

/* ============================================================
   MOBILE OVERRIDES
   ============================================================ */
@media (max-width: 640px) {
  .tb-search { display: none; }
  .topbar-appname { display: none; }
  #topnav { display: none; }
  .content-body { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .ms-tbl th:nth-child(n+4), .ms-tbl td:nth-child(n+4) { display: none; }
}
@media (max-width: 900px) {
  .kb-badge { display: none; }
  #topnav { display: none; }
}

/* ============================================================
   PRINT
   ============================================================ */


/* URL Bar */
.url-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 8px;
  font-size: 12px; color: var(--ms-muted);
  font-family: 'Segoe UI', monospace;
}
.url-bar i { font-size: 12px; color: var(--ms-muted); flex-shrink: 0; }
.url-bar-text {
  color: var(--ms-blue); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============================================================
   DARK MODE — CSS Variables Override
   ============================================================ */
body.dark-mode {
  --ms-blue: #4da6ff;
  --ms-blue-dark: #82c0ff;
  --ms-blue-light: #1a3a52;
  --ms-topbar-bg: #111111;
  --ms-sidebar-bg: #1e1e1e;
  --ms-border: #3a3a3a;
  --ms-hover: #2a2a2a;
  --ms-active-bg: #1a3a52;
  --ms-text: #e8e8e8;
  --ms-muted: #a0a0a0;
  --ms-icon: #888888;
  --ms-shadow: 0 4px 20px rgba(0,0,0,0.5);
  background: #141414;
}

/* Topbar dark adjustment */
body.dark-mode #topbar { background: #111111; border-bottom: 1px solid #2a2a2a; }

/* Sidebar dark */
body.dark-mode #sidebar { background: var(--ms-sidebar-bg); }
body.dark-mode .sb-sub-l2 { background: #181818; }
body.dark-mode .sb-sub-l3 { background: #161616; }
body.dark-mode .sb-toggle { border-bottom-color: #2a2a2a; }
body.dark-mode .sb-bottom { border-top-color: #2a2a2a; }
body.dark-mode .sb-section-lbl { color: #666; }

/* Dropdowns & panels dark */
body.dark-mode .tn-dropdown,
body.dark-mode .tn-mega,
body.dark-mode .topbar-panel,
body.dark-mode .quick-search-panel {
  background: #1e1e1e;
  border-color: #3a3a3a;
}
body.dark-mode .dd-header,
body.dark-mode .mob-sub-header,
body.dark-mode .mob-mega-group-title { color: #888; }
body.dark-mode .dd-sep,
body.dark-mode .mob-sub-sep { border-color: #3a3a3a; }
body.dark-mode .panel-header { border-bottom-color: #3a3a3a; }
body.dark-mode .notif-item { border-bottom-color: #2a2a2a; }
body.dark-mode .panel-footer { border-top-color: #3a3a3a; }
body.dark-mode .profile-head { border-bottom-color: #3a3a3a; }
body.dark-mode hr[style*="border-top:1px solid var(--ms-border)"] { border-color: #3a3a3a !important; }

/* Content area dark */
body.dark-mode #main-content { background: #141414; }
body.dark-mode .content-header { background: #141414; border-bottom-color: #2a2a2a; }
body.dark-mode .ms-card,
body.dark-mode .kpi-card,
body.dark-mode .fn-block { background: #1e1e1e; border-color: #3a3a3a; }
body.dark-mode .ms-card-head { border-bottom-color: #2a2a2a; }
body.dark-mode .ms-tbl th { background: #252525; border-bottom-color: #3a3a3a; }
body.dark-mode .ms-tbl td { border-bottom-color: #252525; }
body.dark-mode .ms-tbl tr:hover td { background: #252525; }
body.dark-mode .ms-cmdbar { border-bottom-color: #2a2a2a; }
body.dark-mode .ms-cmd:hover { background: #2a2a2a; }
body.dark-mode .ms-ph { border-bottom-color: #2a2a2a; }
body.dark-mode .pb-bar { background: #3a3a3a; }
body.dark-mode .cmd-sep { background: #3a3a3a; }

/* Dark mode toggle button */
.dark-toggle {
  width: 36px; height: var(--ms-topbar-h);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.8);
  cursor: pointer; font-size: 16px;
  transition: background var(--ms-t), color var(--ms-t);
  border: none; background: transparent;
}
.dark-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Smooth theme transition */
body {
  transition: background 0.25s ease, color 0.25s ease;
}
#sidebar, #topbar, .tn-dropdown, .tn-mega, .topbar-panel,
.kpi-card, .ms-card, .content-header {
  transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* Mobile app menu dark */
body.dark-mode .mob-appmenu-header { background: #1a3a52; }
body.dark-mode .mob-sub { background: #1a1a1a; border-left-color: #2a2a2a; }

/* Sidebar overlay dark */
body.dark-mode #sidebar-overlay { background: rgba(0,0,0,0.65); }

/* Search bar dark */
body.dark-mode .tb-search { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.1); }

/* Badges */
body.dark-mode .ms-badge.b-active { background: #1a4a1a; color: #6fcf6f; }
body.dark-mode .ms-badge.b-pending { background: #3a2e00; color: #f0c040; }
body.dark-mode .ms-badge.b-neutral { background: #2a2a2a; color: #a0a0a0; }
body.dark-mode .kpi-trend.t-up { background: #1a4a1a; color: #6fcf6f; }
body.dark-mode .kpi-trend.t-dn { background: #4a1a1a; color: #f08080; }

/* URL bar dark */
body.dark-mode .url-bar { background: #1e1e1e; border-color: #3a3a3a; color: #e8e8e8; }


@media print {
  #topbar, #sidebar, #sidebar-overlay { display: none !important; }
  #main-content { margin: 0 !important; }
}