/* GRC Tools — Component Stylesheet. Import after grc-tokens.css. */

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

body.grc-app {
  font-family: var(--grc-font-sans);
  font-size: var(--grc-text-base);
  background: var(--grc-bg-base);
  color: var(--grc-text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--grc-border-strong);
  border-radius: var(--grc-radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--grc-text-muted);
}

/* ============================================================
   APP SHELL — TOPBAR
   ============================================================ */
.grc-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--grc-topbar-height);
  background: var(--grc-bg-surface);
  border-bottom: 1px solid var(--grc-border);
  display: flex;
  align-items: center;
  padding: 0 var(--grc-space-6);
  gap: var(--grc-space-4);
  box-shadow: var(--grc-shadow-sm);
}

.grc-topbar__logo {
  display: flex;
  align-items: center;
  gap: var(--grc-space-2);
  text-decoration: none;
  color: var(--grc-text-primary);
  flex-shrink: 0;
}

.grc-topbar__logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.grc-topbar__logo-text {
  font-family: var(--grc-font-display);
  font-size: var(--grc-text-md);
  font-weight: 900;
  letter-spacing: var(--grc-tracking-tight);
  color: var(--grc-text-primary);
}

.grc-topbar__divider {
  color: var(--grc-text-muted);
  font-size: var(--grc-text-lg);
  margin: 0 var(--grc-space-1);
  user-select: none;
}

.grc-topbar__app-name {
  font-size: var(--grc-text-sm);
  font-weight: 600;
  color: var(--grc-text-secondary);
  letter-spacing: var(--grc-tracking-wide);
}

.grc-topbar__spacer {
  flex: 1;
}

.grc-topbar__nav {
  display: flex;
  align-items: center;
  gap: var(--grc-space-2);
}

.grc-topbar__nav-link {
  color: var(--grc-text-secondary);
  text-decoration: none;
  font-size: var(--grc-text-sm);
  font-weight: 500;
  padding: var(--grc-space-2) var(--grc-space-3);
  border-radius: var(--grc-radius-sm);
  transition: all var(--grc-transition);
}

.grc-topbar__nav-link:hover {
  color: var(--grc-text-primary);
  background: var(--grc-bg-raised);
}

.grc-topbar__nav-link--active {
  color: var(--grc-interactive);
}

.grc-topbar__user {
  font-size: var(--grc-text-sm);
  color: var(--grc-text-muted);
}

/* Theme toggle button */
.grc-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--grc-radius-sm);
  border: 1px solid var(--grc-border);
  background: transparent;
  color: var(--grc-text-secondary);
  cursor: pointer;
  transition: all var(--grc-transition);
  flex-shrink: 0;
}

.grc-theme-toggle:hover {
  background: var(--grc-bg-raised);
  color: var(--grc-text-primary);
  border-color: var(--grc-border-strong);
}

.grc-theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--grc-glow);
}

/* ============================================================
   APP SHELL — PAGE LAYOUT
   ============================================================ */
.grc-page {
  display: flex;
  min-height: calc(100vh - var(--grc-topbar-height));
}

/* ============================================================
   APP SHELL — SIDEBAR
   ============================================================ */
.grc-sidebar {
  width: var(--grc-sidebar-width);
  flex-shrink: 0;
  background: var(--grc-bg-surface);
  border-right: 1px solid var(--grc-border);
  padding: var(--grc-space-6) 0;
  position: sticky;
  top: var(--grc-topbar-height);
  height: calc(100vh - var(--grc-topbar-height));
  overflow-y: auto;
}

.grc-sidebar__section {
  padding: 0 var(--grc-space-4) var(--grc-space-4);
}

.grc-sidebar__label {
  font-size: var(--grc-text-xs);
  font-weight: 600;
  color: var(--grc-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--grc-tracking-wider);
  padding: var(--grc-space-2) var(--grc-space-4);
  margin-bottom: var(--grc-space-1);
}

