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

button, input, select, textarea {
  font-family: inherit;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-body-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Accessibility: Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* App Container */
.app-container {
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 2rem 5.5rem 2rem; /* Clean clearance for console drawer */
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  transition: padding-bottom var(--transition-normal);
}

/* Dynamic clearance when console drawer is expanded (P4) */
body.terminal-expanded .app-container,
body:has(.terminal-drawer:not(.minimized)) .app-container {
  padding-bottom: 285px;
}

/* Top Sticky Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0.75rem 2rem;
  background: var(--bg-topbar);
  backdrop-filter: var(--backdrop-blur);
  border-bottom: 1px solid var(--border-subtle);
  width: 100%;
  gap: 1.25rem;
}

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

.topbar-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.topbar-brand:hover,
.topbar-brand:focus,
.topbar-brand:visited {
  color: var(--text-main);
  text-decoration: none;
}

.brand-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--text-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 0.675rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.fleet-status-pill {
  font-size: 0.725rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-translucent);
  border: 1px solid var(--border-subtle);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Studio Breadcrumb */
.studio-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-pill);
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.breadcrumb-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  transition: color var(--transition-fast);
}

.breadcrumb-back:hover {
  color: var(--text-main);
}

.breadcrumb-sep {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.breadcrumb-current {
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 700;
}

/* View Switcher & Global Controls */
.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  justify-content: flex-end;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-divider);
  margin: 0 0.25rem;
}

.view-switcher {
  display: flex;
  background: var(--bg-pill);
  padding: 0.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.view-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.view-btn:hover {
  color: var(--text-main);
}

.view-btn.active {
  background: var(--bg-translucent-hover);
  color: var(--text-main);
  box-shadow: var(--shadow-card);
}

/* Focus Profiles Bar */
.profiles-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-pill);
  padding: 0.25rem 0.35rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.profile-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.profile-btn:hover {
  color: var(--text-main);
  background: var(--bg-translucent);
}

.profile-btn.active {
  background: var(--bg-pill-active);
  color: var(--text-main);
  border: 1px solid var(--border-glow);
  box-shadow: var(--shadow-glow);
}

/* 2-Level View Panels */
.view-panel {
  display: none;
  animation: fade-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.view-panel.active {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

/* Fleet Radar Metrics Strip */
.fleet-pulse {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.pulse-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow-card);
  backdrop-filter: var(--backdrop-blur);
}

.pulse-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-translucent);
}

.pulse-data {
  display: flex;
  flex-direction: column;
}

.pulse-label {
  font-size: 0.675rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.pulse-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.pulse-sub {
  font-size: 0.725rem;
  color: var(--text-dim);
  font-weight: 500;
}

/* Projects Grid View */
.projects-container.grid-mode {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  align-items: start; /* Prevents card height stretch on adjacent cards */
}

/* Projects List / Table View */
.projects-container.list-mode {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Responsive Breakpoints & Accessibility */
@media (max-width: 1200px) {
  .projects-container.grid-mode {
    grid-template-columns: 1fr;
  }
  .fleet-pulse {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
  }
  .topbar-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .topbar-center {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding: 0.2rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar-center::-webkit-scrollbar {
    display: none;
  }
  .profiles-bar {
    width: max-content;
  }
  .topbar-controls {
    order: 2;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: nowrap;
  }
  .topbar-divider {
    display: none;
  }
  #fleet-status-pill {
    display: none;
  }
  .view-switcher {
    display: none;
  }
  .app-container {
    padding: 0.75rem 0.85rem 4rem 0.85rem;
  }
  /* C1 Fix: On mobile, terminal is an overlay sheet - never squeeze body by 335px! */
  body.terminal-expanded .app-container,
  body:has(.terminal-drawer:not(.minimized)) .app-container {
    padding-bottom: 4rem;
  }
  .fleet-pulse {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }
}

@media (max-width: 540px) {
  .app-container {
    padding: 0.5rem 0.5rem 4.5rem 0.5rem;
  }
  .fleet-pulse {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .brand-text h1 {
    font-size: 0.95rem;
  }
  .brand-sub {
    display: none; /* Hide low-contrast tiny sub-brand on mobile to clean header */
  }
  .topbar-controls {
    gap: 0.25rem;
  }
  #btn-launch-active .btn-text,
  #btn-stop-all .btn-text {
    display: none;
  }
  #btn-launch-active,
  #btn-stop-all {
    padding: 0.4rem 0.6rem;
  }
  .fleet-filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .fleet-category-pills {
    overflow-x: auto;
    width: 100%;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .fleet-category-pills::-webkit-scrollbar {
    display: none;
  }
  .fleet-search-wrap {
    width: 100%;
  }
}
