/* ==========================================================================
   Spacebook Builder v2.0: Deep Space Glassmorphic Theme
   Conforms to Spacebook Specification v2.0 (TKT-9212), GIPS-3.0,
   RULE-FO-SQUID-007 (Zero External CDNs/Fonts), and Rule 25 (Zero-Mojibake UTF-8).
   ========================================================================== */

:root {
  /* Color Palette - Deep Space & Cosmic Accents */
  --bg-primary: #040812;
  --bg-secondary: #070e1e;
  --bg-tertiary: #0c152b;
  --card-bg: #0b1324;
  --card-bg-translucent: rgba(11, 19, 36, 0.85);
  --card-hover: #111d38;
  
  /* Borders */
  --border-subtle: #1e2f52;
  --border-accent: #2e477a;
  --border-active: #38bdf8;
  --border-glow: rgba(56, 189, 248, 0.35);

  /* Accents */
  --accent-cyan: #38bdf8;
  --accent-cyan-dim: rgba(56, 189, 248, 0.15);
  --accent-emerald: #10b981;
  --accent-emerald-dim: rgba(16, 185, 129, 0.15);
  --accent-amber: #fbbf24;
  --accent-amber-dim: rgba(251, 191, 36, 0.15);
  --accent-rose: #ef4444;
  --accent-rose-dim: rgba(239, 68, 68, 0.15);
  --accent-purple: #a855f7;
  --accent-purple-dim: rgba(168, 85, 247, 0.15);
  --accent-blue: #3b82f6;

  /* Typography Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-dim: #475569;

  /* System Font Stack - Zero External CDNs */
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, "Courier New", monospace;

  /* Layout Dimensions */
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(30, 47, 82, 0.6);
  --shadow-glow: 0 0 15px -3px var(--border-glow);
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

code, pre, kbd, samp {
  font-family: var(--font-mono);
}

/* App Layout Grid */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, #0c1a36 0%, #040812 70%);
}

/* Header Bar */
.top-header {
  height: var(--header-height);
  background: rgba(7, 14, 30, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-emerald));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--bg-primary);
  font-size: 16px;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-family: var(--font-mono);
}

.header-center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.project-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  padding: 4px 8px 4px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.project-selector-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.project-select {
  background: transparent;
  color: var(--text-primary);
  border: none;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
}

.project-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

.durability-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-md);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-family: var(--font-mono);
  font-size: 12px;
}

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

.durability-value {
  color: var(--accent-emerald);
  font-weight: 700;
}

.subsigner-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: rgba(30, 47, 82, 0.3);
  border: 1px solid var(--border-subtle);
}

/* Layout Container */
.main-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar Navigation */
.nav-sidebar {
  width: var(--sidebar-width);
  background: rgba(7, 14, 30, 0.6);
  backdrop-filter: blur(8px);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-shrink: 0;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.nav-link.active {
  background: var(--card-bg);
  color: var(--accent-cyan);
  border-color: var(--border-accent);
  box-shadow: 0 2px 12px rgba(56, 189, 248, 0.12);
}

.nav-link-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.nav-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 9999px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.nav-link.active .nav-badge {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
  border-color: rgba(56, 189, 248, 0.3);
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.status-dot.offline {
  background: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
}

/* Main Viewport */
.content-area {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.view-section {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.view-section.active {
  display: block;
}

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

/* Page Headers */
.view-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.view-title-group h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.view-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  font-family: inherit;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1, #0284c7);
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.45);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

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

.btn-emerald {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.btn-emerald:hover {
  background: linear-gradient(135deg, #047857, #059669);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45);
}

.btn-amber {
  background: linear-gradient(135deg, #d97706, #fbbf24);
  color: #040812;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(251, 191, 36, 0.3);
}

.btn-amber:hover {
  background: linear-gradient(135deg, #b45309, #d97706);
  color: #ffffff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-rose);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: var(--accent-rose);
  color: #ffffff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* Cards & Surfaces */
.card {
  background: var(--card-bg-translucent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: all 0.25s ease;
}

.card:hover {
  border-color: var(--border-accent);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control, .form-select, .form-textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
}

.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--accent-cyan-dim);
}

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

.form-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Health and Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.badge-excellent {
  background: var(--accent-emerald-dim);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-good {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-fair {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-degraded {
  background: var(--accent-amber-dim);
  color: var(--accent-amber);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.badge-critical {
  background: var(--accent-rose-dim);
  color: var(--accent-rose);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-pristine {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.badge-adoption {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.4);
  animation: pulseAdoption 2s infinite ease-in-out;
}

@keyframes pulseAdoption {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.02); }
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(4, 8, 18, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-container {
  background: var(--card-bg);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8), 0 0 24px rgba(56, 189, 248, 0.2);
  animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-container.modal-lg {
  max-width: 860px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

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

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(7, 14, 30, 0.5);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--card-bg);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  min-width: 280px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: toastSlide 0.3s ease forwards;
  font-size: 13px;
}

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

.toast-info { border-color: var(--accent-cyan); color: var(--text-primary); }
.toast-success { border-color: var(--accent-emerald); color: var(--text-primary); }
.toast-warning { border-color: var(--accent-amber); color: var(--text-primary); }
.toast-error { border-color: var(--accent-rose); color: var(--text-primary); }

/* SVG Simulator Chart Styles */
.chart-container {
  width: 100%;
  height: 280px;
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}

.chart-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-grid-line {
  stroke: var(--border-subtle);
  stroke-dasharray: 3, 3;
  stroke-width: 1;
}

.chart-axis {
  stroke: var(--border-accent);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--accent-cyan);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.5));
}

.chart-area {
  fill: url(#hazardGradient);
  opacity: 0.35;
}

.chart-point {
  fill: var(--bg-primary);
  stroke: var(--accent-cyan);
  stroke-width: 2;
  cursor: pointer;
  transition: r 0.2s ease;
}

.chart-point:hover {
  r: 6;
  fill: var(--accent-cyan);
}

.chart-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-mono);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

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

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .nav-sidebar {
    width: 210px;
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
  }
  .nav-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px;
  }
  .nav-menu {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-item {
    width: auto;
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  .content-area {
    padding: 16px;
  }
}