.grc-sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--grc-space-3);
  padding: var(--grc-space-2) var(--grc-space-4);
  color: var(--grc-text-secondary);
  text-decoration: none;
  font-size: var(--grc-text-sm);
  font-weight: 500;
  border-radius: var(--grc-radius-sm);
  margin: 1px 0;
  transition: all var(--grc-transition);
}

.grc-sidebar__link:hover {
  background: var(--grc-bg-raised);
  color: var(--grc-text-primary);
}

.grc-sidebar__link--active {
  background: rgba(37,99,235,.15);
  color: var(--grc-interactive);
}

/* ─── Sidebar footer: user identity + sign-out (pinned bottom-left) ──────── */
.grc-sidebar__footer {
  margin-top: auto;
  padding-top: var(--grc-space-3);
  border-top: 1px solid var(--grc-border-subtle);
}
.grc-sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--grc-space-3);
  padding: var(--grc-space-2) var(--grc-space-4);
}
.grc-sidebar__avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--grc-radius-full);
  background: var(--grc-bg-overlay);
  color: var(--grc-text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--grc-text-sm);
  font-weight: 600;
}
.grc-sidebar__user-info { display: flex; flex-direction: column; min-width: 0; }
.grc-sidebar__user-name {
  font-size: var(--grc-text-sm);
  font-weight: 600;
  color: var(--grc-text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grc-sidebar__user-role {
  font-size: var(--grc-text-xs);
  color: var(--grc-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grc-sidebar__signout {
  display: flex;
  align-items: center;
  gap: var(--grc-space-2);
  margin: var(--grc-space-1) var(--grc-space-2) 0;
  padding: var(--grc-space-2) var(--grc-space-3);
  font-size: var(--grc-text-sm);
  font-weight: 500;
  color: var(--grc-text-secondary);
  background: transparent;
  border: 1px solid var(--grc-border);
  border-radius: var(--grc-radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--grc-transition);
  width: calc(100% - var(--grc-space-4));
}
.grc-sidebar__signout:hover {
  background: var(--grc-bg-raised);
  color: var(--grc-text-primary);
}
.grc-sidebar__signout-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

/* ============================================================
   APP SHELL — CONTENT AREA
   ============================================================ */
.grc-content {
  flex: 1;
  min-width: 0;
  padding: var(--grc-space-8) var(--grc-space-8);
}

.grc-content__inner {
  max-width: var(--grc-content-max-width);
  margin: 0 auto;
}

.grc-page-header {
  margin-bottom: var(--grc-space-8);
}

.grc-page-title {
  font-size: var(--grc-text-2xl);
  font-weight: 700;
  letter-spacing: var(--grc-tracking-tight);
  color: var(--grc-text-primary);
}

.grc-page-subtitle {
  font-size: var(--grc-text-base);
  color: var(--grc-text-secondary);
  margin-top: var(--grc-space-2);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.grc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--grc-space-2);
  padding: var(--grc-space-2) var(--grc-space-4);
  font-family: var(--grc-font-sans);
  font-size: var(--grc-text-sm);
  font-weight: 600;
  border-radius: var(--grc-radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--grc-transition);
  white-space: nowrap;
  line-height: 1.4;
}

.grc-btn:focus-visible {
  outline: none;
  box-shadow: var(--grc-glow);
}

.grc-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.grc-btn--primary {
  background: var(--grc-interactive);
  color: #fff;
  border-color: var(--grc-interactive);
}

.grc-btn--primary:hover:not(:disabled) {
  background: var(--grc-interactive-hover);
  border-color: var(--grc-interactive-hover);
}

.grc-btn--primary:active:not(:disabled) {
  background: var(--grc-interactive-active);
}

.grc-btn--secondary {
  background: var(--grc-bg-raised);
  color: var(--grc-text-primary);
  border-color: var(--grc-border-strong);
}

.grc-btn--secondary:hover:not(:disabled) {
  background: var(--grc-bg-overlay);
}

.grc-btn--ghost {
  background: transparent;
  color: var(--grc-text-secondary);
  border-color: transparent;
}

.grc-btn--ghost:hover:not(:disabled) {
  background: var(--grc-bg-raised);
  color: var(--grc-text-primary);
}

.grc-btn--danger {
  background: var(--grc-danger);
  color: #fff;
  border-color: var(--grc-danger);
}

.grc-btn--danger:hover:not(:disabled) {
  filter: brightness(1.1);
}

.grc-btn--sm {
  padding: var(--grc-space-1) var(--grc-space-3);
  font-size: var(--grc-text-xs);
}

.grc-btn--lg {
  padding: var(--grc-space-3) var(--grc-space-6);
  font-size: var(--grc-text-md);
}

.grc-btn--full {
  width: 100%;
}

/* ============================================================
   BADGES
   ============================================================ */
.grc-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--grc-radius-full);
  font-size: var(--grc-text-xs);
  font-weight: 600;
}

.grc-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.grc-badge--success {
  background: var(--grc-success-bg);
  color: var(--grc-success);
}

.grc-badge--warning {
  background: var(--grc-warning-bg);
  color: var(--grc-warning);
}

.grc-badge--danger {
  background: var(--grc-danger-bg);
  color: var(--grc-danger);
}

.grc-badge--info {
  background: var(--grc-info-bg);
  color: var(--grc-info);
}

/* ============================================================
   RISK LABELS
   ============================================================ */
.grc-risk {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--grc-radius-sm);
  font-size: var(--grc-text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--grc-tracking-wider);
}

