/* rs_server/server/static/dashboard/dashboard.css */
/* RedSwarm Brain Design System — dark maroon theme with red primary accent */

/* ===================================================================
   1. DESIGN TOKENS
   =================================================================== */
:root {
  /* --- Brand Colors --- */
  --rs-primary: #d93636;
  --rs-primary-dark: #b82e2e;
  --rs-primary-rgb: 217, 54, 54;

  /* --- Semantic Colors (status / severity) --- */
  --rs-success: #1cc88a;
  --rs-info: #36b9cc;
  --rs-warning: #f6c23e;
  --rs-danger: #e74a3b;
  --rs-secondary: #858796;

  /* --- Surface / Background --- */
  --rs-bg-dark: #2c1810;
  --rs-bg-gradient: linear-gradient(
    135deg,
    #3d2018 0%,
    #2c1810 50%,
    #1a0f0c 100%
  );
  --rs-form-bg: #f5f5f5;
  --rs-code-bg: #f8f9fa;
  --rs-surface: #ffffff;

  /* --- Text --- */
  --rs-text-dark: #1f2937;
  --rs-text-muted: #858796;
  --rs-text-light: #d1d5db;

  /* --- Typography --- */
  --rs-font-size-xs: 0.7rem;
  --rs-font-size-sm: 0.85rem;
  --rs-font-size-base: 0.95rem;
  --rs-font-size-lg: 1.1rem;

  /* --- Spacing --- */
  --rs-border-left-width: 0.25rem;
  --rs-card-gap: 1.5rem;

  /* --- Z-index layers --- */
  --rs-z-sidebar: 1040;
  --rs-z-backdrop: 1030;
  --rs-z-mobile-header: 1050;

  /* --- Transitions --- */
  --rs-transition-fast: 0.2s ease;
  --rs-transition-base: 0.25s ease-out;

  /* --- Scrollable container max-heights --- */
  --rs-scroll-sm: 300px;
  --rs-scroll-md: 400px;
  --rs-scroll-lg: 600px;

  /* Chart.js: RGB triplets for rgb() usage */
  --rs-chart-line: 217, 54, 54;
  --rs-chart-detected: 217, 54, 54;
  --rs-chart-neutral: 108, 117, 125;
}

/* ===================================================================
   2. BOOTSTRAP OVERRIDES (primary brand color)
   =================================================================== */
.btn-primary,
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--rs-primary);
  border-color: var(--rs-primary);
}
.btn-primary:hover {
  background-color: var(--rs-primary-dark);
  border-color: var(--rs-primary-dark);
}
.btn-primary:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--rs-primary-rgb), 0.5);
}
.btn-primary:active {
  background-color: #a52828;
  border-color: #a52828;
}
.text-primary {
  color: var(--rs-primary) !important;
}
.border-primary {
  border-color: var(--rs-primary) !important;
}
a.text-primary:hover,
a.text-primary:focus {
  color: var(--rs-primary-dark) !important;
}

body {
  font-size: var(--rs-font-size-base);
}

/* ===================================================================
   3. MOBILE HEADER
   =================================================================== */
.dashboard-mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--rs-z-mobile-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--rs-bg-gradient);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.dashboard-mobile-header-brand {
  color: #fff;
  font-weight: 600;
  font-size: var(--rs-font-size-lg);
}

/* ===================================================================
   4. SIDEBAR BACKDROP
   =================================================================== */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--rs-z-backdrop);
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--rs-transition-fast),
    visibility var(--rs-transition-fast);
}
body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  visibility: visible;
}

