/* CSS Variables for theming */
:root {
  --bg: #0b0c10;
  --panel: #121318;
  --text: #e6e6e6;
  --text-muted: #9aa0a6;
  --accent: #4da3ff;
  --accent-hover: #3d8bdb;
  --border: #2a2d35;
  --border-light: #3a3d45;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --shadow: rgba(0, 0, 0, 0.3);
  --kbd-bg: #2a2d35;
  --kbd-border: #3a3d45;
  --selection: rgba(77, 163, 255, 0.3);
  --code-bg: #1a1d23;
}

[data-theme="light"] {
  --bg: #ffffff;
  --panel: #fafafa;
  --text: #111111;
  --text-muted: #606368;
  --accent: #1e64d1;
  --accent-hover: #1557b8;
  --border: #e5e7eb;
  --border-light: #d1d5db;
  --success: #059669;
  --warning: #d97706;
  --error: #dc2626;
  --shadow: rgba(0, 0, 0, 0.1);
  --kbd-bg: #f3f4f6;
  --kbd-border: #d1d5db;
  --selection: rgba(30, 100, 209, 0.2);
  --code-bg: #f8fafc;
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
}

::selection {
  background: var(--selection);
}

/* App layout */
#app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: 
    "header"
    "main"
    "footer";
}

/* Toolbar */
.toolbar {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 20px;
  flex-wrap: wrap;
}

.toolbar-left {
  flex-shrink: 0;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
}

.title-icon {
  font-size: 1.2rem;
}

.toolbar-center {
  flex: 1;
  max-width: 600px;
}

.search-container {
  position: relative;
  width: 100%;
}

#search-input {
  width: 100%;
  padding: 10px 40px 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  transition: all 0.2s ease;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--selection);
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  color: var(--text);
}

.search-clear.visible {
  display: flex;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-group select {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: var(--border);
  border-color: var(--border-light);
}

.btn-secondary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-secondary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-icon {
  padding: 8px;
}

.theme-icon {
  font-size: 14px;
}

/* Main content */
.main-content {
  grid-area: main;
  display: grid;
  grid-template-columns: 400px 1fr;
  overflow: hidden;
}

/* Results panel */
.results-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.results-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.results-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.results-count {
  font-weight: 600;
  color: var(--accent);
}

.keyboard-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.collapse-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
}

.collapse-toggle:hover {
  background: var(--border);
  border-color: var(--border-light);
}

.collapse-icon {
  font-size: 14px;
  transition: transform 0.3s ease;
  line-height: 1;
}

.results-panel.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.main-content.collapsed {
  grid-template-columns: auto 1fr;
}

.results-panel.collapsed {
  width: auto;
  min-width: 0;
}

.results-panel.collapsed .results-list,
.results-panel.collapsed .keyboard-hint {
  display: none;
}

.results-panel.collapsed .results-header {
  padding: 16px 12px;
}

.results-panel.collapsed .results-count {
  display: none;
}