.grc-risk--low {
  background: var(--grc-success-bg);
  color: var(--grc-success);
}

.grc-risk--medium {
  background: var(--grc-warning-bg);
  color: var(--grc-warning);
}

.grc-risk--high {
  background: var(--grc-danger-bg);
  color: var(--grc-danger);
}

.grc-risk--critical {
  background: var(--grc-danger-bg);
  color: var(--grc-danger);
  animation: grc-pulse 1.5s ease-in-out infinite;
}

@keyframes grc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

/* ============================================================
   CARDS
   ============================================================ */
.grc-card {
  background: var(--grc-bg-surface);
  border: 1px solid var(--grc-border);
  border-radius: var(--grc-radius-lg);
  box-shadow: var(--grc-shadow-sm);
  overflow: hidden;
}

.grc-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--grc-space-6);
  border-bottom: 1px solid var(--grc-border);
}

.grc-card__title {
  font-size: var(--grc-text-md);
  font-weight: 700;
  color: var(--grc-text-primary);
  letter-spacing: var(--grc-tracking-tight);
}

.grc-card__subtitle {
  font-size: var(--grc-text-sm);
  color: var(--grc-text-secondary);
  margin-top: var(--grc-space-1);
}

.grc-card__body {
  padding: var(--grc-space-6);
}

.grc-card__footer {
  padding: var(--grc-space-4) var(--grc-space-6);
  border-top: 1px solid var(--grc-border);
  display: flex;
  align-items: center;
  gap: var(--grc-space-3);
}

.grc-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--grc-space-6);
}

/* ============================================================
   ALERTS
   ============================================================ */
.grc-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--grc-space-4);
  padding: var(--grc-space-4) var(--grc-space-6);
  border-radius: var(--grc-radius);
  border: 1px solid transparent;
}

.grc-alert__title {
  font-size: var(--grc-text-sm);
  font-weight: 700;
  margin-bottom: var(--grc-space-1);
}

.grc-alert__body {
  font-size: var(--grc-text-sm);
}

.grc-alert--info {
  background: var(--grc-info-bg);
  border-color: var(--grc-info);
  color: var(--grc-info);
}

.grc-alert--success {
  background: var(--grc-success-bg);
  border-color: var(--grc-success);
  color: var(--grc-success);
}

.grc-alert--warning {
  background: var(--grc-warning-bg);
  border-color: var(--grc-warning);
  color: var(--grc-warning);
}

.grc-alert--danger {
  background: var(--grc-danger-bg);
  border-color: var(--grc-danger);
  color: var(--grc-danger);
}

/* ============================================================
   TABLES
   ============================================================ */
.grc-table-wrap {
  overflow-x: auto;
  border-radius: var(--grc-radius-lg);
  border: 1px solid var(--grc-border);
}

