@import 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap';

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --bg-dark: #0F172A;
  --bg-sidebar: #1E293B;
  --bg-card: rgba(30, 41, 59, 0.7);
  --border-light: rgba(148, 163, 184, 0.2);
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --success: #10B981;
  --danger: #EF4444;
}

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

body {
  font-family: Inter, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
}

/* App Shell Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
  background-image: radial-gradient(circle at top right, #1e1b4b 0%, #0F172A 60%);
  background-attachment: fixed;
}

.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

h1.logo {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(to right, #818cf8, #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2.5rem;
}

/* Navigation Links */
.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  font-weight: 500;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-link.active {
  background: rgba(79, 70, 229, 0.15);
  color: #818cf8;
}

/* Glass Panels & Components */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 500;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: Inter, sans-serif;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

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

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

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

.btn-icon {
  background: none;
  border: none;
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-icon.text-danger:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Dashboard Specifics */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metric-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: default;
}

.metric-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  border-color: rgba(148, 163, 184, 0.4);
}

.metric-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
}

.metric-card-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin-top: 0.5rem;
}

.health-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  margin-top: 1rem;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
  animation: pulse 2s infinite;
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }

  50% {
    transform: scale(1.05);
    opacity: 1;
  }

  100% {
    transform: scale(0.95);
    opacity: 0.8;
  }
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
}

.section-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Data Tables */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 1rem 1.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  background: rgba(15, 23, 42, 0.4);
}

.data-table tbody tr {
  transition: background 0.2s;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

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

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 60px;
}

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: Inter, sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  margin-top: 0.5rem;
}

.retry-btn:hover {
  background-color: var(--primary-hover);
}

.justify-end {
  justify-content: flex-end;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

/* Utility Classes */
.text-primary {
  color: var(--primary);
}

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

.text-danger {
  color: var(--danger);
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.d-flex {
  display: flex;
}

.align-center {
  align-items: center;
}

.gap-2 {
  gap: 0.5rem;
}

.font-medium {
  font-weight: 500;
}

.py-8 {
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.small-text {
  font-size: 0.875rem;
}

.badge {
  background: rgba(79, 70, 229, 0.15);
  color: #818cf8;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
}

/* Loading & Error States */
.loading-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  gap: 1rem;
  color: var(--text-secondary);
}

.error-state {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  padding: 2rem;
  border-radius: 12px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.loader {
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

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

  100% {
    transform: rotate(360deg);
  }
}

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

.entity-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.4);
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.entity-item:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: var(--border-light);
  transform: translateX(4px);
}

.entity-icon {
  background: var(--bg-dark);
  padding: 0.75rem;
  border-radius: 8px;
  color: var(--primary);
}

.entity-content {
  flex: 1;
}

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

.entity-type {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(79, 70, 229, 0.2);
  color: #818cf8;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.entity-namespace {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.entity-text {
  font-size: 0.95rem;
  line-height: 1.5;
  color: #CBD5E1;
}

.chart-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
}

/* ─── Detail Modal (wide variant) ─── */
.detail-modal-wide {
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.detail-field {
  margin-bottom: 1.5rem;
}

.detail-field-label {
  display: block;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.detail-field-value {
  background: rgba(15, 23, 42, 0.4);
  padding: 0.75rem;
  border-radius: 6px;
}

.detail-field-value--mono {
  font-family: monospace;
  font-size: 0.9rem;
}

.detail-field-value--pre {
  padding: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* ─── Inline Error Message ─── */
.error-inline {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ─── Form Layout Helpers ─── */
.form-row {
  display: flex;
  gap: 1rem;
}

.flex-1 {
  flex: 1;
}

.flex-2 {
  flex: 2;
}

.no-margin {
  margin: 0;
}

/* ─── Toolbar (EntityExplorer filter bar) ─── */
.toolbar {
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1rem;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-light);
}

.search-input {
  background: transparent;
  border: none;
  color: white;
  outline: none;
  flex: 1;
}

/* ─── EntityExplorer Header ─── */
.explorer-header {
  margin-bottom: 1.5rem;
}

.explorer-title {
  border: none;
  padding: 0;
  margin: 0;
}

.explorer-subtitle {
  margin-left: 2.5rem;
  margin-top: 0.25rem;
}

/* ─── Policy Trigger Builder ─── */
.trigger-card {
  padding: 1rem;
  background: rgba(15, 23, 42, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  position: relative;
}

.trigger-remove-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 0.25rem;
}

.trigger-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.trigger-label {
  font-size: 0.8rem;
  color: #94a3b8;
}

.trigger-compact {
  padding: 0.4rem;
  font-size: 0.9rem;
}

.form-group--inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.form-hint {
  display: block;
  margin-top: 0.25rem;
}

.btn-add-trigger {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

/* ─── Confirm Dialog ─── */
.confirm-dialog {
  max-width: 440px;
}

.confirm-dialog-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.confirm-dialog-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(79, 70, 229, 0.15);
  color: var(--primary);
  flex-shrink: 0;
}

.confirm-dialog-icon--danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.confirm-dialog-message {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

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

.btn-danger:hover {
  background-color: #dc2626;
}

/* ─── Table cell actions (no bottom border) ─── */
.table-actions {
  border: none !important;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  h1.logo {
    margin-bottom: 0;
    font-size: 1.25rem;
  }

  .nav-links {
    flex-direction: row;
    gap: 0.25rem;
    margin-left: auto;
  }

  .nav-link {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  .main-content {
    padding: 1rem;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .charts-row {
    grid-template-columns: 1fr;
  }

  .metric-card-value {
    font-size: 1.75rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .toolbar {
    flex-direction: column;
  }

  .form-row {
    flex-direction: column;
  }

  .data-table th,
  .data-table td {
    padding: 0.75rem;
    font-size: 0.875rem;
  }

  .trigger-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    margin: 1rem;
    max-width: calc(100% - 2rem);
  }
}