/* ==========================================================================
   GCP IAM Changelog — Dark Theme
   Color palette:
     Background:  #0d1117
     Card bg:     #161b22
     Border:      #30363d
     Text:        #c9d1d9
     Muted text:  #8b949e
     CRITICAL:    #ff4444
     HIGH:        #ff8800
     MEDIUM:      #ffcc00
     INFO:        #58a6ff
     Accent:      #238636 (green actions)
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  --bg:           #0d1117;
  --card-bg:      #161b22;
  --border:       #30363d;
  --text:         #c9d1d9;
  --muted:        #8b949e;

  --critical:     #ff4444;
  --high:         #ff8800;
  --medium:       #ffcc00;
  --info:         #58a6ff;
  --accent:       #238636;

  --radius:       6px;
  --header-h:     49px;
  --font-mono:    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --font-sans:    -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --transition:   0.15s ease;
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

ol, ul { list-style: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   Loading Overlay
   -------------------------------------------------------------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay.hidden { display: none; }

.loading-content {
  text-align: center;
  max-width: 360px;
  padding: 2rem;
}

.loading-shield {
  width: 3rem;
  height: 3rem;
  color: var(--info);
  margin-bottom: 1rem;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}

.loading-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--info);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.loading-status {
  font-size: 0.85rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-icon {
  width: 1.4rem;
  height: 1.4rem;
  color: var(--info);
  flex-shrink: 0;
}

h1 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.last-updated {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Filter Bar
   -------------------------------------------------------------------------- */
.filter-bar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h); /* below header */
  z-index: 99;
}

.filter-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-group-search { flex: 1 1 200px; }

.filter-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 500;
}

.filter-sep {
  font-size: 0.8rem;
  color: var(--muted);
}

.chip-group { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 2rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  background: transparent;
  letter-spacing: 0.04em;
}

.chip:not(.active) { opacity: 0.35; }
.chip:hover { opacity: 1; }
.chip:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

.chip-critical { color: var(--critical); border-color: var(--critical); }
.chip-critical.active { background: rgba(255, 68, 68, 0.1); }

.chip-high { color: var(--high); border-color: var(--high); }
.chip-high.active { background: rgba(255, 136, 0, 0.1); }

.chip-medium { color: var(--medium); border-color: var(--medium); }
.chip-medium.active { background: rgba(255, 204, 0, 0.1); }

.chip-info { color: var(--info); border-color: var(--info); }
.chip-info.active { background: rgba(88, 166, 255, 0.1); }

.chip-count {
  background: rgba(255,255,255,0.08);
  border-radius: 1rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
}

.filter-select,
.filter-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition);
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: var(--info);
}

.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.filter-search { width: 100%; padding-right: 5rem; }

.search-count {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

/* Date preset buttons */
.date-presets {
  display: flex;
  gap: 0.2rem;
}

.btn-preset {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  white-space: nowrap;
}

.btn-preset:hover { color: var(--text); border-color: var(--info); }
.btn-preset.active { color: var(--info); border-color: var(--info); background: rgba(88, 166, 255, 0.1); }

/* --------------------------------------------------------------------------
   Active Filter Tags
   -------------------------------------------------------------------------- */
.active-filters {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.active-filters.hidden { display: none; }

.active-filters-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.4rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 2rem;
  font-size: 0.75rem;
  color: var(--text);
  white-space: nowrap;
}

.filter-tag-label {
  color: var(--muted);
  font-weight: 500;
}

.filter-tag-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.1rem;
  transition: color var(--transition);
}

.filter-tag-remove:hover { color: var(--critical); }

.btn-clear-all {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
  margin-left: auto;
}

.btn-clear-all:hover { color: var(--text); border-color: var(--text); }

/* --------------------------------------------------------------------------
   Stats Bar
   -------------------------------------------------------------------------- */
.stats-bar {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.stats-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}

.stat-num {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-critical .stat-num { color: var(--critical); }
.stat-high     .stat-num { color: var(--high); }
.stat-medium   .stat-num { color: var(--medium); }
.stat-info     .stat-num { color: var(--info); }

.stat-export {
  margin-left: auto;
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  color: var(--info);
  border: 1px solid var(--info);
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn-export:hover {
  background: rgba(88, 166, 255, 0.12);
}

.btn-export:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.btn-export:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.export-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Main / Timeline
   -------------------------------------------------------------------------- */
.timeline-container {
  flex: 1;
  max-width: 1200px;
  margin: 1.5rem auto;
  width: 100%;
  padding: 0 1.5rem;
}

.timeline { display: flex; flex-direction: column; gap: 0.6rem; }

/* --------------------------------------------------------------------------
   Entry Card
   -------------------------------------------------------------------------- */
.entry-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 4px solid transparent;
  overflow: hidden;
  transition: border-color var(--transition);
}

.entry-card[data-severity="CRITICAL"] { border-left-color: var(--critical); }
.entry-card[data-severity="HIGH"]     { border-left-color: var(--high); }
.entry-card[data-severity="MEDIUM"]   { border-left-color: var(--medium); }
.entry-card[data-severity="INFO"]     { border-left-color: var(--info); }

.entry-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  user-select: none;
  flex-wrap: wrap;
}

