:root {
  --bg-app: #090d16;
  --bg-panel: rgba(17, 24, 39, 0.7);
  --bg-panel-hover: rgba(17, 24, 39, 0.8);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-primary-glow: rgba(99, 102, 241, 0.15);
  
  --color-critical: #ef4444;
  --color-high: #f97316;
  --color-medium: #eab308;
  --color-low: #10b981;
  
  --color-security: #ec4899;
  --color-correctness: #3b82f6;
  --color-performance: #8b5cf6;
  --color-style: #10b981;

  --console-bg: #030712;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
  gap: 1rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  backdrop-filter: blur(12px);
}

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

.logo-icon {
  background: var(--color-primary-glow);
  color: var(--color-primary);
  padding: 0.5rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #fff, #9ca3af);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text .sub-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.header-status-group {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-unknown { background-color: var(--text-muted); }
.dot-healthy { background-color: var(--color-low); box-shadow: 0 0 8px var(--color-low); }
.dot-unhealthy { background-color: var(--color-critical); box-shadow: 0 0 8px var(--color-critical); }

.uptime-badge {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

/* Grid Layout */
.app-grid {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0; /* Important for scroll */
}

/* Panel Styles */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  min-height: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.panel:hover {
  background: var(--bg-panel-hover);
}

.panel-header {
  margin-bottom: 1.25rem;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.panel-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Forms & Controls */
.control-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.flex-grow {
  flex: 1;
  min-height: 0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 0.75rem;
}

label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.6rem 0.75rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  padding-right: 2.5rem;
}

.btn-icon {
  position: absolute;
  right: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.btn-icon:hover {
  color: var(--text-primary);
}

.textarea-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.1rem;
}

.textarea-actions {
  display: flex;
  gap: 0.5rem;
}

textarea {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  resize: none;
  flex: 1;
  min-height: 0;
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.04);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.btn-small {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 4px;
}

.btn-block {
  width: 100%;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.hidden {
  display: none !important;
}

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

/* Right Panel Layout */
.results-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.job-status-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid transparent;
}

.job-status-badge.queued {
  background: rgba(234, 179, 8, 0.1);
  color: var(--color-medium);
  border-color: rgba(234, 179, 8, 0.2);
}

.job-status-badge.running {
  background: rgba(59, 130, 246, 0.1);
  color: var(--color-correctness);
  border-color: rgba(59, 130, 246, 0.2);
  animation: pulse 1.5s infinite alternate;
}

.job-status-badge.done {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-low);
  border-color: rgba(16, 185, 129, 0.2);
}

.job-status-badge.failed {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-critical);
  border-color: rgba(239, 68, 68, 0.2);
}

@keyframes pulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

.results-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.results-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.section-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: var(--text-secondary);
}

.badge {
  font-size: 0.7rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.stream-stats {
  display: flex;
  gap: 0.35rem;
}

.findings-count-badge {
  background: var(--color-primary-glow);
  color: var(--color-primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
}

/* Log Console */
.log-console-wrapper {
  flex: 1;
  min-height: 0;
  background: var(--console-bg);
  border-radius: 8px;
  padding: 0.75rem;
  overflow-y: auto;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.log-console {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #a7f3d0;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.console-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.log-entry {
  animation: fadeIn 0.15s ease-out;
}

.log-entry.info { color: #93c5fd; }
.log-entry.success { color: #6ee7b7; }
.log-entry.warning { color: #fde047; }
.log-entry.error { color: #fca5a5; }

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

/* Findings Viewer */
.findings-list-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

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

.findings-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.8rem;
  text-align: center;
  padding: 2rem 0;
}

/* Finding Card */
.finding-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  animation: slideIn 0.2s ease-out;
}

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

.finding-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.finding-badges {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.card-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* Severities */
.card-badge.critical { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.card-badge.high { background: rgba(249, 115, 22, 0.15); color: #fed7aa; border: 1px solid rgba(249, 115, 22, 0.3); }
.card-badge.medium { background: rgba(234, 179, 8, 0.15); color: #fef08a; border: 1px solid rgba(234, 179, 8, 0.3); }
.card-badge.low { background: rgba(16, 185, 129, 0.15); color: #a7f3d0; border: 1px solid rgba(16, 185, 129, 0.3); }

/* Categories */
.card-badge.security { background: rgba(236, 72, 153, 0.1); color: #fbcfe8; }
.card-badge.correctness { background: rgba(59, 130, 246, 0.1); color: #bfdbfe; }
.card-badge.performance { background: rgba(139, 92, 246, 0.1); color: #ddd6fe; }
.card-badge.style { background: rgba(16, 185, 129, 0.1); color: #a7f3d0; }

.finding-rule-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.finding-path {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-all;
}

.finding-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.finding-evidence {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  border-left: 3px solid var(--color-primary);
  color: #e5e7eb;
  overflow-x: auto;
  white-space: pre;
}

.finding-card:has(.card-badge.critical) .finding-evidence { border-left-color: var(--color-critical); }
.finding-card:has(.card-badge.high) .finding-evidence { border-left-color: var(--color-high); }
.finding-card:has(.card-badge.medium) .finding-evidence { border-left-color: var(--color-medium); }
.finding-card:has(.card-badge.low) .finding-evidence { border-left-color: var(--color-low); }

/* Footer */
.app-footer {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  flex-wrap: wrap;
}

.footer-spec-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
}

.spec-label {
  color: var(--text-secondary);
}

.spec-value {
  font-weight: 600;
  color: var(--text-primary);
}

.footer-version {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
  .app-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  body {
    overflow: auto;
  }
  .app-container {
    height: auto;
  }
}