/* ===================================================================
   5. SIDEBAR
   =================================================================== */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: var(--rs-z-sidebar);
  padding: 0;
  width: 240px;
  background: var(--rs-bg-gradient);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.2);
  transition: transform var(--rs-transition-base);
}
@media (max-width: 767.98px) {
  .sidebar {
    top: 0;
    width: 280px;
    max-width: 85vw;
    transform: translateX(-100%);
    display: block;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .dashboard-main {
    margin-left: 0;
    padding-top: 3.5rem;
  }
  /* Improve readability of stat card labels on small screens */
  .stat-card-icon {
    font-size: 1.5rem;
  }
  /* Prevent long code/pattern strings from breaking layout */
  .list-group-item code,
  td code {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-all;
  }
  /* Stack action buttons vertically on narrow screens */
  .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.8);
  padding: 0.75rem 1rem;
}
.sidebar .nav-link:hover {
  color: #fff;
  background-color: rgba(var(--rs-primary-rgb), 0.25);
}
.sidebar .nav-link.active {
  color: #fff;
  background-color: var(--rs-primary);
}
.sidebar .nav-link:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: -2px;
}
.sidebar .nav-link i {
  margin-right: 0.5rem;
}
.sidebar .sidebar-group-label {
  padding-top: 0.75rem;
  margin-top: 0.25rem;
}
.sidebar .sidebar-group-label:first-child {
  padding-top: 0;
  margin-top: 0;
}

/* ===================================================================
   6. MAIN CONTENT AREA
   =================================================================== */
body {
  overflow-x: hidden;
}
.dashboard-main {
  margin-left: 0;
  padding: 0 1rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
@media (min-width: 768px) {
  .dashboard-main {
    margin-left: 240px;
    padding: 0 1.5rem;
    width: calc(100% - 240px);
  }
}

/* ===================================================================
   7. CARDS & STAT CARD BORDERS
   =================================================================== */
.card {
  margin-bottom: var(--rs-card-gap);
}

.border-left-primary {
  border-left: var(--rs-border-left-width) solid var(--rs-primary) !important;
}
.border-left-success {
  border-left: var(--rs-border-left-width) solid var(--rs-success) !important;
}
.border-left-info {
  border-left: var(--rs-border-left-width) solid var(--rs-info) !important;
}
.border-left-warning {
  border-left: var(--rs-border-left-width) solid var(--rs-warning) !important;
}
.border-left-danger {
  border-left: var(--rs-border-left-width) solid var(--rs-danger) !important;
}
.border-left-secondary {
  border-left: var(--rs-border-left-width) solid var(--rs-secondary) !important;
}

/* Stat card icon sizing (replacing SB Admin's fa-2x) */
.stat-card-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--rs-text-light);
}

