/*
 * Abertay admin shell redesign
 * Scoped to the signed-in shell under #root. No page content or behaviour is
 * supplied by this stylesheet. The menu control must continue to update
 * data-at-menu and its own accessible name/expanded state in the shell script.
 */

html[data-at-admin='shell'] #root {
  --at-canvas: #edf8f3;
  --at-canvas-deep: #d9f1e7;
  --at-white: #ffffff;
  --at-ink: #173c35;
  --at-muted: #66827a;
  --at-line: #dcece4;
  --at-green: #147a57;
  --at-green-dark: #0a6049;
  --at-mint: #e5f6ed;
  --at-focus: #15966c;
  --at-shadow: 0 12px 32px rgba(22, 91, 70, 0.07);
  color: var(--at-ink);
  isolation: isolate;
}

/* Shell grid. The feature/update bar above #root is deliberately untouched. */
html[data-at-admin='shell'] #root > div.min-h-screen {
  display: grid;
  grid-template-columns: 285px minmax(0, 1fr);
  grid-template-rows: 70px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(145deg, #f3fbf7 0%, var(--at-canvas) 46%, var(--at-canvas-deep) 100%);
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex {
  display: contents !important;
}

/* Compact top bar; no high stacking layer that could cover an update bar. */
html[data-at-admin='shell'] #root > div.min-h-screen > header {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  top: auto;
  z-index: auto;
  min-width: 0;
  margin: 12px 22px 4px 16px;
  border: 1px solid rgba(213, 235, 224, 0.95);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(25, 91, 70, 0.06);
}

html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 52px;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 8px 14px;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex > div:first-of-type {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 10px;
  min-width: 0;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex > div:last-of-type {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-width: 0;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header img[src*='logo-admin'] {
  display: none;
  width: auto;
  max-width: 118px;
  max-height: 30px;
  object-fit: contain;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header a {
  color: var(--at-green-dark);
  text-decoration-color: rgba(20, 122, 87, 0.35);
  text-underline-offset: 3px;
}

html[data-at-admin='shell'] #root #at-admin-menu-toggle {
  display: inline-flex;
  position: relative;
  z-index: 3;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 40px;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid #d4eade;
  border-radius: 11px;
  background: #f2faf6;
  color: var(--at-green-dark);
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

html[data-at-admin='shell'] #root #at-admin-menu-toggle:hover {
  border-color: #a9d9c2;
  background: #e2f5eb;
}

html[data-at-admin='shell'] #root #at-admin-menu-toggle:active {
  transform: scale(0.96);
}

/* Sidebar remains independently scrollable and keeps every label available. */
html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: start;
  position: sticky;
  top: 0;
  z-index: auto;
  box-sizing: border-box;
  width: 285px !important;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-right: 1px solid var(--at-line);
  background: var(--at-white);
  box-shadow: 8px 0 24px rgba(30, 97, 74, 0.035);
  transition: transform 200ms ease, visibility 200ms ease;
  scrollbar-width: thin;
  scrollbar-color: #b9ddcb transparent;
}

html[data-at-admin='shell'] #root #at-admin-brand {
  display: flex;
  position: relative;
  align-items: center;
  gap: 12px;
  min-height: 94px;
  box-sizing: border-box;
  margin: 0 16px;
  padding: 20px 8px;
  border-bottom: 1px solid #e7f1eb;
  color: var(--at-muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

html[data-at-admin='shell'] #root #at-admin-brand img {
  display: block;
  flex: 0 1 auto;
  width: auto;
  max-width: 150px;
  max-height: 48px;
  object-fit: contain;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside nav {
  padding: 16px 12px 24px;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside nav > div {
  margin-bottom: 9px;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #5a786e;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside nav button:hover {
  background: #eff9f3;
  color: var(--at-green-dark);
}

/* The explicit IDs also cover injected entries if they sit outside nav. */
html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link) {
  display: flex;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  min-width: 0;
  min-height: 40px;
  margin: 2px 0;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #42685b;
  font-size: 0.875rem;
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

/* Inline colours/backgrounds otherwise win over author styles. Do not override
   inline display, sizing or text, so injected navigation remains accessible. */
html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link)[style] {
  border-color: transparent !important;
  background: transparent !important;
  color: #42685b !important;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link):hover {
  background: #eaf8f0;
  color: var(--at-green-dark);
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link)[style]:hover {
  background: #eaf8f0 !important;
  color: var(--at-green-dark) !important;
}

/* Common semantic and utility-class active states; no route or label is invented. */
html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link):is([aria-current='page'], [aria-current='true'], [data-active='true'], [data-state='active'], .active, [class~='bg-blue-50'], [class~='bg-blue-100'], [class~='bg-green-50'], [class~='bg-emerald-50'], [class~='bg-teal-50'], [class~='bg-teal-600'], [class~='bg-gray-100']) {
  border-color: transparent;
  background: linear-gradient(110deg, #168d5f, #087d76);
  color: #fff;
  box-shadow: 0 7px 16px rgba(15, 127, 91, 0.18);
  font-weight: 650;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a:not(:has(> a)), #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link)[style]:is([aria-current='page'], [aria-current='true'], [data-active='true'], [data-state='active'], .active, [class~='bg-blue-50'], [class~='bg-blue-100'], [class~='bg-green-50'], [class~='bg-emerald-50'], [class~='bg-teal-50'], [class~='bg-teal-600'], [class~='bg-gray-100']) {
  background: linear-gradient(110deg, #168d5f, #087d76) !important;
  color: #fff !important;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a, nav button, #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link) svg {
  flex-shrink: 0;
  color: inherit;
}

/* Main content: card treatment is shared, typography changes are restrained. */
html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 42px) 48px;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main [data-slot='card'] {
  min-width: 0;
  border: 1px solid #e0eee6;
  border-radius: 17px;
  background: var(--at-white);
  box-shadow: var(--at-shadow);
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main :is(h1, h2, h3) {
  color: var(--at-ink);
  letter-spacing: -0.025em;
}

html[data-at-admin='shell'][data-at-dashboard='true'] #root > div.min-h-screen > header + div.flex > main > div:first-child > h1 {
  margin-bottom: 8px;
  font-size: clamp(1.9rem, 3.3vw, 2.8rem);
  font-weight: 750;
  line-height: 1.12;
  letter-spacing: -0.04em;
}

html[data-at-admin='shell'][data-at-dashboard='true'] #root > div.min-h-screen > header + div.flex > main > div:first-child > p:first-of-type {
  max-width: 65ch;
  color: var(--at-muted);
  line-height: 1.6;
}

