:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --ink: #1a1e27;
  --ink-muted: #5b6472;
  --ink-faint: #8b93a1;
  --accent: #2f74c9;
  --accent-hover: #24578e;
  --good: #0ca30c;
  --warn: #d98c00;
  --serious: #c15a37;
  --critical: #c62828;
  --radius: 8px;
  --sidebar-bg: #161a25;
  --sidebar-text: #9aa2b1;
  --sidebar-text-active: #ffffff;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-width: 290px;
}

[data-theme="dark"] {
  --bg: #12141a;
  --surface: #1b1e27;
  --surface-2: #232733;
  --border: #333947;
  --ink: #e7e9ee;
  --ink-muted: #a7aebb;
  --ink-faint: #7b8394;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.9375rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.grcc-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
}
.grcc-loading-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}
.grcc-loading-spinner {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 0.35rem solid var(--border);
  border-top-color: var(--accent);
  animation: grcc-spin 0.7s linear infinite;
}
@keyframes grcc-spin {
  to { transform: rotate(360deg); }
}

img.navbar-brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}

.navbar-brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.8rem;
  flex: 0 0 auto;
}

.grcc-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.grcc-sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 1030; /* keep the notification dropdown above page charts/tables */
}

.grcc-sidebar.collapsed {
  flex-basis: 64px;
  width: 64px;
}
.grcc-sidebar.collapsed .sidebar-brand-text,
.grcc-sidebar.collapsed .sidebar-menu-search-row,
.grcc-sidebar.collapsed .sidebar-link span,
.grcc-sidebar.collapsed .sidebar-user-name,
.grcc-sidebar.collapsed .sidebar-notif-row .sidebar-link span,
.grcc-sidebar.collapsed .text-uppercase {
  display: none;
}
.grcc-sidebar.collapsed .sidebar-brand-row { justify-content: center; }
.grcc-sidebar.collapsed #sidebarCollapseBtn { display: none; }
.grcc-sidebar.collapsed .sidebar-footer { gap: 0.5rem; }
.grcc-sidebar.collapsed .sidebar-user-row { flex-direction: column; gap: 0.5rem; }
.grcc-sidebar.collapsed .notif-badge { left: auto; right: 6px; top: 2px; }
.grcc-sidebar.collapsed .sidebar-link,
.grcc-sidebar.collapsed .sidebar-footer > * {
  justify-content: center;
}
.grcc-sidebar.collapsed #sidebarExpandBtn { display: flex; }
#sidebarExpandBtn { display: none; }
#sidebarExpandBtn:hover { color: var(--sidebar-text-active); }

.sidebar-brand-row {
  display: flex;
  align-items: center;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-user-row .dropdown { min-width: 0; flex: 1 1 auto; }
.sidebar-user-row .sidebar-link { padding: 0.5rem 0; }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--sidebar-text-active);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.25;
  white-space: nowrap;
}
.sidebar-brand:hover { color: var(--sidebar-text-active); text-decoration: none; }
.sidebar-brand-toggles { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; }

.theme-toggle-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  color: var(--sidebar-text-active);
  cursor: pointer;
}
.theme-toggle-btn:hover { background: var(--sidebar-hover-bg); }
.theme-toggle-btn svg { width: 15px; height: 15px; }

.grcc-table-search-row { border-bottom: 1px solid var(--border); }
.grcc-table-search { max-width: 320px; }

.sidebar-notif-row {
  padding: 0 0 0.6rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-notif-row .dropdown-menu.notif-dropdown {
  position: fixed !important;
  margin: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 2000;
}

.sidebar-menu-search-row {
  padding: 0.6rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-menu-search-row input {
  background: var(--sidebar-hover-bg);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text-active);
}
.sidebar-menu-search-row input::placeholder { color: var(--sidebar-text); }
.sidebar-menu-search-row input:focus {
  background: var(--sidebar-hover-bg);
  border-color: var(--accent);
  color: var(--sidebar-text-active);
  box-shadow: none;
}

.sidebar-link.sidebar-search-match { background: rgba(255, 255, 255, 0.14); color: var(--sidebar-text-active); }

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.88rem;
  white-space: nowrap;
}
.sidebar-link svg { flex: 0 0 auto; width: 16px; height: 16px; opacity: 0.9; }
.sidebar-link:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); text-decoration: none; }
.sidebar-link.active { background: var(--accent); color: var(--sidebar-text-active); }

.sidebar-footer {
  flex: 0 0 auto;
  padding: 0.6rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.sidebar-footer .sidebar-user-name { overflow: hidden; text-overflow: ellipsis; }

.grcc-main { flex: 1; min-width: 0; }

.grcc-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Opt-in, page-scoped "fill the viewport, one scroll region" layout - set via
   ViewData["FillHeight"] = true in a view. Everything here is scoped under
   .grcc-shell-fill so it has zero effect on any page that doesn't opt in. */
.grcc-shell-fill { height: 100vh; overflow: hidden; }
/* Belt-and-braces: on some browsers/zoom levels, 100vh plus sub-pixel rounding leaves the body
   itself a hair taller than the viewport, so it (not .table-responsive) ends up as the thing that
   scrolls - which drags the sticky table header off along with it instead of keeping it pinned.
   Locking body/html outright for any FillHeight page removes that possibility entirely. */
body:has(.grcc-shell-fill) { overflow: hidden; height: 100vh; }
.grcc-shell-fill .grcc-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; width: 100%; }
.grcc-shell-fill .grcc-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 1rem 1.25rem 0.75rem;
}
.grcc-shell-fill .grcc-main-content { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; width: 100%; }
.grcc-shell-fill .grcc-card { width: 100%; flex: 0 0 auto; min-width: 0; }

