/**
 * Layout CSS - Main site structure using CSS Grid
 * Based on ADR-0007: Page Layout and Navigation System
 * DARK THEME
 */

:root {
  /* Backgrounds */
  --bg-body: #0e0e0e;
  --bg-primary: #1a1a1a;
  --bg-secondary: #0a0a0a;
  --bg-hover: #242424;
  --bg-disabled: #3a3a3a;
  --bg-darkest: #000000;

  /* Borders */
  --border-primary: #2a2a2a;
  --border-emphasis: #3a3a3a;

  /* Text */
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-muted: #808080;
  --text-disabled: #666666;

  /* Accent */
  --accent-red: #e63946;
  --accent-red-hover: #d62839;
  --accent-red-bg: rgba(230, 57, 70, 0.2);

  /* Status */
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --info: #60a5fa;

  /* Transparent Backgrounds */
  --success-bg: rgba(74, 222, 128, 0.2);
  --error-bg: rgba(248, 113, 113, 0.2);
  --warning-bg: rgba(251, 191, 36, 0.2);
  --info-bg: rgba(96, 165, 250, 0.2);

  /* Scheme */
  color-scheme: dark;
}

/* Light theme overrides */
html[data-theme="light"] {
  /* Backgrounds */
  --bg-body: #f5f5f5;
  --bg-primary: #ffffff;
  --bg-secondary: #eaeaea;
  --bg-hover: #e0e0e0;
  --bg-disabled: #d0d0d0;
  --bg-darkest: #dcdcdc;

  /* Borders */
  --border-primary: #d0d0d0;
  --border-emphasis: #b0b0b0;

  /* Text */
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #707070;
  --text-disabled: #a0a0a0;

  /* Accent — slightly darker for white-bg contrast */
  --accent-red: #d62839;
  --accent-red-hover: #b81e2e;
  --accent-red-bg: rgba(214, 40, 57, 0.1);

  /* Status — darker for white-bg readability */
  --success: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --info: #2563eb;

  /* Transparent Backgrounds */
  --success-bg: rgba(22, 163, 74, 0.1);
  --error-bg: rgba(220, 38, 38, 0.1);
  --warning-bg: rgba(217, 119, 6, 0.1);
  --info-bg: rgba(37, 99, 235, 0.1);

  /* Scheme */
  color-scheme: light;
}

html {
  scrollbar-color: var(--border-primary) var(--bg-body);
}

::selection {
  background-color: var(--accent-red-bg);
}

::marker {
  color: var(--accent-red);
}

input, textarea, select {
  accent-color: var(--accent-red);
  caret-color: var(--accent-red);
}

*, *::before, *::after {
  box-sizing: border-box;
}

/* body should be marginless */
body {
  margin: 0;
}

/* Global link colors */
a {
  color: var(--accent-red);
}

a:visited {
  color: var(--accent-red);
}

a:hover {
  color: var(--accent-red-hover);
}

/* Base layout */
.site {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: 'Lato', sans-serif;
  color: var(--text-primary);
  background: var(--bg-body);
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent-red);
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* Header grid */
.masthead {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "header-left header-right";
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-primary);
  border-bottom: 2px solid var(--border-primary);
}

#header-left { grid-area: header-left; }
#header-right {
  grid-area: header-right;
  justify-self: end;
}

/* Main content grid */
main {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "pre-content pre-content pre-content"
    "sidebar-left content sidebar-right";
  flex: 1;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  background: var(--bg-body);
}

#pre-content { grid-area: pre-content; }
#sidebar-left { grid-area: sidebar-left; min-width: 220px; }
#content {
  grid-area: content;
  max-width: 1200px;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.4);
  border: 1px solid var(--border-primary);
}
#sidebar-right {
  grid-area: sidebar-right;
  min-width: 280px;
  max-width: 350px;
}

/* Activity sidebar — scrollable event timeline in right sidebar */
.activity-sidebar {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1rem;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  position: sticky;
  top: 1rem;
}

.activity-sidebar h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent-red);
  padding-bottom: 0.5rem;
}

.activity-sidebar .activity-entry {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-primary);
  font-size: 0.8125rem;
}

.activity-sidebar .activity-entry:last-child {
  border-bottom: none;
}

.activity-sidebar .activity-entry-new {
  border-left: 2px solid var(--accent-red);
  padding-left: 0.5rem;
}

.activity-sidebar .new-badge {
  display: inline-block;
  background: var(--accent-red);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  padding: 0.0625rem 0.375rem;
  border-radius: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 0.375rem;
  vertical-align: middle;
}

.activity-sidebar .activity-timestamp {
  color: var(--text-muted);
  font-size: 0.75rem;
  display: block;
  margin-bottom: 0.125rem;
}

.activity-sidebar .activity-action {
  color: var(--text-primary);
}

.activity-sidebar .activity-detail {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.activity-sidebar .activity-summary {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

/* Auto-hide empty regions */
.page-region:empty {
  display: none;
}

/* Responsive: Stack on tablet */
@media (max-width: 768px) {
  .masthead {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header-left"
      "header-right";
    padding: 1rem;
  }

  main {
    grid-template-columns: 1fr;
    grid-template-areas:
      "pre-content"
      "sidebar-left"
      "content"
      "sidebar-right";
    padding: 1rem;
    gap: 0.75rem;
  }

  #sidebar-left { min-width: 0; }
  #sidebar-right { min-width: 0; max-width: none; }
  #content { padding: 1rem; }

  /* All sidebar navs: collapsible on mobile */
  #sidebar-left nav .nav-header {
    cursor: pointer;
    position: relative;
    padding-right: 2rem;
  }

  #sidebar-left nav .nav-header::after {
    content: "\2630";
    position: absolute;
    right: 0.5rem;
    top: 0.5rem;
    font-size: 1.2rem;
    color: var(--text-secondary);
  }

  #sidebar-left nav ul {
    display: none;
  }

  #sidebar-left nav.sidebar-open ul {
    display: block;
  }

  #sidebar-left nav.sidebar-open .nav-header::after {
    content: "\2715";
  }
}

/* Responsive: Phone (375px) */
@media (max-width: 480px) {
  .masthead {
    padding: 0.75rem;
  }

  main {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  #content {
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: hidden;
    max-width: 100vw;
  }
}

/* =========================================================================
   Bootstrap Loading Overlay
   ========================================================================= */

.bootstrap-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  animation: bootstrap-fade-in 0.2s ease-out;
}

.bootstrap-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2.5rem 3rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  min-width: 280px;
  max-width: 400px;
}

.bootstrap-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-emphasis);
  border-top-color: var(--accent-red);
  border-radius: 50%;
  animation: bootstrap-spin 0.8s linear infinite;
}

.bootstrap-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.bootstrap-requests {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
}

.bootstrap-request {
  padding: 0.3rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.bootstrap-request::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.6rem;
  border-radius: 50%;
  background: var(--accent-red);
  animation: bootstrap-pulse 1.2s ease-in-out infinite;
}

@keyframes bootstrap-spin {
  to { transform: rotate(360deg); }
}

@keyframes bootstrap-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes bootstrap-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

/* Re-auth overlay (reuses bootstrap-overlay/modal/spinner) */
.reauth-message {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

.reauth-cancel {
  margin-top: 0.5rem;
}
