/* IMS DBMS Portal v2.2A — Portal Experience and Design System
   This layer intentionally overrides legacy presentation without changing workflows. */
:root,
html[data-theme="institutional"] {
  --ds-primary: #174f7f;
  --ds-primary-strong: #103b63;
  --ds-primary-soft: #e9f2f9;
  --ds-accent: #087b74;
  --ds-accent-soft: #e4f4f1;
  --ds-canvas: #f4f7fa;
  --ds-surface: #ffffff;
  --ds-surface-subtle: #f8fafc;
  --ds-text: #1e2937;
  --ds-text-muted: #607086;
  --ds-border: #d7e0e8;
  --ds-success: #17704d;
  --ds-warning: #8b5a08;
  --ds-danger: #a7352d;
  --ds-focus: #f0a51a;
  --ds-header-start: #10375e;
  --ds-header-end: #185a86;
  --ds-shadow-sm: 0 2px 8px rgba(20, 50, 78, .07);
  --ds-shadow-md: 0 10px 30px rgba(20, 50, 78, .09);
  --ds-radius-sm: 8px;
  --ds-radius-md: 13px;
  --ds-radius-lg: 18px;
  --ds-space-1: .25rem;
  --ds-space-2: .5rem;
  --ds-space-3: .75rem;
  --ds-space-4: 1rem;
  --ds-space-5: 1.5rem;
  --ds-space-6: 2rem;
  --ds-content: 1280px;
  --navy: var(--ds-primary-strong);
  --blue: var(--ds-primary);
  --blue-2: #2879b5;
  --teal: var(--ds-accent);
  --ink: var(--ds-text);
  --muted: var(--ds-text-muted);
  --line: var(--ds-border);
  --soft: var(--ds-canvas);
  --green: var(--ds-success);
  --amber: var(--ds-warning);
  --red: var(--ds-danger);
  --shadow: var(--ds-shadow-md);
}

html[data-theme="slate"] {
  --ds-primary: #3d5268;
  --ds-primary-strong: #26394c;
  --ds-primary-soft: #e9eef3;
  --ds-accent: #526c81;
  --ds-accent-soft: #edf1f5;
  --ds-canvas: #f3f5f7;
  --ds-header-start: #26394c;
  --ds-header-end: #465f76;
  --blue-2: #607f99;
}

html[data-theme="teal"] {
  --ds-primary: #176b69;
  --ds-primary-strong: #104f50;
  --ds-primary-soft: #e5f3f1;
  --ds-accent: #176b69;
  --ds-accent-soft: #e2f2ef;
  --ds-canvas: #f2f8f7;
  --ds-header-start: #104f50;
  --ds-header-end: #1c7470;
  --blue-2: #258d87;
}

html[data-theme="contrast"] {
  --ds-primary: #003b73;
  --ds-primary-strong: #001f3f;
  --ds-primary-soft: #e8f3ff;
  --ds-accent: #006b3c;
  --ds-accent-soft: #e5f7ec;
  --ds-canvas: #ffffff;
  --ds-surface-subtle: #f5f7f9;
  --ds-text: #101820;
  --ds-text-muted: #3e4b57;
  --ds-border: #93a1ae;
  --ds-focus: #ffbf00;
  --ds-header-start: #001f3f;
  --ds-header-end: #003b73;
  --ds-shadow-sm: 0 0 0 1px #93a1ae;
  --ds-shadow-md: 0 0 0 2px #647482;
  --blue-2: #005da8;
}

html { scroll-behavior: smooth; }
body {
  color: var(--ds-text);
  background:
    radial-gradient(circle at 95% 2%, color-mix(in srgb, var(--ds-primary-soft) 78%, transparent) 0, transparent 28rem),
    var(--ds-canvas);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}
body.has-open-navigation { overflow: hidden; }

