/* Shared theme controls, depth and touch navigation; semantic danger/warning stay distinct. */
body[data-school-theme] .main-sidebar.portal-school-sidebar{background:linear-gradient(160deg,var(--sdn-sidebar-start,#153b3f),var(--sdn-sidebar-end,#102e32))!important}
body[data-school-theme] .portal-school-sidebar .nav-link{position:relative;border:1px solid #ffffff13;background:linear-gradient(120deg,#ffffff09,#ffffff01);box-shadow:inset 0 1px #ffffff10,0 3px 6px #00000012;transition:transform .2s,box-shadow .2s,background .2s}
body[data-school-theme] .portal-school-sidebar .nav-link:hover{transform:translateX(3px);box-shadow:inset 0 1px #ffffff30,0 5px 12px #0003}
body[data-school-theme] .portal-school-sidebar .nav-link.active{background:var(--sdn-accent-gradient,linear-gradient(110deg,#246b60,#328373))!important;box-shadow:inset 0 2px #ffffff40,0 5px 14px #0004;color:#fff!important}
body[data-school-theme] :is(.btn-primary,.btn-info,.button:not(.button-ghost),.bos-tab-active){background:var(--sdn-accent-gradient,linear-gradient(110deg,#246b60,#328373))!important;border-color:var(--sdn-accent)!important;color:#fff!important;box-shadow:inset 0 1px #ffffff45,0 4px 10px #00000018;transition:transform .18s,box-shadow .18s}
body[data-school-theme] :is(.btn-primary,.btn-info,.button):hover{transform:translateY(-2px);box-shadow:inset 0 1px #ffffff60,0 6px 14px #0002}
body[data-school-theme] :is(.btn-outline-primary,.btn-outline-info){color:var(--sdn-accent-deep)!important;border-color:var(--sdn-accent)!important;background:var(--sdn-surface,#fff)}
body[data-school-theme] :is(.btn-outline-primary,.btn-outline-info):hover{background:var(--sdn-accent)!important;color:#fff!important}
body[data-school-theme] :is(.card-header,.promotion-summary span){background:var(--sdn-paper,#f5f8f3);color:var(--sdn-ink)}
.sdn4-mobile-nav button{border:0;background:transparent;font:inherit;display:flex;flex:1;align-items:center;justify-content:center;flex-direction:column;color:var(--sdn-muted,#52606d);font-size:.72rem;gap:4px}.sdn4-mobile-nav button i{font-size:1.2rem}
.school-public-mobile-nav{display:none}
.promotion-placement-dialog{border:1px solid var(--sdn-line,#ddd);border-radius:18px;padding:24px;width:min(94vw,520px);max-height:90dvh;overflow:auto;color:var(--sdn-ink);box-shadow:0 22px 70px #0004}.promotion-placement-dialog::backdrop{background:#102e3288;backdrop-filter:blur(4px)}.promotion-placement-dialog label{display:block;margin-top:14px}.promotion-placement-dialog button{margin:16px 8px 0 0}.promotion-placement-dialog h2{font-size:1.3rem}
@media(max-width:767.98px){body[data-school-theme]{padding-bottom:calc(76px + env(safe-area-inset-bottom))}.sdn4-mobile-nav,.school-public-mobile-nav{background:var(--sdn-surface,#fff)!important;border-top:1px solid var(--sdn-line,#ddd);box-shadow:0 -5px 24px #0001;padding-bottom:env(safe-area-inset-bottom);min-height:68px;z-index:1040}.school-public-mobile-nav{display:flex;position:fixed;bottom:0;left:0;right:0;justify-content:space-around;align-items:center}.school-public-mobile-nav a{display:flex;flex:1;flex-direction:column;align-items:center;gap:4px;padding:9px 4px;font-size:12px;color:var(--sdn-ink);text-decoration:none}.school-public-mobile-nav span{font-size:20px}.sdn4-mobile-nav a.active,.school-public-mobile-nav a.active{color:var(--sdn-accent-deep);background:var(--sdn-paper);border-radius:10px;box-shadow:inset 0 3px var(--sdn-accent)}body.sdn4-admin-theme .btn{white-space:normal;min-height:44px}body.sdn4-admin-theme .main-header .btn{font-size:12px;padding:7px 10px}.school-public-mobile-nav~*{scroll-margin-bottom:80px}}
@media(prefers-reduced-motion:no-preference){body[data-school-theme] .portal-school-sidebar .nav-link.active{animation:school-nav-gloss .6s ease-out}@keyframes school-nav-gloss{from{filter:brightness(1.4);transform:translateY(2px)}to{filter:brightness(1);transform:translateY(0)}}}
@media(prefers-reduced-motion:reduce){body[data-school-theme] *{scroll-behavior:auto!important}.portal-school-sidebar .nav-link,body[data-school-theme] .btn,body[data-school-theme] .button{transition:none!important;animation:none!important;transform:none!important}}
@media print{.sdn4-mobile-nav,.school-public-mobile-nav{display:none!important}body[data-school-theme]{padding-bottom:0}}

@media (max-width: 767.98px) {
  body.sdn4-public-theme .school-chat {
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 1041;
  }
  body.sdn4-public-theme .chat-panel {
    max-height: min(720px, calc(100dvh - 170px - env(safe-area-inset-bottom)));
  }
}

/* Admin palette accents keep text on the deeper stops and use the lighter shade for trim. */
@media screen {
  body.sdn4-admin-theme[data-school-theme] {
    --admin-accent:var(--sdn-accent);
    --admin-accent-deep:var(--sdn-accent-deep);
    --admin-tint:color-mix(in srgb,var(--sdn-accent) 8%,var(--sdn-surface));
    --admin-raised:0 2px 0 var(--sdn-accent-deep),0 5px 12px #081c3629;
    --admin-sidebar-width:clamp(288px,22vw,320px);
    --admin-sidebar-surface:var(--sdn-surface);
    --admin-sidebar-text:var(--sdn-ink);
    --admin-sidebar-muted:var(--sdn-muted);
    --admin-sidebar-edge:var(--sdn-line);
  }
  .sdn4-admin-theme[data-school-theme] .main-sidebar.portal-school-sidebar {
    background:var(--admin-sidebar-surface) !important;
    border-right:1px solid var(--admin-sidebar-edge);
    box-shadow:4px 0 18px #142b4c12 !important;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .portal-school-brand {
    width:100%;
    background:var(--admin-sidebar-surface);
    border-bottom-color:var(--admin-sidebar-edge) !important;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .portal-school-user {
    border-bottom-color:var(--admin-sidebar-edge);
    margin-bottom:8px;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar :is(.portal-school-brand strong,.portal-school-user strong) {
    color:var(--admin-sidebar-text);
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar :is(.portal-school-brand small,.portal-school-user small) {
    color:var(--admin-sidebar-muted);
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar :is(.portal-school-avatar,.portal-school-mark:not(.has-school-logo)) {
    background:var(--admin-accent-deep);
    border:0;
    border-radius:13px;
    box-shadow:0 4px 9px #142b4c26;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-header {
    color:var(--admin-sidebar-muted);
    font-weight:750;
    letter-spacing:.09em;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link {
    display:flex;
    align-items:center;
    gap:.55rem;
    width:auto;
    min-height:44px;
    padding:.6rem .65rem;
    color:var(--admin-sidebar-text) !important;
    background:none;
    border:1px solid transparent;
    box-shadow:none;
    font-weight:600;
    line-height:1.32;
    transition:background-color .18s ease,color .18s ease;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-link .nav-icon {
    flex:none;
    width:1.45rem;
    margin:0;
    color:var(--admin-sidebar-muted);
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-link p {
    flex:1;
    min-width:0;
    overflow-wrap:anywhere;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-link[aria-expanded] p { padding-right:.85rem; }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-link .right { top:calc(50% - .46em); right:.65rem; }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-treeview > .nav-item > .nav-link {
    margin:2px .5rem;
    font-size:.91rem;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-treeview {
    margin:.25rem .5rem .45rem .95rem;
    padding-left:.35rem;
    border-left:1px solid var(--admin-sidebar-edge);
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link:hover:not(.active),
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .menu-open > .nav-link:not(.active) {
    background:var(--admin-tint,var(--sdn-paper)) !important;
    box-shadow:none;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link:hover {
    transform:none;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link.active {
    color:#fff !important;
    background:var(--admin-accent-deep) !important;
    box-shadow:inset 4px 0 var(--sdn-yellow) !important;
    font-weight:750;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link :is(p,.right) { color:inherit !important; }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link.active .nav-icon { color:inherit !important; }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-link:focus-visible {
    outline:2px solid var(--admin-accent);
    outline-offset:-3px;
  }
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar > .sidebar {
    scrollbar-color:var(--admin-sidebar-edge) var(--admin-sidebar-surface);
  }

  .sdn4-admin-theme[data-school-theme] .main-header {
    background:var(--sdn-surface) !important;
    border-bottom-color:var(--admin-accent);
    box-shadow:0 4px 14px #1128451c;
  }
  .sdn4-admin-theme[data-school-theme] .card > .card-header {
    background:var(--admin-tint,var(--sdn-surface)) !important;
    border-top-color:var(--admin-accent);
    box-shadow:none;
  }
  .sdn4-admin-theme[data-school-theme] .main-footer {
    background:var(--sdn-sidebar-end) !important;
    border-top-color:var(--admin-accent);
  }
  .sdn4-admin-theme[data-school-theme] .website-editor .website-tabs {
    background:var(--admin-tint,var(--sdn-paper));
    border:1px solid var(--sdn-line);
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-primary,.btn-info,.website-editor .website-tabs .nav-link.active) {
    background:var(--admin-accent-deep) !important;
    border-color:var(--admin-accent-deep) !important;
    color:#fff !important;
    box-shadow:var(--admin-raised);
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-success,.btn-outline-success) {
    --admin-action-bg:#176b49;
    --admin-action-hover:#115438;
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-danger,.btn-outline-danger) {
    --admin-action-bg:#a92b43;
    --admin-action-hover:#872033;
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-warning,.btn-outline-warning) {
    --admin-action-bg:#edb947;
    --admin-action-hover:#d8a438;
    --admin-action-ink:#342300;
    --admin-action-outline:#78530c;
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-secondary,.btn-outline-secondary) {
    --admin-action-bg:#4c5e72;
    --admin-action-hover:#3b4c60;
  }
  .sdn4-admin-theme[data-school-theme] .btn:is(.btn-success,.btn-warning,.btn-danger,.btn-secondary) {
    background:var(--admin-action-bg);
    border-color:var(--admin-action-bg);
    color:var(--admin-action-ink,#fff);
    box-shadow:0 3px 8px #10253626;
  }
  .sdn4-admin-theme[data-school-theme] .btn:is(.btn-success,.btn-warning,.btn-danger,.btn-secondary):is(:hover,:active,:focus-visible,.active) {
    background:var(--admin-action-hover);
    border-color:var(--admin-action-hover);
    color:var(--admin-action-ink,#fff);
  }
  .sdn4-admin-theme[data-school-theme] .btn:is(.btn-outline-success,.btn-outline-warning,.btn-outline-danger,.btn-outline-secondary) {
    color:var(--admin-action-outline,var(--admin-action-bg));
    background:var(--sdn-surface);
    border-color:currentColor;
  }
  .sdn4-admin-theme[data-school-theme] .btn:is(.btn-outline-success,.btn-outline-warning,.btn-outline-danger,.btn-outline-secondary):is(:hover,:active,:focus-visible,.active) {
    color:var(--admin-action-ink,#fff);
    background:var(--admin-action-hover);
    border-color:var(--admin-action-hover);
  }
  .sdn4-admin-theme[data-school-theme] :is(.btn-outline-primary,.btn-outline-info):not(:hover):not(.active) {
    background:var(--admin-tint,var(--sdn-surface));
  }
  .sdn4-admin-theme[data-school-theme] .btn:is(:disabled,.disabled,[aria-disabled="true"]):not(.btn-link) {
    background:var(--sdn-paper) !important;
    border-color:var(--sdn-line) !important;
    color:var(--sdn-ink) !important;
    opacity:1;
    box-shadow:none !important;
    transform:none !important;
  }
  body[data-school-theme] :is(.sdn4-mobile-nav,.school-public-mobile-nav) a.active {
    color:#fff;
    background:var(--sdn-accent-deep);
    box-shadow:inset 0 3px var(--sdn-yellow);
  }
}

@media screen and (min-width: 992px) {
  .sdn4-admin-theme.sidebar-mini:not(.sidebar-collapse) .main-sidebar.portal-school-sidebar,
  .sdn4-admin-theme.sidebar-mini.sidebar-collapse .main-sidebar.portal-school-sidebar:is(:hover,.sidebar-focused) {
    width:var(--admin-sidebar-width);
  }
  body.sdn4-admin-theme.sidebar-mini:not(.sidebar-collapse):not(.layout-top-nav) :is(.content-wrapper,.main-header,.main-footer) {
    margin-left:var(--admin-sidebar-width);
  }
}

@media screen and (max-width: 991.98px) {
  body.sdn4-admin-theme[data-school-theme] { --admin-sidebar-width:min(86vw,304px); }
  .sdn4-admin-theme[data-school-theme] .main-sidebar.portal-school-sidebar { width:var(--admin-sidebar-width); }
  .sdn4-admin-theme[data-school-theme]:not(.sidebar-open) .main-sidebar.portal-school-sidebar {
    margin-left:calc(-1 * var(--admin-sidebar-width));
  }
}

@media screen and (prefers-reduced-motion:no-preference) {
  .sdn4-admin-theme[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link.active {
    animation:admin-nav-arrive .38s ease-out;
  }
  @keyframes admin-nav-arrive {
    from { transform:translateY(2px); }
    to { transform:translateY(0); }
  }
  body[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link.active {
    position: relative;
    isolation: isolate;
    overflow: hidden;
  }
  body[data-school-theme] .portal-school-sidebar .nav-sidebar .nav-link.active::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: linear-gradient(108deg, transparent 37%, #ffffff24 49%, transparent 61%);
    animation: school-active-menu-shine 10s ease-in-out infinite;
  }
  @keyframes school-active-menu-shine {
    0% { transform: translateX(-115%); }
    45%, 100% { transform: translateX(115%); }
  }
}

/* Staff panels share neutral surfaces. Sidebar and theme previews keep their own palette. */
body.sdn4-admin-theme[data-staff-workspace][data-school-theme]
  :is(.content-wrapper,.main-header,.main-footer,.modal-content,.select2-dropdown) {
  --sdn-surface:#fff;
  --sdn-paper:#f5f6f8;
  --sdn-line:#dae2ec;
  --admin-tint:#f5f6f8;
  --cbt-tint:var(--admin-tint);
  --paper:var(--sdn-paper);
  --line:var(--sdn-line);
  --staff-table-header:#115667;
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme]
  :is(.main-header,.main-footer,.modal-content) {
  background:var(--sdn-surface) !important;
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] .content-wrapper {
  background:var(--sdn-paper) !important;
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] .main-footer {
  color:var(--sdn-muted) !important;
  border-top:1px solid var(--sdn-line);
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] .main-footer a:hover {
  color:var(--sdn-accent-deep);
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content)
  :is(.card-body,:is(.form-control,.custom-select):enabled:not([readonly])):where(:not([class*="bg-"])) {
  background-color:var(--sdn-surface);
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content) .card > .card-header {
  background:var(--sdn-surface) !important;
}

body.sdn4-admin-theme[data-staff-workspace][data-school-theme] .content-wrapper
  :is(.card > .card-footer,.note-editor .note-toolbar,.note-editor .note-statusbar) {
  background:var(--admin-tint);
  border-color:var(--sdn-line);
}

@media screen {
  body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content) table {
    background-color:var(--sdn-surface);
  }

  /* Cover both section-level and per-cell header colors used by existing tables. */
  body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content)
    :is(thead,thead > tr > :is(th,td)) {
    background:var(--staff-table-header) !important;
    color:#fff !important;
    border-color:#ffffff30;
  }

  body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content)
    tbody > tr:where(:not([class*="table-"],[class*="bg-"])) {
    background-color:var(--sdn-surface);
  }

  body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content)
    .table-hover tbody > tr:where(:not([class*="table-"],[class*="bg-"])):hover {
    background:var(--sdn-paper) !important;
    box-shadow:none;
  }

  body.sdn4-admin-theme[data-staff-workspace][data-school-theme] :is(.content-wrapper,.modal-content)
    tbody th:where(:not([class*="text-"],[class*="table-"],[class*="bg-"])) {
    color:var(--sdn-ink);
  }
}

/* Student content uses neutral surfaces while navigation keeps its theme palette. */
body.sdn4-admin-theme[data-student-workspace][data-school-theme] :is(.content-wrapper,.main-header) {
  --sdn-surface:#fff;
  --sdn-paper:#f4f5f7;
  --sdn-line:#dce2e9;
  --admin-tint:#f8f9fb;
}

body.sdn4-admin-theme[data-student-workspace][data-school-theme] .content-wrapper {
  background:var(--sdn-paper) !important;
}

body.sdn4-admin-theme[data-student-workspace][data-school-theme] .content-wrapper .table-striped tbody tr:nth-of-type(odd) {
  background-color:var(--sdn-paper);
}