html[data-at-admin='shell'][data-at-dashboard='true'] #root #at-admin-example-note {
  margin: 12px 0 20px;
  color: var(--at-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Only the six-card dashboard grid is normalized; other grids keep their layout. */
html[data-at-admin='shell'][data-at-dashboard='true'] #root > div.min-h-screen > header + div.flex > main > div:first-child > .grid:has(> [data-slot='card']:nth-child(6)) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main [data-slot='table-container'] {
  max-width: 100%;
  overflow-x: auto;
}

html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main :is(input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']):not([type='file']):not([type='button']):not([type='submit']):not([type='reset']), select, textarea) {
  border-color: #d4e7dc;
  border-radius: 9px;
}

html[data-at-admin='shell'] #root :is(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--at-focus);
  outline-offset: 3px;
}

/* Desktop collapse is an off-canvas drawer rather than hiding link labels. */
@media (min-width: 901px) {
  html[data-at-admin='shell'][data-at-menu='collapsed'] #root > div.min-h-screen {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  html[data-at-admin='shell'][data-at-menu='collapsed'] #root > div.min-h-screen > header + div.flex > aside {
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-105%);
  }
}

@media (max-width: 900px) {
  html[data-at-admin='shell'] #root > div.min-h-screen {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  html[data-at-admin='shell'] #root > div.min-h-screen > header {
    grid-column: 1;
    grid-row: 1;
    margin: 10px 14px 0;
  }

  html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex {
    height: auto;
  }

  html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside {
    position: fixed !important;
    top: 0 !important;
    left: 0;
    z-index: 2;
    width: min(285px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px);
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-105%);
    box-shadow: 12px 0 36px rgba(17, 72, 53, 0.14);
  }

  html[data-at-admin='shell'][data-at-menu='open'] #root > div.min-h-screen > header + div.flex > aside {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
  }

  /* A separate in-drawer close button remains accessible when the drawer overlays the header. */
  html[data-at-admin='shell'][data-at-menu='open'] #root #at-admin-brand { padding-right: 52px; }
  html[data-at-admin='shell'][data-at-menu='open'] #root #at-admin-brand .at-brand-caption { display: none; }
  html[data-at-admin='shell'][data-at-menu='open'] #root .at-admin-menu-close { display: inline-flex; }

  html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > main {
    grid-column: 1;
    grid-row: 2;
    padding: 26px 18px 40px;
  }

  html[data-at-admin='shell'][data-at-dashboard='true'] #root > div.min-h-screen > header + div.flex > main > div:first-child > .grid:has(> [data-slot='card']:nth-child(6)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  html[data-at-admin='shell'] #root > div.min-h-screen > header > div.flex > div:last-of-type {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  html[data-at-admin='shell'] #root > div.min-h-screen > header img[src*='logo-admin'] {
    max-width: 105px;
    max-height: 28px;
  }

  html[data-at-admin='shell'][data-at-dashboard='true'] #root > div.min-h-screen > header + div.flex > main > div:first-child > .grid:has(> [data-slot='card']:nth-child(6)) {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-at-admin='shell'] #root #at-admin-menu-toggle,
  html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside,
  html[data-at-admin='shell'] #root > div.min-h-screen > header + div.flex > aside :is(nav a, nav button, #course-register-nav-link, #at-perf-sidebar-link, #staff-leave-side-link) {
    transition: none;
  }
}