::selection { background: var(--ds-primary); color: #fff; }
a { color: var(--ds-primary); text-underline-offset: 3px; }
a:hover { color: var(--ds-primary-strong); }

.skip-link {
  background: var(--ds-focus);
  border-radius: 0 0 var(--ds-radius-sm) var(--ds-radius-sm);
  color: #17120a;
  font-weight: 700;
  left: 1rem;
  padding: .7rem 1rem;
  position: fixed;
  top: -5rem;
  transition: top .15s ease;
  z-index: 2000;
}
.skip-link:focus { top: 0; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--ds-focus);
  outline-offset: 3px;
}

.header-inner, .nav-inner, .page { width: min(var(--ds-content), calc(100% - 40px)); }
.site-header {
  background: linear-gradient(112deg, var(--ds-header-start), var(--ds-header-end));
  border-bottom: 3px solid color-mix(in srgb, var(--ds-primary) 35%, #8cc9ec);
}
.header-inner { min-height: 76px; gap: var(--ds-space-4); }
.brand { gap: 11px; }
.brand-mark {
  background: rgba(255,255,255,.1);
  border-radius: 11px;
  height: 44px;
  width: 44px;
}
.brand strong { font-size: 1.06rem; font-weight: 650; letter-spacing: -.01em; }
.brand small { color: #d6e7f3; font-size: .78rem; }
.instructor-identity { padding-block: 5px; }
.instructor-identity strong { font-size: .94rem; font-weight: 650; }
.theme-control { display: grid; gap: 2px; min-width: 148px; }
.theme-control label { color: #d6e7f3; font-size: .68rem; font-weight: 650; letter-spacing: .04em; }
.theme-control select {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 7px;
  color: #fff;
  font-size: .77rem;
  min-height: 34px;
  padding: .35rem .55rem;
}
.theme-control option { color: #17202b; background: #fff; }
.account { gap: 10px; }
.account > span { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-button { min-height: 36px; font-weight: 600; }

.nav { box-shadow: var(--ds-shadow-sm); position: sticky; top: 0; z-index: 80; }
.nav-inner { gap: 2px; scrollbar-width: thin; }
.nav a {
  border-bottom-width: 3px;
  color: var(--ds-primary-strong);
  font-size: .84rem;
  font-weight: 600;
  padding: .82rem .72rem;
}
.nav a:hover { background: var(--ds-primary-soft); border-color: var(--ds-primary); }
.nav a[aria-current="page"] {
  background: var(--ds-primary-soft);
  border-color: var(--ds-primary);
  color: var(--ds-primary-strong);
}

.page { min-height: calc(100vh - 178px); padding: 30px 0 56px; }
h1, h2, h3, h4 { color: var(--ds-primary-strong); font-weight: 650; }
h1 { font-size: clamp(1.75rem, 3vw, 2.45rem); letter-spacing: -.025em; line-height: 1.14; }
h2 { font-size: clamp(1.15rem, 2vw, 1.4rem); letter-spacing: -.01em; }
h3 { font-size: 1.05rem; }
.content-title { text-transform: none; }
.eyebrow { color: var(--ds-accent); font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.muted, .help { color: var(--ds-text-muted); }

.page-heading, .dashboard-hero, .section-heading {
  align-items: flex-end;
  display: flex;
  gap: var(--ds-space-5);
  justify-content: space-between;
  margin-bottom: var(--ds-space-5);
}
.dashboard-hero {
  align-items: center;
  background: linear-gradient(120deg, var(--ds-surface), var(--ds-primary-soft));
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-sm);
  padding: clamp(1.2rem, 3vw, 2rem);
}
.dashboard-hero h1, .section-heading h2 { margin-block: .2rem .45rem; }
.dashboard-hero p:not(.eyebrow), .section-heading p:not(.eyebrow) { color: var(--ds-text-muted); margin: 0; }
.section-heading { align-items: center; margin-top: 2.2rem; }
.section-heading h2 { font-size: clamp(1.35rem, 2.2vw, 1.75rem); }
.actions { align-items: center; display: flex; flex-wrap: wrap; gap: .65rem; }

.panel, .assignment-card, .metric {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-shadow-sm);
}
.panel { padding: clamp(1.1rem, 2.5vw, 1.5rem); }
.panel:hover, .assignment-card:hover { border-color: color-mix(in srgb, var(--ds-primary) 34%, var(--ds-border)); }
.panel-heading { align-items: center; gap: 1rem; }

.metric-grid { gap: .85rem; }
.metric { overflow: hidden; padding: 1.15rem 1.25rem; position: relative; }
.metric::before { background: var(--ds-accent); content: ""; inset: 0 auto 0 0; position: absolute; width: 4px; }
.metric span { color: var(--ds-text-muted); font-size: .8rem; font-weight: 650; }
.metric strong { color: var(--ds-primary-strong); font-size: clamp(1.65rem, 3vw, 2.1rem); font-weight: 650; }
.metric small { color: var(--ds-text-muted); }

.assignment-grid { gap: 1rem; }
.assignment-card { border-top: 4px solid var(--ds-primary); min-height: 0; padding: 1.15rem; transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
.assignment-card:hover { box-shadow: var(--ds-shadow-md); transform: translateY(-2px); }
.assignment-card h2 { font-size: 1.12rem; line-height: 1.35; min-height: 0; }
.assignment-number { background: var(--ds-primary); }
.pill { background: var(--ds-primary-soft); color: var(--ds-primary-strong); }
.meta > div, .result-breakdown > div, .preview-metadata div { background: var(--ds-surface-subtle); border-color: var(--ds-border); }

.button {
  background: var(--ds-primary);
  border: 1px solid var(--ds-primary);
  border-radius: var(--ds-radius-sm);
  box-shadow: none;
  font-size: .88rem;
  font-weight: 650;
  min-height: 40px;
  padding: .62rem .95rem;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.button:hover { background: var(--ds-primary-strong); border-color: var(--ds-primary-strong); filter: none; transform: translateY(-1px); }
.button.secondary { background: var(--ds-primary-soft); border-color: color-mix(in srgb, var(--ds-primary) 28%, var(--ds-border)); color: var(--ds-primary-strong); }
.button.secondary:hover { background: color-mix(in srgb, var(--ds-primary-soft) 78%, var(--ds-primary)); }
.button.danger { background: var(--ds-danger); border-color: var(--ds-danger); }
.text-button, .back { font-weight: 650; }

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  background: var(--ds-surface);
  border: 1px solid #b9c5d0;
  border-radius: var(--ds-radius-sm);
  color: var(--ds-text);
  min-height: 42px;
  padding: .65rem .75rem;
}
textarea { min-height: 110px; resize: vertical; }
label { color: var(--ds-text); }
.stack { gap: .8rem; }
.stack label, .field label, .form-grid label { font-size: .84rem; font-weight: 650; }
.form-grid { gap: 1rem; }
fieldset { border-color: var(--ds-border); border-radius: var(--ds-radius-md); }

.table-scroll {
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  outline: none;
  overflow: auto;
  scrollbar-color: var(--ds-primary) var(--ds-primary-soft);
}
.table-scroll:focus-visible { outline: 3px solid var(--ds-focus); outline-offset: 2px; }
table { background: var(--ds-surface); font-size: .86rem; }
th {
  background: var(--ds-primary-strong);
  color: #fff;
  font-size: .72rem;
  font-weight: 650;
  letter-spacing: .035em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 2;
}
th, td { border-bottom-color: var(--ds-border); padding: .75rem .8rem; }
tbody tr:nth-child(even) { background: var(--ds-surface-subtle); }
tbody tr:hover { background: var(--ds-primary-soft); }
td:first-child, th:first-child { position: sticky; left: 0; z-index: 1; }
td:first-child { background: inherit; }
th:first-child { z-index: 3; }

.status, .pill, .notification-priority, .sample-note { font-weight: 650; }
.status.success { background: #e4f3eb; color: #145c40; }
.status.waiting { background: #fff2d8; color: #754c06; }
.alert, .message, .notice { border-radius: var(--ds-radius-sm); border-width: 1px 1px 1px 4px; }
.messages { display: grid; gap: .65rem; margin-bottom: 1rem; }
.message { background: var(--ds-primary-soft); border: 1px solid var(--ds-border); border-left: 4px solid var(--ds-primary); padding: .8rem 1rem; }
.message.success { background: #e8f5ee; border-left-color: var(--ds-success); }
.message.error { background: #fff0ef; border-left-color: var(--ds-danger); }
.empty, .empty-state { text-align: center; }
.empty { border-style: dashed; box-shadow: none; padding-block: 2.5rem; }

.login-page .nav, .login-page .mobile-bottom-nav { display: none; }
.login-shell { gap: clamp(2rem, 6vw, 5rem); min-height: 570px; }
.login-intro h1 { color: var(--ds-primary-strong); font-size: clamp(2.2rem, 5vw, 4rem); max-width: 720px; }
.login-panel { border-top: 5px solid var(--ds-primary); max-width: 500px; width: 100%; }
.login-guidance { background: var(--ds-primary-soft); border-radius: var(--ds-radius-sm); padding: .75rem .9rem; }
.course-strip span { font-weight: 600; }

.connection-status { background: var(--ds-warning); }
.pwa-install-banner { border-color: var(--ds-border); box-shadow: var(--ds-shadow-md); }
.mobile-bottom-nav { background: color-mix(in srgb, var(--ds-surface) 96%, transparent); border-top-color: var(--ds-border); }
.mobile-bottom-nav a[aria-current="page"] { color: var(--ds-primary-strong); }

footer { background: color-mix(in srgb, var(--ds-surface) 92%, transparent); border-top-color: var(--ds-border); color: var(--ds-text-muted); }

@media (max-width: 1120px) {
  .instructor-identity small { display: none; }
  .theme-control { min-width: 132px; }
  .nav a { padding-inline: .62rem; }
}

@media (max-width: 760px) {
  .header-inner, .nav-inner, .page { width: min(100% - 24px, var(--ds-content)); }
  .header-inner { min-height: 68px; }
  .brand small, .instructor-identity, .account, .theme-control label { display: none; }
  .theme-control { min-width: 0; order: 2; }
  .theme-control select { max-width: 118px; min-height: 38px; width: 118px; }
  .mobile-menu-button { order: 3; }
  .nav { position: fixed; }
  .nav-inner { width: 100%; }
  .page { padding-top: 22px; }
  .dashboard-hero, .page-heading, .section-heading { align-items: stretch; flex-direction: column; }
  .dashboard-hero .actions, .page-heading .actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .dashboard-hero .button, .page-heading .button { width: 100%; }
  .table-scroll { border-radius: 10px; }
  table { min-width: 680px; }
  .mobile-bottom-nav { backdrop-filter: blur(12px); }
  .mobile-bottom-nav a { min-height: 58px; }
}

@media (max-width: 520px) {
  body { font-size: 14px; }
  .brand strong { font-size: .92rem; }
  .brand-mark { height: 40px; width: 40px; }
  .theme-control select { max-width: 96px; width: 96px; }
  .dashboard-hero, .panel { border-radius: 12px; }
  .login-shell { min-height: 0; }
  .login-intro { padding-block: 10px; }
  .login-intro h1 { font-size: 2.25rem; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric { padding: .9rem; }
  .metric strong { font-size: 1.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .assignment-card:hover, .button:hover { transform: none; }
}

@media print {
  .site-header, .nav, .mobile-bottom-nav, .pwa-install-banner, .theme-control, .button, footer { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; width: 100%; }
  .panel, .assignment-card, .metric { box-shadow: none; break-inside: avoid; }
}
