/* Global design tokens: ONLY black, white, dark red */
:root {
  --color-bg: #ffffff;
  --color-text: #000000;
  --color-accent: #8b0000; /* dark red */
  --color-card-bg: #ffffff;
  --color-border: #000000;
  --color-muted: rgba(0, 0, 0, 0.7);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* Dark mode via data-theme attribute */
html[data-theme="dark"] {
  --color-bg: #000000;
  --color-text: #ffffff;
  --color-card-bg: #000000;
  --color-border: #ffffff;
  --color-muted: rgba(255, 255, 255, 0.7);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* Fallback to prefers-color-scheme if no data-theme is set */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --color-bg: #000000;
    --color-text: #ffffff;
    --color-card-bg: #000000;
    --color-border: #ffffff;
    --color-muted: rgba(255, 255, 255, 0.7);
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.6);
  }
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

body {
  height: 100vh;
  display: flex;
}

#app-root {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: #000000;
  border-right: 1px solid var(--color-border);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  color: #ffffff;
  position: relative;
}

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

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 600;
  letter-spacing: 0.05em;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: #ffffff;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-item.active {
  background: var(--color-accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(139, 0, 0, 0.3);
}

/* Main area */
.main {
  padding: 2rem 2.5rem;
  overflow: auto;
  background: var(--color-bg);
  min-height: 100vh;
}

.main-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

html[data-theme="dark"] .main-header {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

.main-header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.subtitle {
  margin: 0.5rem 0 0;
  font-size: 1rem;
  color: var(--color-muted);
  line-height: 1.5;
}

/* Buttons */
.primary-btn,
.ghost-btn {
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
}

.primary-btn {
  background: var(--color-accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(139, 0, 0, 0.25);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 0, 0, 0.35);
  background: #a00000;
}

.primary-btn:active {
  transform: translateY(0);
}

.ghost-btn {
  background: transparent;
  color: var(--color-accent);
  border: 1.5px solid var(--color-accent);
}

.ghost-btn.small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.ghost-btn:hover {
  background: rgba(139, 0, 0, 0.1);
  border-color: #a00000;
  color: #a00000;
}

.delete-btn {
  color: var(--color-accent) !important;
  border-color: var(--color-accent) !important;
}

.delete-btn:hover {
  background: rgba(139, 0, 0, 0.15) !important;
  border-color: #a00000 !important;
  color: #a00000 !important;
}

/* Cards & layout */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--color-card-bg);
  border-radius: 12px;
  border: 1px solid var(--color-border);
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.card[data-view] {
  cursor: pointer;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-accent);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.card:hover::before {
  transform: scaleX(1);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(-4px);
  border-color: rgba(139, 0, 0, 0.3);
}

.muted {
  color: var(--color-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.view {
  display: none;
  animation: fadeIn 0.4s ease;
}

.view.visible {
  display: block;
}

/* Form */
.form-card {
  max-width: 800px;
}

.form-card h2 {
  margin-bottom: 1.5rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-row label,
.form-row fieldset {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text);
}

input[type="text"],
input[type="url"],
select {
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-card-bg);
  color: var(--color-text);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

input[type="text"]:focus,
input[type="url"]:focus,
select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.1);
  background: var(--color-card-bg);
}

fieldset {
  border-radius: 0.75rem;
  border: 1px solid var(--color-border);
  padding: 0.85rem 0.9rem 0.9rem;
}

legend {
  padding: 0 0.35rem;
  color: var(--color-muted);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  cursor: pointer;
  font-size: 0.8rem;
  background: var(--color-card-bg);
}