.grc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--grc-text-sm);
}

.grc-table thead tr {
  background: var(--grc-bg-raised);
}

.grc-table th {
  padding: var(--grc-space-3) var(--grc-space-4);
  text-align: left;
  font-size: var(--grc-text-xs);
  font-weight: 700;
  color: var(--grc-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--grc-tracking-wider);
  white-space: nowrap;
}

.grc-table td {
  padding: var(--grc-space-4);
  color: var(--grc-text-secondary);
  vertical-align: middle;
}

.grc-table tbody tr {
  border-top: 1px solid var(--grc-border);
  transition: background var(--grc-transition);
}

.grc-table tbody tr:hover {
  background: var(--grc-bg-raised);
}

.grc-table-cell--primary {
  color: var(--grc-text-primary);
  font-weight: 500;
}

.grc-table-cell--muted {
  color: var(--grc-text-muted);
  font-size: var(--grc-text-xs);
}

/* ============================================================
   FORMS
   ============================================================ */
.grc-field {
  display: flex;
  flex-direction: column;
  gap: var(--grc-space-2);
}

.grc-field-label {
  font-size: var(--grc-text-sm);
  font-weight: 600;
  color: var(--grc-text-primary);
}

.grc-field-label--required::after {
  content: ' *';
  color: var(--grc-danger);
}

.grc-input {
  width: 100%;
  padding: var(--grc-space-3) var(--grc-space-4);
  background: var(--grc-bg-raised);
  border: 1px solid var(--grc-border);
  border-radius: var(--grc-radius);
  font-family: var(--grc-font-sans);
  font-size: var(--grc-text-sm);
  color: var(--grc-text-primary);
  transition: border-color var(--grc-transition), box-shadow var(--grc-transition);
  outline: none;
}

.grc-input::placeholder {
  color: var(--grc-text-muted);
}

.grc-input:focus {
  border-color: var(--grc-border-focus);
  box-shadow: var(--grc-glow);
}

.grc-input--error {
  border-color: var(--grc-danger);
}

.grc-field-hint {
  font-size: var(--grc-text-xs);
  color: var(--grc-text-muted);
}

.grc-field-error {
  font-size: var(--grc-text-xs);
  color: var(--grc-danger);
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.grc-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grc-bg-base);
  padding: var(--grc-space-6);
}

.grc-login-card {
  width: 100%;
  max-width: 400px;
  background: var(--grc-bg-surface);
  border: 1px solid var(--grc-border);
  border-radius: var(--grc-radius-lg);
  padding: var(--grc-space-12) var(--grc-space-8);
  box-shadow: var(--grc-shadow-lg);
  text-align: center;
}

.grc-login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--grc-space-3);
  margin-bottom: var(--grc-space-8);
}

.grc-login-title {
  font-size: var(--grc-text-2xl);
  font-weight: 700;
  letter-spacing: var(--grc-tracking-tight);
  margin-bottom: var(--grc-space-2);
}

