/* ========================================
   ThreatModeler - Modern CSS
   ======================================== */

:root {
  /* Dark Theme (Default) */
  --bg-primary: #0f1419;
  --bg-secondary: #1a1f2e;
  --bg-tertiary: #252b3b;
  --text-primary: #e4e6eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #374151;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.15);
}

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

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

/* ========================================
   Layout
   ======================================== */

.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.logo i {
  font-size: 1.5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 0.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 0.875rem;
}

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

.nav-item.active {
  background: var(--accent);
  color: white;
}

.nav-item i {
  width: 1.25rem;
  text-align: center;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-left > button:first-child {
  display: none; /* Hide on desktop, mobile-menu-toggle will show on mobile */
}

@media (max-width: 768px) {
  .topbar-left > button:first-child {
    display: none !important; /* Use mobile-menu-toggle instead */
  }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

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

/* ========================================
   Components
   ======================================== */

.btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

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

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

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

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

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

.input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-critical { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.badge-high { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.badge-medium { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.badge-low { background: rgba(16, 185, 129, 0.2); color: #10b981; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s;
}

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

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.grid {
  display: grid;
  gap: 1.5rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

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

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

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-secondary);
  color: var(--accent);
}

/* ========================================
   Canvas
   ======================================== */

.canvas-container {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  height: 600px;
  position: relative;
  overflow: hidden;
}

.canvas-toolbar {
  position: absolute;
  top: 1rem;
  left: 1rem;
  display: flex;
  gap: 0.5rem;
  background: var(--bg-secondary);
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

/* ========================================
   Animations
   ======================================== */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  /* Mobile Layout */
  .app-container {
    display: block !important;
  }
  
  .sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%) !important;
    width: 280px;
  }
  
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: var(--shadow-lg);
  }
  
  /* Mobile overlay when sidebar is open */
  .sidebar.open::after {
    content: '';
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
  
  /* Grids to single column */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  /* Content padding */
  .content-area {
    padding: 1rem;
    width: 100%;
  }
  
  /* Mobile header */
  .header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }
  
  /* Mobile buttons */
  .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }
  
  .btn-sm {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
  }
  
  /* Mobile cards */
  .card {
    padding: 1rem;
  }
  
  /* Mobile modals */
  .modal {
    width: 95%;
    max-width: 95%;
    margin: 1rem;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  /* Mobile forms */
  .input, .select, .textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Mobile tables */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  /* Hide text on small buttons */
  .btn i + span {
    display: none;
  }
  
  /* Mobile navigation */
  .nav-item {
    padding: 0.75rem;
  }
  
  /* Mobile canvas */
  canvas {
    max-width: 100%;
    height: auto !important;
  }
  
  /* Mobile flex */
  .flex {
    flex-wrap: wrap;
  }
  
  /* Mobile typography */
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.125rem; }
  
  /* Touch targets */
  button, a, .nav-item {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 220px;
  }
  
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .content-area {
    padding: 1.5rem;
  }
}

/* Mobile landscape */
@media (max-width: 768px) and (orientation: landscape) {
  .modal {
    max-height: 85vh;
  }
  
  .sidebar {
    width: 260px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .sidebar {
    width: 100%;
  }
  
  .modal {
    width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }
  
  .card {
    padding: 0.75rem;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
  
  .flex.gap-2 {
    gap: 0.5rem;
  }
}

/* ========================================
   Utilities
   ======================================== */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }



/* ========================================
   Mobile Touch Optimizations
   ======================================== */

/* Smooth scrolling on mobile */
* {
  -webkit-overflow-scrolling: touch;
}

/* Remove tap highlight */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Better touch targets */
button, a, input, select, textarea {
  touch-action: manipulation;
}

/* Prevent text selection on buttons */
button {
  -webkit-user-select: none;
  user-select: none;
}

/* Mobile-friendly scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Mobile safe areas (notch support) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Mobile menu toggle button */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 0.5rem;
  padding: 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  width: 44px;
  height: 44px;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;

.mobile-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .mobile-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
  }
}

    align-items: center;
    justify-content: center;
  }
}

/* Mobile-friendly canvas */
@media (max-width: 768px) {
  #architecture-canvas {
    touch-action: pan-x pan-y pinch-zoom;
  }
}

/* Responsive images */
img {
  max-width: 100%;
  height: auto;
}

/* Mobile-friendly tables */
@media (max-width: 768px) {
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 600px;
  }
}