.pill input {
  accent-color: var(--color-accent);
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

html[data-theme="dark"] .form-actions {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.form-message {
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.55rem;
  font-size: 0.85rem;
}

.form-message.hidden {
  display: none;
}

.form-message.success {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid #000000;
  color: var(--color-text);
}

.form-message.error {
  background: rgba(139, 0, 0, 0.08);
  border: 1px solid var(--color-accent);
  color: var(--color-accent);
}

/* Table */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.table-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.table-wrapper {
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-card-bg);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  text-align: left;
}

html[data-theme="dark"] th,
html[data-theme="dark"] td {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

th {
  background: rgba(0, 0, 0, 0.03);
  font-weight: 600;
  color: var(--color-text);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

html[data-theme="dark"] th {
  background: rgba(255, 255, 255, 0.05);
}

tbody tr {
  transition: background 0.2s ease;
}

tbody tr:hover {
  background: rgba(139, 0, 0, 0.05);
}

tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.badge.status-pending {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.status-in_progress {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.status-completed {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.status-failed {
  background: rgba(139, 0, 0, 0.12);
  color: var(--color-accent);
}

.risk-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--color-border);
  background: var(--color-card-bg);
}

.risk-low {
  border-color: var(--color-border);
}

.risk-medium {
  border-color: var(--color-border);
}

.risk-high {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.risk-critical {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Detail / findings */
#investigation-detail.open {
  border: 2px solid rgba(139, 0, 0, 0.35);
  box-shadow: 0 8px 28px rgba(139, 0, 0, 0.12);
  margin-bottom: 1.25rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

tbody tr.selected {
  background: rgba(139, 0, 0, 0.08);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.org-link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--color-accent);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.org-link-btn:hover {
  opacity: 0.85;
}

.detail-content {
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Loading */
.form-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  font-size: 0.9rem;
  color: var(--color-muted);
}

.form-loading.hidden {
  display: none !important;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.inline-spinner {
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.5rem;
  width: 16px;
  height: 16px;
}

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

/* Progress */
.progress-wrapper {
  margin-top: 0.75rem;
  width: 100%;
  max-width: 320px;
}

.progress-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 999px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-label {
  margin-top: 0.35rem;
  font-size: 0.8rem;
}

/* Findings & details layout (kept simple, colors via tokens) */
.findings-by-category {
  margin-top: 1rem;
}

.findings-categories {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.finding-category {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--color-card-bg);
}

.finding-category-summary {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  list-style: none;
  transition: background 0.15s ease;
}

.finding-category-summary::-webkit-details-marker {
  display: none;
}

.finding-category-summary:hover {
  background: rgba(0, 0, 0, 0.04);
}

.finding-list {
  margin: 0;
  padding: 0 0 0.5rem 0;
  list-style: none;
}

.finding-item {
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--color-border);
}

.finding-item-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.finding-item-header strong {
  flex: 1;
  min-width: 0;
}

.finding-item-meta {
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.finding-item-desc {
  margin-top: 0.35rem;
  line-height: 1.4;
}

.finding-sources {
  margin-top: 0.35rem;
  font-size: 0.8rem;
}

.finding-sources a,
.finding-sources-list a {
  color: var(--color-accent);
  text-decoration: none;
}

.finding-sources a:hover,
.finding-sources-list a:hover {
  text-decoration: underline;
}

.finding-sources-list {
  margin: 0.25rem 0 0 0;
  padding-left: 1.25rem;
  list-style: disc;
  font-size: 0.8rem;
}

.finding-sources-list li {
  margin-top: 0.2rem;
}

/* Details sections */
.investigation-details {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.details-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.details-section {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.9rem 1rem;
}

.details-section-title {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.details-dl {
  margin: 0;
  display: grid;
  gap: 0.25rem 1rem;
  grid-template-columns: auto 1fr;
  font-size: 0.875rem;
}

.details-dl dt {
  color: var(--color-muted);
  font-weight: 500;
}

.details-dl dd {
  margin: 0;
  color: var(--color-text);
  word-break: break-word;
}

.details-summary,
.details-recommendations {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.45;
}

.details-summary p,
.details-recommendations ul {
  margin: 0.35rem 0 0 0;
}

/* Severity badges (all monochrome / dark red) */
.badge.severity-info {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.severity-low {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.severity-medium {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

.badge.severity-high {
  background: rgba(139, 0, 0, 0.12);
  color: var(--color-accent);
}

.badge.severity-critical {
  background: rgba(139, 0, 0, 0.18);
  color: var(--color-accent);
}

.hidden {
  display: none !important;
}

/* Simple fade-in for detail areas */
.detail-content,
.findings-by-category {
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
@media (max-width: 900px) {
  #app-root {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 1rem;
  }

  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .finding-item-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