.entry-summary:focus-visible { outline: 2px solid var(--info); outline-offset: -2px; }

.entry-expand-icon {
  color: var(--muted);
  transition: transform var(--transition);
  flex-shrink: 0;
  font-size: 0.8rem;
}

.entry-card.expanded .entry-expand-icon { transform: rotate(90deg); }

.badge-severity {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

[data-severity="CRITICAL"] .badge-severity { background: rgba(255,68,68,0.15);  color: var(--critical); }
[data-severity="HIGH"]     .badge-severity { background: rgba(255,136,0,0.15);  color: var(--high); }
[data-severity="MEDIUM"]   .badge-severity { background: rgba(255,204,0,0.15);  color: var(--medium); }
[data-severity="INFO"]     .badge-severity { background: rgba(88,166,255,0.15); color: var(--info); }

.badge-dimension {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  flex-shrink: 0;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.entry-main-text {
  flex: 1 1 200px;
  font-size: 0.92rem;
  color: var(--text);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-main-text mark {
  background: rgba(255, 204, 0, 0.3);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.entry-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.entry-date {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.entry-commit {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.tag-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  border: 1px solid;
  font-weight: 600;
}

.tag-PrivEsc            { color: var(--critical); border-color: var(--critical); background: rgba(255,68,68,0.1); }
.tag-CredentialExposure { color: var(--high);     border-color: var(--high);     background: rgba(255,136,0,0.1); }
.tag-DataAccess         { color: var(--medium);   border-color: var(--medium);   background: rgba(255,204,0,0.1); }

/* --------------------------------------------------------------------------
   Entry Detail Panel
   -------------------------------------------------------------------------- */
.entry-details {
  display: none;
  border-top: 1px solid var(--border);
  padding: 0.8rem 1rem;
  background: rgba(0,0,0,0.2);
}

.entry-card.expanded .entry-details { display: block; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem 1.2rem;
  margin-bottom: 0.6rem;
}

.detail-row { display: flex; flex-direction: column; gap: 0.1rem; }

.detail-key {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-val {
  font-size: 0.88rem;
  color: var(--text);
  font-family: var(--font-mono);
  word-break: break-all;
}

.detail-val mark {
  background: rgba(255, 204, 0, 0.3);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.detail-raw {
  margin-top: 0.5rem;
}

.detail-raw pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   Empty State
   -------------------------------------------------------------------------- */
.no-results {
  padding: 3rem 1rem;
}

.no-results.hidden { display: none; }

.empty-state {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-icon {
  width: 3rem;
  height: 3rem;
  color: var(--muted);
  opacity: 0.5;
}

.empty-title {
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 600;
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-reset-empty {
  background: transparent;
  color: var(--info);
  border: 1px solid var(--info);
  border-radius: var(--radius);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-top: 0.5rem;
}

.btn-reset-empty:hover {
  background: rgba(88, 166, 255, 0.1);
}

/* --------------------------------------------------------------------------
   Error
   -------------------------------------------------------------------------- */
.error-msg {
  background: rgba(255,68,68,0.1);
  border: 1px solid var(--critical);
  border-radius: var(--radius);
  color: var(--critical);
  padding: 1rem 1.2rem;
  text-align: center;
  font-size: 0.9rem;
}

.error-msg.hidden { display: none; }

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.pagination {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.pagination[hidden] { display: none; }

.pagination-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.btn-page {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  min-width: 2rem;
  text-align: center;
}

.btn-page:hover:not(:disabled):not(.active) { border-color: var(--info); color: var(--info); }
.btn-page:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-page.active {
  background: var(--info);
  color: #fff;
  border-color: var(--info);
}

.page-ellipsis {
  color: var(--muted);
  padding: 0 0.3rem;
  font-size: 0.85rem;
  user-select: none;
}

.pagination-options {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.per-page-select {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
}

.jump-to-page {
  display: flex;
  gap: 0.25rem;
}

.jump-input {
  width: 4.5rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  text-align: center;
}

/* Remove spinner from number input */
.jump-input::-webkit-outer-spin-button,
.jump-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.jump-input[type=number] { -moz-appearance: textfield; }

.btn-go {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer p { max-width: 1200px; margin: 0 auto; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .pagination-inner {
    flex-direction: column;
    align-items: center;
  }
  .pagination-options { flex-wrap: wrap; justify-content: center; }
}

@media (max-width: 640px) {
  .header-inner  { flex-direction: column; align-items: flex-start; }
  .filter-inner  { padding: 0.5rem 1rem; }
  .filter-row    { gap: 0.5rem; }
  .stats-inner   { gap: 0.8rem; justify-content: center; }
  .entry-main-text { white-space: normal; }
  .active-filters-inner { padding: 0.4rem 1rem; }
  .timeline-container { padding: 0 1rem; margin: 1rem auto; }
}
