/* =============================================
   Attack Graph Modeler — Design System
   ============================================= */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Custom Properties --- */
:root {
  /* Backgrounds */
  --bg-primary: #0a0e17;
  --bg-secondary: #121a2b;
  --bg-tertiary: #1a2540;
  --bg-surface: #1e2d4a;

  /* Text */
  --text-primary: #e2e8f0;
  --text-secondary: #8899b4;
  --text-muted: #4a5a78;

  /* Accents */
  --accent-cyan: #00d4ff;
  --accent-cyan-dim: #0088aa;

  /* Threat */
  --threat-red: #ff3b5c;
  --threat-orange: #ff8c42;
  --threat-yellow: #ffd166;

  /* Control */
  --control-green: #00e676;
  --control-green-dim: #00994d;

  /* Group */
  --group-purple: #7c4dff;
  --group-purple-dim: #5a35cc;

  /* Borders & Shadows */
  --border: #1e2d4a;
  --border-focus: #00d4ff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);

  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-primary);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr 320px;
  grid-template-areas:
    "toolbar toolbar"
    "canvas panel"
    "status status";
  height: 100vh;
}

#app.panel-collapsed {
  grid-template-columns: 1fr 0;
}

/* --- Toolbar --- */
.toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.toolbar__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--accent-cyan);
  margin-right: var(--space-lg);
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.toolbar__separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 var(--space-xs);
}

/* --- Canvas --- */
.canvas {
  grid-area: canvas;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

#cy {
  width: 100%;
  height: 100%;
}

/* --- Empty State --- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-xl);
  pointer-events: none;
  z-index: 5;
}

.empty-state.hidden {
  display: none;
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.6;
}

.empty-state__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-sm);
}

.empty-state__text {
  font-size: var(--text-base);
  color: var(--text-secondary);
  max-width: 420px;
  margin: 0 0 var(--space-xs);
  line-height: 1.5;
}

.empty-state__hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-lg);
}

.empty-state__actions {
  display: flex;
  gap: var(--space-sm);
  pointer-events: auto;
}

.empty-state .btn {
  pointer-events: auto;
}

/* --- Empty Group Actions --- */
.empty-group-actions {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  gap: var(--space-xs);
  z-index: 5;
  pointer-events: auto;
}

.empty-group-actions .btn--sm {
  font-size: var(--text-xs);
  padding: 2px 8px;
  height: 26px;
}

/* --- Detail Panel --- */
.panel {
  grid-area: panel;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.panel__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.panel__content {
  padding: var(--space-md);
  flex: 1;
}

.panel__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-xl);
}

/* --- Status Bar --- */
.status-bar {
  grid-area: status;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  height: 36px;
  padding: 0 var(--space-md);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent-cyan);
  color: var(--bg-primary);
}

.btn--primary:hover {
  background: var(--accent-cyan-dim);
}

.btn--danger {
  background: var(--threat-red);
  color: white;
}

.btn--danger:hover {
  opacity: 0.85;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn--icon {
  width: 36px;
  padding: 0;
  justify-content: center;
}

.btn--small {
  height: 28px;
  padding: 0 var(--space-sm);
  font-size: var(--text-xs);
}

.btn--active {
  background: var(--bg-tertiary);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

/* --- Inputs --- */
.input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  color: var(--text-primary);
  transition: border-color 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.2);
}

.input::placeholder {
  color: var(--text-muted);
}

textarea.input {
  height: auto;
  min-height: 72px;
  padding: var(--space-sm);
  resize: vertical;
}

select.input {
  cursor: pointer;
}

/* --- Form Fields --- */
.field {
  margin-bottom: var(--space-md);
}

.field__label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

.field__help {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* --- Tags --- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.tag--attack {
  background: rgba(255, 59, 92, 0.15);
  color: var(--threat-red);
}

.tag--group {
  background: rgba(124, 77, 255, 0.15);
  color: var(--group-purple);
}

.tag--control {
  background: rgba(0, 230, 118, 0.15);
  color: var(--control-green);
}

.tag__remove {
  cursor: pointer;
  opacity: 0.6;
}

.tag__remove:hover {
  opacity: 1;
}

/* --- Tag Input --- */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: var(--space-xs);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 36px;
  cursor: text;
}

.tag-input:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.2);
}

.tag-input__field {
  flex: 1;
  min-width: 80px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  outline: none;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal__body {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
}

/* --- Cards --- */
.card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

.card__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-xs);
}

.card__meta {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* --- Path Analysis Results --- */
.path-result {
  border-left: 3px solid var(--threat-yellow);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
  background: rgba(255, 209, 102, 0.05);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.path-result__cost {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--threat-yellow);
}

.path-result__steps {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* --- Entity Property List --- */
.prop-list {
  list-style: none;
}

.prop-list__item {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.prop-list__label {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.prop-list__value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* --- Risk Badge --- */
.risk-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

.risk-badge--high {
  background: rgba(255, 59, 92, 0.15);
  color: var(--threat-red);
}

.risk-badge--medium {
  background: rgba(255, 140, 66, 0.15);
  color: var(--threat-orange);
}

.risk-badge--low {
  background: rgba(255, 209, 102, 0.15);
  color: var(--threat-yellow);
}

/* --- Blocked Badge --- */
.blocked-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: rgba(0, 230, 118, 0.15);
  color: var(--control-green);
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast--success {
  background: var(--control-green-dim);
  color: white;
}

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

.toast--info {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-surface);
}

/* --- Context Menu --- */
.context-menu {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: var(--space-xs) 0;
  z-index: 150;
  min-width: 180px;
}

.context-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.1s;
}

.context-menu__item:hover {
  background: var(--bg-tertiary);
}

.context-menu__item--danger {
  color: var(--threat-red);
}

.context-menu__separator {
  height: 1px;
  background: var(--border);
  margin: var(--space-xs) 0;
}

/* --- Loading --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--accent-cyan);
  font-size: var(--text-lg);
}

.loading__spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: var(--space-sm);
}

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