.grcc-dashboard-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  margin-top: -0.25rem;
}
/* RiskRegister/ControlRegister wrap .grcc-table-card in a <form> for GET-based filtering,
   inserting an extra flex-chain link between .grcc-main-content and .grcc-card. A flex item's
   default min-height is auto (not 0), so that form grows to fit all rows instead of being
   capped by the viewport - which is what silently removed the table's inner scrollbar. */
.grcc-shell-fill .grcc-main-content > form { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; width: 100%; }
.grcc-shell-fill .grcc-table-card { flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.grcc-shell-fill .grcc-table-card .table-responsive {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-height: none;
  overflow-y: auto;
}
.grcc-shell-fill .grcc-table-card table { width: 100%; }

.card, .grcc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-header, .grcc-card-header {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--ink);
  padding: 0.6rem 1rem;
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 100%;
}

.kpi-tile .kpi-value { font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.kpi-tile .kpi-label { color: var(--ink-muted); font-size: 0.8rem; margin-top: 0.25rem; }
.kpi-tile.tile-critical { border-left-color: var(--critical); }
.kpi-tile.tile-warn { border-left-color: var(--warn); }
.kpi-tile.tile-good { border-left-color: var(--good); }

.table { color: var(--ink); --bs-table-bg: transparent; --bs-table-border-color: var(--border); }
.table > thead { color: var(--ink-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-hover > tbody > tr:hover > * { background-color: var(--surface-2); color: var(--ink); }

.table-responsive { max-height: 75vh; overflow-y: auto; }
/* border-collapse merges the header's bottom border with the first body row's top border into one
   shared line owned by neither cell - under position:sticky that shared line doesn't travel with the
   stuck header, so it visually detaches and stays behind as you scroll. border-separate makes each
   cell fully own its own borders, so the header's bottom edge scrolls with the header like everything
   else in it. */
.table-responsive .table { border-collapse: separate; border-spacing: 0; }
.table > thead > tr > th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border);
}

.badge-band-low { background: var(--good); color: #fff; }
.badge-band-medium { background: var(--warn); color: #1a1400; }
.badge-band-high { background: var(--critical); color: #fff; }
.badge-band-critical { background: #7a1414; color: #fff; }

.badge-rag-green { background: var(--good); color: #fff; }
.badge-rag-amber { background: var(--warn); color: #1a1400; }
.badge-rag-red { background: var(--critical); color: #fff; }
.badge-rag-grey { background: #8b93a1; color: #fff; }

.badge-overdue { background: var(--critical); color: #fff; }
.badge-upcoming { background: var(--warn); color: #1a1400; }

.form-control, .form-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}

.form-control:focus, .form-select:focus {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(47, 116, 201, 0.25);
}

.form-control::placeholder { color: var(--ink-faint); }
.form-label { color: var(--ink-muted); font-size: 0.85rem; }
label.form-label { margin-bottom: 0.25rem; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.nav-tabs { border-bottom-color: var(--border); }
.nav-tabs .nav-link { color: var(--ink-muted); border: 1px solid transparent; }
.nav-tabs .nav-link:hover { color: var(--ink); border-color: var(--border) var(--border) var(--border); }
.nav-tabs .nav-link.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--surface);
  border-color: var(--border) var(--border) var(--surface);
}
.btn-outline-light { color: var(--ink); border-color: var(--border); }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a1432 0%, #1c2e5e 100%);
}

.auth-heading { color: #ffffff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45); }
.auth-heading .text-muted-grcc { color: #dbe3f5 !important; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.text-muted-grcc { color: var(--ink-muted) !important; }

.notif-bell { position: relative; color: var(--ink-muted); }
.notif-badge {
  position: absolute;
  top: -4px;
  left: 18px;
  background: #dc3545;
  color: #fff;
  border-radius: 999px;
  font-size: 0.65rem;
  line-height: 1;
  padding: 2px 5px;
  font-weight: 600;
}
.notif-dropdown { background: var(--surface); border: 1px solid var(--border); min-width: 320px; max-height: 400px; overflow-y: auto; }
.notif-item { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); display: block; color: var(--ink); }
.notif-item.unread { background: var(--surface-2); }
.notif-item small { color: var(--ink-muted); }

.heatmap-grid { display: grid; gap: 4px; }
.heatmap-cell {
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  min-height: 44px;
  font-size: 0.85rem;
}
.heatmap-axis-label { color: var(--ink-muted); font-size: 0.75rem; display: flex; align-items: center; justify-content: center; }

/* Edge/IE show their own built-in password-reveal eye icon on every <input type="password">,
   which doubles up wherever the app already has its own show/hide toggle button - hide the
   native one everywhere so only our own toggle shows. */
input[type="password"]::-ms-reveal, input[type="password"]::-ms-clear { display: none; }
.grcc-back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); font-size: 0.85rem; text-decoration: none; }
.grcc-back-link:hover { color: var(--accent); text-decoration: underline; }