/* Existing React navigation has a wrapper anchor around each visual anchor. */
html[data-at-admin='shell'] #root aside nav a:has(> a) { display:block; margin:0; padding:0; color:inherit; text-decoration:none; }
html[data-at-admin='shell'] #root #at-admin-brand .at-brand-caption { display:flex; flex-direction:column; gap:4px; white-space:nowrap; }
html[data-at-admin='shell'] #root #at-admin-brand strong { width:max-content; border-radius:5px; padding:2px 6px; background:#e3f5ea; color:#176949; font-size:10px; letter-spacing:.08em; }
html[data-at-admin='shell'][data-at-dashboard='true'] #root main > div:first-child > h1::before { content:'ABERTAY TRAINING · ADMIN OVERVIEW'; display:block; margin-bottom:12px; color:#398467; font-family:Inter,system-ui,sans-serif; font-size:11px; font-weight:800; letter-spacing:.13em; }
html[data-at-admin='shell'] #root #at-admin-menu-toggle .at-menu-icon { font-size:16px; line-height:1; }

html[data-at-admin='shell'] #root .at-admin-menu-close { display:none; position:absolute; right:0; top:26px; align-items:center; justify-content:center; width:40px; height:40px; border:1px solid #d4eade; border-radius:10px; background:#f2faf6; color:#0a6049; font-size:25px; cursor:pointer; }
@media(max-width:900px) { html[data-at-admin='shell'][data-at-menu='open'] #root .at-admin-menu-close { display:inline-flex; } }
/* The pre-existing feature bar has its own z-index; only raise the root while the phone drawer is open. */
@media (max-width: 900px) {
  html[data-at-admin='shell'][data-at-menu='open'] #root { position: relative; z-index: 16; }
}
/* Course Registers is an independently rendered admin workspace, not the React shell. */
@media screen {
html[data-at-admin='register'] body { background: #edf8f3; }
html[data-at-admin='register'] #course-register-root { max-width: none; padding: 24px clamp(18px,3vw,42px) 48px; background: linear-gradient(145deg,#f3fbf7 0%,#edf8f3 48%,#d9f1e7 100%); color: #173c35; }
html[data-at-admin='register'] #at-register-toolbar { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:12px; min-height:52px; box-sizing:border-box; padding:10px 18px; margin-bottom:28px; border:1px solid #dcece4; border-radius:15px; background:#fff; box-shadow:0 8px 24px rgba(25,91,70,.06); color:#173c35; font-weight:750; }
html[data-at-admin='register'] #at-register-toolbar a { color:#0a6049; font-size:14px; font-weight:700; text-decoration:none; }
html[data-at-admin='register'] #at-register-toolbar a:hover { text-decoration:underline; }
html[data-at-admin='register'] #course-register-root .cr-top { flex-wrap:wrap; align-items:center; }
html[data-at-admin='register'] #course-register-root .cr-top > div:first-child { flex:1 1 360px; }
html[data-at-admin='register'] #course-register-root :is(.cr-top h1,.cr-card h2) { color:#173c35; letter-spacing:-.025em; }
html[data-at-admin='register'] #course-register-root .cr-card { border:1px solid #e0eee6; border-radius:17px; box-shadow:0 12px 32px rgba(22,91,70,.07); }
html[data-at-admin='register'] #course-register-root :is(.cr-field input,.cr-field select,.cr-field textarea) { border-color:#d4e7dc; border-radius:9px; }
html[data-at-admin='register'] #course-register-root :is(a,button,input,select,textarea):focus-visible { outline:3px solid #15966c; outline-offset:3px; }
}
@media print { html[data-at-admin='register'] #at-register-toolbar { display:none; } }

/* Other standalone workspaces have their own controls and navigation; theme only their surfaces. */
@media screen {
  #root > #acq-dashboard { background:linear-gradient(145deg,#f3fbf7 0%,#edf8f3 48%,#d9f1e7 100%); color:#173c35; }
  #root > #acq-dashboard :is(.acq-card,.acq-metric) { border-color:#e0eee6; border-radius:17px; box-shadow:0 12px 32px rgba(22,91,70,.07); }
  #root > #acq-dashboard .acq-top h1 { color:#173c35; letter-spacing:-.025em; }
  #root:has(> #per-manual-manager-20260519) { min-height:100vh; background:linear-gradient(145deg,#f3fbf7 0%,#edf8f3 48%,#d9f1e7 100%); }
  #root > #per-manual-manager-20260519 .manual-card { border-color:#e0eee6; border-radius:17px; box-shadow:0 12px 32px rgba(22,91,70,.07); }
  #root > #per-manual-manager-20260519 .pm-head h1 { color:#173c35; letter-spacing:-.025em; }
  #root:has(> #tmse) { min-height:100vh; background:linear-gradient(145deg,#f3fbf7 0%,#edf8f3 48%,#d9f1e7 100%); }
  #root > #tmse .tmse-card { border-color:#e0eee6; border-radius:17px; box-shadow:0 12px 32px rgba(22,91,70,.07); }
}