.results-list {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.result-item {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

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

.result-item.selected {
  background: var(--accent);
  color: white;
}

.result-item.selected .result-meta {
  color: rgba(255, 255, 255, 0.8);
}

.result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.result-id {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  min-width: 60px;
}

.result-item.selected .result-id {
  color: white;
}

.result-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}

.severity-badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.severity-info { background: #3b82f6; color: white; }
.severity-low { background: #10b981; color: white; }
.severity-medium { background: #f59e0b; color: white; }
.severity-high { background: #ef4444; color: white; }

.result-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

/* Detail panel */
.detail-panel {
  background: var(--bg);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.detail-content {
  padding: 32px;
  max-width: 800px;
}

.detail-placeholder {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.detail-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.detail-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.detail-id {
  color: var(--accent);
}

.detail-meta {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.meta-label {
  color: var(--text-muted);
  font-weight: 500;
}

.detail-section {
  margin-bottom: 32px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--accent);
}

.section-content {
  line-height: 1.7;
}

.section-content ul {
  margin-left: 20px;
}

.section-content li {
  margin-bottom: 8px;
}

.mitre-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mitre-tag {
  padding: 4px 12px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
}

/* Query sections */
.query-section {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.query-header {
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.query-title {
  font-weight: 600;
  font-size: 14px;
}

.copy-btn {
  padding: 4px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.copy-btn:hover {
  background: var(--accent-hover);
}

.copy-btn.copied {
  background: var(--success);
}

.query-content {
  padding: 16px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Footer */
.footer {
  grid-area: footer;
  padding: 8px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.keyboard-shortcuts {
  display: flex;
  gap: 16px;
}

/* Keyboard hints */
kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: white;
}

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

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow);
  transform: translateX(100%);
  animation: slideIn 0.3s ease forwards;
  max-width: 300px;
}

.toast.success {
  border-color: var(--success);
  background: var(--success);
  color: white;
}

.toast.error {
  border-color: var(--error);
  background: var(--error);
  color: white;
}

@keyframes slideIn {
  to { transform: translateX(0); }
}

/* Responsive design */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: 300px 1fr;
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .toolbar-center {
    order: 3;
    max-width: none;
  }
  
  .filter-group {
    justify-content: center;
  }
  
  .detail-content {
    padding: 20px;
  }
}

@media (max-width: 600px) {
  .toolbar {
    padding: 12px 16px;
  }
  
  .filter-group {
    flex-direction: column;
  }
  
  .filter-group select {
    width: 100%;
  }
  
  .detail-meta {
    flex-direction: column;
    gap: 8px;
  }
  
  .keyboard-shortcuts {
    display: none;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border: #666;
    --border-light: #888;
  }
  
  [data-theme="light"] {
    --border: #333;
    --border-light: #555;
  }
}

/* Focus styles for keyboard navigation */
.result-item:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

#search-input:focus,
select:focus,
button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Modal styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 80px);
}

/* Dashboard styling */
.dashboard-content {
  width: 1200px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.dashboard-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.dashboard-card h3 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: var(--panel);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Kill Chain styling */
.killchain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.killchain-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.killchain-item:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--selection);
}

.killchain-item.has-events {
  border-color: var(--accent);
  background: var(--selection);
}

.killchain-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.killchain-count {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

/* Severity Chart */
.severity-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.severity-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.severity-label {
  min-width: 80px;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.severity-progress {
  flex: 1;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.severity-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.3s ease;
}

.severity-fill.high { background: var(--error); }
.severity-fill.medium { background: var(--warning); }
.severity-fill.low { background: var(--success); }
.severity-fill.info { background: var(--accent); }

.severity-count {
  min-width: 40px;
  text-align: right;
  font-weight: 600;
}

/* Quick Actions */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-btn {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Hunting Templates */
.hunting-content {
  width: 1000px;
}

.hunting-templates {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.template-category h3 {
  margin: 0 0 16px 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
}

.template-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

.template-card h4 {
  margin: 0 0 8px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.template-card p {
  margin: 0 0 16px 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.template-events {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.event-tag {
  background: var(--accent);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.use-template-btn {
  background: var(--success);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.use-template-btn:hover {
  background: var(--success);
  filter: brightness(1.1);
}

/* Advanced search features */
.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.search-suggestion {
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease;
}

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

.search-suggestion:last-child {
  border-bottom: none;
}

.suggestion-text {
  font-weight: 500;
}

.suggestion-type {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 8px;
}

/* Event correlation indicators */
.correlation-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--warning);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}

.correlation-chain {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.chain-event {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chain-event:hover {
  border-color: var(--accent);
  background: var(--selection);
}

/* Responsive design for modals */
@media (max-width: 1200px) {
  .dashboard-content {
    width: 95vw;
  }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1000px) {
  .hunting-content {
    width: 95vw;
  }
}

@media (max-width: 600px) {
  .modal-body {
    padding: 16px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .quick-actions {
    grid-template-columns: 1fr;
  }
  
  .killchain-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}