/* Clickable stat card hover lift */
a:hover > .card[style*="cursor:pointer"] {
  transform: translateY(-3px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

/* ===================================================================
   8. UTILITY CLASSES
   =================================================================== */
.text-xs {
  font-size: var(--rs-font-size-xs);
}
.text-gray-800 {
  color: var(--rs-text-dark);
}
.text-gray-300 {
  color: var(--rs-text-light);
}
.font-weight-bold {
  font-weight: 700;
}

/* Scrollable containers (replaces inline style="max-height: Xpx; overflow-y: auto") */
.rs-scroll-sm {
  max-height: var(--rs-scroll-sm);
  overflow: auto;
}
.rs-scroll-md {
  max-height: var(--rs-scroll-md);
  overflow: auto;
}
.rs-scroll-lg {
  max-height: var(--rs-scroll-lg);
  overflow: auto;
}

/* ===================================================================
   9. COMPONENT DEFAULTS
   =================================================================== */
.badge {
  font-size: var(--rs-font-size-sm);
}
.badge-critical {
  background-color: #85182a;
}

/* Access Control Matrix gap highlighting */
.acm-gap-critical {
  background-color: rgba(220, 53, 69, 0.15) !important;
}
.acm-gap-warning {
  background-color: rgba(255, 193, 7, 0.12) !important;
}
.acm-gap-critical td:first-child::before {
  content: "\26A0\FE0F ";
}

/* ACM Role filter toggle — distinct colors per role with higher contrast on hover */
.acm-role-toggle {
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.acm-role-toggle:nth-child(6n+1) { --_role-hue: 210; }
.acm-role-toggle:nth-child(6n+2) { --_role-hue: 150; }
.acm-role-toggle:nth-child(6n+3) { --_role-hue: 30;  }
.acm-role-toggle:nth-child(6n+4) { --_role-hue: 270; }
.acm-role-toggle:nth-child(6n+5) { --_role-hue: 0;   }
.acm-role-toggle:nth-child(6n+6) { --_role-hue: 180; }
.acm-role-toggle.active {
  background-color: hsl(var(--_role-hue, 210) 55% 45%);
  border-color: hsl(var(--_role-hue, 210) 55% 45%);
  color: #fff;
}
.acm-role-toggle:hover {
  background-color: hsl(var(--_role-hue, 210) 65% 35%);
  border-color: hsl(var(--_role-hue, 210) 65% 35%);
  color: #fff;
}
.acm-role-toggle:not(.active) {
  background-color: transparent;
  border-color: hsl(var(--_role-hue, 210) 40% 60%);
  color: hsl(var(--_role-hue, 210) 40% 50%);
}
.acm-role-toggle:not(.active):hover {
  background-color: hsl(var(--_role-hue, 210) 50% 92%);
  border-color: hsl(var(--_role-hue, 210) 50% 45%);
  color: hsl(var(--_role-hue, 210) 50% 30%);
}

/* ACM table: URL column left-aligned, compact badges */
#acmTable td code {
  font-size: var(--rs-font-size-sm);
  word-break: break-all;
}
#acmTable .badge {
  font-size: var(--rs-font-size-xs);
  padding: 0.2em 0.45em;
}

/* Visited URLs table: URL column left-aligned with break */
.table td.text-break code {
  font-size: var(--rs-font-size-sm);
  word-break: break-all;
}

/* Collapse chevron rotation */
[data-bs-toggle="collapse"][aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
  transition: transform 0.2s ease;
}
[data-bs-toggle="collapse"] .bi-chevron-down {
  transition: transform 0.2s ease;
}

code {
  font-size: 0.9em;
  background-color: var(--rs-code-bg);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  overflow-wrap: break-word;
  word-break: break-word;
}
pre code {
  background-color: inherit;
  color: inherit;
  padding: 0;
  border-radius: 0;
}
pre {
  overflow-x: auto;
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ===================================================================
   10. LOGIN PAGE
   =================================================================== */
.login-body {
  background: var(--rs-bg-gradient);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.login-card-header {
  background: var(--rs-primary);
  color: white;
  text-align: center;
  padding: 1.75rem 1.5rem;
}
.login-card-header i {
  font-size: 2.5rem;
  opacity: 0.95;
}
.login-card-header h3 {
  margin: 0.5rem 0 0.25rem;
  font-weight: 600;
  font-size: 1.35rem;
}
.login-card-header p {
  margin: 0;
  font-size: var(--rs-font-size-base);
  opacity: 0.95;
}
.login-card-body {
  background: var(--rs-form-bg);
  padding: 1.75rem 1.5rem;
}
.login-card-body .form-label {
  font-weight: 600;
  color: #333;
}
.btn-login {
  width: 100%;
  padding: 0.75rem;
  font-weight: 500;
  background-color: var(--rs-primary);
  border-color: var(--rs-primary);
}
.btn-login:hover {
  background-color: var(--rs-primary-dark);
  border-color: var(--rs-primary-dark);
}

/* ===================================================================
   11. BULK ACTIONS TOOLBAR
   =================================================================== */
.bulk-actions-toolbar {
  display: none;
  background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
  border-bottom: 2px solid var(--rs-primary);
  animation: slideDown 0.2s ease-out;
}
.bulk-actions-toolbar.is-visible {
  display: block;
}
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Row checkboxes */
.table .form-check-input {
  width: 1.15em;
  height: 1.15em;
  cursor: pointer;
}
.table .form-check-input:checked {
  background-color: var(--rs-primary);
  border-color: var(--rs-primary);
}
.table tbody tr {
  transition: background-color 0.15s ease;
}
.table tr:has(.form-check-input:checked) {
  background-color: rgba(133, 24, 42, 0.04);
}

/* Toast notifications */
.toast-container .toast {
  min-width: 300px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-radius: 0.5rem;
}

/* Confirm-delete modal */
#confirmDeleteModal .modal-content {
  border-top: 3px solid var(--bs-danger);
  border-radius: 0.75rem;
}
#confirmDeleteModal .modal-body {
  font-size: 0.95rem;
  line-height: 1.6;
}
#confirmDeleteModal .modal-body ul {
  list-style: disc;
  padding-left: 1.5rem;
  font-size: 0.9rem;
  color: var(--bs-secondary);
}