.grc-login-subtitle {
  font-size: var(--grc-text-sm);
  color: var(--grc-text-secondary);
  margin-bottom: var(--grc-space-8);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.grc-empty {
  text-align: center;
  padding: var(--grc-space-16) var(--grc-space-8);
  color: var(--grc-text-muted);
}

.grc-empty__icon {
  font-size: 2.5rem;
  margin-bottom: var(--grc-space-4);
}

.grc-empty__title {
  font-size: var(--grc-text-lg);
  font-weight: 600;
  color: var(--grc-text-secondary);
  margin-bottom: var(--grc-space-2);
}

.grc-empty__body {
  font-size: var(--grc-text-sm);
}

/* ============================================================
   STAT PATTERN
   ============================================================ */
.grc-stat {
  display: flex;
  flex-direction: column;
  gap: var(--grc-space-1);
}

.grc-stat__value {
  font-size: var(--grc-text-3xl);
  font-weight: 700;
  letter-spacing: var(--grc-tracking-tight);
  color: var(--grc-text-primary);
  line-height: 1.1;
}

.grc-stat__label {
  font-size: var(--grc-text-sm);
  color: var(--grc-text-secondary);
  font-weight: 500;
}

/* ============================================================
   MOBILE SIDEBAR — HAMBURGER + BACKDROP + RESPONSIVE LAYOUT
   ============================================================ */

/* Hamburger button — hidden on desktop, appears in topbar on mobile */
.grc-sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  width: 36px;
  height: 28px;
  padding: 4px 0;
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.grc-sidebar-toggle span {
  display: block;
  height: 2px;
  background: var(--grc-text-secondary);
  border-radius: 2px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.grc-sidebar-toggle:focus-visible {
  outline: none;
  box-shadow: var(--grc-glow);
  border-radius: var(--grc-radius-sm);
}

/* Backdrop — covers content when sidebar is open */
.grc-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 49;
}

/* Open state — toggled via JS (body.grc-sidebar-open) */
body.grc-sidebar-open .grc-sidebar-backdrop { display: block; }
body.grc-sidebar-open .grc-sidebar-toggle span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
body.grc-sidebar-open .grc-sidebar-toggle span:nth-child(2) { opacity: 0; }
body.grc-sidebar-open .grc-sidebar-toggle span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 900px) {
  .grc-sidebar-toggle { display: flex; }

  /* Sidebar becomes a fixed drawer that slides in from the left */
  .grc-sidebar {
    position: fixed;
    left: 0;
    top: var(--grc-topbar-height);
    width: min(280px, 84vw);
    height: calc(100vh - var(--grc-topbar-height));
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    /* flex layout so footer pins to bottom */
    display: flex;
    flex-direction: column;
  }

  body.grc-sidebar-open .grc-sidebar { transform: translateX(0); }

  /* Sidebar footer sticks to the bottom of the drawer */
  .grc-sidebar__footer { margin-top: auto; }

  /* Content takes full width since sidebar is out of flow */
  .grc-content { padding: var(--grc-space-4); }

  /* Hide app sub-label to save topbar space on small screens */
  .grc-topbar__divider,
  .grc-topbar__app-name { display: none; }
}

/* ============================================================
   DESKTOP SIDEBAR COLLAPSE
   ============================================================ */
.grc-sidebar__collapse-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--grc-space-3) var(--grc-space-4);
  background: transparent;
  border: none;
  border-top: 1px solid var(--grc-border);
  color: var(--grc-text-muted);
  cursor: pointer;
  transition: color var(--grc-transition), background var(--grc-transition);
  flex-shrink: 0;
}
.grc-sidebar__collapse-btn:hover {
  color: var(--grc-text-primary);
  background: var(--grc-bg-raised);
}
.grc-sidebar__collapse-btn:focus-visible {
  outline: none;
  box-shadow: var(--grc-glow);
}

@media (min-width: 901px) {
  .grc-sidebar__collapse-btn { display: flex; }

  body.grc-sidebar-collapsed .grc-sidebar {
    width: 52px;
    overflow: hidden;
  }
  body.grc-sidebar-collapsed .grc-sidebar__label,
  body.grc-sidebar-collapsed .grc-sidebar__user-info {
    display: none;
  }
  body.grc-sidebar-collapsed .grc-sidebar__link,
  body.grc-sidebar-collapsed .grc-sidebar__signout {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    white-space: nowrap;
  }
  body.grc-sidebar-collapsed .grc-sidebar__user {
    justify-content: center;
  }
  body.grc-sidebar-collapsed .grc-sidebar__collapse-btn svg {
    transform: scaleX(-1);
  }
  body.grc-sidebar-collapsed .grc-content {
    flex: 1;
  }
}

/* ============================================================
   REDUCED MOTION — disable animations for vestibular safety
   (WCAG 2.1 SC 2.3.3 / ADA)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .grc-sidebar,
  .grc-sidebar-toggle span,
  .grc-theme-toggle,
  .grc-sidebar__link,
  .grc-topbar__logo,
  .grc-btn {
    transition: none !important;
    animation: none !important;
  }
}