/* API Key reveal modal — smooth entrance */
#apiKeyModal .modal-dialog {
  transition:
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.3s ease;
}
#apiKeyModal.modal.fade .modal-dialog {
  transform: scale(0.85) translateY(20px);
  opacity: 0;
}
#apiKeyModal.modal.show .modal-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}
#apiKeyModal .modal-content {
  border-top: 3px solid var(--rs-primary);
  border-radius: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

/* ===================================================================
   12. CHART CONTAINERS
   =================================================================== */
.chart-pie {
  min-height: 200px;
}
canvas {
  max-width: 100%;
}

/* ===================================================================
   12b. PAGINATION — unified brand-color style (« < 1 2 3 … N > »)
   =================================================================== */
.rs-pagination .page-link {
  color: #6c757d;
  background-color: #fff;
  border: 1px solid #dee2e6;
  padding: 0.375rem 0.7rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  min-width: 2.2rem;
  text-align: center;
  transition:
    color 0.15s ease-in-out,
    background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out;
}
.rs-pagination .page-link:hover {
  color: var(--rs-primary-dark);
  background-color: #f8f9fa;
  border-color: #dee2e6;
  z-index: 2;
}
.rs-pagination .page-link:focus {
  box-shadow: 0 0 0 0.2rem rgba(var(--rs-primary-rgb), 0.25);
  z-index: 3;
}
.rs-pagination .page-item.active .page-link {
  color: #fff;
  background-color: var(--rs-primary);
  border-color: var(--rs-primary);
  z-index: 3;
}
.rs-pagination .page-item.disabled .page-link {
  color: #c8c8c8;
  background-color: #fff;
  border-color: #dee2e6;
  pointer-events: none;
}
/* Legacy non-.rs-pagination overrides (backward compat) */
.page-item.active .page-link {
  background-color: var(--rs-primary);
  border-color: var(--rs-primary);
}
.page-link {
  color: var(--rs-primary);
}
.page-link:hover {
  color: var(--rs-primary-dark);
}

/* ===================================================================
   12c. TABLE ALIGNMENT & COLUMN WIDTHS
   =================================================================== */
.table > thead > tr > th {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  font-size: var(--rs-font-size-sm);
}
.table > tbody > tr > td {
  vertical-align: middle;
  text-align: center;
}
.table > tbody > tr > td:first-child,
.table > thead > tr > th:first-child {
  text-align: left;
}
.table .text-start {
  text-align: left !important;
}
.table .text-end {
  text-align: right !important;
}

/* ===================================================================
   13. FOCUS RING (accessibility)
   =================================================================== */
:focus-visible {
  outline: 2px solid var(--rs-primary);
  outline-offset: 2px;
}

/* ===================================================================
   14. PRINT STYLES
   =================================================================== */
@media print {
  .sidebar,
  .sidebar-backdrop,
  .dashboard-mobile-header,
  .bulk-actions-toolbar,
  .btn {
    display: none !important;
  }
  .dashboard-main {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 0 !important;
  }
}
